In the Lunar New Year, I played Insomni’hack teaser 2023, one of the topics labeled forensics, realistic, windows aroused my interest, I solved him. And I learned some knowledge from it. This is the record writeup
Autopsy:
Wireshark loads through the export object and selects http, save all and then filters to get three files SYSTEM, SECURITY, ntds.dit
Then after searching, you can learn some relevant content about credential extraction
classKeyTabContent(Structure): structure = ( ('num_components', '>h'), ('realmlen', '>h-realm'), ('realm', ':'), ('components', ':'), ('restdata',':') ) deffromString(self, data): self.components = [] Structure.fromString(self, data) data = self['components'] for i inrange(self['num_components']): ktentry = OctetString(data)
data = data[ktentry['len']+2:] self.components.append(ktentry) self.restfields = KeyTabContentRest(data)
defgetData(self): self['num_components'] = len(self.components) # We modify the data field to be able to use the # parent class parsing self['components'] = b''.join([component.getData() for component in self.components]) self['restdata'] = self.restfields.getData() data = Structure.getData(self) return data
# Add your own keys here! # Keys are tuples in the form (keytype, 'hexencodedkey') # Common keytypes for Windows: # 23: RC4 # 18: AES-256 # 17: AES-128 # Wireshark takes any number of keys in the keytab, so feel free to add # krbtgt keys, service keys, trust keys etc keys = [ (23, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), (18, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), (17, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), (18, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), (23, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') ]
nkt = KeyTab() nkt.entries = []
for key in keys: ktcr = KeyTabContentRest() ktcr['keytype'] = key[0] ktcr['key'] = binascii.unhexlify(key[1]) nktcontent = KeyTabContent() nktcontent.restfields = ktcr # The realm here doesn't matter for wireshark but does of course for a real keytab nktcontent['realm'] = b'TESTSEGMENT.LOCAL' krbtgt = OctetString() krbtgt['value'] = 'krbtgt' nktcontent.components = [krbtgt] nktentry = KeyTabEntry() nktentry['content'] = nktcontent nkt.entries.append(nktentry)
data = nkt.getData() iflen(sys.argv) < 2: print('Usage: keytab.py <outputfile>') print('Keys should be written to the source manually') else: withopen(sys.argv[1], 'wb') as outfile: outfile.write(data)
Then fill in the key obtained above into the keys of lines 112-118 of the script