26.09.2018 Views

Antivirus hackers handbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

134 Part II ■ <strong>Antivirus</strong> Software Evasion<br />

engines based on static data (data extracted from the portable executable, or PE,<br />

header). Another tip is that, in general, if a file format cannot be correctly parsed<br />

by the scanner or engine responsible for handling a specific file format (such<br />

as a “malformed” PE file), it will be discarded from any and all PE routines,<br />

but cyclic redundancy check (CRC) signatures may still be applied to the file<br />

(for example, CRCs at some specific offset). Later in this chapter, you will see<br />

examples with various file formats.<br />

Another trick is that instead of trying to make it difficult for the antivirus<br />

engine to parse the file format, you can try to fool one or more of the core’s support<br />

functionalities or libraries. The typical core support functionality resides<br />

in the emulator and the disassembler. As far as I know, every antivirus engine,<br />

except ClamAV, contains an emulator for at least Intel 8086 and a disassembler<br />

for Intel x86. Can you attack the disassembler or the emulator to affect or evade<br />

the scanner? Many analysis routines rely on the emulation and disassembling<br />

functionality to gather evidence and behavioral data from malware. If you can<br />

somehow manage to execute invalid instructions in the emulator or if you can<br />

craft valid but unimplemented or incorrectly implemented instructions in the<br />

disassembly engine, you get the same behavior in most AV scanners: no analysis<br />

routine is able to navigate through the disassembly of your file because the core<br />

kernel support functionality is flawed.<br />

The following sections discuss more tricks that you can use to evade scanners.<br />

Fingerprinting Emulators<br />

Fingerprinting emulators is one of the most commonly used evasion techniques.<br />

Malware samples usually become a more likely candidate for emulation when<br />

they contain polymorphic or metamorphic code. Using a static analysis engine<br />

is not enough because writing a complex and foolproof static analysis engine is<br />

too expensive. To identify an emulator in an AV kernel, you can rely on the fact<br />

that the emulator may correctly or fully emulate not a whole operating system<br />

but only the most commonly executed functions. In many cases, you can give<br />

the illusion that all the operating system functions are implemented by creating<br />

stubs for those functions that, very often, return hard-coded values. The following<br />

example uses the Comodo antivirus emulator for Linux. If you open the<br />

library libMACH32.so (which is full of symbols, something that is very helpful)<br />

in IDA, you will discover functions like the following one:<br />

.text:000000000018B93A ; PRUint32 __cdecl Emu_OpenMutexW<br />

(void *pVMClass)<br />

.text:000000000018B93A<br />

public _Z14Emu_OpenMutexWPv<br />

.text:000000000018B93A _Z14Emu_OpenMutexWPv proc near<br />

; DATA XREF: .data:kernel32ApiInf<br />

.text:000000000018B93A pVMClass = rdi<br />

; void *<br />

.text:000000000018B93A mov eax, 0BBBBh

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

Saved successfully!

Ooh no, something went wrong!