CS 378 Trojans and Viruses Vitaly Shmatikov slide

  • Slides: 19
Download presentation
CS 378 Trojans and Viruses Vitaly Shmatikov slide 1

CS 378 Trojans and Viruses Vitaly Shmatikov slide 1

Malware u. Malicious code often masquerades as good software or attaches itself to good

Malware u. Malicious code often masquerades as good software or attaches itself to good software u. Some malicious programs need host programs • Trojan horses, logic bombs, viruses u. Others can exist and propagate independently • Worms, automated viruses u. There are many infection vectors and propagation mechanisms 2

Trojan Horses u. A trojan horse is malicious code hidden in an apparently useful

Trojan Horses u. A trojan horse is malicious code hidden in an apparently useful host program u. When the host program is executed, trojan does something harmful or unwanted • User must be tricked into executing the host program • In 1995, a program distributed as PKZ 300 B. EXE looked like a new version of PKZIP… When executed, it formatted your hard drive. u. Trojans do not replicate • This is the main difference from worms and viruses 3

“Reflections on Trusting Trust” u Ken Thompson’s 1983 Turing Award lecture – Linked from

“Reflections on Trusting Trust” u Ken Thompson’s 1983 Turing Award lecture – Linked from the course website (reference section) 1. Added a backdoor-opening Trojan to login program 2. Anyone looking at source code would see this, so changed the compiler to add backdoor at compile-time 3. Anyone looking at compiler source code would see this, so changed the compiler to recognize when it’s compiling a new compiler and to insert Trojan into it u “The moral is obvious. You can’t trust code you did not totally create yourself. (Especially code from companies that employ people like me). ” 4

Viruses u. Virus propagates by infecting other programs • Automatically creates copies of itself,

Viruses u. Virus propagates by infecting other programs • Automatically creates copies of itself, but to propagate, a human has to run an infected program – Self-propagating malicious programs are usually called worms u. Viruses employ many propagation methods • Insert a copy into every executable (. COM, . EXE) • Insert a copy into boot sectors of disks – “Stoned” virus infected PCs booted from infected floppies, stayed in memory and infected every floppy inserted into PC • Infect TSR (terminate-and-stay-resident) routines – By infecting a common OS routine, a virus can always stay in memory and infect all disks, executables, etc. 5

Virus Techniques u. Stealth viruses • Infect OS so that infected files appear normal

Virus Techniques u. Stealth viruses • Infect OS so that infected files appear normal to user u. Macro viruses • A macro is an executable program embedded in a word processing document (MS Word) or spreadsheet (Excel) • When infected document is opened, virus copies itself into global macro file and makes itself auto-executing (e. g. , gets invoked whenever any document is opened) u. Polymorphic viruses • Viruses that mutate and/or encrypt parts of their code with a randomly generated key 6

Evolution of Polymorphic Viruses (1) u. Anti-virus scanners detect viruses by looking for signatures

Evolution of Polymorphic Viruses (1) u. Anti-virus scanners detect viruses by looking for signatures (snippets of known virus code) • Virus writers constantly try to foil scanners u. Encrypted viruses: virus consists of a constant decryptor, followed by the encrypted virus body • Cascade (DOS), Mad (Win 95), Zombie (Win 95) • Relatively easy to detect because decryptor is constant u. Oligomorphic viruses: different versions of virus have different encryptions of the same body • Small number of decryptors (96 for Memorial viruses); to detect, must understand how they are generated 7

Evolution of Polymorphic Viruses (2) u. Polymorphic viruses: constantly create new random encryptions of

Evolution of Polymorphic Viruses (2) u. Polymorphic viruses: constantly create new random encryptions of the same virus body • Marburg (Win 95), HPS (Win 95), Coke (Win 32) • Virus must contain a polymorphic engine for creating new keys and new encryptions of its body – Rather than use an explicit decryptor in each mutation, Crypto virus (Win 32) decrypts its body by brute-force key search u. Polymorphic viruses can be detected by emulation • When analyzing an executable, scanner emulates CPU for a bit. Virus will eventually decrypt and try to execute its body, which will be recognized by scanner. • This only works because virus body is constant! 8

Virus Detection by Emulation Randomly generates a new key and corresponding decryptor code Decrypt

Virus Detection by Emulation Randomly generates a new key and corresponding decryptor code Decrypt and execute Mutation A Virus body Mutation B Mutation C To detect an unknown mutation of a known virus , emulate CPU execution of until the current sequence of instruction opcodes matches the known sequence for virus body 9

Metamorphic Viruses u. Obvious next step: mutate the virus body, too! u. Virus can

Metamorphic Viruses u. Obvious next step: mutate the virus body, too! u. Virus can carry its source code (which deliberately contains some useless junk) and recompile itself • Apparition virus (Win 32) • Virus first looks for an installed compiler – Unix machines have C compilers installed by default • Virus changes junk in its source and recompiles itself – New binary mutation looks completely different! u. Many macro and script viruses evolve and mutate their code • Macros/scripts are usually interpreted, not compiled 10

Metamorphic Mutation Techniques u. Same code, different register names • Regswap (Win 32) u.

Metamorphic Mutation Techniques u. Same code, different register names • Regswap (Win 32) u. Same code, different subroutine order • Bad. Boy (DOS), Ghost (Win 32) • If n subroutines, then n! possible mutations u. Decrypt virus body instruction by instruction, push instructions on stack, insert and remove jumps, rebuild body on stack • Zmorph (Win 95) • Can be detected by emulation because the rebuilt body has a constant instruction sequence 11

Real Permutating Engine (RPME) u. Introduced in Zperm virus (Win 95) in 2000 u.

Real Permutating Engine (RPME) u. Introduced in Zperm virus (Win 95) in 2000 u. Available to all virus writers, employs entire bag of metamorphic and anti-emulation techniques • • Instructions are reordered, branch conditions reversed Jumps and NOPs inserted in random places Garbage opcodes inserted in unreachable code areas Instruction sequences replaced with other instructions that have the same effect, but different opcodes – Mutate SUB EAX, EAX into XOR EAX, EAX or PUSH EBP; MOV EBP, ESP into PUSH EBP; PUSH ESP; POP EBP u. There is no constant, recognizable virus body! 12

Example of Zperm Mutation u. From Szor and Ferrie, “Hunting for Metamorphic” • Linked

Example of Zperm Mutation u. From Szor and Ferrie, “Hunting for Metamorphic” • Linked from the course website (reference section) 13

Defeating Anti-Virus Emulators u. Recall: to detect polymorphic viruses, emulators execute suspect code for

Defeating Anti-Virus Emulators u. Recall: to detect polymorphic viruses, emulators execute suspect code for a little bit and look for opcode sequences of known virus bodies u. Some viruses use random code block insertion engines to defeat emulation • Routine inserts a code block containing millions of NOPs at the entry point prior to the main virus body • Emulator executes code for a while, does not see virus body and decides the code is benign… when main virus body is finally executed, virus propagates • Bistro (Win 95) used this in combination with RPME 14

Putting It All Together: Zmist u. Zmist was designed in 2001 by Russian virus

Putting It All Together: Zmist u. Zmist was designed in 2001 by Russian virus writer Z 0 mbie of “Total Zombification” fame u. New technique: code integration • Virus merges itself into the instruction flow of its host • “Islands” of code are integrated into random locations in the host program and linked by jumps • When/if virus code is run, it infects every available portable executable – Randomly inserted virus entry point may not be reached in a particular execution 15

MISTFALL Disassembly Engine u. To integrate itself into host ’s instruction flow, virus must

MISTFALL Disassembly Engine u. To integrate itself into host ’s instruction flow, virus must disassemble and rebuild host binary • See overview at http: //vx. netlux. org/lib/vzo 21. html u. This is very tricky • Addresses are based on offsets, which must be recomputed when new instructions are inserted • Virus must perform complete instruction-by-instruction disassembly and re-generation of the host binary – This is an iterative process: rebuild with new addresses, see if branch destinations changed, then rebuild again – This requires 32 MB of RAM and explicit section names (DATA, CODE, etc. ) in the host binary – doesn’t work with every file 16

Simplified Zmist Infection Process Randomly insert indirect call OR jump to decryptor’s entry point

Simplified Zmist Infection Process Randomly insert indirect call OR jump to decryptor’s entry point OR rely on instruction flow to reach it Pick a Portable Executable binary < 448 Kb in size Decryptor must restore host’s registers to preserve host’s functionality Disassemble, insert space for new Insert mutated virus body code blocks, generate new binary • Split into jump-linked “islands” Encrypt virus body by XOR (ADD, SUB) with a • Mutate opcodes (XOR SUB, OR TEST) randomly generated key, • Swap register moves and PUSH/POP, etc. insert mutated decryptor Insert random garbage instructions using Executable Trash Generator 17

How Hard Is It to Write a Virus? u 498 matches for “virus creation

How Hard Is It to Write a Virus? u 498 matches for “virus creation tool” in Spyware Encyclopedia • Including dozens of poly- and metamorphic engines u. Over. Writting Virus Construction Toolkit • "The perfect choice for beginners“ u. Biological Warfare Virus Creation Kit • Note: all viruses will be detected by Norton Anti-Virus u. Vbs Worm Generator (for Visual Basic worms) • Used to create the Anna Kournikova worm u. Many others 18

Reading Assignment u. Stallings 10. 1 u. Optional: “Hunting for Metamorphic” by Szor and

Reading Assignment u. Stallings 10. 1 u. Optional: “Hunting for Metamorphic” by Szor and Ferrie • Linked from the course website (reference section) 19