Copyright 2015 MathEmbedded Ltd.r. Finding security vulnerabilities by fuzzing and dynamic code analysis

Similar documents
Fuzzing. compass-security.com 1

Fuzzing AOSP. AOSP for the Masses. Attack Android Right Out of the Box Dan Austin, Google. Dan Austin Google Android SDL Research Team

CSC 405 Introduction to Computer Security Fuzzing

The Fuzzing Project

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

Automatic program generation for detecting vulnerabilities and errors in compilers and interpreters

Structure-aware fuzzing

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

New features in AddressSanitizer. LLVM developer meeting Nov 7, 2013 Alexey Samsonov, Kostya Serebryany

Dynamic code analysis tools

CSE 565 Computer Security Fall 2018

Fuzzing techniques & software vulnerabilities

Software Security IV: Fuzzing

It was a dark and stormy night. Seriously. There was a rain storm in Wisconsin, and the line noise dialing into the Unix machines was bad enough to

Fast dynamic program analysis Race detection. Konstantin Serebryany May

Juwei Lin. - Joined TrendMicro Since Windows Kernel/Rootkit/Bootkit - Ransomware Decryption - ios/android/mac Vulnerability Hunting

Enhancing Memory Error Detection for Large-Scale Applications and Fuzz testing

Buffer overflow background

MBFuzzer - MITM Fuzzing for Mobile Applications

Secure Software Development: Theory and Practice

CS 161 Computer Security

Programming in C. Lecture 9: Tooling. Dr Neel Krishnaswami. Michaelmas Term

CIS 551 / TCOM 401 Computer and Network Security. Spring 2007 Lecture 2

Simple Overflow. #include <stdio.h> int main(void){ unsigned int num = 0xffffffff;

Coverage-guided Fuzzing of Individual Functions Without Source Code

Verification & Validation of Open Source

Finding media bugs in Android using file format fuzzing. Costel Maxim Intel OTC Security

Advanced Debugging and the Address Sanitizer

logistics: ROP assignment

Writing a fuzzer. for any language with american fuzzy lop. Ariel Twistlock Labs

Honours/Master/PhD Thesis Projects Supervised by Dr. Yulei Sui

Secure Coding in C and C++

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

Stack Overflow. Faculty Workshop on Cyber Security May 23, 2012

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

Memory Corruption 101 From Primitives to Exploit

SoK: Eternal War in Memory Laszlo Szekeres, Mathias Payer, Tao Wei, and Dawn Song In: Oakland 14

Rabbit in the Loop. A primer on feedback directed fuzzing using American Fuzzy Lop. by Kevin Läufer

CSE 565 Computer Security Fall 2018

How to implement SDL and don t turn gray. Andrey Kovalev, Security Engineer

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

Buffer overflow prevention, and other attacks

Fuzzing For Worms 16/06/2018. Fuzzing For Worms. AFL for Linux Network Servers

Understanding Undefined Behavior

Memory corruption countermeasures

DEBUGGING: DYNAMIC PROGRAM ANALYSIS

ECE/ME/EMA/CS 759 High Performance Computing for Engineering Applications

Enhancing Memory Error Detection for Larg e-scale Applications and Fuzz testing

Improving Linux Development with better tools. Andi Kleen. Oct 2013 Intel Corporation

Buffer Overflow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Applications. Cloud. See voting example (DC Internet voting pilot) Select * from userinfo WHERE id = %%% (variable)

Buffer Overflows Defending against arbitrary code insertion and execution

Software Vulnerabilities August 31, 2011 / CS261 Computer Security

To Detect Stack Buffer Overflow With Polymorphic Canaries

Buffer Overflow. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Improving Linux development with better tools

CS-527 Software Security

ECE 471 Embedded Systems Lecture 22

finding vulnerabilities

A program execution is memory safe so long as memory access errors never occur:

Overview AEG Conclusion CS 6V Automatic Exploit Generation (AEG) Matthew Stephen. Department of Computer Science University of Texas at Dallas

The first Secure Programming Laboratory will be today! 3pm-6pm in Forrest Hill labs 1.B31, 1.B32.

Outline. Classic races: files in /tmp. Race conditions. TOCTTOU example. TOCTTOU gaps. Vulnerabilities in OS interaction

The Automated Exploitation Grand Challenge. A Five-Year Retrospective

Browser Bug Hunting and Mobile

Low level security. Andrew Ruef

Secure Programming Lecture 6: Memory Corruption IV (Countermeasures)

Stack Overflow COMP620

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

Lecture 4: Threats CS /5/2018

This time. Defenses and other memory safety vulnerabilities. Everything you ve always wanted to know about gdb but were too afraid to ask

Software Vulnerability

Memory Safety (cont d) Software Security

Lecture 4 September Required reading materials for this class

INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS

In-Memory Fuzzing in JAVA

Software Security II: Memory Errors - Attacks & Defenses

Foreword by Katie Moussouris... Acknowledgments... xvii. Introduction...xix. Chapter 1: The Basics of Networking... 1

Security Testing. Ulf Kargén Department of Computer and Information Science (IDA) Division for Database and Information Techniques (ADIT)

Lecture 08 Control-flow Hijacking Defenses

TI2725-C, C programming lab, course

What You Corrupt Is Not What You Crash: Challenges in Fuzzing Embedded Devices

SoK: Eternal War in Memory

SQLite with a Fine-Toothed Comb. John Regehr Trust-in-So1 / University of Utah

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

in memory: an evolution of attacks Mathias Payer Purdue University

C/C++ toolchain. Static and dynamic code analysis. Karel Kubíček. Masaryk University. Brno, Czech Republic

Integration of the softscheck Security Testing Process into the V-Modell

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

libfuzzer Kostya Serebryany May 2016

Hardening the C++ Standard Template Library

Computer Security Course. Midterm Review

CMPT 473 Software Quality Assurance. Security. Nick Sumner - Fall 2014

Lecture 14 Notes. Brent Edmunds

Code: analysis, bugs, and security

KLEE Workshop Feeding the Fuzzers. with KLEE. Marek Zmysłowski MOBILE SECURITY TEAM R&D INSTITUTE POLAND

Guarding Vulnerable Code: Module 1: Sanitization. Mathias Payer, Purdue University

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

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

Reserve Engineering & Buffer Overflow Attacks. Tom Chothia Computer Security, Lecture 17

Transcription:

Finding security vulnerabilities by fuzzing and dynamic code analysis

Security Vulnerabilities Top code security vulnerabilities don t change much:

Security Vulnerabilities Top code security vulnerabilities are still: Buffer Overflow Improper Input Validation (inc. Command Injection) Resource management (inc. Dynamic Memory problems) Leading to: modification of program data change of program control flow arbitrary code execution

Security Vulnerabilities Buffer Overflow: Often due to lack of bounds checking in C void foo (void) { char buffer[8]; fill (buffer); process (buffer); output(buffer); } 2. This stack frame corrupted void fill (char *p_buffer) { gets (p_buffer); } 1. No protection against writing more than 8 chars

Security Vulnerabilities Top code security vulnerabilities are still: Buffer Overflow, Command Injection, Memory Access Because: We don't sanitise our inputs No bounds checking in C We don't test all code paths Bad code often hard to locate

Security Vulnerabilities Buffer overflow often hard to locate: void foo (void) { char buffer[8]; fill (buffer); process (buffer); output(buffer); } void fill (char *p_buffer) { gets (p_buffer); } 2. No effect until parent exits if at all 1. Buffer overflows here

Security Vulnerabilities Default run-time protection may not help much gcc -fstack-protector -o foo foo.c Enter Buffer: overflowed Filling buffer 'overflowed Processing Buffer 'overflowed Output Buffer 'overflowed *** stack smashing detected ***:./buffer-foo terminated

Address Sanitizer Compilers can now add Dynamic Code Analysis AddressSanitizer detects C/C++ runtime memory errors: Use after free (dangling pointer dereference) Heap/Stack/Global buffer overflow Use after return Use after scope Initialization order bugs Memory leaks Compiler option for LLVM/clang (> v3.1) and GCC (> v4.8)

Address Sanitizer ASan detects the error as soon as it happens clang g fsanitize=address -o foo foo.c Enter Buffer: overflowed ======================== ==8635==ERROR: AddressSanitizer: stack-buffer-overflow READ of size 11 at 0x7ffd6d5cf288 thread T0 #0 0x443d3d in fill /tmp/foo.c:6 followed by detailed information and memory map

Address Sanitizer ASan identifies the source line of affected memory and the bad code void foo (void) { char buffer[8]; fill (buffer); process (buffer); output(buffer); } This stack frame corrupted void fill (char *p_buffer) { gets (p_buffer); } Buffer overflows here

Address Sanitizer Trade-off between coverage and performance: -f stack-protector About 5% performance penalty OK for well tested production code -f sanitizer=address About 100% performance penalty, OK for testing

Security Vulnerabilities Top code security vulnerabilities are still: Buffer Overflow, Command Injection, Memory Access Because: We don't sanitise our inputs No bounds checking in C We don't test all code paths Use Fuzzing? Bad code often hard to locate Use Compiler Sanitizers

What is Fuzzing? A stormy night in 1988 Barton Miller logs in from home using a 1200 baud modem The noisy line alters the Unix commands he types Some of the random changes cause programs to crash And more surprising to me were the programs that were crashing -- common Unix utilities that we all use everyday He started a student project to build a fuzz generator

What is Fuzzing? The Fuzz Generator worked well they succeeded well beyond my expectations. As we reported in the first fuzz paper [1990], they could crash or hang between 25-33% of the utility programs on the seven Unix variants that they tested.

Fuzzing Works The Fuzz Generator showed Random input creates new test cases that developers haven t considered = Better test case coverage

Fuzzing Works You can fuzz binary code You can fuzz hardware You can fuzz at scale: FFmpeg and a thousand fixes

Fuzzing Works 2014: FFmpeg and a thousand fixes Google blog: 1,120 bugs in ffmpeg mostly found by fuzzing 10% - 20% of them exploitable security vulnerabilities

Fuzzing Works 2014: FFmpeg and a thousand fixes Google blog: 1,120 bugs in ffmpeg mostly found by fuzzing 10% - 20% of them exploitable security vulnerabilities Test suite + 7,000 media files from the Internet 200 cores making random changes Several dozen iterations over 2 years No small project!

Fuzz data Fuzzing normally starts with good test data and makes random changes: Bit flip Byte swap Extend or truncate input Maximum, minimum values

Fuzz data Purely random changes can be inefficient Data may not get past validation checks, like CRC Save and reuse random data the does penetrate the code Fixup data (e.g. CRC) after randomisation Compile without validation Compile with permissive stub libraries Fuzz layers separately, e.g. Fuzzed HTTP in valid IP packets Specialist fuzzers for common protocols

Intelligent Fuzzing 2015: American Fuzzy Lop Tries various different input mutation strategies Instruments the code to detect code paths exercised Remembers data that hits new code paths = Better code coverage

Intelligent Fuzzing

Security Vulnerabilities Top two code security vulnerabilities are still: Command Injection Buffer Overflow Because: We don't sanitise our inputs No bounds checking in C We don't test all code paths Use Intelligent Fuzzing Bad code often hard to locate Use Compiler Sanitizers

A Winning Combination A typical example: 13 security vulnerabilities reported

A Winning Combination found with AFL and Sanitisers Description: audiofile is a C-based library for reading and writing audio files in many common formats. A fuzz with a wav file as input produced an heap overflow. The complete ASan output: ==6096==ERROR: AddressSanitizer: heap-buffer-overflow A Winning Combination Note: This bug was found with American Fuzzy Lop.

A Winning Combination Intelligent Fuzzers create test data for Create test data you hadn t thought of Improve code path test coverage E.g. AFL, libfuzz Compiler Sanitisers isolate the problem AddressSanitizer (detects addressability issues) LeakSanitizer (detects memory leaks) ThreadSanitizer (detects data races and deadlocks) for C++ and Go MemorySanitizer (detects use of uninitialized memory) UndefinedBehaviourSanitizer (detects conversion and overflow problems)

Fuzzing Services Google OSS-Fuzz Continuous fuzzing of important open source code Microsoft Project Springfield Fuzz testing service

Webliography I AddressSanitizer, Clang 5 Documentation, http://clang.llvm.org/docs/addresssanitizer.html Sanitizers project home, Google, https://github.com/google/sanitizers American Fuzzy Lop: http://lcamtuf.coredump.cx/afl/ Basic Fuzzing Framework, CERT, http://www.cert.org/download/bff/, (BFF is based on zzuf) Buffer overflow protection, Wikipedia, https://en.wikipedia.org/wiki/buffer_overflow_protection Defensive code s impact on software performance, NIST, 2015, http://nvlpubs.nist.gov/nistpubs/technicalnotes/nist.tn.1860.pdf Enhance application security with FORTIFY_SOURCE, Redhat, 2014, https://access.redhat.com/blogs/766093/posts/1976213 FFmpeg and a thousand fixes, Google blog, http://j00ru.vexillium.org/?p=2211 The Fuzzing Project, tutorials, fuzz vectors and other resources: https://fuzzing-project.org/ Fuzzing the RTL, Mary Yeoh, http://conference.hitb.org/hitbsecconf2010kul/materials/d1t2%20- %20Mary%20Yeoh%20-%20Fuzzing%20the%20RTL.pdf

Webliography II libfuzzer a library for coverage-guided fuzz testing, LLVM, http://llvm.org/docs/libfuzzer.html Google OSS-Fuzz project, https://github.com/google/oss-fuzz Microsoft Springfield fuzz testing service: https://www.microsoft.com/en-us/springfield/ OWASP SQL injection examples, https://www.owasp.org/index.php/testing_for_sql_injection_(otg- INPVAL-005) OWASP fuzzing guide: https://www.owasp.org/index.php/fuzzing OWASP ZAP Fuzzer: https://www.owasp.org/index.php/owasp_zed_attack_proxy_project zzuf Multipurpose Fuzzer: http://caca.zoy.org/wiki/zzuf SanitizerCoverage, Clang 5 Documentation, http://clang.llvm.org/docs/sanitizercoverage.html Image credits http://howtorabbit.blogspot.co.uk/2015/02/rabbit-species-american-fuzzy-lop.html First Place Ribbon: Copyright: snake3d / 123RF Stock Photo, http://www.123rf.com/profile_snake3d

Thank you Finding security vulnerabilities by fuzzing and dynamic code analysis MathEmbedded Embedded Security Reviews Secure Software Design Security Training www.mathembedded.com