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

Method processRecord

examples/GetADUsers.py:80–110  ·  view source on GitHub ↗
(self, item)

Source from the content-addressed store, hash-verified

78 return t
79
80 def processRecord(self, item):
81 if isinstance(item, ldapasn1.SearchResultEntry) is not True:
82 return
83 sAMAccountName = ''
84 pwdLastSet = ''
85 mail = ''
86 lastLogon = 'N/A'
87 try:
88 for attribute in item['attributes']:
89 if str(attribute['type']) == 'sAMAccountName':
90 if attribute['vals'][0].asOctets().decode('utf-8').endswith('$') is False:
91 # User Account
92 sAMAccountName = attribute['vals'][0].asOctets().decode('utf-8')
93 elif str(attribute['type']) == 'pwdLastSet':
94 if str(attribute['vals'][0]) == '0':
95 pwdLastSet = '<never>'
96 else:
97 pwdLastSet = str(datetime.fromtimestamp(self.getUnixTime(int(str(attribute['vals'][0])))))
98 elif str(attribute['type']) == 'lastLogon':
99 if str(attribute['vals'][0]) == '0':
100 lastLogon = '<never>'
101 else:
102 lastLogon = str(datetime.fromtimestamp(self.getUnixTime(int(str(attribute['vals'][0])))))
103 elif str(attribute['type']) == 'mail':
104 mail = str(attribute['vals'][0])
105
106 print((self.__outputFormat.format(*[sAMAccountName, mail, pwdLastSet, lastLogon])))
107 except Exception as e:
108 logging.debug("Exception", exc_info=True)
109 logging.error('Skipping item, cannot process due to error %s' % str(e))
110 pass
111
112 def run(self):
113 # Connect to LDAP

Callers

nothing calls this directly

Calls 3

getUnixTimeMethod · 0.95
formatMethod · 0.80
decodeMethod · 0.45

Tested by

no test coverage detected