CMSC 426/626: Secure Coding Krishna M. Sivalingam Sources: From Secure Coding, Mark and van Wyk, O’Reilly, 2003 www.cert.org/secure-coding.

Slides:



Advertisements
Similar presentations
Defenses. Preventing hijacking attacks 1. Fix bugs: – Audit software Automated tools: Coverity, Prefast/Prefix. – Rewrite software in a type safe languange.
Advertisements

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.
CMSC 414 Computer and Network Security Lecture 22 Jonathan Katz.
K. Salah1 Buffer Overflow The crown jewel of attacks.
Stack-Based Buffer Overflows Attacker – Can take over a system remotely across a network. local malicious users – To elevate their privileges and gain.
1 Protection Protection = access control Goals of protection Protecting general objects Example: file protection in Linux.
CMSC 414 Computer and Network Security Lecture 24 Jonathan Katz.
It’s always better live. MSDN Events Security Best Practices Part 2 of 2 Reducing Vulnerabilities using Visual Studio 2008.
TaintCheck and LockSet LBA Reading Group Presentation by Shimin Chen.
Information Networking Security and Assurance Lab National Chung Cheng University The Ten Most Critical Web Application Security Vulnerabilities Ryan J.W.
Information Networking Security and Assurance Lab National Chung Cheng University 1 Top Vulnerabilities in Web Applications (I) Unvalidated Input:  Information.
SQL Injection and Buffer overflow
Methods For The Prevention, Detection And Removal Of Software Security Vulnerabilities Jay-Evan J. Tevis Department of Computer Science and Software Engineering.
Web Application Vulnerabilities Checklist. EC-Council Parameter Checklist  URL request  URL encoding  Query string  Header  Cookie  Form field 
Java Security Updated May Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security.
Java Security. Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security Manager.
Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar, and Ravishankar K. Iyer Brett Hodges April 8, 2010.
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
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.
A Security Review Process for Existing Software Applications
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.
Attacking Applications: SQL Injection & Buffer Overflows.
CGI Security COEN 351. CGI Security Security holes are exploited by user input. We need to check user input against Buffer overflows etc. that cause a.
Chapter 2. Core Defense Mechanisms. Fundamental security problem All user input is untrusted.
Buffer Overflow Detection Stuart Pickard CSCI 297 June 14, 2005.
Mitigation of Buffer Overflow Attacks
Top Five Web Application Vulnerabilities Vebjørn Moen Selmersenteret/NoWires.org Norsk Kryptoseminar Trondheim
COMPUTER SECURITY MIDTERM REVIEW CS161 University of California BerkeleyApril 4, 2012.
Week 10-11c Attacks and Malware III. Remote Control Facility distinguishes a bot from a worm distinguishes a bot from a worm worm propagates itself and.
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 Proofing of Code Binaries By Ramya Reguramalingam Graduate Student, Computer Science Advisor: Dr. Gopal Gupta.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
A Tool for Pro-active Defense Against the Buffer Overrun Attack D. Bruschi, E. Rosti, R. Banfi Presented By: Warshavsky Alex.
Operating Systems Security
Unix Security Assessing vulnerabilities. Classifying vulnerability types Several models have been proposed to classify vulnerabilities in UNIX-type Oses.
Security Issues with PHP  PHP installation  PHP programming Willa Zhu & Eugene Burger.
Introduction Program File Authorization Security Theorem Active Code Authorization Authorization Logic Implementation considerations Conclusion.
Dynamic Taint Analysis for Automatic Detection, Analysis, and Signature Generation of Exploits on Commodity Software Paper by: James Newsome and Dawn Song.
Group 9. Exploiting Software The exploitation of software is one of the main ways that a users computer can be broken into. It involves exploiting the.
Security Attacks Tanenbaum & Bo, Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
Slides by Kent Seamons and Tim van der Horst Last Updated: Nov 11, 2011.
MOPS: an Infrastructure for Examining Security Properties of Software Authors Hao Chen and David Wagner Appears in ACM Conference on Computer and Communications.
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.
Buffer Overflows: Attacks and Defenses for the Vulnerability of the Decade Crispin Cowan SANS 2000.
Software Security. Bugs Most software has bugs Some bugs cause security vulnerabilities Incorrect processing of security related data Incorrect processing.
CS703 - Advanced Operating Systems By Mr. Farhan Zaidi.
Chapter 29: Program Security Dr. Wayne Summers Department of Computer Science Columbus State University
Mitigation against Buffer Overflow Attacks
Introduction to Operating Systems
CMSC 345 Defensive Programming Practices from Software Engineering 6th Edition by Ian Sommerville.
Protecting Memory What is there to protect in memory?
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
Protecting Memory What is there to protect in memory?
Module 30 (Unix/Linux Security Issues II)
Protecting Memory What is there to protect in memory?
A Security Review Process for Existing Software Applications
Security mechanisms and vulnerabilities in .NET
Introduction to Operating Systems
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Chapter 14: Protection.
Chapter 14: Protection.
Software Security Lesson Introduction
CS5123 Software Validation and Quality Assurance
Operating System Concepts
Understanding and Preventing Buffer Overflow Attacks in Unix
Presentation transcript:

CMSC 426/626: Secure Coding Krishna M. Sivalingam Sources: From Secure Coding, Mark and van Wyk, O’Reilly,

Where can errors occur? During entire software lifecycle  Security Architecture/Design stage  Man-in-the-middle attack  Race condition attack  Replay attack  Implementation Stage  Buffer overflow attack  Parsing error attack  Back door attacks (aka Trapdoors)  Code Maintenance Stage

Flaw Classifications  Landwehr’s Scheme  Bishop’s Scheme  Aslam’s Scheme  Du/Mathur’s classification  Flaws are Intentional and Inadvertent  Inadvertent Flaw Classifications  Validation Error  Domain Error  Serialization and Aliasing  Inadequate Authentication and Identification  Boundary Condition Violation  Other exploitable logic error

Study of Buffer Overflow Attack  Cowan, Crispin, Perry Wagle, Calton Pu, Steve Beattie, and Jonathan Walpole. "Buffer Overflows: Attacks and Defenses for the Vulnerability of the Decade." Proceedings of DARPA Information Survivability Conference and Expo (DISCEX), 1999 

Buffer Overflows  Inject attack code by overflowing the buffer  Usually involves adding code based on target machines’ CPU opcodes  Execute code with all the privileges of the vulnerable program  Thus, if program is running as root, attacker can run at will any code as root  Typically, manage to invoke execve /bin/sh or similar to get a root shell

Program Segments  An executing program consists of:  Code  Initialized Data  Global variables  Stack  Heap (for dynamic allocation)  Remember that local variables, return address, etc. are stored in the stack when a function is invoked  When a local variable is over-run, it can alter return address, etc.

Where to Inject Code  On the stack (automatic variables)  On the heap (malloc or calloc variables)  In static data areas  Executable code need not be restricted to the overflowing buffer – code can be injected elsewhere  One can also use existing code  For example, if exec(arg) exists in program, modify running code by making arg point to “/bin/sh”

Jump to Attacker’s Code  Activation Record  Overflow into return address on the stack and make it point at the code.  Function pointers  Overflow into “void (*foo())()” and it point at the code  Setjmp and longjmp commands, that are used for checkpointing and recovery  Alter address given to longjmp to point to attacker’s code

Buffer Overflow Details  Look at Mudge’s sample buffer overflow attack

Buffer Overflow Defenses  Writing Correct Code  Vulnerable programs continue to emerge on a regular basis  C has many error-prone idioms and a culture that favors performance over correctness.  Static Analysis Tools  Fortify – looks for vulnerable constructs  Too many false positives Crispin Cowan’s SANS 2000 Talk on Web From Crispin Cowan’s SANS 2000 Talk on Web

Buffer Overflow Defenses  Non-executable buffers  Non executable data segments  Optimizing compiles emit code into program data segments  Non executable stack segments  Highly effective against code injection on the stack but not against code injections on the heap or static variables.

Buffer Overflow Defenses  Array Bound Checking  Can run 12x-30x slower  a[3] is checked but *(a+3) is not  Type safe languages: Java or ML  There are millions of lines of C code in operating systems and security system applications  Attack the Java Virtual Machine which is a C program  StackGuard program: Adds a “canary” value, which is a 32- bit random # or a known string terminator (CR, LF, ‘\0’, etc.)  Compiler adds canary and system can check for this value at runtime  Entire RedHat system has been recompiled with this and shown to be less vulnerable

Race Conditions  criv/ucd-ecs pdf   pment/secure-programming/bishop-dilger checking-for-race-conditions-in-file-accesses.pdf

Race condition: What is it?  Consider a setuid program, owned by root  UserA is presently executing the program, hence is running it as root  Assume that the program wants to write to a file. The system must check whether UserA has the right privileges on this file, checked as follows: if (access(filename, W_OK) == 0){ if ((fd = open(filename, O_WRONLY)) == NULL){ perror(filename); return(0); } /* now write to the file */

Race condition: What is it?  In the time between verifying access and opening the file, if the file referred to changes, then its access will not have been checked  Called TOCTTOU (Time-of-check-To-Time-of- Use) binding flaw  For example, if access is originally checked on /tmp/X AND before execution of write statement:  /tmp/X is deleted AND  Hard link from /etc/passwd is created to /tmp/X  Then, process will write to /etc/passwd!  Present in xterm program, while logging sessions

Source: Bishop and Dilger’s 1996 paper in Computing Systems

Race conditions, contd.  Similar attack possible on binmail program  Binmail appends mail to an existing mail spool file  E.g. /usr/spool/mail/jkl  Binmail verifies if file exists (and is not a symbolic link)  Before binmail writes to file, jkl is deleted AND made a hard link to /etc/passwd  Now, binmail appends data to /etc/passwd  Attacker can create a new account with no password and root privileges  Note that binding flaws do not arise when file descriptors are used!

Good Practices in Implementation  Inform Yourself  Follow Vulnerability Discussions and Alerts (eg.  Read books and papers on secure coding practices, analyses of software flaws, etc.  Explore open source software  Examples of how to and how not to write code

Good Practices in Implementation  Handle Data with Caution  Cleanse data: Examine input data for malicious intent (altering character sets, using dis-allowed characters)  Perform bounds checking  Check array indices  Check configuration files  Can be modified by attacker  Check command-line parameters  Don’t trust web URLs and parameters within  Be careful of web content (variables hidden in HTML fields)

Good Practices in Implementation  Check web cookies  Check environment variables  Set valid initial values for data  Understand filename references and use them correctly  Check for indirect file references (e.g. Shortcuts, symbolic links)  Be careful of how program and data files are located (as in searching using PATH variable)  Reuse “Good” Code whenever Practical

Good Practices in Implementation  Sound Review Processes  Perform Peer review of Code  Perform Independent Validation and Verification  Use automated security tools  Static Code checkers  RATS - Rough Auditing Tool for Security  SPLINT – Source code scanner  Uno:  Runtime checkers  Libsafe:  PurifyPlus:  Immunix Tools:

Good Practices in Implementation  Profiling Tools  Papillon for Solaris:  Gprof from GNU  Janus – policy enforcement and profiling;  Black-box Testing for Fault-Injection Tools  Appscan:  Whisker: wiretrip.net  ISS Database Scanner:  Perform network-based vulnerability scans  Nmap:  Nessus:  ISS Internet Scanner

Good Practices in Implementation  Make Generous Use of Checklists  Security checklists must be created and checked against. For example:  Application requires password for access  All user ID logins are unique  Uses role-based access control  Encryption is used  Code should be Maintainable  Practice standards of in-line documentation  Remove obsolete code  Test all code changes

Implementation, Don’ts  Don’t write code that uses relative filenames  Fully qualified filenames should be used  Don’t refer to a file twice in the same program by its name  Always use file descriptors after initial open  Prevents “race condition attack” that exploit time between access check and file execution  Don’t invoke untrusted programs from within trusted ones  Avoid using setuid or similar mechanisms whenever possible  Don’t assume that users are not malicious

Implementation, Don’ts  Don’t dump core – code must fail gracefully  Coredump can be used to extract valuable data stored in memory during execution  Don’t assume that a system call (or any function call) is always successful – always check for return values and error variable values  Computer-based random number generators are “pseudo-random” and can have repitition  Don’t invoke shell or command line from within a program  Don’t use world writable storage, even for temporary files

Implementation, Don’ts  Don’t trust user-writable storage not to be tampered with  Don’t keep sensitive data in a database without password protection  Don’t code usernames/passwords into an application  Don’t echo passwords!  Don’t rely on host-level file protection mechanisms  Don’t make access decisions based on environment variables or command-line arguments  Don’t issue passwords via

To be Continued