Skip to content

Commit 1527104

Browse files
committed
Land rapid7#19330, Add SSL opt in start_service
The start_service method now allows users to specify their SSL preferences directly through the opts parameter. If the ssl option is not provided in opts, it will default to the value in datastore["SSL"]
2 parents 6f1acf4 + 434593d commit 1527104

19 files changed

+57
-147
lines changed

lib/msf/core/exploit/remote/http_server.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,17 @@ def check_dependencies
116116
# completely on the datastore. (See dlink_upnp_exec_noauth)
117117
def start_service(opts = {})
118118

119+
# Keep compatibility with modules that don't pass the ssl option to the start server but rely on the datastore instead.
120+
opts['ssl'] = opts['ssl'].nil? ? datastore['SSL'] : opts['ssl']
121+
119122
check_dependencies
120123

121124
# Start a new HTTP server service.
122125
self.service = Rex::ServiceManager.start(
123126
Rex::Proto::Http::Server,
124127
(opts['ServerPort'] || bindport).to_i,
125128
opts['ServerHost'] || bindhost,
126-
datastore['SSL'], # XXX: Should be in opts, need to test this
129+
opts['ssl'],
127130
{
128131
'Msf' => framework,
129132
'MsfExploit' => self,
@@ -149,7 +152,7 @@ def start_service(opts = {})
149152
'Path' => opts['Path'] || resource_uri
150153
}.update(opts['Uri'] || {})
151154

152-
proto = (datastore["SSL"] ? "https" : "http")
155+
proto = (opts['ssl'] ? "https" : "http")
153156

154157
# SSLCompression may or may not actually be available. For example, on
155158
# Ubuntu, it's disabled by default, unless the correct environment

modules/auxiliary/gather/magento_xxe_cve_2024_34102.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,16 @@ def run
154154
fail_with(Failure::BadConfig, 'SRVHOST must be set to an IP address (0.0.0.0 is invalid) for exploitation to be successful')
155155
end
156156

157-
if datastore['SSL']
158-
ssl_restore = true
159-
datastore['SSL'] = false
160-
end
161157
start_service({
162158
'Uri' => {
163159
'Proc' => proc do |cli, req|
164160
on_request_uri(cli, req)
165161
end,
166162
'Path' => '/'
167-
}
163+
},
164+
'ssl' => false
168165
})
169-
datastore['SSL'] = true if ssl_restore
166+
170167
xxe_request
171168
rescue Timeout::Error => e
172169
fail_with(Failure::TimeoutExpired, e.message)

modules/exploits/linux/http/dlink_diagnostic_exec_noauth.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,6 @@ def exploit
122122
if (datastore['DOWNHOST'])
123123
service_url = 'http://' + datastore['DOWNHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri
124124
else
125-
#do not use SSL
126-
if datastore['SSL']
127-
ssl_restore = true
128-
datastore['SSL'] = false
129-
end
130125

131126
#we use SRVHOST as download IP for the coming wget command.
132127
#SRVHOST needs a real IP address of our download host
@@ -144,9 +139,10 @@ def exploit
144139
on_request_uri(cli, req)
145140
},
146141
'Path' => resource_uri
147-
}})
142+
},
143+
'ssl' => false # do not use SSL
144+
})
148145

149-
datastore['SSL'] = true if ssl_restore
150146
end
151147

152148
#

modules/exploits/linux/http/dlink_dir615_up_exec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,6 @@ def exploit
155155
if (datastore['DOWNHOST'])
156156
service_url = 'http://' + datastore['DOWNHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri
157157
else
158-
#do not use SSL
159-
if datastore['SSL']
160-
ssl_restore = true
161-
datastore['SSL'] = false
162-
end
163158

164159
if (datastore['SRVHOST'] == "0.0.0.0" or datastore['SRVHOST'] == "::")
165160
srv_host = Rex::Socket.source_address(rhost)
@@ -174,9 +169,10 @@ def exploit
174169
on_request_uri(cli, req)
175170
},
176171
'Path' => resource_uri
177-
}})
172+
},
173+
'ssl' => false # do not use SSL
174+
})
178175

179-
datastore['SSL'] = true if ssl_restore
180176
end
181177

182178
#

modules/exploits/linux/http/dlink_hnap_login_bof.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,6 @@ def exploit
253253
@elf_sent = false
254254
resource_uri = '/' + downfile
255255

256-
#do not use SSL
257-
if datastore['SSL']
258-
ssl_restore = true
259-
datastore['SSL'] = false
260-
end
261-
262256
if (datastore['SRVHOST'] == "0.0.0.0" or datastore['SRVHOST'] == "::")
263257
srv_host = Rex::Socket.source_address(rhost)
264258
else
@@ -272,9 +266,10 @@ def exploit
272266
on_request_uri(cli, req)
273267
},
274268
'Path' => resource_uri
275-
}})
269+
},
270+
'ssl' => false # do not use SSL
271+
})
276272

277-
datastore['SSL'] = true if ssl_restore
278273
print_status("#{peer} - Asking the device to download and execute #{service_url}")
279274

280275
filename = rand_text_alpha_lower(rand(8) + 2)

modules/exploits/linux/http/linksys_e1500_apply_exec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,6 @@ def exploit
151151
if (datastore['DOWNHOST'])
152152
service_url = 'http://' + datastore['DOWNHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri
153153
else
154-
#do not use SSL
155-
if datastore['SSL']
156-
ssl_restore = true
157-
datastore['SSL'] = false
158-
end
159154

160155
#we use SRVHOST as download IP for the coming wget command.
161156
#SRVHOST needs a real IP address of our download host
@@ -172,9 +167,10 @@ def exploit
172167
on_request_uri(cli, req)
173168
},
174169
'Path' => resource_uri
175-
}})
170+
},
171+
'ssl' => false # do not use SSL
172+
})
176173

177-
datastore['SSL'] = true if ssl_restore
178174
end
179175

180176
#

modules/exploits/linux/http/linksys_wrt54gl_apply_exec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,6 @@ def exploit
304304
if (datastore['DOWNHOST'])
305305
service_url = 'http://' + datastore['DOWNHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri
306306
else
307-
#do not use SSL
308-
if datastore['SSL']
309-
ssl_restore = true
310-
datastore['SSL'] = false
311-
end
312307

313308
#we use SRVHOST as download IP for the coming wget command.
314309
#SRVHOST needs a real IP address of our download host
@@ -325,9 +320,10 @@ def exploit
325320
on_request_uri(cli, req)
326321
},
327322
'Path' => resource_uri
328-
}})
323+
},
324+
'ssl' => false # do not use SSL
325+
})
329326

330-
datastore['SSL'] = true if ssl_restore
331327
end
332328

333329
#

modules/exploits/linux/http/netgear_dgn1000b_setup_exec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,6 @@ def exploit
155155
if (datastore['DOWNHOST'])
156156
service_url = 'http://' + datastore['DOWNHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri
157157
else
158-
#do not use SSL
159-
if datastore['SSL']
160-
ssl_restore = true
161-
datastore['SSL'] = false
162-
end
163158

164159
#we use SRVHOST as download IP for the coming wget command.
165160
#SRVHOST needs a real IP address of our download host
@@ -176,9 +171,10 @@ def exploit
176171
on_request_uri(cli, req)
177172
},
178173
'Path' => resource_uri
179-
}})
174+
},
175+
'ssl' => false # do not use SSL
176+
})
180177

181-
datastore['SSL'] = true if ssl_restore
182178
end
183179

184180
#

modules/exploits/linux/http/netgear_dgn2200b_pppoe_exec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,6 @@ def exploit
270270
if (datastore['DOWNHOST'])
271271
service_url = 'http://' + datastore['DOWNHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri
272272
else
273-
#do not use SSL
274-
if datastore['SSL']
275-
ssl_restore = true
276-
datastore['SSL'] = false
277-
end
278273

279274
#we use SRVHOST as download IP for the coming wget command.
280275
#SRVHOST needs a real IP address of our download host
@@ -291,9 +286,10 @@ def exploit
291286
on_request_uri(cli, req)
292287
},
293288
'Path' => resource_uri
294-
}})
289+
},
290+
'ssl' => false # do not use SSL
291+
})
295292

296-
datastore['SSL'] = true if ssl_restore
297293
end
298294

299295
#

modules/exploits/linux/http/vestacp_exec.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -252,28 +252,19 @@ def on_request_uri(cli, _request)
252252
end
253253

254254
def start_http_server
255-
#
256-
# HttpClient and HttpServer use same SSL variable :(
257-
# We don't need SSL for payload delivery so we
258-
# will disable it temporarily.
259-
#
260-
if datastore['SSL']
261-
ssl_restore = true
262-
datastore['SSL'] = false
263-
end
264255
start_service({
265256
'Uri' => {
266257
'Proc' => proc do |cli, req|
267258
on_request_uri(cli, req)
268259
end,
269260
'Path' => resource_uri
270-
}
261+
},
262+
'ssl' => false # do not use SSL
271263
})
272264
print_status("Second payload download URI is #{get_uri}")
273265
# We need to use instance variables since get_uri keeps using
274266
# the SSL setting from the datastore.
275267
# Once the URI is retrieved, we will restore the SSL settings within the datastore.
276268
@second_stage_url = get_uri
277-
datastore['SSL'] = true if ssl_restore
278269
end
279270
end

0 commit comments

Comments
 (0)