ch03 ProgramSecurity 2f
ch03 ProgramSecurity 2f
p 3
Program Security
Ch l P.
Charles P Pfleeger
Pfl & Sh
Sharii LLawrence Pfl
Pfleeger, SSecurity
i ini Computing,
C i
4th Ed., Pearson Education, 2007 1
y In this chapter
y Programming
P i errors with
i h security
i implications:
i li i bbuffer
ff overflows,
fl
incomplete access control
y Malicious
M li i code: d viruses,
i worms, TTrojan
j hhorses
y Program development controls against malicious code and
vulnerabilities:
l biliti software
ft engineering
i i principles
i i l andd practices
ti
y Controls to protect against program flaws in execution: operating
system
t supportt andd administrative
d i i t ti controlst l
2
g
3.1. Secure Programs
y Security implies some degree of trust that the program enforces
expectedd confidentiality,
fid i li iintegrity,i andd availability
il bili
y An assessment of security can also be influenced by someone's general
perspective
ti on software
ft quality
lit
y E.g., if your manager's idea of quality is conformance to
specifications,
ifi ti then
th she h might
i ht consider
id theth coded secure if it meets
t
security requirements, whether or not the requirements are
completel t or correct.t
8
y There are two reasons for this distressing situation.
1. PProgram controlsl apply
l at the
h level
l l off the
h individual
i di id l program andd
programmer.
2. Programming
P i andd software
ft engineering
i i ttechniques
hi change
h andd
evolve far more rapidly than do computer security techniques.
y Types of Flaws
y validation
lid i error (incomplete
(i l or iinconsistent):
i ) permission
i i checks
h k
y domain error: controlled access to data
y serialization
i li ti andd aliasing:
li i program flflow order
d
y inadequate identification and authentication: basis for
authorization
th i ti
y boundary condition violation: failure on first or last case
y other
th exploitable
l it bl logic
l i errors
10
g Errors
3.2. Nonmalicious Program
y Buffer Overflows
y A bbuffer
ff ((or array or string)
i ) iis a space iin which
hi h ddata can bbe hheld.
ld
y A buffer's capacity is finite.
11
y Now
N we execute
t th
the statement:
tt t
sample[10] = 'B';
13
14
15
y Security Implication
y Two
T bbuffer
ff overflow fl attacks k that
h are usedd frequently
f l
1. The attacker may replace code in the system space. By replacing a few
instructions right after returning from his or her own procedure,
procedure the
attacker regains control from the operating system, possibly with raised
privileges.
2. On the other hand, the attacker may make use of the stack pointer or the
return register. Subprocedure calls are handled with a stack, a data
structure in which the most recent item inserted is the next one removed
(last arrived, first served).
16
y An alternative style of buffer overflow occurs when parameter values
are passedd iinto a routine,
i especially
i ll when
h theh parameters are passedd
to a web server on the Internet. Parameters are passed in the URL line,
with
ith a syntax
t similar
i il tto
http://www.somesite.com/subpage/userinput.asp?
http://www somesite com/subpage/userinput asp?
parm1=(808)555-1212 &parm2=2009Jan17
The attacker might question what the server would do with a really
long telephone number, say, one with 500 or 1000 digits.
17
y Incomplete Mediation
y Consider
C id the h example
l
http://www.somesite.com/subpage/userinput.asp?
parm1=(808)555-1212 &parm2=2009Jan17
y What
Wh t would
ld happen
h if parm22 were submitted
b itt d as 1800Jan01?
1800J 01? Or
O
1800Feb30? Or 2048Min32? Or 1Aardvark2Many?
18
y Security Implication
y Consider
C id thishi example
l
http://www.things.com/order.asp?custID=101&part=555A&q
y=20&price =10&ship=boat&shipcost=5&total=205
19
20
y Time-of-Check to Time-of-Use Errors (Cont’d)
y Suppose
S a requestt tto access a fil
file were presented
t d as a ddata
t structure,
t t with ith th
the
name of the file and the mode of access presented in the structure.
y To carry out this authorization sequence, the access control mediator would
have to look up the file name in tables. The mediator could compare the
names ini the
th table
t bl to
t the
th fil
file name in
i the
th ddata
t structure
t t tto determine
d t i whether
h th
access is appropriate. More likely, the mediator would copy the file name
into its own local storage
g area and comparep from there
21
23
24
N b off malware
Number l signatures
i t
1800000
1600000
1400000
1200000
1000000
800000
600000
400000
200000
0
2002 2003 2004 2005 2006 2007 2008
Symantec report 2009
25
Al t 30 years off M
Almost Malware
l
26
y From Malware fighting malicious code
Attack Sophistication vs.
Intruder Technical Knowledge Auto
Coordinated
Cross site scripting Tools
“stealth” / advanced
High scanning techniques
sniffers distributed
attack tools
Intruder sweepers www attacks
Knowledge
automated probes/scans
GUI
back doors
disabling audits network mgmt. diagnostics
hijacking
burglaries sessions
Attack exploiting known vulnerabilities
Sophistication
password cracking
self-replicating code
password guessing
Intruders
Low
1980 1985 1990 1995 2004
27
28
y Kinds of Malicious Code (Cont’d)
y A Trojan
T j horse
h isi malicious
li i code
d that,
h iin addition
ddi i to iits primary
i
effect, has a second, nonobvious malicious effect
y A logic
l i bbombb isi a class
l off malicious
li i coded that
th t "detonates"
"d t t " or goes
off when a specified condition occurs.
y A time
ti bomb
b b isi a llogici bbombb whose
h trigger
t i isi a time
ti or ddate.
t
y A trapdoor or backdoor is a feature in a program by which
someone can access theth program other
th ththan bby th
the obvious,
b i di directt
call
29
30
y How Viruses Attach
y Appended
A d d Vi
Viruses
31
32
y How Viruses Attach (Cont’d)
y Integrated
I d Vi
Viruses andd Replacements
R l
33
34
y How Viruses Gain Control
35
36
y Homes for Viruses (Cont’d)
y Memory-Resident
M R id Viruses
Vi
y Other Homes for Viruses
y Application
A li ti programs
y Libraries
y Data files – need a startup
p program
p g
37
y Virus Signatures
y A signature
i – a telltale
ll l pattern
y E.g., signature for the Code Red
/default.ida?NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN %u9090%u6858%ucbd3
%u7801%u9090%u6858%ucdb3%u7801%u9090%u6858 %ucbd3%u7801%u9090
%u9090%u8190%u00c3%u0003%ub00%u531b%u53ff %u0078%u0000%u00=a
HTTP/1 0
HTTP/1.0
38
y Virus Signatures
y Storage
S Patterns
P - Most
M viruses
i attachh to programs that
h are storedd
on media such as disks. The attached virus piece is invariant, so the
start
t t off th
the virus
i code
d bbecomes a ddetectable
t t bl signature.
i t
39
y Virus Signatures
y Execution
E i Patterns
P - A virus
i writer
i may want a virus
i to do
d severall
things at the same time, namely, spread infection, avoid detection,
andd cause hharm.
y Transmission Patterns - A virus is effective only if it has some
means off transmission
t i i from
f one location
l ti to t another.
th
40
y Polymorphic Viruses
y A virus
i thath can change
h iits appearance
y Encrypting viruses
y Uses
U encryptionti underd various
i kkeys tto make
k the
th stored
t d form
f off th
the virus
i
different.
y Contain three distinct parts:
p
y a decryption key,
y the (encrypted) object code of the virus
y the (unencrypted) object code of the decryption routine.
41
42
y Prevention of Virus Infection (Cont’d)
y Several
S l techniques
hi ffor bbuilding
ildi a reasonably
bl safe
f community
i ffor
electronic contact, including the following:
y UUse only
l commerciali l software
ft acquired
i d from
f reliable,
li bl well-established
ll t bli h d
vendors.
y Test all new software
f on an isolated computer.
p
y Open attachments only when you know them to be safe
y Make a recoverable system image and store it safely.
y Make and retain backup copies of executable system files.
y Use virus detectors (often called virus scanners) regularly and update them
daily.
daily
43
g
3.4. Targeted Malicious Code
y Trapdoors - an undocumented entry point to a module
y Examples
E l
y A system is composed of modules or components.
y Programmers first test each small component of the system separate
from the other components, in a step called unit testing, to ensure that
the component works correctly by itself.
y Then, developers test components together during integration testing, to
see how they function as they send messages and data from one to the
other.
44
45
46
y Causes of Trapdoors
y forget
f to remove them
h
y intentionally leave them in the program for testing
y intentionally
i t ti ll leave
l them
th ini the
th program for
f maintenance
i t off the
th
finished program, or
y intentionally
i t ti ll leave
l them
th ini th
the program as a covertt means off
access to the component after it becomes an accepted part of a
production
d ti system t
47
y Salami Attack
y merges bi
bits off seemingly
i l iinconsequential
i l ddata to yield
i ld powerful
fl
results.
48
y Privilege Escalation - a means for malicious code to be launched by a
user with
i h lower
l privileges
i il but
b run with
i h hi
higher
h privileges.
i il
y Interface
I t f Ill Illusions
i - a spoofing
fi attack
tt k iin which
hi h allll or partt off a webb
page is false.
50
51
52
File Existence Channel Used to Signal
g 100
53
54
y Developmental Controls
y The
Th Nature
N off Software
S f Development
D l
y Collaborative effort, involving people with different skill sets who
combine
bi their
th i expertise
ti tto produce
d a workingki product
d t
y Development requires people who can specify, design,
i l
implement, t test,
t t review,
i document,
d t manage, maintain
i t i the
th
system.
55
56
y Developmental Controls (Cont’d)
y Modularization
M d l i i isi the
h process off dividing
di idi a taskk into
i subtasks.
b k
57
58
y Developmental Controls (Cont’d)
y Modularization
M d l i i
y Several advantages to having small, independent components.
y Maintenance.
Maintenance If a component implements a single function,
function it can be
replaced easily with a revised one if necessary.
y Understandability
y Reuse
y Correctness
y Testing.
59
60
y Developmental Controls (Cont’d)
y Encapsulation
E l i
y Encapsulation hides a component's implementation details, but it does not
necessarily mean complete isolation
y Berard [BER00] notes that encapsulation is the "technique for packaging the
information [inside a component] in such a way as to hide what should be
hidden and make visible what is intended to be visible.“
61
62
y Developmental Controls (Cont’d)
y Information
I f i Hiding
Hidi (Cont’d)
(C ’d)
63
64
y Developmental Controls (Cont’d)
y Confinement
C fi
y A confined program is strictly limited in what system resources it can access.
If a program is not trustworthy,
trustworthy the data it can access are strictly limited
limited.
y Genetic Diversity
y Tight
g integration
g of products
p is a concern.
y A vulnerability in one of these can also affect the others.
y Fixing a vulnerability in one can have an impact on the others.
65
67
68
y Developmental Controls (Cont’d)
y Peer
P review
i (C(Cont’d)
’d)
F lt Discovery
Fault Di RRate
t RReported
t d att Hewlett-Packard
H l tt P k d
69
70
y Developmental Controls (Cont’d)
y Hazard
H d analysis l i
y A set of systematic techniques intended to expose potentially hazardous
system states.
states
y Usually involves developing hazard lists, as well as procedures for exploring
"what if" scenarios to trigger consideration of nonobvious hazards.
y A variety of techniques support the identification and management of
potential hazards. Among the most effective are
y Hazard and operability studies (HAZOP)
y Failure modes and effects analysis (FMEA)
y Fault tree analysis (FTA)
71
Deductive analysis,
Description of system
Known effect including fault tree
behavior
analysis
y
Inductive analysis,
Exploratory analysis,
Exploratory analysis
Unknown including failure modes
including hazard and
effect and effects analysis
operability
studies
72
y Developmental Controls (Cont’d)
y Testing
T i
y A process activity that homes in on product quality: making the product
failure free or failure tolerant.
tolerant
73
74
y Developmental Controls (Cont’d)
y Testing
T i (C (Cont’d)
’d)
y Usually involves several stages. (Cont’d)
y A function test evaluates the system to determine whether the functions
described by the requirements specification are actually performed by
the integrated system.
y A performance test compares the system with the remainder of these
software and hardware requirements.
y An acceptance test, in which the system is checked against the
customer's requirements description.
75
76
y Developmental Controls (Cont’d)
y Testing
T i (C (Cont’d)
’d)
y Each of the types of tests listed here can be performed from two
perspectives
y Black-box testing treats a system or its components as black boxes;
testers cannot "see inside" the system
y Clear-box testing (a.k.a. white box). - testers can examine the design and
code directly, generating test cases based on the code's actual
construction
77
79
81
82
y Developmental Controls (Cont’d)
y Static
S i Analysis
A l i - examine
i its
i design
d i andd code
d to llocate andd repairi
security flaws before a system is up and running
y severall aspects
t off th
the ddesign
i andd code:
d
y control flow structure - the sequence in which instructions are executed,
including iterations and loops.
loops
y data flow structure - follows the trail of a data item as it is accessed and
modified by the system
y data structure - the way in which the data are organized, independent of
the system itself.
83
84
y Developmental Controls (Cont’d)
y Configuration
C fi i Management
M (Cont’d)
(C ’d)
y Four activities are involved in configuration management:
y configuration identification
y configuration control and change management
y configuration auditing
y status accounting
85
86
y Developmental Controls (Cont’d)
y Configuration
C fi i Management
M (Cont’d)
(C ’d)
y Configuration control and configuration management - ensure we can
coordinate separate,
separate related versions
versions.
y Three ways to control the changes
y Separate files - have different files for each release or version.
y Delta - designate a particular version as the main version of a system
and then define other versions in terms of what is different.
y Conditional compilation, whereby a single code component
addresses all versions , relying on the compiler to determine which
statements to apply to which versions.
versions
87
88
y Developmental Controls (Cont’d)
y Configuration
C fi i Management
M (Cont’d)
(C ’d)
y All activities are performed by a configuration and change control board,
or CCB.
CCB
y The CCB contains representatives from all organizations with a vested
interest in the system
y The board reviews all proposed changes and approves changes based on
need, design integrity, future plans for the software, cost, and more.
89
90
y Developmental Controls (Cont’d)
y Proofs
P f off PProgram Correctness
C
y Proving program correctness is hindered by several factors.
y Correctness proofs depend on a programmer or logician to translate a
program's statements into logical implications.
y Deriving the correctness proof from the initial assertions and the
implications of statements is difficult, and the logical engine to generate
proofs runs slowly.
y The current state of program verification is less well developed than code
production.
91