-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuac.go
259 lines (209 loc) · 5.48 KB
/
uac.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
package ldap
import "strings"
/*
ADS_UF_SCRIPT = 0x1,
ADS_UF_ACCOUNTDISABLE = 0x2,
ADS_UF_HOMEDIR_REQUIRED = 0x8,
ADS_UF_LOCKOUT = 0x10,
ADS_UF_PASSWD_NOTREQD = 0x20,
ADS_UF_PASSWD_CANT_CHANGE = 0x40,
ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED = 0x80,
ADS_UF_TEMP_DUPLICATE_ACCOUNT = 0x100,
ADS_UF_NORMAL_ACCOUNT = 0x200,
ADS_UF_INTERDOMAIN_TRUST_ACCOUNT = 0x800,
ADS_UF_WORKSTATION_TRUST_ACCOUNT = 0x1000,
ADS_UF_SERVER_TRUST_ACCOUNT = 0x2000,
ADS_UF_DONT_EXPIRE_PASSWD = 0x10000,
ADS_UF_MNS_LOGON_ACCOUNT = 0x20000,
ADS_UF_SMARTCARD_REQUIRED = 0x40000,
ADS_UF_TRUSTED_FOR_DELEGATION = 0x80000,
ADS_UF_NOT_DELEGATED = 0x100000,
ADS_UF_USE_DES_KEY_ONLY = 0x200000,
ADS_UF_DONT_REQUIRE_PREAUTH = 0x400000,
ADS_UF_PASSWORD_EXPIRED = 0x800000,
ADS_UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION = 0x1000000
*/
// UAC represents the User Account Control flags for a user.
// https://learn.microsoft.com/en-us/windows/win32/adschema/a-useraccountcontrol
type UAC struct {
LogonScript bool
AccountDisabled bool
HomeDirRequired bool
Lockout bool
PasswordNotRequired bool
PasswordCantChange bool
EncryptedTextPasswordAllowed bool
TempDuplicateAccount bool
NormalAccount bool
InterdomainTrustAccount bool
WorkstationTrustAccount bool
ServerTrustAccount bool
NoPasswordExpiration bool
MNSLogonAccount bool
SmartCardRequired bool
TrustedForDelegation bool
NotDelegated bool
UseDESKeyOnly bool
DontRequirePreauth bool
PasswordExpired bool
TrustedToAuthenticateForDelegation bool
}
func UACFromUint32(v uint32) UAC {
return UAC{
LogonScript: v&0x1 != 0,
AccountDisabled: v&0x2 != 0,
HomeDirRequired: v&0x8 != 0,
Lockout: v&0x10 != 0,
PasswordNotRequired: v&0x20 != 0,
PasswordCantChange: v&0x40 != 0,
EncryptedTextPasswordAllowed: v&0x80 != 0,
TempDuplicateAccount: v&0x100 != 0,
NormalAccount: v&0x200 != 0,
InterdomainTrustAccount: v&0x800 != 0,
WorkstationTrustAccount: v&0x1000 != 0,
ServerTrustAccount: v&0x2000 != 0,
NoPasswordExpiration: v&0x10000 != 0,
MNSLogonAccount: v&0x20000 != 0,
SmartCardRequired: v&0x40000 != 0,
TrustedForDelegation: v&0x80000 != 0,
NotDelegated: v&0x100000 != 0,
UseDESKeyOnly: v&0x200000 != 0,
DontRequirePreauth: v&0x400000 != 0,
PasswordExpired: v&0x800000 != 0,
TrustedToAuthenticateForDelegation: v&0x1000000 != 0,
}
}
func (u UAC) Uint32() uint32 {
var v uint32 = 0
if u.LogonScript {
v |= 0x1
}
if u.AccountDisabled {
v |= 0x2
}
if u.HomeDirRequired {
v |= 0x8
}
if u.Lockout {
v |= 0x10
}
if u.PasswordNotRequired {
v |= 0x20
}
if u.PasswordCantChange {
v |= 0x40
}
if u.EncryptedTextPasswordAllowed {
v |= 0x80
}
if u.TempDuplicateAccount {
v |= 0x100
}
if u.NormalAccount {
v |= 0x200
}
if u.InterdomainTrustAccount {
v |= 0x800
}
if u.WorkstationTrustAccount {
v |= 0x1000
}
if u.ServerTrustAccount {
v |= 0x2000
}
if u.NoPasswordExpiration {
v |= 0x10000
}
if u.MNSLogonAccount {
v |= 0x20000
}
if u.SmartCardRequired {
v |= 0x40000
}
if u.TrustedForDelegation {
v |= 0x80000
}
if u.NotDelegated {
v |= 0x100000
}
if u.UseDESKeyOnly {
v |= 0x200000
}
if u.DontRequirePreauth {
v |= 0x400000
}
if u.PasswordExpired {
v |= 0x800000
}
if u.TrustedToAuthenticateForDelegation {
v |= 0x1000000
}
return v
}
func (u UAC) String() string {
s := strings.Builder{}
if u.LogonScript {
s.WriteString("LogonScript, ")
}
if u.AccountDisabled {
s.WriteString("AccountDisabled, ")
}
if u.HomeDirRequired {
s.WriteString("HomeDirRequired, ")
}
if u.Lockout {
s.WriteString("Lockout, ")
}
if u.PasswordNotRequired {
s.WriteString("PasswordNotRequired, ")
}
if u.PasswordCantChange {
s.WriteString("PasswordCantChange, ")
}
if u.EncryptedTextPasswordAllowed {
s.WriteString("EncryptedTextPasswordAllowed, ")
}
if u.TempDuplicateAccount {
s.WriteString("TempDuplicateAccount, ")
}
if u.NormalAccount {
s.WriteString("NormalAccount, ")
}
if u.InterdomainTrustAccount {
s.WriteString("InterdomainTrustAccount, ")
}
if u.WorkstationTrustAccount {
s.WriteString("WorkstationTrustAccount, ")
}
if u.ServerTrustAccount {
s.WriteString("ServerTrustAccount, ")
}
if u.NoPasswordExpiration {
s.WriteString("NoPasswordExpiration, ")
}
if u.MNSLogonAccount {
s.WriteString("MNSLogonAccount, ")
}
if u.SmartCardRequired {
s.WriteString("SmartCardRequired, ")
}
if u.TrustedForDelegation {
s.WriteString("TrustedForDelegation, ")
}
if u.NotDelegated {
s.WriteString("NotDelegated, ")
}
if u.UseDESKeyOnly {
s.WriteString("UseDESKeyOnly, ")
}
if u.DontRequirePreauth {
s.WriteString("DontRequirePreauth, ")
}
if u.PasswordExpired {
s.WriteString("PasswordExpired, ")
}
if u.TrustedToAuthenticateForDelegation {
s.WriteString("TrustedToAuthenticateForDelegation, ")
}
return strings.TrimSuffix(s.String(), ", ")
}