Secure Coding Techniques

Similar documents
ECE 471 Embedded Systems Lecture 22

Defeat Exploit Mitigation Heap Attacks. compass-security.com 1

Mitigating the unkn0wn When your SMB exploit fails. Nicolas Joly

Identifying Memory Corruption Bugs with Compiler Instrumentations. 이병영 ( 조지아공과대학교

Lecture 4 September Required reading materials for this class

Is Exploitation Over? Bypassing Memory Protections in Windows 7

Dynamic Memory Allocation: Advanced Concepts

Part 7. Stacks. Stack. Stack. Examples of Stacks. Stack Operation: Push. Piles of Data. The Stack

12 th January MWR InfoSecurity Security Advisory. WebSphere MQ xcsgetmem Heap Overflow Vulnerability. Contents

Sandboxing Untrusted Code: Software-Based Fault Isolation (SFI)

Other array problems. Integer overflow. Outline. Integer overflow example. Signed and unsigned

Module: Return-oriented Programming. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security

CSCE 548 Building Secure Software Buffer Overflow. Professor Lisa Luo Spring 2018

My other computer is YOURS!

Stack Overflow COMP620

Secure Software Development: Theory and Practice

Buffer overflow background

Software and Web Security 1. Root Cause Analysis. Abstractions Assumptions Trust. sws1 1

CSC C69: OPERATING SYSTEMS

Secure C Coding...yeah right. Andrew Zonenberg Alex Radocea

Hackveda Training - Ethical Hacking, Networking & Security

SoK: Eternal War in Memory

Beyond Stack Smashing: Recent Advances in Exploiting. Jonathan Pincus(MSR) and Brandon Baker (MS)

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING

Week 5, continued. This is CS50. Harvard University. Fall Cheng Gong

Black Hat Webcast Series. C/C++ AppSec in 2014

1.1 For Fun and Profit. 1.2 Common Techniques. My Preferred Techniques

(Early) Memory Corruption Attacks

Verification & Validation of Open Source

18-642: Code Style for Compilers

Survey of Cyber Moving Targets. Presented By Sharani Sankaran

Last week. Data on the stack is allocated automatically when we do a function call, and removed when we return

Software Security II: Memory Errors - Attacks & Defenses

CSE 565 Computer Security Fall 2018

Dynamic Memory Allocation

CNIT 127: Exploit Development. Ch 18: Source Code Auditing. Updated

A Heap of Trouble Exploiting the Linux Kernel SLOB Allocator

CMPSC 497 Buffer Overflow Vulnerabilities

2 Sadeghi, Davi TU Darmstadt 2012 Secure, Trusted, and Trustworthy Computing Chapter 6: Runtime Attacks

IS THERE A HOLE IN YOUR RISC-V SECURITY STACK? JOTHY ROSENBERG DOVER MICROSYSTEMS

C and C++ Secure Coding 4-day course. Syllabus

ECS 153 Discussion Section. April 6, 2015

Lecture Embedded System Security A. R. Darmstadt, Runtime Attacks

Reflections on using C(++) Root Cause Analysis

ISA564 SECURITY LAB. Code Injection Attacks

Offensive Security My First Buffer Overflow: Tutorial

20: Exploits and Containment

Confinement (Running Untrusted Programs)

Threat Modeling. Bart De Win Secure Application Development Course, Credits to

Buffer Overflows. A brief Introduction to the detection and prevention of buffer overflows for intermediate programmers.

SECURE CODING PART 1 MAGDA LILIA CHELLY ENTREPRENEUR CISO ADVISOR CYBERFEMINIST PEERLYST BRAND AMBASSADOR TOP 50 CYBER CYBER

Memory Corruption 101 From Primitives to Exploit

Advanced Systems Security: Ordinary Operating Systems

Module: Program Vulnerabilities. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security

Secure Programming I. Steven M. Bellovin September 28,

CS 161 Computer Security

Security Workshop HTS. LSE Team. February 3rd, 2016 EPITA / 40

Cyber Moving Targets. Yashar Dehkan Asl

Cling: A Memory Allocator to Mitigate Dangling Pointers. Periklis Akritidis

Software Vulnerabilities August 31, 2011 / CS261 Computer Security

Module: Program Vulnerabilities. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security

CSE 509: Computer Security

Automotive Software Security Testing

Calling Conventions. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See P&H 2.8 and 2.12

Securing Applications in C/C++

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

CNIT 127: Exploit Development. Ch 14: Protection Mechanisms. Updated

Analysis of MS Multiple Excel Vulnerabilities

I run a Linux server, so we re secure

Limitations of the stack

Patching Exploits with Duct Tape: Bypassing Mitigations and Backward Steps

Hypervisor security. Evgeny Yakovlev, DEFCON NN, 2017

Question No: 1 After running a packet analyzer on the network, a security analyst has noticed the following output:

(In columns, of course.)

Module: Program Vulnerabilities. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security

MSRPC Heap Overflow Part II

Anti-Virus Software 0Day Party

Computer Security. 04r. Pre-exam 1 Concept Review. Paul Krzyzanowski. Rutgers University. Spring 2018

BUFFER OVERFLOW. Jo, Heeseung

Buffer Overflow. Jo, Heeseung

OpenBSD Remote Exploit

Buffer Overflows. Buffers. Administrative. COMP 435 Fall 2017 Prof. Cynthia Sturton. Buffers

vector and Free Store

Intro to x86 Binaries. From ASM to exploit

Fast Byte-Granularity Software Fault Isolation

Pointers and References

Let's cyber: hacking, 0days and vulnerability research. PATROKLOS ARGYROUDIS CENSUS S.A.

Lecture 4: Mechanism of process execution. Mythili Vutukuru IIT Bombay

EURECOM 6/2/2012 SYSTEM SECURITY Σ

Dynamic Memory Allocation (and Multi-Dimensional Arrays)

Core GraphicsMemory Corruption CVE PDF Indexed colorspace buffer overflow

Reversed Buffer Overflow Cross Stack Attacks. Kris Kaspersky Endeavor Security, Inc.

We will focus on Buffer overflow attacks SQL injections. See book for other examples

The Life And Death of Kernel Object Abuse. Saif ElSherei (0x5A1F) & Ian Kronquist

CS140 Operating Systems Final December 12, 2007 OPEN BOOK, OPEN NOTES

CS 161 Computer Security

KCon. Breaking ios Mitigation Jails to Achieve Your Own Private Jailbreak. Min(Spark) Alibaba Mobile Security

in memory: an evolution of attacks Mathias Payer Purdue University

Control Flow Hijacking Attacks. Prof. Dr. Michael Backes

Lecture 1: Buffer Overflows

Transcription:

Secure Coding Techniques "... the world outside your function should be treated as hostile and bent upon your destruction" [Writing Secure Code, Howard and LeBlanc] "Distrust and caution are the parents of security" - Benjamin Franklin

Three Critical Programming Errors* 1. accepting input from users without validating and sanitizing the input the number one killer of healthy software Monster Mitigations [2011, The MITRE Corporation] 2. allowing data placed in buffers to exceed the length of the buffer Buffer overflows are Mother Nature's little reminder of that law of physics that says: if you try to put more stuff into a container than it can hold, you're going to make a mess. Classic Buffer Overflow [2011, The MITRE Corporation] 3. handling integers incorrectly In the real world, 255+1=256. But to a computer program, sometimes 255+1=0, or 0-1=65535, or maybe 40,000+40,000=14464. [ ] When programmers forget that computers don't do math like people, bad things ensue - anywhere from crashes, faulty price calculations, infinite loops, and execution of code. Integer Overflow [2011, The MITRE Corporation] *Responsible for 90% of the critical security vulnerabilities in 2006; SANS Institute. ** 2011 CWE/SANS Top 25 Most Dangerous Software Errors [2011, The MITRE Corporation]

March 23, 2017 Three days, $833,000 acquiring 51 different bugs. Targets: Microsoft, Apple, Adobe and Mozilla with extra incentives for SYSTEM or ROOT level privileges. [Pwn2Own, hosted by Zero Day Initiative, Trend Micro @ CanSecWest.] Mozilla Firefox - an integer overflow and an uninitialized buffer in the Windows kernel to escalate privileges Apple Safari - an info disclosure, 4 different type confusion bugs, and use-after-free vulnerability to escalate to root Adobe Reader - an info leak in Reader followed by a UAF to get code execution. Then leveraged a UAF in the kernel to gain SYSTEM-level privileges. Microsoft Edge - an arbitrary write in Chakra and a logic bug within the sandbox to escape the sandbox. Microsoft Windows - an integer overflow in the kernel to escalate privileges.

March 25, 2017 Final Day: escaping the virtual machine, getting root, and how to go from guest to root. [Pwn2Own, hosted by Zero Day Initiative, Trend Micro @ CanSecWest.] a heap overflow in Microsoft Edge, a type confusion in the Windows kernel, and an uninitialized buffer in VMware Workstation for a complete virtual machine escape. two separate use-after-free (UAF) bugs in Microsoft Edge and then escalated to SYSTEM using a buffer overflow in the Windows kernel. Virtual Machine Escapes (Guest-to-Host) category: a Windows kernel UAF, a VMWare Workstation info leak, and an uninitialized buffer in Workstation to go guest-to-host. [VMware Tools were not installed in the guest.]

Buffer Overflows data can be stored: - in the program area - on the stack - in the heap in many systems, a memory area is either writable or executable but not both e.g. cannot write into program area heap error buffer overflows in this configuration (program data area) are rare main data area 1 sr1 data area 2 sr2 JSR XXX DC.L data DC.L data data area 3

Static Buffer Overflow (stack frame configuration) calling program: define return area push parameters on stack call routine parameter cleanup called program: set up stack frame with local area save registers do stuff restore registers collapse frame return A6 SP saved registers local area A6 old PC (return) parameters return area

Static Buffer Overflow the local area of the routine contains the buffer for a string routine depends on a null terminated string BUT does not calculate the length of the string OR calculates string length but doesn t verify it against the maximum length user input overflows the buffer intentional vs unintentional SP A6 saved registers local area A6 old PC (return) parameters

Static Buffer Overflow What would you like to do? 1. replace the return address with the address of your routine 2. trash the pointer/return for denial of service 3. put payload in local area and execute now or later - remember, you can use the frame pointer to do address calculations and local area does not disappear 4. payload in local area modifies parameter on previously stacked frame

Heap-based Buffer Overflows heaps are dynamically allocated hdr 1[nxt,prev,s,u] memory space 1 can overwrite key data can overwrite function pointers in memory can inject code and manipulate pointer to cause execution hdr 2[nxt,prev,s,u] memory space 2 header free free memory MS adds cookies to the heap. If cookies are missing/corrupt, raise a heap buffer s/w exception.

Heap-based Buffer Overflows hdr 1[nxt,prev,s,u] memory space 1 hdr 2 memory space 2 header free free memory

Buffer Overflows Attacker s goal: run own code with privilege To achieve the goal: attack code must be available in the original program s address space inject the code (payload) on the stack (local variables) on the heap (malloc d variables) in the static data area (DC,DS) already on user s machine original program must jump to the attack code modify code addresses

Reading: Three Programming Errors Most Frequently Responsible for Critical Security Vulnerabilities [SANS, 2007] Secure Coding Guide Types of Security Vulnerabilities [ 2014 Apple Inc.] Understanding Pool Corruption Part 1 Buffer Overflows (optional) [@2016 Microsoft] Pool is kernel mode memory used as a storage space for drivers (software that allows your computer to communicate with hardware or devices). If a driver uses more space than is allocated (a buffer overflow), they will write into the next driver s space and corrupt that driver s data. When this corrupted memory is run, things will not go well (typically, a blue screen). @RISK: The Consensus Security Vulnerability Alert: March 23, 2017 @RISK provides a weekly summary of (1) newly discovered attack vectors, (2) vulnerabilities with active new exploits, (3) explanations of how recent attacks worked.