4 Software
4 Software
Part 4 Software 1
Why Software?
Why is software as important to security as crypto, access
control, protocols?
Virtually all information security features are implemented
in software
If your software is subject to attack, your security can be
broken
o Regardless of strength of crypto, access control, or protocols
Software is a poor foundation for security
Part 4 Software 2
Bad Software is Ubiquitous
NASA Mars Lander (cost $165 million)
o Crashed into Mars due to…
o …error in converting English and metric units of measure
o Believe it or not
Denver airport
o Baggage handling system very buggy software
o Delayed airport opening by 11 months
o Cost of delay exceeded $1 million/day
o What happened to person responsible for this fiasco?
MV-22 Osprey
o Advanced military aircraft
o Faulty software can be fatal
Part 4 Software 3
Software Issues
Part 4 Software 4
Complexity
“Complexity is the enemy of security”, Paul
Kocher, Cryptography Research, Inc.
Part 4 Software 6
Software Security Topics
Program flaws (unintentional)
o Buffer overflow
o Incomplete mediation
o Race conditions
Malicious software (intentional)
o Viruses
o Worms
o Other breeds of malware
Part 4 Software 7
Program Flaws
An error is a programming mistake
o To err is human
An error may lead to incorrect state: fault
o A fault is internal to the program
A fault may lead to a failure, where a system departs from
its expected behavior
o A failure is externally observable
Part 4 Software 8
Example
char 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 failure
o Program behaves incorrectly (external)
We use the term flaw for all of the above
Part 4 Software 9
Secure Software
In software engineering, try to ensure that a program
does what is intended
Secure software engineering requires that software does
what is intended…
…and nothing more
Absolutely secure software? Dream on…
o Absolute security anywhere is impossible
How can we manage software risks?
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 mediation
o Race conditions
These are the most common flaws
Part 4 Software 11
Buffer Overflow
Part 4 Software 12
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 attack
o If so, attack could be carried out by anyone with Internet access
Part 4 Software 13
Buffer Overflow
int main(){
int buffer[10];
buffer[20] = 37;}
Part 4 Software 14
Simple Buffer Overflow
Consider boolean flag for authentication
Buffer overflow could overwrite flag
allowing anyone to authenticate
Boolean flag
buffer
F OU R S C … T
F
Part 4 Software 16
Simplified Stack Example
(Let func is called)
low
high b ¬ SP
Part 4 Software 17
Smashing the Stack
low
What happens if :
??? :
buffer overflows?
Program “returns” ¬ SP
to wrong location buffer
overflow
ret ¬ ret…
SP NOT!
A crash is likely
overflow
a ¬ SP
high b ¬ SP
Part 4 Software 18
Smashing the Stack
low
Trudy has a
:
better idea… :
Code injection
Trudy can run ¬ SP
code of her evil code
choosing… ret
ret ¬ SP
a ¬ SP
o …on your machine
high b ¬ SP
Part 4 Software 19
Smashing the Stack
:
:
Trudy may not know… NOP
1) Address of evil code :
2) Location of ret on stack NOP
Part 4 Software 21
Stack Smashing Example
Suppose program asks for a serial number
that Trudy does not know
Also, Trudy does not have source code
Trudy only has the executable (exe)
Part 4 Software 26
Buffer Overflow
Trudy did not require access to the source code
Only tool used was a disassembler to determine
address to jump to
Find desired address by trial and error?
o Necessary if attacker does not have exe
o For example, a remote attack
Part 4 Software 27
Source Code
Source code for buffer overflow example
Flaw easily
exploited by
attacker…
…without
access to
source code!
Part 4 Software 28
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
Address space layout randomization (ASLR)
Use safe languages (Java, C#)
Use safer C functions
o For unsafe functions, safer versions exist
o For example, strncpy instead of strcpy
Part 4 Software 29
Stack Smashing Defenses
low
:
Canary :
o Run-time stack check
o Push canary onto stack
o Canary value: buffer
Constant 0x000aff0d overflow
canary ¬
Part 4 Software 31
ASLR
Address Space Layout Randomization
o Randomize place where code loaded in memory
Makes most buffer overflow attacks
probabilistic
Windows Vista used 256 random layouts
o So about 1/256 chance buffer overflow works
Similar thing in Mac OS X and other OSs
Attacks against Microsoft’s ASLR do exist
o Possible to “de-randomize”
Part 4 Software 32
Buffer Overflow
A major security threat yesterday, today,
and tomorrow
The good news?
o It is possible to reduce overflow attacks (safe
languages, NX bit, ASLR, education, etc.)
The bad news?
o Buffer overflows will exist for a long time
o Why? Legacy code, bad development practices,
clever attacks, etc.
Part 4 Software 33
Incomplete Mediation
Part 4 Software 34
Input Validation
Consider: strcpy(buffer, argv[1])
A buffer overflow occurs if
len(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
Part 4 Software 35
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&t
otal=205
Suppose input is not checked on server
o Why bother since input checked on client?
o Then attacker could send http message
http://www.things.com/orders/
final&custID=112&num=55A&qty=20&price=10&shipping=5&t
otal=25
Part 4 Software 36
Incomplete Mediation
Linux kernel
o Research revealed many buffer overflows
o Lots of these due to incomplete mediation
Linux kernel is “good” software since
o Open-source
o Kernel written by coding gurus
Tools exist to help find such problems
o But incomplete mediation errors can be subtle
o And tools useful for attackers too!
Part 4 Software 37
Race Conditions
Part 4 Software 38
Race Condition
Security processes should be atomic
o Occur “all at once”
Race conditions can arise when security-
critical process occurs in stages
Attacker makes change between stages
o Often, between stage that gives authorization,
but before stage that transfers ownership
Example: Unix mkdir
Part 4 Software 39
mkdir Race Condition
mkdircreates new directory
How mkdir is supposed to work
mkdir
1. Allocate
space
2. Transfer
ownership
Part 4 Software 40
mkdir Attack
The mkdir race condition
mkdir
1. Allocate
space
3. Transfer
ownership
2. Create link to
password file
Part 4 Software 42
Malware
Part 4 Software 43
Malicious Software
Malware is not new…
o Fred Cohen’s seminal virus work in 1980’s
Types of malware (no standard definition)
o Virus passive propagation
o Worm active propagation
o Trojan horse unexpected functionality
o Trapdoor/backdoor unauthorized access
o Rabbit exhaust system resources
o Spyware steals info, such as passwords
o Botnets malware for hire
o Ransomware Use malware to encrypt data
Part 4 Software 44
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!
Part 4 Software 45
Malware Timeline
Brain virus (1986)
Morris worm (1988)
Code Red (2001)
SQL Slammer (2004)
Botnets
Stuxnet (2010)
Ransomware
Future of malware?
Part 4 Software 46
Brain
q First appeared in 1986
q More annoying than harmful
q A prototype for later viruses
q Not much reaction by users
q What it did
1. Placed itself in boot sector (and other places)
2. Screened disk calls to avoid detection
3. Each disk read, checked boot sector to see if
boot sector infected; if not, goto 1
q Brain did nothing really malicious
Part 4 Software 47
Morris Worm
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 systems
o Led to resource exhaustion
o Effect was like a so-called rabbit
Part 4 Software 48
How Morris Worm Spread
Part 4 Software 49
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…
Part 4 Software 50
How to Remain Undetected?
Part 4 Software 51
Morris Worm: Bottom Line
Shocked the Internet community of 1988
o Internet of 1988 much different than today
Internet designed to survive nuclear war
o 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
Part 4 Software 52
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 software
o Then monitor traffic on port 80, looking
for other susceptible servers
Part 4 Software 53
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 access
o Rebooted to flush worm, leaving only trapdoor
Some said it was “beta test for info warfare”
o But, no evidence to support this
Part 4 Software 54
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
Part 4 Software 55
Why was Slammer Successful?
Worm size: one 376-byte UDP packet
Firewalls often let one packet thru
o Then monitor ongoing “connections”
Expectation was that much more data
required for an attack
o So no need to worry about 1 small packet
Slammer defied “experts”
Part 4 Software 56
Stuxnet
Malware for information warfare…
Discovered in 2010
o Origins go back to 2008, or earlier
Apparently, targeted Iranian nuclear
processing facility
o Reprogrammed specific type of PLC
o Changed speed of centrifuges, causing
damage to 1000 (or more) of them
Part 4 Software 57
Stuxnet
Many advanced features including…
o Infect system via removable drives
able to get behind “airgap” firewalls
o Used 4 unpatched MS vulnerabilities
o Updates via P2P over LAN
o Contact C&C server for code/updates
o Includes a Windows rootkit for stealth
o Significant exfiltration/recon capability
o Used a compromised private key
Part 4 Software 58
Malware Related to Stuxnet
Duqu (2011)
o Likely that developers had access to Stuxnet source
code
o Apparently, used mostly for info stealing
Flame (2012)
o May be “most complex” malware ever
o Very sophisticated spyware mechanisms
Part 4 Software 59
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 opens
o Music in mp3 file plays
But for freeMusic.mp3, unexpected results…
Part 4 Software 60
Mac Trojan
Double click on freeMusic.mp3
o iTunes opens (expected)
o “Wild Laugh” (not expected)
o Message box (not expected)
Part 4 Software 61
Trojan Example
How does freeMusic.mp3 trojan work?
This “mp3” is an application, not data
Part 4 Software 63
Botnet Examples
XtremBot
o Similar bots: Agobot, Forbot, Phatbot
o Highly modular, easily modified
o Source code readily available (GPL license)
UrXbot
o Similar bots: SDBot, UrBot, Rbot
o Less sophisticated than XtremBot type
GT-Bots and mIRC-based bots
o mIRC is common IRC client for Windows
Part 4 Software 64
More Botnet Examples
Mariposa
o Used to steal credit card info
o Creator arrested in July 2010
Conficker
o Estimated 10M infected hosts (2009)
Kraken
o Largest as of 2008 (400,000 infections)
Srizbi
o For spam, one of largest as of 2008
Part 4 Software 65
Ransomware
Part 4 Software 67
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 0000
o 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 be in normal code
o At random, chance is only 1/2112
o But software is not random…
Part 4 Software 68
Signature Detection
Advantages
o Effective on “ordinary” malware
o Minimal burden for users/administrators
Disadvantages
o Signature file can be large (10s of thousands)…
o …making scanning slow
o Signature files must be kept up to date
o Cannot detect unknown viruses
o Cannot detect some advanced types of malware
The most popular detection method
Part 4 Software 69
Change Detection
Viruses must live somewhere
If you detect a file has changed
unexpectedly, 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
Part 4 Software 70
Change Detection
Advantages
o Few (if any) false negatives
o Can detect previously unknown malware
Disadvantages
o Many files change and often
o May be many false alarms (false positives)
o Heavy burden on users/administrators
o If suspicious change detected, then what?
Might have to fall back on signature detection
Part 4 Software 71
Anomaly Detection
Monitor system for anything “unusual” or
“virus-like” or “potentially malicious” or …
Examples of anomalous things
o Files change in some unexpected way
o System misbehaves in some way
o Unexpected network activity
o Unexpected file access, etc., etc., etc., etc.
But, we must first define “normal”
o And normal can (and must) change over time
Part 4 Software 72
Anomaly Detection
Advantages
o Chance of detecting unknown malware
Disadvantages
o No proven track record
o Trudy might make abnormal look normal (go slow)
o Typically, anomaly detection is combined with another
method (e.g., signature detection)
Also popular in intrusion detection (IDS)
Difficult unsolved (unsolvable?) problem
o This sounds like a job for AI (equivalently, machine
learning, deep learning, big data)
Part 4 Software 73
Machine Learning
Machine learning and AI is not widely
applied to malware detection problem
o Some AV systems claim to only use AI
Models trained on features extracted
from known malware samples
Then trained models used to classify
Models can be viewed as higher-level
“signatures”
Part 4 Software 74
Future of Malware
Recent trends
o Encrypted, polymorphic, metamorphic malware
o Fast replication/Warhol worms
o Flash worms, slow worms
o Botnets, ransomware, and ???
The future is bright for malware
o Good news for the bad guys…
o …bad news for the good guys
Future of malware detection?
Part 4 Software 75
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 bits
o Different key, then different “random” bits
o So, different copies have no common signature
Encryption often used in viruses today
Part 4 Software 76
Encrypted Viruses
How to detect encrypted viruses?
Scan for the decryptor code
o More-or-less standard signature detection
o 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
Part 4 Software 77
Polymorphic Malware
Polymorphic worm
o Body of worm is encrypted
o Decryptor code is “mutated” (or “morphed”)
o Trying to hide decryptor signature
o Like an encrypted worm on steroids…
Q: How to detect?
A: Emulation might work
o Let the code decrypt itself
o Slow, and anti-emulation is possible
Part 4 Software 78
Metamorphic Malware
A metamorphic worm mutates before
infecting a new system
o Sometimes called “body polymorphic”
Such a worm can, in principle, evade
signature-based detection
Mutated worm must function the same
o And be “different enough” to avoid detection
Detection is a difficult research problem
Part 4 Software 79
Metamorphic Worm
One approach to metamorphic replication…
o The worm is disassembled
o Worm then stripped to a base form
o Random variations inserted into code (permute
the code, insert dead code, etc., etc.)
o Assemble the resulting code
Part 4 Software 80
Future Malware Detection?
There is so much malware, maybe it is better to
“detect” good code
o If code not on approved list, assume it’s bad?
o That is, use whitelist instead of blacklist
Part 4 Software 81
Miscellaneous
Software-Based
Attacks
Part 4 Software 82
Miscellaneous Attacks
Numerous attacks involve software
We’ll discuss a few issues that do not fit into
previous categories
o Salami attack
o Linearization attack
o Time bomb
o Can you ever trust software?
Part 4 Software 83
Salami Attack
What is Salami attack?
o Programmer “slices off” small amounts of money
o Slices are hard for victim to detect
Example
o Bank calculates interest on accounts
o Programmer “slices off” any fraction of a cent
and puts it in his own account
o No customer notices missing partial cent
o Bank may not notice any problem
o Over time, programmer makes lots of money!
Part 4 Software 84
Salami Attack
Such attacks are possible for insiders
Do salami attacks actually occur?
o Or is it just Office Space folklore?
Programmer added a few cents to every
employee payroll tax withholding
o But money credited to programmer’s tax
o Programmer got a big tax refund!
Rent-a-car franchise in Florida inflated gas
tank capacity to overcharge customers
Part 4 Software 85
Salami Attacks
Employee reprogrammed Taco Bell cash
register: $2.99 item registered as $0.01
o Employee pocketed $2.98 on each such item
o A large “slice” of salami!
In LA, four men installed computer chip
that overstated amount of gas pumped
o Customers complained when they had to pay for
more gas than tank could hold
o Hard to detect since chip programmed to give
correct amount when 5 or 10 gallons purchased
o Inspector usually asked for 5 or 10 gallons
Part 4 Software 86
Linearization Attack
Program checks for
serial number
S123N456
For efficiency,
check made one
character at a time
Can attacker take
advantage of this?
Part 4 Software 87
Linearization Attack
Correct number takes longer than incorrect
Trudy tries all 1st characters
o Find that S takes longest
Then she guesses all 2nd characters: S
o Finds S1 takes longest
And so on…
Trudy can recover one character at a time!
o Same principle as used in lock picking
Part 4 Software 88
Linearization Attack
What is the advantage to attacking serial number one
character at a time?
Suppose serial number is 8 characters and each has 128
possible values
o Then 1288 = 256 possible serial numbers
o Attacker would guess the serial number in about 255 tries a lot
of work!
o Using the linearization attack, the work is about 8 (128/2) = 29
which is easy
Part 4 Software 89
Linearization Attack
A real-world linearization attack
TENEX, an ancient OS (timeshare)
o Passwords checked one character at a time
o Careful timing was not necessary, instead…
o …could arrange for a “page fault” when next
unknown character guessed correctly
o Page fault register was user accessible
This attack was very easy in practice
Part 4 Software 90
Time Bomb
In 1986 Donald Gene Burleson told employer
to stop withholding taxes from his paycheck
His company refused
He planned to sue his company
o He used company time to prepare legal docs
o Company found out and fired him
Burleson had been working on malware…
o After being fired, his software “time bomb”
deleted important company data
Part 4 Software 91
Time Bomb
Company was reluctant to pursue the case
o So Burleson sued company for back pay!
o Then the company finally sued Burleson
In 1988 Burleson fined $11,800
o Case took years to prosecute…
o Cost company many thousands of dollars…
o Resulted in a slap on the wrist for attacker
An early example of a computer crime cases
Many cases since follow a similar pattern
o That is, companies are reluctant to prosecute
Part 4 Software 92
Trusting Software
Can you ever trust software?
o See Reflections on Trusting Trust
Consider the following thought experiment
Suppose C compiler has a virus
o When compiling login program, virus creates
backdoor (account with known password)
o When recompiling the C compiler, virus
incorporates itself into new C compiler
Difficult to get rid of this virus!
Part 4 Software 93
Trusting Software
Suppose you notice something is wrong
So you start over from scratch
First, you recompile the C compiler
Then you recompile the OS
o Including login program…
o You have not gotten rid of the problem!
Real-world example
o Underhanded C Contest
o Write code that looks like it does something
innocent, but instead is “subtly evil”
Part 4 Software 94
Chapter 12:
Insecurity in Software
Every time I write about the impossibility of effectively protecting digital files
on a general-purpose computer, I get responses from people decrying the
death of copyright. “How will authors and artists get paid for their work?”
they ask me. Truth be told, I don’t know. I feel rather like the physicist
who just explained relativity to a group of would-be interstellar travelers,
only to be asked: “How do you expect us to get to the stars, then?”
I’m sorry, but I don't know that, either.
Bruce Schneier
So much time and so little to do! Strike that. Reverse it. Thank you.
Willy Wonka
Part 4 Software 95
Software Reverse
Engineering (SRE)
Part 4 Software 96
SRE
Software Reverse Engineering
o Also known as Reverse Code Engineering (RCE)
o Or simply “reversing”
Can be used for good...
o Understand malware
o Understand legacy code
…or not-so-good
o Remove usage restrictions from software
o Find and exploit flaws in software
o Cheat at games, etc.
Part 4 Software 97
SRE
We assume…
o Reverse engineer is an attacker
o Attacker only has exe (no source code)
o No bytecode (i.e., not Java, .Net, etc.)
Attacker might want to
o Understand the software
o Modify (“patch”) the software
SRE usually focused on Windows
o So we focus on Windows
Part 4 Software 98
SRE Tools
Disassembler
o Converts exe to assembly (as best it can)
o Cannot always disassemble 100% correctly
o In general, not possible to re-assemble
disassembly into working executable
Debugger
o Must step thru code to completely understand it
o Labor intensive lack of useful tools
Hex Editor
o To patch (modify) exe file
Process Monitor, VMware, etc.
Part 4 Software 99
Specific Tools
IDA Pro good disassembler/debugger
o Costs a few hundred dollars (free version exists)
o Converts binary to assembly (as best it can)
OllyDbg high-quality shareware debugger
o Includes a good disassembler
Hex editor to view/modify bits of exe
o UltraEdit is good freeware
o HIEW useful for patching exe
Process Monitor freeware
It works!
Can Trudy do “better”?
Part 4 Software 108
SRE Example
Again, IDA Pro disassembly
Assembly Hex
test eax,eax 85 C0 …
xor eax,eax 33 C0 …
serial.exe
serialPatch.exe
Save as serialPatch.exe
Part 4 Software 112
SRE Example
serial.exe
serialPatch.exe
MTBF = t/K
The good news: security improves with testing
The bad news: security only improves linearly
with testing!
Part 4 Software 137
Security and Testing
The “mean time between failures” is
approximately
MTBF = t/K
To have 1,000,000 hours between security
failures, must test 1,000,000 hours!