Software Security. Bugs Most software has bugs Some bugs cause security vulnerabilities Incorrect processing of security related data Incorrect processing.

Slides:



Advertisements
Similar presentations
Cross-Site Scripting Issues and Defenses Ed Skoudis Predictive Systems © 2002, Predictive Systems.
Advertisements

Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
CSc 352 Programming Hygiene Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
©2009 Justin C. Klein Keane PHP Code Auditing Session 5 XSS & XSRF Justin C. Klein Keane
By Philipp Vogt, Florian Nentwich, Nenad Jovanovic, Engin Kirda, Christopher Kruegel, and Giovanni Vigna Network and Distributed System Security(NDSS ‘07)
Cross Site Scripting a.k.a. XSS Szymon Siewior. Disclaimer Everything that will be shown, was created for strictly educational purposes. You may reuse.
Breno de MedeirosFlorida State University Fall 2005 Buffer overflow and stack smashing attacks Principles of application software security.
1 CHAPTER 8 BUFFER OVERFLOW. 2 Introduction One of the more advanced attack techniques is the buffer overflow attack Buffer Overflows occurs when software.
CMSC 414 Computer and Network Security Lecture 24 Jonathan Katz.
By Brian Vees.  SQL Injection  Username Enumeration  Cross Site Scripting (XSS)  Remote Code Execution  String Formatting Vulnerabilities.
Stack buffer overflow
Teaching Buffer Overflow Ken Williams NC A&T State University.
Beyond Stack Smashing: Recent Advances in Exploiting Buffer Overruns Jonathan Pincus Microsoft Research Brandon Baker Microsoft Carl Hartung CSCI 7143:
Teaching Buffer Overflow Ken Williams NC A&T State University.
Control hijacking attacks Attacker’s goal: – Take over target machine (e.g. web server) Execute arbitrary code on target by hijacking application control.
Exploits: XSS, SQLI, Buffer Overflow
Lecture 16 Page 1 CS 236 Online Cross-Site Scripting XSS Many sites allow users to upload information –Blogs, photo sharing, Facebook, etc. –Which gets.
Introduction to InfoSec – Recitation 10 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
University of Washington CSE 351 : The Hardware/Software Interface Section 5 Structs as parameters, buffer overflows, and lab 3.
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
Prevent Cross-Site Scripting (XSS) attack
Web Application Access to Databases. Logistics Test 2: May 1 st (24 hours) Extra office hours: Friday 2:30 – 4:00 pm Tuesday May 5 th – you can review.
Lecture 0 Appendix on Implementation Threats Material from Warren Page & Chpt 11, Information Security by Mark Stamp.
Exploiting Buffer Overflows on AIX/PowerPC HP-UX/PA-RISC Solaris/SPARC.
Computer Security and Penetration Testing
BLENDED ATTACKS EXPLOITS, VULNERABILITIES AND BUFFER-OVERFLOW TECHNIQUES IN COMPUTER VIRUSES By: Eric Chien and Peter Szor Presented by: Jesus Morales.
Mitigation of Buffer Overflow Attacks
CIS 450 – Network Security Chapter 7 – Buffer Overflow Attacks.
Security Scanners Mark Shtern. Popular attack targets Web – Web platform – Web application Windows OS Mac OS Linux OS Smartphone.
Top Five Web Application Vulnerabilities Vebjørn Moen Selmersenteret/NoWires.org Norsk Kryptoseminar Trondheim
Website Development with PHP and MySQL Saving Data.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Security Attacks CS 795. Buffer Overflow Problem Buffer overflows can be triggered by inputs that are designed to execute code, or alter the way the program.
Buffer Overflow Attack-proofing by Transforming Code Binary Gopal Gupta Parag Doshi, R. Reghuramalingam The University of Texas at Dallas 11/15/2004.
Crash Course in Web Hacking
Module 2 – User Safety Privacy Attacks on end users Browser vulnerabilities.
Chapter-4 Software Security Why Software?  Why is software as important to security as crypto, access control and protocols?  Virtually all of information.
Buffer Overflow Proofing of Code Binaries By Ramya Reguramalingam Graduate Student, Computer Science Advisor: Dr. Gopal Gupta.
What is exactly Exploit writing?  Writing a piece of code which is capable of exploit the vulnerability in the target software.
Presented By: Chandra Kollipara. Cross-Site Scripting: Cross-Site Scripting attacks are a type of injection problem, in which malicious scripts are injected.
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
CNIT 127: Exploit Development Ch 8: Windows Overflows Part 2.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Buffer overflow and stack smashing attacks Principles of application software security.
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
Sairajiv Burugapalli. This chapter covers three main categories of classic software vulnerability: Buffer overflows Integer vulnerabilities Format string.
Information Security - 2. A Stack Frame. Pushed to stack on function CALL The return address is copied to the CPU Instruction Pointer when the function.
Slides by Kent Seamons and Tim van der Horst Last Updated: Nov 11, 2011.
VM: Chapter 7 Buffer Overflows. csci5233 computer security & integrity (VM: Ch. 7) 2 Outline Impact of buffer overflows What is a buffer overflow? Types.
Beyond Stack Smashing: Recent Advances In Exploiting Buffer Overruns Jonathan Pincus and Brandon Baker Microsoft Researchers IEEE Security and.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Web Security (cont.) 1. Referral issues r HTTP referer (originally referrer) – HTTP header that designates calling resource  Page on which a link is.
Content Coverity Static Analysis Use cases of Coverity Examples
Object Lifetime and Pointers
Mitigation against Buffer Overflow Attacks
Introduction to Operating Systems
Protecting Memory What is there to protect in memory?
Section 6.3 Server-side Scripting
World Wide Web policy.
Protecting Memory What is there to protect in memory?
Static Detection of Cross-Site Scripting Vulnerabilities
Protecting Memory What is there to protect in memory?
PHP / MySQL Introduction
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Software Security Lesson Introduction
CS5123 Software Validation and Quality Assurance
Cross-Site Scripting Issues and Defenses Ed Skoudis Predictive Systems
System and Cyber Security
Presentation transcript:

Software Security

Bugs Most software has bugs Some bugs cause security vulnerabilities Incorrect processing of security related data Incorrect processing of input allowing an attacker to –Read data –Write data –Execute programs

Example 1 int main (int argc, char *argv[]) {char password_ok = 0; if (strcmp(password,"bgu_cse")==0) password_ok=1; else password_ok=1; if (password_ok==1) {...} }

Example 2 int main (i) {int j; char tmp; char password_ok = 0; const char *password = “bgu_cse”; for (j=0; j<7; j++) { tmp = receive_next_password_char(); if (tmp != password[j]) { send (error_message); return password_ok; } password_ok=1; if (password_ok==1) {...} }

Example 3 int main (int argc, char *argv[]) {char password_ok; char password[8]; password_ok = 0; strcpy (password,argv[1]); if (strcmp(password,"bgu_cse")==0) password_ok=1; if (password_ok==1) {...} }

Buffer Overflow Up to 2005 the most common security hole The length of an input buffer is not checked Arbitrary data is appended to legal input Data can be written to memory More importantly: program flow control can be hijacked by attacker Examples: Microsoft IIS version 5.0 (see Blaster vulnerability.

Buffer Overflow stages Send user-controlled data that overflows buffer Include an overflow of a flow-control memory location Use new code –The code can be supplied by the attacker –The code can already exist as part of the attacked software –Injected code is written in machine code to be executed

Buffer Overflow on Stack Local Variables Return Address Parameters Stack Single function memory Stack growth String growth

Function pointers The C language has pointers to functions void (* Pfunc) () declares a variable that points to a function that returns void Function pointers are used when different functions are called according to input/changing state etc. An overflowing buffer next to a function pointer can cause similar problems to stack smashing

Counter Measures Language level –Languages/Libraries that check buffer limits –No buffer overflows in Java or C# –Exchange “unsafe” standard functions with safe counterparts –Block return address overwrite Source code level Compilation level – –Bounds checking at compiler level –Separate stack for return addresses –Canary values between locals and return addresses

Counter Measures (cont.) Operating system level: –Non-executable stack (NX bit) –Mapping standard functions to addresses beginning with 0x00 –First measure does not block arbitrary calls to program functions.

Overflow and pointers void func1 (char *external) { int a, *b; char*array; … strcpy (array, external); … *b = a; } a b array overflow PC Stored execution pointer Exploit code

Stages of pointer based overflow Send user-controlled data that overflows buffer Include exploit code in the overflow Carefully set values of variables a and b When program runs *b=a instruction, the stored pointer for execution that b points to is changed to beginning of exploit code Program execution jumps to exploit code

Heap overflow A program stores data in three places –Data segment for static variables –Stack segments for a function’s local variables –Heap for dynamically allocated memory Memory in heap allocated by instructions such as malloc or new Buffer overflow in heap allows “pointer based” exploit Heap operation depends on platform

Heap A program performs two operations with dynamic memory –It allocates memory –It frees allocated memory The heap manages memory Fragmentation of memory blocks – one of the main problems of managing dynamic memory Solution – merge free blocks together when possible

Example: heap as linked list Heap consists of doubly linked list of memory blocks Each block –Previous pointer –Next pointer –Size – number of words –Used flag – 0 if the block is free and 1 if it’s used

Example: Initialization Null NextPrevSizeUsed

Example: allocation of block Null9920 NextPrevSizeUsed 1 Data 4Null

Data 4Null 1 Data 4 Example: another allocation NextPrevSizeUsed heap heap  next heap  next  next

Null Data 4Null 0 Data 4 Example: free a block NextPrevSizeUsed ptr  next  next  prev= ptr  next  prev ptr  next= ptr  next  next ptr ptr  next 1 Data 4

Null Data 4Null 0 Data 12 Example: free a block NextPrevSizeUsed ptr  next  next  prev= ptr  next  prev ptr  next= ptr  next  next ptr ptr  next

Null Data 4Null 0 Data 4 Exploit: heap overflow NextPrevSizeUsed ptr  next  next  prev= ptr  next  prev ptr  next= ptr  next  next ptr ptr  next 1 Data 4 Pointer to Exploit code Pointer to Execution address Overflow

Cross Site Scripting

HTTP Basic function –A web client requests a page –Requests are identified by URL –A web server serves the page In this basic scheme, content is dull Enhancements –Client supplies data to web application (server) –Server returns answers as function of data –Client executes local scripts

Client side scripts Javascript Active-X VBscript Executing scripts is essential for most web applications, e.g. gmail Client allows remote entity (server) to run software (script) on client machine The scripts are therefore limited to browser context: passwords, cookies etc.

Cross site The client allows a trusted server (e.g. gmail) to invoke a script When surfing to another site, that site can’t run scripts that use the trusted site’s data (e.g. password). Cross site scripting: attacker runs a script as if it came from the trusted site. Google ads on different sites learn user preferences and serve appropriate ads

Example

Example – source HTML

Cross Site Scripting Attack (XSS) Web server is vulnerable to attack –Sends scripts to client –Doesn’t check source or content of script –Example – echoing client URL back to the client without checking –Example – serving content provided by an attacker (e.g. forum) Client is target of attack –Executes script

XSS – what is at stake? Script can read any data in the web site’s context –Cookies –Passwords –Keystrokes Script can pass this data to attacker –Directly in URL –Indirectly by opening a side channel (e.g. loading one out of a pair of pictures to signisl a bit 0 or 1)

XSS-Attack: Reflected Attack Click on this great link attack code 1. Attacker sends malicious code 2. Client user sends code (unwittingly) to server 3. Server reflects code to client 4. Browser executes script attack code attack code Attacker Client Web Server !!! attack code !!! Source: Eurosec project

XSS-Attack: Stored Attack Post Forum Message: Subject: GET Money for FREE !!! Body: attack code 1. Attacker sends malicious code 2. Server stores message Did you know this? User requests message 4. Message is delivered by server 5. Browser executes script in message GET Money for FREE !!! attack code Get /forum.jsp?fid=122&mid=2241 Attacker Client Web Server GET Money for FREE !!! attack code !!! attack code !!! Re: Error message on startup..... I found a solution!..... Can anybody help?..... Error message on startup..... Source: Eurosec project

Where script is executed... Source: [IE] & [code] [N4] &{[code]}; [N4] [IE] [N4] [code] "> <meta http-equiv="refresh" content="0;url=javascript:[code]"> <div style="background-image: url(javascript:[code]);"> [IE] [Mozilla] [IE] [N4] [code] [IE] <object classid="clsid:..." codebase="javascript:[code]"> [code]//--> [code] " onmouseover="[code]"> <script>[code]</script>; <div datafld="b" dataformatas="html" datasrc="#X"> [UTF-8; IE, Opera] [\xC0][\xBC]script>[code][\xC0][\xBC]/script>

Countermeasures - Server Fairly easy –Canonicalization of user supplied data (Unicode and other translations are turned into canonical representation) –Do not reflect scripts –Do not store scripts –Check all data, including hidden HTTP fields: referrer, method etc. Harder (site wishes to serve user supplied scripts) –Check that user supplied data does no harm –How exactly?

Countermeasures - Client Easy –Canonicalization of server data –Block all scripts Effect – very boring surfing experience Tainting objects –Do not send sensitive data (e.g. cookies) to any site other than original site –Do not send any data changed (“tainted”) by sensitive data Limitations –Some data, such as keystrokes is difficult to classify –Indirect information passing, such as the picture method may bypass such measures. –Performance hit