MCPcopy Create free account
hub / github.com/fortra/impacket / Query

Method Query

examples/net.py:159–196  ·  view source on GitHub ↗
(self, name)

Source from the content-addressed store, hash-verified

157 self._close_domain()
158
159 def Query(self, name):
160 domain_handle = self._open_domain(False)
161 try:
162 user_handle = self._get_user_handle(domain_handle, name)
163 response = samr.hSamrQueryInformationUser2(self._dce, user_handle, samr.USER_INFORMATION_CLASS.UserAllInformation)
164 response = response['Buffer']['All']
165
166 # Get groups that user is member of
167 groups = samr.hSamrGetGroupsForUser(self._dce, user_handle)['Groups']['Groups']
168 group_id_list = list(map(lambda g: g['RelativeId'], groups))
169
170 sidArray = samr.SAMPR_PSID_ARRAY()
171 for gid in group_id_list:
172 group_handle = samr.hSamrOpenGroup(self._dce, domain_handle, groupId=gid)['GroupHandle']
173 group_sid = samr.hSamrRidToSid(self._dce, group_handle, gid)['Sid']
174 si = samr.PSAMPR_SID_INFORMATION()
175 si['SidPointer'] = group_sid
176 sidArray['Sids'].append(si)
177 samr.hSamrCloseHandle(self._dce, group_handle)
178
179 global_lookup_ids = samr.hSamrLookupIdsInDomain(self._dce, domain_handle, group_id_list)
180 response.fields['GlobalGroups'] = list(map(lambda a: a['Data'], global_lookup_ids['Names']['Element']))
181
182 self._close_domain()
183 domain_handle = self._open_domain(True)
184
185 alias_membership = samr.hSamrGetAliasMembership(self._dce, domain_handle, sidArray)
186 alias_id_list = list(map(lambda a: a['Data'], alias_membership['Membership']['Element']))
187
188 local_lookup_ids = samr.hSamrLookupIdsInDomain(self._dce, domain_handle, alias_id_list)
189 response.fields['LocalGroups'] = list(map(lambda a: a['Data'], local_lookup_ids['Names']['Element']))
190 return response
191
192 except samr.DCERPCSessionError as e:
193 if str(e).find('STATUS_MORE_ENTRIES') < 0:
194 raise
195 finally:
196 self._close_domain()
197
198 def Create(self, name, new_password, new_nt_hash=''):
199 domain_handle = self._open_domain()

Callers 2

SetUserAccountControlMethod · 0.95
runMethod · 0.45

Calls 4

_open_domainMethod · 0.80
_get_user_handleMethod · 0.80
appendMethod · 0.80
_close_domainMethod · 0.80

Tested by

no test coverage detected