You are on page 1of 21

CAP6135: Malware and Software Vulnerability Analysis

Cliff Zou

Spring 2012


This lecture uses some contents from the lecture notes from:

Dr. Vitaly Shmatikov CS 378 - Network Security and Privacy Introduction to Computer Security, M.T. goodrich & R. Tamassia, 2011.


Virus propagates by infecting other programs

Automatically creates copies of itself, but to propagate, a human has to run an infected program

Many propagation methods

Self-propagating malicious programs are usually called worms

Insert a copy into every executable (.COM, .EXE) Insert a copy into boot sectors of disks

Infect TSR (terminate-and-stay-resident) routines

Stoned virus infected PCs booted from infected floppies, stayed in memory and infected every floppy inserted into PC

By infecting a common OS routine, a virus can always stay in memory and infect all disks, executables, etc.

Virus Phases

Dormant phase. During this phase, the virus just existsthe virus is laying low and avoiding detection. Propagation phase. During this phase, the virus is replicating itself, infecting new files on new systems. Triggering phase. In this phase, some logical condition causes the virus to move from a dormant or propagation phase to perform its intended action. Action phase. In this phase, the virus performs the malicious action that it was designed to perform, called payload.

This action could include something seemingly innocent, like displaying a silly picture on a computers screen, or something quite malicious, such as deleting all essential files on the hard drive.

Virus Techniques

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)
Infect OS so that infected files appear normal

Stealth techniques

Mutate, encrypt parts of code with random key

Used by rootkits (well look at them later)

Viruses in P2P Networks

[Shin, Jung, Balakrishnan]

Millions of users willingly download files

KaZaA: 2.5 million users in May 2006

Easy to insert an infected file into the network

Pretend to be an executable of a popular application Infected MP3 files are rare

Adobe Photoshop 10 full.exe, WinZip 8.1.exe, ICQ and Trillian seem to be the most popular names

Malware can open backdoor, steal confidential information, spread spam

70% of infected hosts already on DNS spam blacklists

Prevalence of Viruses in KaZaA

[Shin, Jung, Balakrishnan]

2006 study of 500,000 KaZaA files

Look for 364 patterns associated with 71 viruses

52 different viruses and Trojans Another study found that 44% of all executable files on KaZaA contain malicious code When searching for ICQ or Trillian, chances of hitting an infected file are over 70% 5% of infected hosts seen in February 2006 were still active in May 2006

Up to 22% of all KaZaA files infected

Some infected hosts are active for a long time

Dangerous KaZaA Queries

[Shin, Jung, Balakrishnan]

Stealth Techniques
[Shin, Jung, Balakrishnan]

Mutation: virus has multiple binary variants

Defeats nave signature-based detection Used by the most successful (i.e., widespread) viruses

Aliasing: virus places its copies under different names into the infected hosts sharing folder

Tanked: 62 variants, SdDrop: 14 variants

ICQ Lite .exe, ICQ Pro 2003b.exe, MSN Messenger 5.2.exe

Propagation via Websites

[Moshchuk et al.]

Websites with popular content

Games: 60% of websites contain executable content, one-third contain at least one malicious executable Celebrities, adult content, everything except news

Most popular sites with malicious content (Oct 2005) Large variety of malware

But most of the observed programs are variants of the same few adware applications (e.g., WhenU)


Malicious Functionality
[Moshchuk et al.]


Display unwanted pop-up ads

Modify home page, search tools, redirect URLs

Browser hijackers

Trojan downloaders

Download and install additional malware

Dialer (expensive toll numbers) Keylogging


Drive-By Downloads

Website pushes malicious executable to users browser with inline Javascript or pop-up window

Nave user may click Yes in the dialog box

Can also install malicious software automatically by exploiting bugs in the users browser

1.5% of URLs crawled in the Moshchuk et al. study

Constant change

Many infectious sites exist only for a short time or change substantially from month to month Many sites behave non-deterministically



Encrypted virus

Decryption engine + encrypted body Randomly generate encryption key +brute force decryption Detection looks for decryption engine Encrypted virus with random variations of the decryption engine (e.g., padding code) Detection using CPU emulator
Different virus bodies Approaches include code permutation and instruction replacement Challenging to detect

Polymorphic virus

Metamorphic virus

Polymorphic Viruses

Encrypted viruses: virus consists of a constant decryptor, followed by the encrypted virus body

Relatively easy to detect because decryptor is constant

Polymorphic viruses: constantly create new random encryptions of the same virus body

Marburg (Win95), HPS (Win95), Coke (Win32) Virus includes an engine for creating new keys and new encryptions of the virus body

Decryptor can start with millions of NOPs to defeat emulation

Crypto (Win32) decrypts its body by brute-force key search to avoid explicit decryptor code


Anti-Virus Technologies

Simple anti-virus scanners

Look for signatures (fragments of known virus code) Heuristics for recognizing code associated with viruses

Integrity checking to find modified files

Polymorphic viruses often use decryption loops Record file sizes, checksums, MACs (keyed hashes of contents) Often used for rootkit detection (well see TripWire later)

Generic decryption and emulation

Emulate CPU execution for a few hundred instructions, virus will eventually decrypt, can recognize known body

Does not work very well against mutating viruses and viruses not located near beginning of infected executable


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

Metamorphic Viruses

Obvious next step: mutate the virus body, too! Virus can carry its source code (which deliberately contains some useless junk) and recompile itself

Apparition virus (Win32) Virus first looks for an installed compiler

Virus changes junk in its source and recompiles itself

Unix machines have C compilers installed by default

New binary mutation looks completely different!

Mutation is common in macro and script viruses

Macros/scripts are usually interpreted, not compiled


Obfuscation and Anti-Debugging

Common in worms, viruses, bots Goal: prevent analysis of code and signature-based detection; foil reverse-engineering

Insert garbage opcodes and change control structure Different code in each instance

Packed binaries

Effect of code execution is the same, but difficult to detect by passive analysis

Detect debuggers and virtual machines, terminate execution


Mutation / Obfuscation Techniques

Same code, different register names

Regswap (Win32)

Same code, different subroutine order

BadBoy (DOS), Ghost (Win32) If n subroutines, then n! possible mutations

Decrypt virus body instruction by instruction, push instructions on stack, insert and remove jumps, rebuild body on stack

Zmorph (Win95) Can be detected by emulation because the rebuilt body has a constant instruction sequence


Mutation Engines

Real Permutating Engine/RPME, ADMutate, etc. Large set of obfuscating 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

There is no constant, recognizable virus body!



Example of Zperm Mutation

From Szor and Ferrie, Hunting for Metamorphic