for fun and profit - pages.cs.wisc.edu

69
Malicious Code Malicious Code for Fun and Profit for Fun and Profit Mihai Christodorescu [email protected] 23 March 2006

Upload: others

Post on 22-Jan-2022

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: for Fun and Profit - pages.cs.wisc.edu

Malicious CodeMalicious Codefor Fun and Profitfor Fun and Profit

Mihai [email protected]

23 March 2006

Page 2: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 2

What is Malicious Code?What is Malicious Code?

Viruses, worms, trojans, …Code that breaks your security policy.

CharacteristicsAttack vectorPayloadSpreading algorithm

Page 3: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 3

OutlineOutline

• Attack Vectors

• Payloads

• Spreading Algorithms

• Case Studies

Page 4: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 4

Attack VectorsAttack Vectors

• Social engineering“Make them want to run it.”

• Vulnerability exploitation“Force your way into the system.”

• Piggybacking“Make it run when other programs run.”

Page 5: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 5

Social EngineeringSocial Engineering

• Suggest to user that the executable is:– A game.– A desirable picture/movie.– An important document.– A security update from Microsoft.– A security update from the IT department.

• Spoofing the sender helps.

Page 6: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 6

OutlineOutline

• Attack Vectors:Social EngineeringVulnerability ExploitationPiggybacking

• Payloads• Spreading Algorithms• Case Studies

Page 7: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 7

Vulnerability ExploitationVulnerability Exploitation

• Make use of flaws in software input handling.

• Sample techniques:– Buffer overflow attacks.– Format string attacks.– Return-to-libc attacks.– SQL injection attacks.

Page 8: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 8

Basic PrinciplesBasic Principles

A buffer overflow occurs when data is stored past the boundaries of an array or a string.

The additional data now overwrites nearby program variables.

Result:Attacker controls or takes over acurrently running process.

BufferOverflows

Page 9: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 9

ExampleExample

Expected input: \\hostname\path

BufferOverflows

void process_request( char * req )

{

// Get hostname

char host[ 20 ];

int pos = find_char( req, ‘\\’, 2 );

strcpy( host,

substr( req, 2, pos – 1 ) );

...

return;

}

process_request( “\\tux12\usr\foo.txt” ); ⇒ OK

process_request( “\\aaabbbcccdddeeefffggghhh\bar” ); ⇒ BAD

Page 10: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 10

A stack frame per procedure call.

Program StackProgram StackBuffer

Overflows

void process_request( char * req )

{

// Get hostname

char host[ 20 ];

int pos = find_char( req, ‘\\’, 2 );

strcpy( host,

substr( req, 2, pos – 1 ) );

...

return;

}

main()

process_request()

strcpy()

Page 11: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 11

A stack frame per procedure call.

Program StackProgram StackBuffer

Overflows

void process_request( char * req )

{

// Get hostname

char host[ 20 ];

int pos = find_char( req, ‘\\’, 2 );

strcpy( host,

substr( req, 2, pos – 1 ) );

...

return;

}

main()

process_request()

strcpy()

Page 12: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 12

A stack frame per procedure call.

Program StackProgram StackBuffer

Overflows

void process_request( char * req )

{

// Get hostname

char host[ 20 ];

int pos = find_char( req, ‘\\’, 2 );

strcpy( host,

substr( req, 2, pos – 1 ) );

...

return;

}

main()

process_request()

strcpy()

arg: req

Page 13: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 13

A stack frame per procedure call.

Program StackProgram StackBuffer

Overflows

void process_request( char * req )

{

// Get hostname

char host[ 20 ];

int pos = find_char( req, ‘\\’, 2 );

strcpy( host,

substr( req, 2, pos – 1 ) );

...

return;

}

main()

process_request()

strcpy()

return address

frame pointer

arg: req

Page 14: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 14

A stack frame per procedure call.

Program StackProgram StackBuffer

Overflows

void process_request( char * req )

{

// Get hostname

char host[ 20 ];

int pos = find_char( req, ‘\\’, 2 );

strcpy( host,

substr( req, 2, pos – 1 ) );

...

return;

}

main()

process_request()

strcpy()

return address

frame pointer

arg: req

local: host

Page 15: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 15

A stack frame per procedure call.

Program StackProgram StackBuffer

Overflows

void process_request( char * req )

{

// Get hostname

char host[ 20 ];

int pos = find_char( req, ‘\\’, 2 );

strcpy( host,

substr( req, 2, pos – 1 ) );

...

return;

}

main()

process_request()

strcpy()

return address

local: pos

frame pointer

arg: req

local: host

Page 16: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 16

Normal ExecutionNormal ExecutionBuffer

Overflows

void process_request( char * req )

{

// Get hostname

char host[ 20 ];

int pos = find_char( req, ‘\\’, 2 );

strcpy( host,

substr( req, 2, pos – 1 ) );

...

return;

}

main()

process_request() return address

frame pointer

arg: req

local: host

local: pos

process_request( “\\tux12\usr\foo.txt” );

Page 17: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 17

Normal ExecutionNormal ExecutionBuffer

Overflows

void process_request( char * req )

{

// Get hostname

char host[ 20 ];

int pos = find_char( req, ‘\\’, 2 );

strcpy( host,

substr( req, 2, pos – 1 ) );

...

return;

}

main()

process_request() return address

7

frame pointer

arg: req

local: host

process_request( “\\tux12\usr\foo.txt” );

local: post u x 1

2 \0

Page 18: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 18

Overflow ExecutionOverflow ExecutionBuffer

Overflows

void process_request( char * req )

{

// Get hostname

char host[ 20 ];

int pos = find_char( req, ‘\\’, 2 );

strcpy( host,

substr( req, 2, pos – 1 ) );

...

return;

}

main()

process_request() return address

32

frame pointer

arg: req

local: host

process_request( “\\aaabbbcccdddeeefffggghhhiiijjj\bar” );

local: posa a a b

b b c c

c d d d

e e e f

f f g g

g

i i i j

h h h

j j \0

Characters that overwrite the

return address.

Page 19: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 19

The attacker gets one chance to gain control.

Craft an input string such that:• The return address is overwritten with a pointer

to malicious code.• The malicious code is placed inside the input

string.

Smashing the StackSmashing the StackBuffer

Overflows

Malicious code can create a root shell by executing “/bin/sh”.

Page 20: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 20

Shell CodeShell Code

C0310876895E17EB

0BB00C4689074688

CDD231084E8DF389

b/FFFFFFE4E880

i n / s h \0 arg 2

to code

pointerarg 1arg 2

BufferOverflows

Code for exec(“/bin/sh”):

mov edx, arg2mov ecx, arg1mov ebx, “/bin/sh”mov eax, 0Bhint 80h

Pointer value foroverwriting the return address.

Page 21: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 21

• Defense against stack-smashing attacks:– Bounds-checking. – Protection libraries.– Non-executable stack.

– setuid()/chroot().– Avoid running programs as root!– Address randomization.

– Behavioral monitoring.

Thicker ArmorThicker ArmorBuffer

Overflows

Page 22: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 22

More InfoMore Info

“Smashing the Stack for Fun and Profit”by Aleph One

StackGuard, RAD, PAX, ASLR

CERT

Page 23: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 23

Format String AttacksFormat String Attacks

• Another way to illegally control program values.

• Uses flaws in the design of printf():

printf( “%s: %d” , s, x );

FormatStrings

Page 24: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 24

printfprintf()() OperationOperation

printf( “%s: %d, %x”,

s, x, y );

FormatStrings

foo()

printf()

y

x

s

format string ptr

Page 25: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 25

Attack 1: Read Any ValueAttack 1: Read Any Value

What the code says:printf( str );

What the programmer meant:printf( “%s”, str );

If str = “%x%x%x%x%s”

FormatStrings

secret key ptr

format string ptr

Page 26: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 26

Attack 2: Write to AddressAttack 2: Write to Address

What the code says:printf( str );

If str = “%x%x%x%x%n”

FormatStrings

return address

format string ptr

4

Page 27: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 27

DefensesDefenses

Never use printf() without a format string!

FormatGuard.

FormatStrings

Page 28: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 28

OutlineOutline

• Attack Vectors:Social EngineeringVulnerability ExploitationPiggybacking

• Payloads• Spreading Algorithms• Case Studies

Page 29: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 29

PiggybackingPiggybacking

Malicious code injected into a benign program or data file.

• Host file can be:– An executable.– A document with some executable content

(Word documents with macros, etc.).

Page 30: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 30

Piggybacking ExecutablesPiggybacking Executables

• Modify program on disk:

Variations:

• Jump to malicious code only on certain actions.

• Spread malicious code throughout program.

Page 31: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 31

Piggybacking ExecutablesPiggybacking Executables

• Modify program on disk:

Variations:

• Jump to malicious code only on certain actions.

• Spread malicious code throughout program.

Page 32: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 32

Piggybacking ExecutablesPiggybacking Executables

• Modify program on disk:

jmp evil_code

Variations:

• Jump to malicious code only on certain actions.

• Spread malicious code throughout program.

Page 33: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 33

Piggybacking ExecutablesPiggybacking Executables

• Modify program on disk:

jmp evil_code

Variations:

• Jump to malicious code only on certain actions.

• Spread malicious code throughout program.

Page 34: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 34

Piggybacking DocumentsPiggybacking Documents

• Documents with macros:Microsoft Office supports documents with

macros scripted in Visual Basic (VBA).

• Macro triggered on:– Document open– Document close– Document save– Send document by email

Page 35: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 35

OutlineOutline

• Attack Vectors:Social EngineeringVulnerability ExploitationPiggybacking

• Payloads• Spreading Algorithms• Case Studies• Defenses

Page 36: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 36

PayloadPayload

Target the interesting data:

• Passwords

• Financial data

• User behavior

• User attention

Keylogger

Screen scraper

Spyware

Adware

Page 37: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 37

KeyloggerKeylogger UseUse

Page 38: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 38

Screen Scraper UseScreen Scraper Use

Page 39: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 39

More Payload IdeasMore Payload Ideas

Victim machines are pawns in larger attack:

– Botnets.

– Distributed denial of service (DDoS).

– Spam proxies.

– Anonymous FTP sites.

– IRC servers.

Page 40: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 40

OutlineOutline

• Attack Vectors:Social EngineeringVulnerability ExploitationPiggybacking

• Payloads• Spreading Algorithms• Case Studies• Defenses

Page 41: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 41

Spreading MethodsSpreading Methods

Depends on the attack vector:Email-based⇒ need email addresses

Vulnerability-based⇒ need IP addresses of hosts running the

vulnerable service

Piggybacking⇒ need more files to infect

Page 42: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 42

Spreading through EmailSpreading through Email

MalwareInternet

HTML files (from cache)

Windows Address Book

Outlook Express folders

Outlook folders

Page 43: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 43

Vulnerable Target DiscoveryVulnerable Target Discovery

Need to find Internet (IP) addresses.

• Scanning:

• Target list:

• Passive: Contagion worms

RandomSequentialBandwidth-limited

Pre-generatedExternally-generated ⇒ Metaserver wormsInternal target list ⇒ Topological worms

Page 44: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 44

OutlineOutline

• Attack Vectors:Social EngineeringVulnerability ExploitationPiggybacking

• Payloads• Spreading Algorithms• Case Studies

Page 45: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 45

Types of Malicious CodeTypes of Malicious Code

• VirusSelf-replicating, infects programs and documents.

e.g.: Chernobyl/CIH, Melissa, Elkern

• WormSelf-replicating, spreads across a network.

e.g.: ILoveYou, Code Red, B(e)agle, Witty

McGraw and Morrisett “Attacking malicious code: A report to the Infosec Research Council” Sept./Oct. 2000.

Page 46: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 46

Types of Malicious CodeTypes of Malicious Code

• Trojan– Malware hidden inside useful programs

e.g.: NoUpdate, KillAV, Bookmarker

• Backdoor– Tool allowing unauthorized remote access

e.g.: BackOrifice, SdBot, Subseven

Page 47: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 47

Types of Malicious CodeTypes of Malicious Code

• Spyware– Secretly monitors system activity

e.g.: ISpynow, KeyLoggerPro, Look2me

• Adware– Monitors user activity for advertising purposes

e.g.: WildTangent, Gator, BargainBuddy

Page 48: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 48

OutlineOutline

• Attack Vectors:Social EngineeringVulnerability ExploitationPiggybacking

• Payloads• Spreading Algorithms• Case Studies: Sobig

Page 49: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 49

The The SobigSobig WormWorm

• Mass-mailing, network-aware worm• Multi-stage update capabilities

10 Sept 200318 Aug 2003Sobig.F

14 July 200325 June 2003Sobig.E

2 July 200318 June 2003Sobig.D

8 June 200331 May 2003Sobig.C

31 May 200318 May 2003Sobig.B

-9 Jan. 2003Sobig.A

DeactivationLaunch

Page 50: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 50

• E-mail

• Network shares

SobigSobig: Attack Vector: Attack Vector

[email protected]:

Subject:

[email protected]@[email protected]@yahoo.com

• Compressed executable attachment with renamed extension.

• Later: attachment in ZIP file.

Page 51: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 51

SobigSobig: Payload: Payload

Geocities web page

Trojan web server

• 1st stage:Backdoor (Lala)& keylogger

• 2nd stage:Proxy (WinGate)

Page 52: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 52

SobigSobig: Payload: Payload

...Hacked DSL/cable hosts

Trojan web server

1

22

Page 53: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 53

SobigSobig: Spreading Algorithm: Spreading Algorithm

• E-mail addresses extracted from files on disk.

• Network shares automatically discovered.

Page 54: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 54

Sobig.FSobig.F in Numbersin Numbers

August: 19 20 21 22 23

Cour

tesy

of

Mes

sage

Labs

.com

Page 55: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 55

OutlineOutline

• Attack Vectors:Social EngineeringVulnerability ExploitationPiggybacking

• Payloads• Spreading Algorithms• Case Studies: Sobig, Blaster

Page 56: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 56

The The BlasterBlaster WormWorm

• Multi-stage worm exploiting Windows vulnerability

17

August2003: July

1917151311312516

Microsoft releases patch

LSD Research exploit released

CERT advisory

Blaster appears 1.2 million hosts infected

Metasploit refined exploit

FRB Atlanta, MD DMV, BMW

Scandinavian bank closes all 70 branches

Page 57: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 57

Blaster: Attack VectorBlaster: Attack Vector

• Uses a Microsoft Windows RPC DCOM vulnerability.

• Coding flaw:1. The RPC service passes part of the request to

function GetMachineName().2. GetMachineName() copies machine name to

a fixed 32-byte buffer.

Page 58: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 58

Blaster: Attack VectorBlaster: Attack Vector

Exploit 1

Page 59: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 59

Blaster: Attack VectorBlaster: Attack Vector

Exploit 1

“tftp GET msblast.exe” 2

Page 60: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 60

Blaster: Attack VectorBlaster: Attack Vector

Exploit 1

“tftp GET msblast.exe” 2

TFTPServer

“GET msblast.exe”3

Page 61: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 61

Blaster: Attack VectorBlaster: Attack Vector

Exploit 1

“tftp GET msblast.exe” 2

TFTPServer

“GET msblast.exe”3

4

Page 62: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 62

Blaster: Attack VectorBlaster: Attack Vector

Exploit 1

“tftp GET msblast.exe” 2

TFTPServer

“GET msblast.exe”3

4

“start msblast.exe” 5

Page 63: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 63

Blaster: PayloadBlaster: Payload

• Worm installs itself to start automatically.

• All infected hosts perform DDoS against windowsupdate.com .– SYN flood attack with spoofed source IP,

Aug 15 → Dec 31 andafter the 15th of all other months.

Page 64: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 64

Blaster: Effect on Local HostBlaster: Effect on Local Host

• RPC/DCOM disabled:– Inability to cut/paste.– Inability to move icons.– Add/Remove Programs list empty.– DLL errors in most Microsoft Office programs.– Generally slow, or unresponsive system

performance.

Page 65: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 65

Blaster: Spreading AlgorithmBlaster: Spreading Algorithm

• Build IP address list:40% chance to start with local IP address.60% chance to generate random IP address.

• Probe 20 IPs at a time.

• Exploit type:80% Windows XP.20% Windows 2000.

Page 66: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 66

Blaster: Infection RateBlaster: Infection Rate

Page 67: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 67

Future Threat: Future Threat: SuperwormSuperworm

“Curious Yellow: the First Coordinated Worm Design” – Brandon Wiley

• Fast replication & adaptability:– Pre-scan the network for targets.– Worm instances communicate to coordinate

infection process.– Attack vectors can be updated.– Worm code mutates.

Page 68: for Fun and Profit - pages.cs.wisc.edu

23 March 2006 Mihai Christodorescu 68

ConclusionsConclusions

• Vulnerabilities left unpatched can and will be used against you.

• Attackers are more sophisticated.

• Need to understand the attackers’ perspective.

Page 69: for Fun and Profit - pages.cs.wisc.edu

Malicious CodeMalicious Codefor Fun and Profitfor Fun and Profit

Mihai [email protected]

23 March 2006