+ All Categories
Home > Documents > Su 2 Software

Su 2 Software

Date post: 21-Jul-2016
Category:
Upload: karthickamsec
View: 217 times
Download: 0 times
Share this document with a friend
25
Software Vulnerabilities
Transcript
Page 1: Su 2 Software

Software

Vulnerabilities

Page 2: Su 2 Software

“ There are two things I am sure after all these years: there is a growing societal need for high assurance software, and market forces are never going to provide it”

- Earl Boebert

Page 3: Su 2 Software

* Attacks that exploit software vulnerabilities

• Buffer Overflow • Cross-site scripting • SQL Injection • Format String . . .

What about phishing?What about malware attacks?

Page 4: Su 2 Software

* Buffer Overflow (BOF)

• The BOF vulnerability is one of the oldest and, by far, the most common of software vulnerabilities.

• As early as 1988, the Morris worm was one of the first to exploit this vulnerability.

• Since then, many creative ways of converting such a vulnerability into an exploit have been devised.

Page 5: Su 2 Software

* Buffer Overflow (BOF) contd.• A buffer overflow (BOF) occurs when the space allocated to a

variable (typically an array or string variable) is insufficient to accommodate the variable in its entirety.

• For example, a certain amount of buffer space is allocated for an array. If array bounds are not checked while populating it, the array may overflow into contiguous memory and corrupt it.

• Interestingly, this could cause an attacker to subvert the normal flow of a program. Malicious code supplied by the attacker in the buffer could be executed.

Page 6: Su 2 Software

* Buffer Overflow (BOF) contd.

To understand Buffer Overflow, we need to understand:

– The Virtual Memory map of the machine– Subroutine calling conventions– Organization of the Program Stack

Page 7: Su 2 Software

* Subroutine Call and Program Stack

int A( ) void B(int k ){ { B(5); char buffer[100]; return 0; int j = 3+k;} printf( “ Enter name: ” ); gets(buffer); printf(“ Hello %s ”,

buffer); return;

}

Page 8: Su 2 Software

* Subroutine Call and Program Stack

Page 9: Su 2 Software

* What’s passed on the program stack

When A calls B, the following are allocated or loaded on the stack:

– The arguments (parameters) used while calling B– A’s return address, i.e., the address at which A resumes on

completion of B– A copy of A’s Frame Pointer – The local or automatic variables of B.

(In this case, the local variable, buffer, is declared to be an array of 100 characters. So 100 bytes have been allocated on the stack for buffer.)

Page 10: Su 2 Software

* Exploiting Stack Overflows• Provide input to a buffer on the stack which includes

malicious code (often called shellcode)

• Overflow the buffer so that the return address to the calling program is overwritten with the address of the malicious code

• That way, when the called function terminates, it will not return to the calling program. Instead, the malicious code will be executed

Page 11: Su 2 Software

* Exploiting Stack Overflows (contd.)

• Another exploit is the Return-into-LibC exploit

• Here malicious code is not placed on the stack. Instead, this exploit makes a call to the C library function, system( ) with parameter “/bin/sh” as below

system(“/bin/sh”)

• This library function spawns a shell through which the attacker can enter various commands

Page 12: Su 2 Software

* Buffer Overflow Defences

There are many defences against BOF.

– Make the stack non-executable. This prevents malicious code on the stack from being executed. However, exploits like return into LibC are still possible

– Compiler-based option: Place a “canary variable” on the stack between the local variables and the return address. If a BOF modifies the return address, the canary will be corrupted. This will be detected by the compiler and the program will be aborted.

Page 13: Su 2 Software

Related Attacks

• Heap Overflow: A program’s dynamically allocated variable are stored on the heap. Buffers in this area may also be overflown leading to Heap buffer overflow attacks.

• Format String Attacks: C language printf( ), for example, uses a format string as function parameter. An attacker may pass a malicious string as input parameter enabling the attacker to read or write arbitrary locations in memory.

Page 14: Su 2 Software

* Cross-site Scripting Attacks• A web site is said to have a cross-site scripting vulnerability if

it inadvertently includes malicious scripts crafted by an attacker in pages returned by it

• For example,<SCRIPT> Malicious Code </SCRIPT>

• The malicious code may, for example, read browser cookies on the victim’s machine and ship these off to an attacker’s web server

Page 15: Su 2 Software

* Persistent XSS Attack• The malicious code (scripts) on a web page is saved on the

web server

• When an innocent user downloads the web page, the malicious scripts execute on that user’s browser

• Example: Users update their profile on a social networking site. These profiles may be read (downloaded) by other users through their browsers

Page 16: Su 2 Software

* Non-persistent XSS Attack• Exploits the fact that some servers echo back certain user

input back to the client without validating it

• For example, a user may be asked for personal details in an HTML form. Suppose he enters his name as “Prashant”. The server then responds with “Hello Prashant”

• Note that the server has echoed back his name

• Now, what would happen if, instead of Prashant, the user enters

<SCRIPT>alert(‘Fire!’)</SCRIPT>

Page 17: Su 2 Software
Page 18: Su 2 Software
Page 19: Su 2 Software
Page 20: Su 2 Software
Page 21: Su 2 Software

* Overcoming XSS• Validate and filter all user input. (Should this be done at the

client or server?)

• One strategy is to make a blacklist of all user input that should be filtered out. For example, single/double quotes, angular brackets, etc. should not appear in an e-mail address input from the user.

• A better solution in most cases is the equivalent of a whitelist approach - specify precisely what user input is expected. This is often accomplished by the use of a regular expression.

Page 22: Su 2 Software

* SQL Injection (Background)• Form parameters may be passed as a query string in

an extended URL to the server as inwww.iitb.ac.in?s_ID=0893571&passwd=4ep*NdF

• The server application retrieves the form parameters and uses them to build an SQL query such as

select s_ID, gpafrom students09where s_ID = 08935710 and passwd = ‘4ep*NdF’

Page 23: Su 2 Software

* Constructing an SQL query directly from user input (Example 1)

select s_ID, gpafrom students09where s_ID = 123 and passwd = ‘abc’ or ‘x’ = ‘x’

Page 24: Su 2 Software

* Constructing an SQL query directly from user input (Example 2)

select s_ID, gpafrom students09where s_ID = 123 or 1=1 - - and passwd = ‘ abc ’

Page 25: Su 2 Software

* Constructing an SQL query directly from user input (Example 3)

select s_ID, gpafrom students09where s_ID = 123; DROP TABLE students09; - - and

passwd = ‘ abc ’


Recommended