-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
172 lines (135 loc) · 2.82 KB
/
Copy pathmain.go
File metadata and controls
172 lines (135 loc) · 2.82 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Dump password hashes and records from an offline Active Directory database.
//
// Usage:
//
// hashdump [-u|g|c] ntds system
//
// The options are:
//
// u
// Dump all users.
// g
// Dump all groups.
// c
// Dump all computers.
//
// The arguments are:
//
// ntds
// Active Directory database (NTDS.dit, required).
// system
// System registry hive (SYSTEM, required).
package main
import (
"context"
"errors"
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"go.foxforensics.eu/bootkey/bootkey"
"go.foxforensics.eu/go-mmap"
"go.foxforensics.eu/hashdump/extract"
)
var Usage = `© 2026 Fox Forensics. Licensed under MIT License.
Usage: hashdump [-ugc] NTDS SYSTEM
-u dump all users
-g dump all groups
-c dump all computers
Report bugs at: foxforensics.eu/issues`
func main() {
flag.Usage = func() {
_, _ = fmt.Fprintln(os.Stderr, Usage)
os.Exit(2)
}
u := flag.Bool("u", false, "dump all users")
g := flag.Bool("g", false, "dump all groups")
c := flag.Bool("c", false, "dump all computers")
flag.Parse()
if flag.NArg() < 2 {
flag.Usage()
}
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
k, err := bootkey.ExtractFromFile(flag.Arg(1))
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
f, err := os.Open(flag.Arg(0))
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
defer func() {
_ = f.Close()
}()
b, err := mmap.Map(f, mmap.RDONLY, 0)
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err.Error())
_ = f.Close()
os.Exit(1)
}
defer func() {
_ = b.Unmap()
}()
switch {
case *u:
err = dumpUsers(ctx, b, k)
case *g:
err = dumpGroups(ctx, b)
case *c:
err = dumpComputers(ctx, b)
default:
err = dumpSecrets(ctx, b, k)
}
if err != nil {
if !errors.Is(err, context.Canceled) {
_, _ = fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
} else {
os.Exit(3)
}
}
}
func dumpUsers(ctx context.Context, b, k []byte) error {
accounts, err := extract.Accounts(ctx, b, k)
if err != nil {
return err
}
for _, account := range accounts {
_, _ = fmt.Println(account.JSON())
}
return nil
}
func dumpGroups(ctx context.Context, b []byte) error {
groups, err := extract.Groups(ctx, b)
if err != nil {
return err
}
for _, group := range groups {
_, _ = fmt.Println(group.JSON())
}
return nil
}
func dumpComputers(ctx context.Context, b []byte) error {
computers, err := extract.Computers(ctx, b)
if err != nil {
return err
}
for _, computer := range computers {
_, _ = fmt.Println(computer.JSON())
}
return nil
}
func dumpSecrets(ctx context.Context, b, k []byte) error {
accounts, err := extract.Accounts(ctx, b, k)
if err != nil {
return err
}
for _, account := range accounts {
_, _ = fmt.Println(account.String())
}
return nil
}