This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
honeybits-win.go
141 lines (126 loc) · 4.08 KB
/
honeybits-win.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package main
import (
"fmt"
"os"
"strings"
"github.com/danieljoos/wincred"
"github.com/spf13/viper"
_ "github.com/spf13/viper/remote"
)
var ASCII = `
/\ /\___ _ __ ___ _ _| |__ (_) |_ ___
/ /_/ / _ \| '_ \ / _ \ | | | '_ \| | __/ __|
/ __ / (_) | | | | __/ |_| | |_) | | |_\__ \
\/ /_/ \___/|_| |_|\___|\__, |_.__/|_|\__|___/
========================|___/=================
`
func check(e error) {
if e != nil {
os.Stderr.WriteString(fmt.Sprintf("Error: %s\n", e.Error()))
}
}
// Load the local or remore config file. For remote config:
// Read the config values from environment variables and then load
// the remote config (remote Key/Value store such as etcd or Consul)
// e.g. $ export HBITS_KVSPROVIDER="consul"
// $ export HBITS_KVSADDR="127.0.0.1:32775"
// $ export HBITS_KVSDIR="/config/hbconf.yaml"
// $ export HBITS_KVSKEY="/etc/secrets/mykeyring.gpg"
func loadCon() (*viper.Viper, error) {
conf := viper.New()
conf.SetEnvPrefix("hbits")
conf.AutomaticEnv()
conf.SetDefault("kvsprovider", "consul")
conf.SetDefault("kvsdir", "/config/hbconf.yaml")
//conf.SetDefault("path.bashhistory", "~/.bash_history")
kvsaddr := conf.GetString("kvsaddr")
kvsprovider := conf.GetString("kvsprovider")
kvsdir := conf.GetString("kvsdir")
// If HBITS_KVSKEY is set, use encryption for the remote Key/Value Store
if conf.IsSet("kvskey") {
kvskey := conf.GetString("kvskey")
conf.AddSecureRemoteProvider(kvsprovider, kvsaddr, kvsdir, kvskey)
} else {
conf.AddRemoteProvider(kvsprovider, kvsaddr, kvsdir)
}
conf.SetConfigType("yaml")
if err := conf.ReadRemoteConfig(); err != nil {
// Reading local config file
fmt.Print("Failed reading remote config. Reading the local config file...\n")
conf.SetConfigName("hbconf")
conf.AddConfigPath(".")
if err := conf.ReadInConfig(); err != nil {
return nil, err
}
fmt.Print("Local config file loaded.\n\n")
return conf, nil
}
fmt.Print("Remote config file loaded\n\n")
return conf, nil
}
func cred_check(ctype string, ctarget string, cuser string) bool {
var res bool
if ctype == "generic" {
if cred, err := wincred.GetGenericCredential(ctarget); err == nil && cred.UserName == cuser {
res = true
}
} else if ctype == "domain" {
if cred, err := wincred.GetDomainPassword(ctarget); err == nil && cred.UserName == cuser {
res = true
}
}
return res
}
func cred_create(ctype string, ctarget string, cuser string, cpass string) {
if ctype == "generic" {
cred := wincred.NewGenericCredential(ctarget)
cred.CredentialBlob = []byte(cpass)
cred.UserName = cuser
err := cred.Write()
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("[+] Generic credential created (%s)\n", ctarget)
}
} else if ctype == "domain" {
cred := wincred.NewDomainPassword(ctarget)
// cred.CredentialBlob = []byte(cpass)
// error: The parameter is incorrect.
// Ref: https://msdn.microsoft.com/en-us/library/windows/desktop/aa380517(v=vs.85).aspx#domain_credentials
cred.UserName = cuser
err := cred.Write()
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("[+] Domain credential created (%s)\n", ctarget)
}
}
}
func main() {
fmt.Print(ASCII)
conf, err := loadCon()
check(err)
//Windows Credential Manager
if conf.GetString("wincreds.enabled") == "true" {
if gcreds := conf.GetStringSlice("wincreds.generic-creds"); len(gcreds) != 0 {
for _, g := range gcreds {
gconf := strings.Split(g, ":")
if cred_check("generic", gconf[0], gconf[1]) {
fmt.Printf("Error: generic credential exists (%s)\n", gconf[0])
} else {
cred_create("generic", gconf[0], gconf[1], gconf[2])
}
}
}
if dcreds := conf.GetStringSlice("wincreds.domain-creds"); len(dcreds) != 0 {
for _, d := range dcreds {
dconf := strings.Split(d, ":")
if cred_check("domain", dconf[0], dconf[1]) {
fmt.Printf("Error: domain credential exists (%s)\n", dconf[0])
} else {
cred_create("domain", dconf[0], dconf[1], dconf[2])
}
}
}
}
}