Program Security Final
Program Security Final
Security
Objective 2
s
To learn the concept of secure programming
Programming errors with security implications: buffer
overflows, incomplete access control
Malicious code: viruses, worms, Trojan horses
Controls against malicious code and vulnerabilities
Controls against program flaws in execution
Lets start 3
with
Why we need security at the program level?
Because programs constitute most to a computing system
and Protecting programs is the heart of computer security.
All kinds of programs, from apps via OS, DBMS,
networks
Issues:
1. How do we keep programs free from flaws?
2. How do we protect computing resources against programs
that contain flaws?
Secure 4
programs
Security implies some degree of trust that the program
enforces expected confidentiality, integrity, and availability.
What is “Program security?”
Depends on who you ask
user - fit for his task
programmer - passes all “his/her” tests
manager - conformance to all specs
Fault tolerance terminology: 5
Bug – mistake in interpreting a requirement, syntax
error
Error – human made mistake , may lead to a fault
Fault – misinterpreted requirements may lead to
several faults in the coding and testing phases
Failure - system malfunction caused by fault, can
be discovered before or after system delivery
Note:
Faults- seen by “insiders” (e.g., programmers)
Failures - seen by “outsiders” (e.g., independent
testers, users)
Error/fault/failure example:
Programmer’s indexing error, leads to buffer
overflow fault
Buffer overflow fault causes system crash (a failure)
Fixing 6
faults
Software that has many faults early on is likely to have many
others still waiting to be found.
Earlier paradigm to judge s/w security: penetrate and patch
Red Team /Tiger Team tries to crack s/w
If software withstands the attack => security is good
We look at three such classic error types and explain why they
are
relevant to security and how can they be prevented.
Buffer 1
overflows 2
sample[10]=‘B’;
// out of bounds error, compiler detects this during compilation.
Now, what if we do
sample[i]=‘B’;
Subroutine finishes
Buffer for char sample[10] is de-allocated
Stack: [A][data][data][...]
RET operation pops B from stack (considers it ret.
addr)
Stack: [data][data][...]
Pgm (which called the subroutine) jumps to B
=> shifts program control to where attacker
wanted
Buffer 1
overflows 9
(Source:
Wikipedia)
Buffer overflows- security 2
implication 0
Even if the flaw came from a honest mistake, the flaw can still
cause
great harm. A malicious attacker can exploit these flaws.
Buffer overflows- security 2
implication 1
Consider:
http://www.somesite.com/subpage/userinput.asp?param1=(808)55
5-
1212¶m2=2009Jan17
Prevention:
Be aware of time lags
Use digital signatures and
certificates to “lock” data values
after checking them
So nobody can modify
TOCTTOU prevention in 2
DBMS 7
Document virus
Spreads via picture, document, spreadsheet,
slide presentation, database, ...
E.g., via .jpg, via MS Office documents .doc, .xls, .ppt
etc.
Kinds of viruses- based on their way 3
of attaching 6
1. Appended Viruses
Appends to program. Often virus code precedes the program code
execution by running its code before the 1st program instruction in exec
file.
Executes whenever program gets executed.
Virus Virus
Code
Code
Original
Original
progra
m progra
m
2. Surrounding viruses 3
Surrounds program
Executes before and after infected program 7
Intercepts its input/output
Erases its tracks
The “after” part might be used to mask virus
existence.
Virus
Code(part a)
Original
progra
m
Virus
Code(part b)
3. Integrating and replacing
3
Integrates into pgm code viruses
Spread within infected pgms
8
(Replacing) virus V gains control over target pgm T by:
Overwriting T on hard disk
OR
Changing pointer to T with pointer to V
OS has File Directory
File Directory has an entry that points to file with code for T
Virus replaces pointer to T’s file with pointer to V’s file
In both cases actions of V replace actions of T when user executes
what she thinks is “T”
Hard to detect
Not easily destroyed or
deactivated
Spreads infection widely
Can re-infect programs
Easy to create
Machine and OS independent
Homes for 4
viruses 1
Ex: if a virus writer has 100 bytes of code and 50 bytes of data;
there
can be ‘n’ arrangements of this code using several jump statements.
Prevention of virus 5
infection 2
Do not receive executable code from an unknown source.
But today, non executable file can have executable code,
like macro’s in docs.
Hidden extension types are another problem, which deceives
the user with a fake format.
Hiding and making the files as read-only will not prevent the
attacks of virus.
Some prevention steps possible are:
Prevention of virus 5
infection 3
1. Use only commercial software acquired from reliable and
well established sources/vendors.
2. Use all new software on an isolated computer.
3. Open attachments only when you know them to be safe.
4. Make a recoverable system image and store it safely
5. Make and retain backup copies of executable system files.
6. Use virus detectors/scanners regularly and update them
frequently with latest virus definitions.
Truths and misconceptions about
5
viruses 4
1. Viruses can infect only Microsoft Windows systems.
2. Viruses can modify “hidden” and “read-only” files.
3. Viruses can appear only in data files, or only in word
documents, or only in programs.
4. Viruses spread only on disk or only through emails.
5. Viruses cannot remain in memory after a complete shutdown or
on reboot.
6. Viruses cannot infect hardware.
7. Viruses can be malevolent, benign or benevolent.
First example of malicious 5
code: 5
Brain Virus
It changes the label of any disk it attacked to the word “BRAIN”.
What is does?
First locates itself in the upper memory
Executes system call to reset the upper memory bound below itself.
(do not disturb mode)
Traps interrupt number 19 (disk read) by resetting the interrupt
address table to point to it and then sets the address for interrupt
number 6 (un- used) to the former address of the interrupt 19.
Virus screens the disk read calls, that would read the boot sector.
It will allow all the other disk calls through the interrupt 6.
Brain 5
6
virus
How it spreads?
Brain virus settles in the boot sector along with other 6 sectors.
One of the 6 sectors contain he actual boot code.
While 2 others contain the parts of the virus code.
Rest 3 sectors contain the duplicate of the others.
Virus marks these 6 sectors as “faulty”, so that OS will not use
them.
Sitting in the memory, this virus will intercept all the disk reads to
boot sector, and verifies the 5th and 6th bytes for its signature.
If signature found: already infected, if not found: infect them.
What did we learn from Brain 5
virus? 7
Uses standard tricks like hiding the virus in the boot sector,
intercepting and screening the interrupts.
This virus just infects every device that tries performing a disk
read. It doesn’t have any other effect than passing its infection.
This has served as a prototype for the viruses later.
Many extensions to this has come ex: Lehigh virus that swept
across all the systems in Lehigh University.
Internet 5
Worm 8
Morris, a jr college student from Cornell university programmed
the
internet worm to accomplish three objectives:
1. Determine where it could spread to
2. Spread its infection
3. Remain undiscovered and undiscoverable