Skip to content

Commit

Permalink
Fix incorrect filetime in mslaps-encryptedpassword attribute header (
Browse files Browse the repository at this point in the history
…#35)

- necessary for `get-lapsadpassword` powershell cmdlet
  • Loading branch information
breakwaterlabs authored Sep 19, 2024
1 parent 12031d2 commit 3270dee
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion laps-runner/laps_runner/laps_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,20 @@ def encryptPassword(self, content):
# 8-12 - blob size, uint32
# 12-16 - flags, currently always 0
preMagic = (
struct.pack('<Q', dt_to_filetime(datetime.now()))
self.rotate_and_pack_msdatetime(dt_to_filetime(datetime.now()))
+ struct.pack('<i', len(encrypted))
+ b'\x00\x00\x00\x00'
)

return preMagic + encrypted

def rotate_and_pack_msdatetime(self, dt):
# MS AD uses upper time and lower time. The current ordering is backwards, which this fixes
# this can be seen by using dnSpy to trace attempts to get-lapsadpassword, which fail on validating the datetime.
left,right = struct.unpack('<LL',struct.pack('Q',dt))
packed = struct.pack('<LL',right,left)
return packed

def generatePassword(self):
return ''.join(secrets.choice(self.cfgAlphabet) for i in range(self.cfgLength))

Expand Down

0 comments on commit 3270dee

Please sign in to comment.