-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
130 lines (115 loc) · 2.73 KB
/
main.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
package main
import (
"bufio"
"encoding/json"
"flag"
"fmt"
"log"
"os"
"path"
"strings"
)
func main() {
// parameters
var csvFile, secretsdumpFile, ntdsFile, systemFile, outDir string
flag.StringVar(&csvFile, "csv", "", "CSV file with hashes (comma separated username and hash)")
flag.StringVar(&secretsdumpFile, "secretsdump", "", "Direct output of impacket's secretsdump")
flag.StringVar(&ntdsFile, "ntds", "", "ntds.dit file")
flag.StringVar(&systemFile, "system", "", "system registry hive")
flag.StringVar(&outDir, "output", "", "output directory")
flag.Parse()
// load hashes
ad := NewAD()
if csvFile != "" {
err := ad.LoadHashesFromCSV(csvFile)
if err != nil {
log.Fatal(err)
}
} else if secretsdumpFile != "" {
err := ad.LoadHashesFromSecretsdump(secretsdumpFile)
if err != nil {
log.Fatal(err)
}
} else if ntdsFile != "" && systemFile != "" {
err := ad.LoadHashesFromNTDS(ntdsFile, systemFile)
if err != nil {
log.Fatal(err)
}
} else {
log.Fatal("No input files")
}
// analyze
ad.Analyze()
// print output
if outDir != "" {
// create output directory
if _, err := os.Stat(outDir); os.IsNotExist(err) {
err := os.Mkdir(outDir, 0700)
if err != nil {
log.Fatal(err)
}
}
// reused passwords CSV
file, err := os.Create(path.Join(outDir, "reuse.csv"))
if err != nil {
log.Fatal(err)
}
w := bufio.NewWriter(file)
for _, r := range ad.ReusedPasswords() {
line := fmt.Sprintf("%s,%d,%s", r.Hash, r.Count, strings.Join(r.Users, ";"))
fmt.Fprintln(w, line)
}
w.Flush()
file.Close()
// reused passwords JSON
file, err = os.Create(path.Join(outDir, "reuse.json"))
if err != nil {
log.Fatal(err)
}
w = bufio.NewWriter(file)
for _, r := range ad.ReusedPasswords() {
data, err := json.Marshal(r)
if err != nil {
log.Fatal(err)
}
fmt.Fprintln(w, string(data[:]))
}
w.Flush()
file.Close()
// reused passwords without hash CSV
file, err = os.Create(path.Join(outDir, "reuse-without-hash.csv"))
if err != nil {
log.Fatal(err)
}
w = bufio.NewWriter(file)
for _, r := range ad.ReusedPasswords() {
line := fmt.Sprintf("%d,%s", r.Count, strings.Join(r.Users, ";"))
fmt.Fprintln(w, line)
}
w.Flush()
file.Close()
// reused passwords without hash JSON
file, err = os.Create(path.Join(outDir, "reuse-without-hash.json"))
if err != nil {
log.Fatal(err)
}
w = bufio.NewWriter(file)
for _, r := range ad.ReusedPasswords() {
r.Hash = ""
data, err := json.Marshal(r)
if err != nil {
log.Fatal(err)
}
fmt.Fprintln(w, string(data[:]))
}
w.Flush()
file.Close()
} else {
fmt.Println("Reused passwords:")
for _, r := range ad.ReusedPasswords() {
if r.Count > 1 {
fmt.Println(r)
}
}
}
}