Finding Security Violations by Using Precise Source- level Analysis by V.Benjamin Livshits and Monica Lam {livshits, SUIF Group CSL,

Slides:



Advertisements
Similar presentations
Static Analysis for Security
Advertisements

Buffer Overflows Nick Feamster CS 6262 Spring 2009 (credit to Vitaly S. from UT for slides)
Smashing the Stack for Fun and Profit
P3 / 2004 Register Allocation. Kostis Sagonas 2 Spring 2004 Outline What is register allocation Webs Interference Graphs Graph coloring Spilling Live-Range.
Automatic Memory Management Noam Rinetzky Schreiber 123A /seminar/seminar1415a.html.
Integrity & Malware Dan Fleck CS469 Security Engineering Some of the slides are modified with permission from Quan Jia. Coming up: Integrity – Who Cares?
Exploring Security Vulnerabilities by Exploiting Buffer Overflow using the MIPS ISA Andrew T. Phillips Jack S. E. Tan Department of Computer Science University.
Register Allocation CS 671 March 27, CS 671 – Spring Register Allocation - Motivation Consider adding two numbers together: Advantages: Fewer.
SPLINT STATIC CHECKING TOOL Sripriya Subramanian 10/29/2002.
CSc 352 Programming Hygiene Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Computer Security: Principles and Practice EECS710: Information Security Professor Hossein Saiedian Fall 2014 Chapter 10: Buffer Overflow.
Computer Security: Principles and Practice First Edition by William Stallings and Lawrie Brown Lecture slides by Lawrie Brown Chapter 11 – Buffer Overflow.
Lecture 16 Buffer Overflow modified from slides of Lawrie Brown.
Prof. Necula CS 164 Lecture 141 Run-time Environments Lecture 8.
Using Programmer-Written Compiler Extensions to Catch Security Holes Authors: Ken Ashcraft and Dawson Engler Presented by : Hong Chen CS590F 2/7/2007.
Stack-Based Buffer Overflows Attacker – Can take over a system remotely across a network. local malicious users – To elevate their privileges and gain.
Finding Security Errors in Java Applications Using Lightweight Static Analysis Benjamin Livshits Computer Science Lab Stanford University.
Gabe Kanzelmeyer CS 450 4/14/10.  What is buffer overflow?  How memory is processed and the stack  The threat  Stack overrun attack  Dangers  Prevention.
CS 536 Spring Run-time organization Lecture 19.
Security Protection and Checking in Embedded System Integration Against Buffer Overflow Attacks Zili Shao, Chun Xue, Qingfeng Zhuge, Edwin H.-M. Sha International.
ReferencesReferences DiscussionDiscussion Vulnerability Example: SQL injection Auditing Tool for Eclipse LAPSE: a Security Auditing Tool for Eclipse IntroductionIntroductionResultsResults.
4/30/2008Prof. Hilfinger CS 164 Lecture 391 Language Security Lecture 39 (from notes by G. Necula)
1 Static Analysis for Bug Finding Benjamin Livshits.
“Tracking Pointers with Path and Context Sensitivity for Bug Detection in C Programs” CMSC 838Z – Spring 2004 V. Benjamin Livshits and Monica S. Lam presented.
Run time vs. Compile time
Finding the Weakest Characterization of Erroneous Inputs Dzintars Avots and Benjamin Livshits.
Netprog: Buffer Overflow1 Buffer Overflow Exploits Taken shamelessly from: netprog/overflow.ppt.
Tracking Pointers with Path and Context Sensitivity for Bug Detection in C Programs by V.Benjamin Livshits and Monica S. Lam {livshits,
Control hijacking attacks Attacker’s goal: – Take over target machine (e.g. web server) Execute arbitrary code on target by hijacking application control.
Buffer Overflow Attacks. Memory plays a key part in many computer system functions. It’s a critical component to many internal operations. From mother.
Statically Detecting Likely Buffer Overflow Vulnerabilities David Larochelle David Evans University of Virginia Department of Computer Science Supported.
Address Obfuscation: An Efficient Approach to Combat a Broad Range of Memory Error Exploits Sandeep Bhatkar, Daniel C. DuVarney, and R. Sekar Stony Brook.
Static Analysis for Security Amir Bazine Per Rehnberg.
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
Buffer overflows.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2011.
Chapter 6 Buffer Overflow. Buffer Overflow occurs when the program overwrites data outside the bounds of allocated memory It was one of the first exploited.
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.
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
Runtime Environments Compiler Construction Chapter 7.
Computer Science Detecting Memory Access Errors via Illegal Write Monitoring Ongoing Research by Emre Can Sezer.
Mitigation of Buffer Overflow Attacks
Cohesion and Coupling CS 4311
Overflow Examples 01/13/2012. ACKNOWLEDGEMENTS These slides where compiled from the Malware and Software Vulnerabilities class taught by Dr Cliff Zou.
Buffer Overflow Proofing of Code Binaries By Ramya Reguramalingam Graduate Student, Computer Science Advisor: Dr. Gopal Gupta.
Buffer Overflow Attack Proofing of Code Binary Gopal Gupta, Parag Doshi, R. Reghuramalingam, Doug Harris The University of Texas at Dallas.
An Undergraduate Course on Software Bug Detection Tools and Techniques Eric Larson Seattle University March 3, 2006.
Memory Layout, File I/O Bryce Boe 2013/06/27 CS24, Summer 2013 C.
A Tool for Pro-active Defense Against the Buffer Overrun Attack D. Bruschi, E. Rosti, R. Banfi Presented By: Warshavsky Alex.
Protecting C Programs from Attacks via Invalid Pointer Dereferences Suan Hsi Yong, Susan Horwitz University of Wisconsin – Madison.
Buffer Overflows Taught by Scott Coté.-. _ _.-. / \.-. ((___)).-. / \ /.ooM \ / \.-. [ x x ].-. / \ /.ooM \ -/ \ /-----\-----/---\--\ /--/---\-----/-----\ / \-
Web Security Firewalls, Buffer overflows and proxy servers.
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.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
Software Security. Bugs Most software has bugs Some bugs cause security vulnerabilities Incorrect processing of security related data Incorrect processing.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Content Coverity Static Analysis Use cases of Coverity Examples
Refs: rootshell, antionline, your favorite hacker site…
Mitigation against Buffer Overflow Attacks
Seminar in automatic tools for analyzing programs with dynamic memory
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Software Security Lesson Introduction
CSC 495/583 Topics of Software Security Format String Bug (2) & Heap
Introduction to Static Analyzer
Format String Vulnerability
Return-to-libc Attacks
Presentation transcript:

Finding Security Violations by Using Precise Source- level Analysis by V.Benjamin Livshits and Monica Lam {livshits, SUIF Group CSL, Stanford University

Computer Break-ins: Major problem Software break-ins: relatively easy to do: a lot of prior art An article selection from [destroy.net]: Smashing The Stack For Fun And Profit [Aleph One] How to write Buffer Overflows [Mudge] Finding and exploiting programs with buffer overflows [Prym] Sites like that describe techniques and provide tools to simplify creating new exploits

Potential Targets Typical targets: Widely available UNIX programs: sendmail, BIND, etc. Various server-type programs ftp, http pop, imap irc, whois, finger Mail clients (overrun filenames for attachments) Netscape mail (7/1998) MS Outlook mail (11/1998) The list goes on and on…

Sad Consequences Patching mode: need to apply patches in a timely manner Recent cost estimate: a survey by analyst group Baroudi Bloor [ 1. Lost Revenue due to Down Time – biggest cost …but also 2. System Admin Time Costs 3. Development Costs 4. Reputation and Good Will -- cannot be measured Legal issues to consider Who is responsible for lost and corrupt data? What to do with stolen credit card numbers, etc.? Legislation demands compliance to security standards Baroudi Bloor report: failure to patch on time If failure to apply a patch costs 4 hours in System Admin Time to clean up the effects and patch the system, 2 hours in Developer Time to re-code any applications that have been affected by the patch or damage done by failure to patch and 30 minutes of downtime the cost of not patching is a whopping: $820 + $410 + $500,000 = $501,230

Most Prevalent Classes SecurityFocus.com study of security reports in 2002 Tried to identify most prevalent classes 3,582 CVE entries (1/2000 to 10/2002) Approximately 25% of the CVE was not classified 62% Would like to address these

Security Vulnerabilities over Time Are they all gone? Or just the easy ones?

Focus of Our Work We believe that tools are needed to detect security vulnerabilities We concentrate on the following types of vulnerabilities: Buffer overruns Format string violations Provide tools that are practical and precise

How Buffer Overruns Work Different flavors of overruns with different levels of complexity Simplest: overrun a static buffer There is no array bounds checking in C – hackers can exploit that Different flavors are descibed in detail in Buffer Overflows: Attacks and Defenses for the Vulnerability of the Decade, [C.Cowan et al] We concentrate on overrunning static buffers Dont want user data to be copied to static buffers!

Mechanics of a Simple Overrun 1. Arrange for suitable code to be available in program address space usually by supplying a string with executable code 2. Get the program to jump to that code with suitable parameters loaded into registers & memory usually by overwriting a return address to point to the string 3. Put something interesting into the exploit code such as exec(sh), etc.

How Format String Violations Work The %n format specifier – root of all evil Stores the number of bytes that are actually formatted: printf(%.20x%n,buffer,&bytes_formatted); This is benign, but the following is not: printf(argv[0]); Can use the power of %n to overwrite return address, etc. Requires some skill to abuse this feature In the best case – a crash, in the worst case – can gain control of the remote machine However the following is fine: printf(%s, argv[0]); Dont want user data to be used as format strings!

Existing Auditing Tools Various specialized dynamic tools Require a particular input/test case to run Areas: Network security Runtime break-in detection StackGuard for buffer overruns, many others Lexical scanners Publicly available RATS [securesoftware.com] ITS4 [cigital.com] pscan [open source] – simple format string violation finder Typically imprecise: Tend to inundate the user with warnings Digging through the warnings is tedious Discourages the user Can we do better with static analysis?

Talk Outline Motivation: need better static analysis for security Detecting security vulnerabilities: existing approaches Static analysis: what are the components? Our approach: IPSSA + tools based on it Results and experience

Existing Static Approaches A First Step Towards Automated Detection of Buffer Overrun Vulnerabilities [D.Wagner] Buffer overruns as an integer range analysis problem Checked Sendmail 8.9.3: 4 bugs/44 warnings Conclusion: following features are necessary to achieve better precision Flow sensitivity Pointer analysis Detecting Format String Vulnerabilities with Type Qualifiers [A.Aiken] Tainted annotations, requires some, infers the rest Conclusion: following features are necessary to achieve better precision Context sensitivity Field sensitivity

void foo(char *s){ } Flow-, Path- & Context Sensitivity Flow- and path sensitivity p = s p = abc printf(p) foo(abc) foo(p) Context sensitivity fgets(s, 100, stdin) if(P) printf(s) gets(p)

a = 2; *p = 3; … is the value of a still 2? Need it to represent data flow in C: Yes if we can prove that p cannot point to a Should we put a flow edge from 3 to a to represent potential flow? Most existing pointer analysis approaches emphasize scalability and not precision Crucial realization: We only need precision in certain places Pointer Analysis: Major Obstacle

To Achieve Precision… Break the pointer analysis problem into two Precisely represent – hot locations Local variables Parameter passing Field accesses and dereferences of parameters and locals All the rest if cold Data structures Arrays etc.

Hot vs Cold Locations Stack push(s, x) y = pop(s) Specific Array Hash a[3] = x y = a[5] h{key} = x y = h{key} Cold location L1L1 L2L2 Conceptual

Putting it All Together: Precision Requirements Ability to analyze code scattered among many functions and files efficiently This is where hard bugs hide Path-sensitivity Precise representation of library routines (Wagner, Aiken) such as strcpy, strncpy, strtok, memcopy, sprintf, snprintf fprintf, printf, fgets, gets Support features of C Pass-by-reference semantics vararg s and va_list treatment Function pointers Flow sensitivity Pointer analysis Field sensitivity Context sensitivity + Wagner et al.Aiken et al. And also…

Tradeoff: Scalability vs Precision fast Speed / Scalability Precision slow and expensive low high Wagner et al Lexical audit tools Formal verification Our tool Aiken et al

Program sources IPSSA construction Buffer overruns Error traces Our Framework Format violations NULL derefs …others… Abstracts away many details. Makes it easy to write tools Analyses: Common framework. Makes it easy to add new analyses Data flow info

To Summarize: New Program Representation: IPSSA Intraprocedurally SSA – static single assignment form Local pointer resolution: pointers are resolved to scalars, new names are introduced Interprocedurally Parameter mapping Globals treated as parameters Side effects of calls are represented explicitly Hot vs Cold locations Hot locations are represented precisely Cold locations are multiple locations lumped together Models for system functions

Models of System Functions non_tainted qualifiers, explicit taint variable vararg s are represented by … Pass-by- reference representation Excerpt from a model specification file tainted io char* gets(non_null char[] s){ s[] = taint; return (s, NULL); }; tainted io char* getenv(non_null char[] s){ ret_loc^ = taint; return (unknown, NULL); }; char* sprintf(char[] buf, non_tainted const char[] format, void*...){ buf^ =...^; return buf; }; char* snprintf(char[] buf, int sz, non_tainted const char[] format, void*...){ buf^ =...^; return buf; }; io void fprintf(non_null FILE* file, non_tainted char[] format, void*...){ safe(...^); };

Analysis Based on IPSSA 1. Start at sources of user input (roots) such as argv[] elements sources of input: fgets, gets, recv, getenv, etc. 2. Follow data flow provided by IPSSA until a sink is found Buffer of statically defined length Vulnerable procedures: printf, fprintf, snprintf, vsnprintf 3. Test path feasibility using predicates (optional step) 4. Report bug, record path

Example: Tainting Violation in muh 0838 s = ( char * )malloc( 1024 ); 0839 while( fgets( s, 1023, messagelog ) ) { 0840 if( s[ strlen( s ) - 1 ] == '\n' ) s[ strlen( s ) irc_notice( &c_client, status.nickname, s ); 0842 } 0843 FREESTRING( s ); irc_notice( &c_client, status.nickname, CLNT_MSGLOGEND ); 257 void irc_notice(connection_type *connection, char nickname[], char *format,... ) 258 { 259 va_list va; 260 char buffer[ BUFFERSIZE ]; va_start( va, format ); 263 vsnprintf( buffer, BUFFERSIZE - 10, format, va ); 264 va_end( va ); muh.c:839 irc.c:263

Example: Buffer Overrun in gzip 0589 if (to_stdout && !test && !list && (!decompress || SET_BINARY_MODE(fileno(stdout)); 0591 } 0592 while (optind < argc) { 0593 treat_file(argv[optind++]); 0704 local void treat_file(iname) 0705 char *iname; 0706 { if (get_istat(iname, &istat) != OK) return; 0997 local int get_istat(iname, sbuf) 0998 char *iname; 0999 struct stat *sbuf; 1000 { strcpy(ifname, iname); gzip.c:593 gzip.c:1009 gzip.c:716 Need to have a model of strcpy

Recurring Patterns: Lessons Learned Hard violations pass through many procedures About 4 on average Not surprising – the further away a root is from a sink, the harded it is to find manually Harder violations pass through many files Relatively few unique root-sink pairs But… potentially many more root-sink paths

Do We Need Predicates? Predicates are sometimes important in reducing false positive ratio Hugely depends on the application: help with NULLs A few places where they matter in the security analysis util.c ( lhttpd 0.1) Predicates are sometimes needed in function models for precision When called with NULL as the first argument, strtok returns portions of the string previously passed into it Otherwise, the passed in string is stored internally No flow between tempstring on line 114 and 165 There is flow between tempstring and ptr2 on lines 165 and while(!feof(in)) 110 { 111 getfileline(tempstring, in); if(feof(in)) break; 114 ptr1 = strtok(tempstring, "\" \t"); 160 while(!feof(in)) 161 { 162 getfileline(tempstring, in); if(feof(in)) break; 165 ptr1 = strtok(tempstring, "\"\t "); 166 ptr2 = strtok(NULL, "\"\t ");

Summary of Experimental Results 7 server-type programs Contained many violations previously reported on SecurityFocus and other security sites

Conclusions Outlined the need for static pointer analysis to detect security violations Presented a program representation designed for bug detection Described how it can be used in an analysis to find security violations Presented experimental data that demonstrate the effectiveness of our approach More details: there is a paper available: Thanks for listening!