21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ecause of its power. Four well-known methods for detecting the presence of<br />

SoftICE exist, which are detailed in the “Discussion” section.<br />

Discussion<br />

The “Meltice” technique is one of the oldest methods for detecting SoftICE. It<br />

attempts to open virtual devices created by SoftICE; if any of these devices exist, the<br />

debugger is present.<br />

#include <br />

BOOL spc_softice_meltice(void) {<br />

HANDLE hFile;<br />

hFile = CreateFile(TEXT("\\.\\SICE"), GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);<br />

if (hFile = = INVALID_HANDLE_VALUE)<br />

hFile = CreateFile(TEXT("\\.\\NTICE"), GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);<br />

if (hFile = = INVALID_HANDLE_VALUE)<br />

hFile = CreateFile(TEXT("\\.\\SIWDEBUG"), GENERIC_READ, 0, 0,<br />

OPEN_EXISTING, 0, 0);<br />

if (hFile = = INVALID_HANDLE_VALUE)<br />

hFile = CreateFile(TEXT("\\.\\SIWVID"), GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);<br />

if (hFile = = INVALID_HANDLE_VALUE) return FALSE;<br />

CloseHandle(hFile);<br />

return TRUE;<br />

}<br />

SoftICE provides an interface via the debug breakpoint (int3) instruction that allows<br />

a process to communicate with the debugger. By loading a magic value (“BCHK”)<br />

into the ebp register and executing an int3, the Boundschecker (originally the<br />

Numega Boundschecker utility) interface can be accessed. The function to be called<br />

is loaded into the eax register; function 4 will set the al register to 0 if SoftICE is<br />

present.<br />

#include <br />

__declspec(naked) BOOL spc_softice_boundschecker(void) {<br />

__asm {<br />

push ebp<br />

mov ebp, 0x4243484B ; "BCHK"<br />

mov eax, 4 ; function 4: boundschecker interface<br />

int 3<br />

test al, al ; test for zero<br />

jnz debugger_not_present<br />

mov eax, 1 ; set the return value to 1<br />

pop ebp<br />

ret<br />

debugger_not_present:<br />

xor eax, eax ; set the return value to 0<br />

pop ebp<br />

ret<br />

}<br />

}<br />

686 | Chapter 12: Anti-Tampering<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!