part iv: software

74
Part 4 Software 1 Part IV: Software

Upload: sagira

Post on 25-Feb-2016

59 views

Category:

Documents


0 download

DESCRIPTION

Part IV: Software. Why Software?. Why is software as important to security as crypto, access control, protocols? Virtually all of information security is implemented in software If your software is subject to attack, your security can be broken - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Part IV: Software

Part 4 Software 1

Part IV: Software

Page 2: Part IV: Software

Part 4 Software 2

Why Software? Why is software as important to security

as crypto, access control, protocols? Virtually all of information security is

implemented in software If your software is subject to attack,

your security can be brokeno Regardless of strength of crypto, access

control or protocols Software is a poor foundation for

security

Page 3: Part IV: Software

Chapter 11: Software Flaws and

Malware

Part 4 Software 3

Page 4: Part IV: Software

Part 4 Software 4

Software IssuesTrudy Actively looks for

bugs and flaws Likes bad

software… …and tries to

make it misbehave Attacks systems

via bad software

Alice and Bob Find bugs and flaws

by accident Hate bad

software… …but must learn to

live with it Must make bad

software work

Page 5: Part IV: Software

Part 4 Software 5

Complexity “Complexity is the enemy of security”, Paul

Kocher, Cryptography Research, Inc.

A new car contains more LOC than was required to land the Apollo astronauts on the moon

System Lines of Code (LOC)Netscape 17 million

Space Shuttle 10 millionLinux kernel 2.6.0 5 million

Windows XP 40 millionMac OS X 10.4 86 million

Boeing 777 7 million

Page 6: Part IV: Software

Part 4 Software 6

Software Security Topics Program flaws (unintentional)

o Buffer overflowo Incomplete mediationo Race conditions

Malicious software (intentional)o Viruseso Wormso Other breeds of malware

Page 7: Part IV: Software

Part 4 Software 7

Program Flaws An error is a programming mistake

o To err is human An error may lead to incorrect state:

faulto A fault is internal to the program

A fault may lead to a failure, where a system departs from its expected behavioro A failure is externally observableerror fault failure

Page 8: Part IV: Software

Part 4 Software 8

Examplechar array[10];for(i = 0; i < 10; ++i)

array[i] = `A`;array[10] = `B`;

This program has an error This error might cause a fault

o Incorrect internal state If a fault occurs, it might lead to a

failureo Program behaves incorrectly (external)

We use the term flaw for all of the above

Page 9: Part IV: Software

Part 4 Software 9

Secure Software Secure software engineering requires

that software does what is intended…

…and nothing more Absolutely secure software is impossible

o But, absolute security anywhere is impossible

How can we manage software risks?

Page 10: Part IV: Software

Part 4 Software 10

Program Flaws Program flaws are unintentional

o But can still create security risks We’ll consider 3 types of flaws

o Buffer overflow (smashing the stack)o Incomplete mediationo Race conditions

These are the most common problems

Page 11: Part IV: Software

Part 4 Software 11

Buffer Overflow

Page 12: Part IV: Software

Part 4 Software 12

Possible Attack Scenario Users enter data into a Web form Web form is sent to server Server writes data to array called buffer,

without checking length of input data Data “overflows” buffer

o Such overflow might enable an attacko If so, attack could be carried out by anyone

with Internet access

Page 13: Part IV: Software

Part 4 Software 13

Buffer Overflow

Q: What happens when code is executed?

A: Depending on what resides in memory at location “buffer[20]”o Might overwrite user data or codeo Might overwrite system data or codeo Or program could work just fine

int main(){ int buffer[10]; buffer[20] = 37;}

Page 14: Part IV: Software

Part 4 Software 14

Simple Buffer Overflow Consider boolean flag for authentication Buffer overflow could overwrite flag

allowing anyone to authenticate

bufferFTF O U R S C …

Boolean flag

Page 15: Part IV: Software

Part 4 Software 15

Memory Organization Text == code Data == static

variables Heap == dynamic

data Stack == “scratch

paper” o Dynamic local variableso Parameters to functionso Return address

stack

heap

data

text

¬ high address

¬ low address

¬ stack pointer (SP)

Page 16: Part IV: Software

Part 4 Software 16

Simplified Stack Example

high

void func(int a, int b){char buffer[10];

}void main(){

func(1, 2);}

::

bufferretab

¬ return address

low

¬ SP¬ SP¬ SP

¬ SP

Page 17: Part IV: Software

Part 4 Software 17

Smashing the Stack

high

What happens if buffer overflows?

::

buffer

ab

¬ ret…

low

¬ SP¬ SP¬ SP

¬ SP

retoverflow

Program “returns” to wrong location

NOT!

???

A crash is likelyoverflow

Page 18: Part IV: Software

Part 4 Software 18

Smashing the Stack

high

Trudy has a better idea… ::

evil code

ab

low

¬ SP¬ SP¬ SP

¬ SP

retret

Code injection Trudy can run

code of her choosing…o …on your

machine

Page 19: Part IV: Software

Part 4 Software 19

Smashing the Stack Trudy may not

know…1) Address of evil code2) Location of ret on

stack Solutions

1) Precede evil code with NOP “landing pad”

2) Insert ret many times

evil code

::

::

ret

ret:

NOP

NOP:

ret¬ ret

Page 20: Part IV: Software

Part 4 Software 20

Stack Smashing Summary A buffer overflow must exist in the code Not all buffer overflows are exploitable

o Things must align properly If exploitable, attacker can inject code Trial and error is likely required

o Fear not, lots of help is available online

Page 21: Part IV: Software

Part 4 Software 21

Stack Smashing Defenses Employ non-executable stack

o “No execute” NX bit (if available) o Seems like the logical thing to do, but some

real code executes on the stack (Java, for example)

Use a canary Use safe languages (Java, C#) Use safer C functions

o For unsafe functions, safer versions existo For example, strncpy instead of strcpy

Page 22: Part IV: Software

Part 4 Software 22

Stack Smashing Defenses

Canaryo Run-time stack checko Push canary onto

stack¬

high

::

buffer

ab

low

overflowretcanaryoverflow

Page 23: Part IV: Software

SQL Injection

o SQL stands for Structured Query Language o Allows us to access a database o ANSI and ISO standard computer language o SQL can:

– execute queries against a database – retrieve data from a database – insert new records in a database – delete records from a database – update records in a database

23

Page 24: Part IV: Software

SQL Injection

o There are many different versions of the SQL languageo They support the same major keywords in a similar manner

(such as SELECT, UPDATE, DELETE, INSERT, WHERE, and others).

o Most of the SQL database programs also have their own proprietary extensions in addition to the SQL standard!

24

Page 25: Part IV: Software

SQL Database Tables

o A relational database contains one or more tables identified each by a name

o Tables contain records (rows) with data o For example, the following table is called "users" and contains

data distributed in rows and columns:

userID Name LastName Login Password

1 John Smith jsmith hello2 Adam Taylor adamt qwerty3 Daniel Thompson dthompson dthompson

25

Page 26: Part IV: Software

SQL Queries

o With SQL, we can query a database and have a result set returned

o Using the previous table, a query like this:SELECT LastName

FROM users WHERE UserID = 1;

o Gives a result set like this:LastName--------------Smith

26

Page 27: Part IV: Software

What is SQL Injection?

o The ability to inject SQL commands into the database enginethrough an existing application

27

Page 28: Part IV: Software

How common is it?

o It is probably the most common Website vulnerability today!o It is a flaw in "web application" development,

it is not a DB or web server problem– Most programmers are still not aware of this problem– A lot of the tutorials & demo “templates” are vulnerable– Even worse, a lot of solutions posted on the Internet are not

good enough

28

Page 29: Part IV: Software

How does SQL Injection work?

o Common vulnerable login query SELECT * FROM users WHERE login = 'ali'AND password = '123'

(If it returns something then login!)

o ASP/MS SQL Server login syntaxvar sql = "SELECT * FROM users WHERE login = '" +

formusr + "' AND password = '" + formpwd + "'";

29

Page 30: Part IV: Software

Injecting through Strings

formusr = ' or 1=1 – – formpwd = anything

Final query would look like this:SELECT * FROM usersWHERE username = ' ' or 1=1 – – AND password = 'anything'

30

Page 31: Part IV: Software

If it were numeric?

SELECT * FROM clients WHERE user= 12345678AND pas= 1111

PHP/MySQL login syntax$sql = "SELECT * FROM clients WHERE " . “user= $formusr AND " . “pas= $formpas";

31

Page 32: Part IV: Software

Injecting Numeric Fields

$formusr = 1 or 1=1 ;-- $formpas = 1111

Final query would look like this:SELECT * FROM clientsWHERE user= 1 or 1=1; --AND pas = 1111

32

Page 33: Part IV: Software

Examples of what can SQL Injection do

o Delete: Select productinfo from table where productname =

‘whatever’; DROP TABLE productinfo; -- ’o Bypass Authentication

o Select * from users where username=’user ’ and password=’passwd ’;

o select * from users where username=’admin’--’ and password=’whocares’;

33

Page 34: Part IV: Software

SQL Injection Characters

o ' or " character String Indicatorso -- or # single-line commento /*…*/ multiple-line commento + addition, concatenate (or space in url)o || (double pipe) concatenateo % wildcard attribute indicatoro ?Param1=foo&Param2=bar URL Parameterso PRINT useful as non transactional commando @variable local variableo @@variable global variableo waitfor delay '0:0:10' time delay

34

Page 35: Part IV: Software

SQL Injection Tools

o SQL Map* is a tool that aids in the fingerprinting of a backend database

o SQL Ninja* http://sqlninja.sourceforge.net/ o Aids in the exploitation of SQL injection vulnerabilities can

provide root level command access to systemo Automagic SQL Injector*

o Designed to work with generic installation of MS SQL http://scoobygang.org/magicsql/

o Videos on SQL injection can be found on the internet one great source

http://securitytube.net/*Source: EC Council Certified Ethical Hacker Volume 3 Chapter 19

35

Page 36: Part IV: Software

SQL Injection Defense

o It is quite simple: input validation– Enforce "strong design" in new applications– You should audit your existing websites and source code

36

Page 37: Part IV: Software

Part 4 Software 37

Incomplete Mediation

Page 38: Part IV: Software

Part 4 Software 38

Input Validation Consider: strcpy(buffer, argv[1]) A buffer overflow occurs iflen(buffer) < len(argv[1])

Software must validate the input by checking the length of argv[1]

Failure to do so is an example of a more general problem: incomplete mediation

Page 39: Part IV: Software

Part 4 Software 39

Input Validation Consider web form data Suppose input is validated on client For example, the following is valid

http://www.things.com/orders/final&custID=112&num=55A&qty=20&price=10&shipping=5&total=205

Suppose input is not checked on servero Why bother since input checked on client?o Then attacker could send http messagehttp://www.things.com/orders/final&custID=112&num=55A&qty=20&price=10&shipping=5&total=25

Page 40: Part IV: Software

Part 4 Software 40

Incomplete Mediation Linux kernel

o Research has revealed many buffer overflows

o Many of these are due to incomplete mediation

Linux kernel is “good” software sinceo Open-source o Kernel written by coding gurus

Tools exist to help find such problemso But incomplete mediation errors can be

subtleo And tools useful to attackers too!

Page 41: Part IV: Software

Part 4 Software 41

Malware

Page 42: Part IV: Software

Part 4 Software 42

Malicious Software Malware is not new…

o Fred Cohen’s initial virus work in 1980’s, used viruses to break MLS systems

Types of malware (lots of overlap)o Virus passive propagationo Worm active propagationo Trojan horse unexpected functionalityo Trapdoor/backdoor unauthorized accesso Rabbit exhaust system resources

Page 43: Part IV: Software

Part 4 Software 43

Where do Viruses Live? They live just about anywhere, such as… Boot sector

o Take control before anything else Memory resident

o Stays in memory Applications, macros, data, etc. Library routines Compilers, debuggers, virus checker, etc.

o These would be particularly nasty!

Page 44: Part IV: Software

Part 4 Software 44

Malware Examples Brain virus (1986) Morris worm (1988) Code Red (2001) SQL Slammer (2004) Botnets (currently fashionable) Future of malware?

Page 45: Part IV: Software

Part 4 Software 45

Brainq First appeared in 1986q More annoying than harmfulq A prototype for later virusesq Not much reaction by usersq What it did

1. Placed itself in boot sector (and other places)

2. Screened disk calls to avoid detection3. Each disk read, checked boot sector to see

if boot sector infected; if not, goto 1q Brain did nothing really malicious

Page 46: Part IV: Software

Part 4 Software 46

Morris Worm First appeared in 1988 What it tried to do

o Determine where it could spread, then…o …spread its infection and…o …remain undiscovered

Morris claimed his worm had a bug!o It tried to re-infect infected systemso Led to resource exhaustiono Effect was like a so-called rabbit

Page 47: Part IV: Software

Part 4 Software 47

How Morris Worm Spread Obtained access to machines by…

o User account password guessingo Exploit buffer overflow in fingerdo Exploit trapdoor in sendmail

Flaws in fingerd and sendmail were well-known, but not widely patched

Page 48: Part IV: Software

Part 4 Software 48

Bootstrap Loader Once Morris worm got access… “Bootstrap loader” sent to victim

o 99 lines of C code Victim compiled and executed code Bootstrap loader fetched the worm Victim authenticated sender!

o Don’t want user to get a bad worm…

Page 49: Part IV: Software

Part 4 Software 49

How to Remain Undetected?

If transmission interrupted, code deleted

Code encrypted when downloaded Code deleted after decrypt/compile When running, worm regularly

changed name and process identifier (PID)

Page 50: Part IV: Software

Part 4 Software 50

Morris Worm: Bottom Line Shock to Internet community of 1988

o Internet of 1988 much different than today Internet designed to withstand nuclear

waro Yet, brought down by one graduate student!o At the time, Morris’ father worked at NSA…

Could have been much worse Result? CERT, more security awareness But should have been a wakeup call

Page 51: Part IV: Software

Part 4 Software 51

Code Red Worm Appeared in July 2001 Infected more than 250,000

systems in about 15 hours Eventually infected 750,000 out of

about 6,000,000 vulnerable systems

Exploited buffer overflow in Microsoft IIS server softwareo Then monitor traffic on port 80,

looking for other susceptible servers

Page 52: Part IV: Software

Part 4 Software 52

Code Red: What it Did Day 1 to 19 of month: spread its infection Day 20 to 27: distributed denial of service

attack (DDoS) on www.whitehouse.gov Later version (several variants)

o Included trapdoor for remote accesso Rebooted to flush worm, leaving only trapdoor

Some say it was “beta test for info warfare”o But no evidence to support this

Page 53: Part IV: Software

Part 4 Software 53

SQL Slammer Infected 75,000

systems in 10 minutes!

At its peak, infections doubled every 8.5 seconds

Spread “too fast”… …so it “burned out”

available bandwidth

Page 54: Part IV: Software

Part 4 Software 54

Why was Slammer Successful?

Worm size: one 376-byte UDP packet

Firewalls often let one packet thruo Then monitor ongoing “connections”

Expectation was that much more data required for an attacko So no need to worry about 1 small

packet Slammer defied “experts”

Page 55: Part IV: Software

Part 4 Software 55

Trojan Horse Example Trojan: unexpected

functionality Prototype trojan for the Mac File icon for freeMusic.mp3: For a real mp3, double click on icon

o iTunes openso Music in mp3 file plays

But for freeMusic.mp3, unexpected results…

Page 56: Part IV: Software

Part 4 Software 56

Mac Trojan Double click on freeMusic.mp3

o iTunes opens (expected)o “Wild Laugh” (not expected)o Message box (not expected)

Page 57: Part IV: Software

Part 4 Software 57

Trojan Example How does freeMusic.mp3 trojan work? This “mp3” is an application, not data

This trojan is harmless, but… …could have done anything user could

doo Delete files, download files, launch apps, etc.

Page 58: Part IV: Software

Part 4 Software 58

Malware Detection Three common detection methods

o Signature detectiono Change detectiono Anomaly detection

We briefly discuss each of theseo And consider advantages…o …and disadvantages

Page 59: Part IV: Software

Part 4 Software 59

Signature Detection A signature may be a string of bits in exe

o Might also use wildcards, hash values, etc. For example, W32/Beast virus has

signature 83EB 0274 EB0E 740A 81EB 0301 0000o That is, this string of bits appears in virus

We can search for this signature in all files If string found, have we found W32/Beast?

o Not necessarily string could appear elsewhere

o At random, chance is only 1/2112 o But software is not random

Page 60: Part IV: Software

Part 4 Software 60

Signature Detection Advantages

o Effective on “ordinary” malwareo Minimal burden for users/administrators

Disadvantageso Signature file can be large (10s of

thousands)…o …making scanning slowo Signature files must be kept up to dateo Cannot detect unknown viruseso Cannot detect some advanced types of

malware The most popular detection method

Page 61: Part IV: Software

Part 4 Software 61

Change Detection Viruses must live somewhere If you detect a file has changed, it

might have been infected How to detect changes?

o Hash files and (securely) store hash values

o Periodically re-compute hashes and compare

o If hash changes, file might be infected

Page 62: Part IV: Software

Part 4 Software 62

Change Detection Advantages

o Virtually no false negativeso Can even detect previously unknown

malware Disadvantages

o Many files change and ofteno Many false alarms (false positives)o Heavy burden on users/administratorso If suspicious change detected, then what?o Might fall back on signature-based system

Page 63: Part IV: Software

Part 4 Software 63

Anomaly Detection Monitor system for anything “unusual”

or “virus-like” or potentially malicious or …

Examples of “unusual”o Files change in some unexpected wayo System misbehaves in some wayo Unexpected network activityo Unexpected file access, etc., etc., etc., etc.

But, we must first define “normal”o Normal can (and must) change over time

Page 64: Part IV: Software

Part 4 Software 64

Anomaly Detection Advantages

o Chance of detecting unknown malware Disadvantages

o No proven track recordo Trudy can make abnormal look normal (go

slow)o Must be combined with another method

(e.g., signature detection) Also popular in intrusion detection (IDS) Difficult unsolved (unsolvable?) problem

o Reminds me of AI…

Page 65: Part IV: Software

Part 4 Software 65

Future of Malware Recent trends

o Encrypted, polymorphic, metamorphic malware

o Fast replication/Warhol wormso Flash worms, slow wormso Botnets

The future is bright for malwareo Good news for the bad guys…o …bad news for the good guys

Future of malware detection?

Page 66: Part IV: Software

Part 4 Software 66

Encrypted Viruses Virus writers know signature detection

used So, how to evade signature detection? Encrypting the virus is a good approach

o Ciphertext looks like random bitso Different key, then different “random” bitso So, different copies have no common

signature Encryption often used in viruses today

Page 67: Part IV: Software

Part 4 Software 67

Encrypted Viruses How to detect encrypted viruses? Scan for the decryptor code

o More-or-less standard signature detectiono But may be more false alarms

Why not encrypt the decryptor code?o Then encrypt the decryptor of the decryptor

(and so on…) Encryption of limited value to virus

writers

Page 68: Part IV: Software

Part 4 Software 68

Polymorphic Malware Polymorphic worm

o Body of worm is encryptedo Decryptor code is “mutated” (or “morphed”) o Trying to hide decryptor signatureo Like an encrypted worm on steroids…

Q: How to detect?A: Emulation let the code decrypt itself

o Slow, and anti-emulation is possible

Page 69: Part IV: Software

Part 4 Software 69

Botnet Botnet: a “network” of infected

machines Infected machines are “bots”

o Victim is unaware of infection (stealthy) Botmaster controls botnet

o Generally, using IRCo P2P botnet architectures exist

Botnets used for…o Spam, DoS attacks, keylogging, ID theft,

etc.

Page 70: Part IV: Software

Part 4 Software 70

Botnet Examples XtremBot

o Similar bots: Agobot, Forbot, Phatbot o Highly modular, easily modifiedo Source code readily available (GPL license)

UrXboto Similar bots: SDBot, UrBot, Rboto Less sophisticated than XtremBot type

GT-Bots and mIRC-based botso mIRC is common IRC client for Windows

Page 71: Part IV: Software

Part 4 Software 71

More Botnet Examples Mariposa

o Used to steal credit card infoo Creator arrested in July 2010

Confickero Estimated 10M infected hosts (2009)

Krakeno Largest as of 2008 (400,000 infections)

Srizbio For spam, one of largest as of 2008

Page 72: Part IV: Software

Part 4 Software 72

Computer Infections Analogies are made between computer

viruses/worms and biological diseases There are differences

o Computer infections are much quickero Ability to intervene in computer outbreak is

more limited (vaccination?)o Bio disease models often not applicableo “Distance” almost meaningless on Internet

But there are some similarities…

Page 73: Part IV: Software

Part 4 Software 73

Computer Infections Cyber “diseases” vs biological diseases One similarity

o In nature, too few susceptible individuals and disease will die out

o In the Internet, too few susceptible systems and worm might fail to take hold

One differenceo In nature, diseases attack more-or-less at

randomo Cyber attackers select most “desirable”

targetso Cyber attacks are more focused and damaging

Page 74: Part IV: Software

Part 4 Software 74

Future Malware Detection? Malware today outnumbers “goodware”

o Metamorphic copies of existing malwareo Many virus toolkits availableo Trudy: recycle old viruses, different

signature So, may be better to “detect” good

codeo If code not on “good” list, assume it’s bado That is, use whitelist instead of blacklist