forked from fortra/impacket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pac.py
270 lines (236 loc) · 7.61 KB
/
pac.py
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
260
261
262
263
264
265
266
267
268
269
# Impacket - Collection of Python classes for working with network protocols.
#
# Copyright (C) 2023 Fortra. All rights reserved.
#
# This software is provided under a slightly modified version
# of the Apache Software License. See the accompanying LICENSE file
# for more information.
#
# Description:
# [MS-PAC] Implementation
#
# Author:
# Alberto Solino (@agsolino)
#
from impacket.dcerpc.v5.dtypes import ULONG, RPC_UNICODE_STRING, FILETIME, PRPC_SID, USHORT, RPC_SID, SID
from impacket.dcerpc.v5.ndr import NDRSTRUCT, NDRUniConformantArray, NDRPOINTER
from impacket.dcerpc.v5.nrpc import USER_SESSION_KEY, CHAR_FIXED_8_ARRAY, PUCHAR_ARRAY, PRPC_UNICODE_STRING_ARRAY
from impacket.dcerpc.v5.rpcrt import TypeSerialization1
from impacket.ldap.ldaptypes import LDAP_SID
from impacket.structure import Structure
################################################################################
# CONSTANTS
################################################################################
# From https://msdn.microsoft.com/library/aa302203#msdn_pac_credentials
# and http://diswww.mit.edu/menelaus.mit.edu/cvs-krb5/25862
PAC_LOGON_INFO = 1
PAC_CREDENTIALS_INFO = 2
PAC_SERVER_CHECKSUM = 6
PAC_PRIVSVR_CHECKSUM = 7
PAC_CLIENT_INFO_TYPE = 10
PAC_DELEGATION_INFO = 11
PAC_UPN_DNS_INFO = 12
PAC_ATTRIBUTES_INFO = 17
PAC_REQUESTOR_INFO = 18
################################################################################
# STRUCTURES
################################################################################
PISID = PRPC_SID
# 2.2.1 KERB_SID_AND_ATTRIBUTES
class KERB_SID_AND_ATTRIBUTES(NDRSTRUCT):
structure = (
('Sid', PISID),
('Attributes', ULONG),
)
class KERB_SID_AND_ATTRIBUTES_ARRAY(NDRUniConformantArray):
item = KERB_SID_AND_ATTRIBUTES
class PKERB_SID_AND_ATTRIBUTES_ARRAY(NDRPOINTER):
referent = (
('Data', KERB_SID_AND_ATTRIBUTES_ARRAY),
)
# 2.2.2 GROUP_MEMBERSHIP
from impacket.dcerpc.v5.nrpc import PGROUP_MEMBERSHIP_ARRAY
# 2.2.3 DOMAIN_GROUP_MEMBERSHIP
class DOMAIN_GROUP_MEMBERSHIP(NDRSTRUCT):
structure = (
('DomainId', PISID),
('GroupCount', ULONG),
('GroupIds', PGROUP_MEMBERSHIP_ARRAY),
)
class DOMAIN_GROUP_MEMBERSHIP_ARRAY(NDRUniConformantArray):
item = DOMAIN_GROUP_MEMBERSHIP
class PDOMAIN_GROUP_MEMBERSHIP_ARRAY(NDRPOINTER):
referent = (
('Data', KERB_SID_AND_ATTRIBUTES_ARRAY),
)
# 2.3 PACTYPE
class PACTYPE(Structure):
structure = (
('cBuffers', '<L=0'),
('Version', '<L=0'),
('Buffers', ':'),
)
# 2.4 PAC_INFO_BUFFER
class PAC_INFO_BUFFER(Structure):
structure = (
('ulType', '<L=0'),
('cbBufferSize', '<L=0'),
('Offset', '<Q=0'),
)
# 2.5 KERB_VALIDATION_INFO
class KERB_VALIDATION_INFO(NDRSTRUCT):
structure = (
('LogonTime', FILETIME),
('LogoffTime', FILETIME),
('KickOffTime', FILETIME),
('PasswordLastSet', FILETIME),
('PasswordCanChange', FILETIME),
('PasswordMustChange', FILETIME),
('EffectiveName', RPC_UNICODE_STRING),
('FullName', RPC_UNICODE_STRING),
('LogonScript', RPC_UNICODE_STRING),
('ProfilePath', RPC_UNICODE_STRING),
('HomeDirectory', RPC_UNICODE_STRING),
('HomeDirectoryDrive', RPC_UNICODE_STRING),
('LogonCount', USHORT),
('BadPasswordCount', USHORT),
('UserId', ULONG),
('PrimaryGroupId', ULONG),
('GroupCount', ULONG),
('GroupIds', PGROUP_MEMBERSHIP_ARRAY),
('UserFlags', ULONG),
('UserSessionKey', USER_SESSION_KEY),
('LogonServer', RPC_UNICODE_STRING),
('LogonDomainName', RPC_UNICODE_STRING),
('LogonDomainId', PRPC_SID),
# Also called Reserved1
('LMKey', CHAR_FIXED_8_ARRAY),
('UserAccountControl', ULONG),
('SubAuthStatus', ULONG),
('LastSuccessfulILogon', FILETIME),
('LastFailedILogon', FILETIME),
('FailedILogonCount', ULONG),
('Reserved3', ULONG),
('SidCount', ULONG),
#('ExtraSids', PNETLOGON_SID_AND_ATTRIBUTES_ARRAY),
('ExtraSids', PKERB_SID_AND_ATTRIBUTES_ARRAY),
('ResourceGroupDomainSid', PISID),
('ResourceGroupCount', ULONG),
('ResourceGroupIds', PGROUP_MEMBERSHIP_ARRAY),
)
class PKERB_VALIDATION_INFO(NDRPOINTER):
referent = (
('Data', KERB_VALIDATION_INFO),
)
# 2.6.1 PAC_CREDENTIAL_INFO
class PAC_CREDENTIAL_INFO(Structure):
structure = (
('Version', '<L=0'),
('EncryptionType', '<L=0'),
('SerializedData', ':'),
)
# 2.6.3 SECPKG_SUPPLEMENTAL_CRED
class SECPKG_SUPPLEMENTAL_CRED(NDRSTRUCT):
structure = (
('PackageName', RPC_UNICODE_STRING),
('CredentialSize', ULONG),
('Credentials', PUCHAR_ARRAY),
)
class SECPKG_SUPPLEMENTAL_CRED_ARRAY(NDRUniConformantArray):
item = SECPKG_SUPPLEMENTAL_CRED
# 2.6.2 PAC_CREDENTIAL_DATA
class PAC_CREDENTIAL_DATA(NDRSTRUCT):
structure = (
('CredentialCount', ULONG),
('Credentials', SECPKG_SUPPLEMENTAL_CRED_ARRAY),
)
# 2.6.4 NTLM_SUPPLEMENTAL_CREDENTIAL
class NTLM_SUPPLEMENTAL_CREDENTIAL(NDRSTRUCT):
structure = (
('Version', ULONG),
('Flags', ULONG),
('LmPassword', '16s=b""'),
('NtPassword', '16s=b""'),
)
# 2.7 PAC_CLIENT_INFO
class PAC_CLIENT_INFO(Structure):
structure = (
('ClientId', '<Q=0'),
('NameLength', '<H=0'),
('_Name', '_-Name', 'self["NameLength"]'),
('Name', ':'),
)
# 2.8 PAC_SIGNATURE_DATA
class PAC_SIGNATURE_DATA(Structure):
structure = (
('SignatureType', '<l=0'),
('Signature', ':'),
)
# 2.9 Constrained Delegation Information - S4U_DELEGATION_INFO
class S4U_DELEGATION_INFO(NDRSTRUCT):
structure = (
('S4U2proxyTarget', RPC_UNICODE_STRING),
('TransitedListSize', ULONG),
('S4UTransitedServices', PRPC_UNICODE_STRING_ARRAY ),
)
# 2.10 UPN_DNS_INFO
class UPN_DNS_INFO(Structure):
structure = (
('UpnLength', '<H=0'),
('UpnOffset', '<H=0'),
('DnsDomainNameLength', '<H=0'),
('DnsDomainNameOffset', '<H=0'),
('Flags', '<L=0')
)
# 2.10 UPN_DNS_INFO
# Full struct including additional fields (use this structure when S Flag is set)
class UPN_DNS_INFO_FULL(Structure):
structure = (
('UpnLength', '<H=0'),
('UpnOffset', '<H=0'),
('DnsDomainNameLength', '<H=0'),
('DnsDomainNameOffset', '<H=0'),
('Flags', '<L=0'),
('SamNameLength', '<H=0'),
('SamNameOffset', '<H=0'),
('SidLength', '<H=0'),
('SidOffset', '<H=0'),
)
# 2.11 PAC_CLIENT_CLAIMS_INFO
class PAC_CLIENT_CLAIMS_INFO(Structure):
structure = (
('Claims', ':'),
)
# 2.12 PAC_DEVICE_INFO
class PAC_DEVICE_INFO(NDRSTRUCT):
structure = (
('UserId', ULONG),
('PrimaryGroupId', ULONG),
('AccountDomainId', PISID ),
('AccountGroupCount', ULONG ),
('AccountGroupIds', PGROUP_MEMBERSHIP_ARRAY ),
('SidCount', ULONG ),
('ExtraSids', PKERB_SID_AND_ATTRIBUTES_ARRAY ),
('DomainGroupCount', ULONG ),
('DomainGroup', PDOMAIN_GROUP_MEMBERSHIP_ARRAY ),
)
# 2.13 PAC_DEVICE_CLAIMS_INFO
class PAC_DEVICE_CLAIMS_INFO(Structure):
structure = (
('Claims', ':'),
)
class VALIDATION_INFO(TypeSerialization1):
structure = (
('Data', PKERB_VALIDATION_INFO),
)
# 2.14 PAC_ATTRIBUTES_INFO
class PAC_ATTRIBUTE_INFO(NDRSTRUCT):
structure = (
('FlagsLength', ULONG),
('Flags', ULONG),
)
# 2.15 PAC_REQUESTOR
class PAC_REQUESTOR(Structure):
structure = (
('UserSid',':',SID),
)