Outline. Heap meta-data. Non-control data overwrite

Similar documents
Outline. Format string attack layout. Null pointer dereference

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

Lecture 08 Control-flow Hijacking Defenses

CSE 127: Computer Security. Memory Integrity. Kirill Levchenko

CS 161 Computer Security

Software Security II: Memory Errors - Attacks & Defenses

This exam contains 7 pages (including this cover page) and 4 questions. Once we tell you to start, please check that no pages are missing.

CS 161 Computer Security

Return-orientated Programming

Software Security: Buffer Overflow Defenses

Inject malicious code Call any library functions Modify the original code

Countermeasures in Modern Operating Systems. Yves Younan, Vulnerability Research Team (VRT)

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

This exam contains 8 pages (including this cover page) and 4 questions. Once we tell you to start, please check that no pages are missing.

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

Software Security: Buffer Overflow Attacks (continued)

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

String Oriented Programming Exploring Format String Attacks. Mathias Payer

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

CSE 127 Computer Security

Software Security: Buffer Overflow Attacks

Lecture 1: Buffer Overflows

CSE 565 Computer Security Fall 2018

Advanced Buffer Overflow

CMPSC 497 Buffer Overflow Vulnerabilities

20: Exploits and Containment

Changelog. Corrections made in this version not in first posting: 1 April 2017: slide 13: a few more %c s would be needed to skip format string part

CSE 127: Computer Security Control Flow Hijacking. Kirill Levchenko

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

Advanced Buffer Overflow

Smashing the Buffer. Miroslav Štampar

Software Vulnerabilities August 31, 2011 / CS261 Computer Security

Runtime Defenses against Memory Corruption

CSC 591 Systems Attacks and Defenses Stack Canaries & ASLR

CSE 127 Computer Security

Università Ca Foscari Venezia

Buffer overflow prevention, and other attacks

Secure Programming Lecture 6: Memory Corruption IV (Countermeasures)

CSE 127 Computer Security

Lab 2: Buffer Overflows

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

Stack Vulnerabilities. CS4379/5375 System Security Assurance Dr. Jaime C. Acosta

Hacking Blind. Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh. Stanford University

CSC 591 Systems Attacks and Defenses Return-into-libc & ROP

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

Security and Privacy in Computer Systems. Lecture 5: Application Program Security

Lecture 4 September Required reading materials for this class

Writing Exploits. Nethemba s.r.o.

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

Secure Systems Engineering

Selected background on ARM registers, stack layout, and calling convention

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Memory corruption countermeasures

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

Remix: On-demand Live Randomization

Buffer Overflow Vulnerability

Bypassing Browser Memory Protections

Lab 2: Buffer Overflows

Architecture-level Security Vulnerabilities

Lecture 10 Code Reuse

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

CSC 405 Computer Security Stack Canaries & ASLR

Abstraction Recovery for Scalable Static Binary Analysis

Hacking Blind BROP. Presented by: Brooke Stinnett. Article written by: Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazie`res, Dan Boneh

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

The Geometry of Innocent Flesh on the Bone

Robust Shell Code Return Oriented Programming and HeapSpray. Zhiqiang Lin

Buffer overflow background

CSE 509: Computer Security

Is Exploitation Over? Bypassing Memory Protections in Windows 7

Software Security: Buffer Overflow Defenses and Miscellaneous

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

Memory Corruption 101 From Primitives to Exploit

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

SoK: Eternal War in Memory

idkwim in SecurityFirst 0x16 years old Linux system security researcher idkwim.tistory.com idkwim.linknow.

BUFFER OVERFLOW DEFENSES & COUNTERMEASURES

COMP3441 Lecture 7: Software Vulnerabilities

4. Jump to *RA 4. StackGuard 5. Execute code 5. Instruction Set Randomization 6. Make system call 6. System call Randomization

Code Injection Attacks Buffer Overflows

Buffer Overflow Attacks

Intro to x86 Binaries. From ASM to exploit

Architecture-level Security Vulnerabilities. Julian Stecklina

Is stack overflow still a problem?

Play with FILE Structure Yet Another Binary Exploitation Technique. Abstract

Biography. Background

Advanced Security for Systems Engineering VO 05: Advanced Attacks on Applications 2

Code with red border means vulnerable code. Code with green border means corrected code. This program asks the user for a password with the function

On The Effectiveness of Address-Space Randomization. H. Shacham, M. Page, B. Pfaff, E.-J. Goh, N. Modadugu, and D. Boneh Stanford University CCS 2004

Software security, secure programming

Playing God With Format String Attacks. Bsides Jax 2016 Travis Phillips 10/22/2016

Betriebssysteme und Sicherheit Sicherheit. Buffer Overflows

ISA 564, Laboratory I: Buffer Overflows

CSc 466/566. Computer Security. 20 : Operating Systems Application Security

Basic Buffer Overflows

Outline. Memory Exploit

CS 161 Computer Security

Exploit Mitigation - PIE

Lecture 09 Code reuse attacks. Stephen Checkoway University of Illinois at Chicago CS 487 Fall 2017

Secure Programming I. Steven M. Bellovin September 28,

Transcription:

Outline CSci 5271 Introduction to Computer Security Day 5: Low-level defenses and counterattacks Stephen McCamant University of Minnesota, Computer Science & Engineering Non-control data overwrite Heap meta-data Overwrite other security-sensitive data No change to program control flow Set user ID to 0, set permissions to all, etc. Boundary tags similar to doubly-linked list Overwritten on heap overflow Arbitrary write triggered on free Simple version stopped by sanity checks Heap meta-data Use after free Write to new object overwrites old, or vice-versa Key issue is what heap object is reused for Influence by controlling other heap operations

Integer overflows Null pointer dereference Easiest to use: overflow in small (8-, 16-bit) value, or only overflowed value used 2GB write in 100 byte buffer Find some other way to make it stop Arbitrary single overwrite Use math to figure out overflowing value Add offset to make a predictable pointer On Windows, interesting address start low Allocate data on the zero page Most common in user-space to kernel attacks Read more dangerous than a write Format string attack Format string attack layout Attacker-controlled format: little interpreter Step one: add extra integer specifiers, dump stack Already useful for information disclosure Format string attack layout Format string attack: overwrite %n specifier: store number of chars written so far to pointer arg Advance format arg pointer to other attacker-controlled data Control number of chars written with padding On x86, use unaligned stores to create pointer

Outline Canary in the coal mine Photo credit: Fir0002 CC-BY-SA Adjacent canary idea Terminator canary Value hard to reproduce because it would tell the copy to stop StackGuard: 0x00 0D 0A FF 0: String functions newline: fgets(), etc. -1: getc() carriage return: similar to newline? Doesn t stop: memcpy, custom loops Random canary XOR canary Can t reproduce because attacker can t guess For efficiency, usually one per execution Ineffective if disclosed Want to protect against non-sequential overwrites XOR return address with value c at entry XOR again with c before return Standard choice for c: see random canary

Further refinements What s usually not protected? More flexible to do earlier in compiler Rearrange buffers after other variables Reduce chance of non-control overwrite Skip canaries for functions with only small variables Who has an overflow bug in an 8-byte array? Backwards overflows Function pointers Adjacent structure fields Adjacent static data objects Where to keep canary value Fast to access Buggy code/attacker can t read or write Linux/x86: %gs:0x14 Complex anti-canary attack Canary not updated on fork in server Attacker controls number of bytes overwritten Complex anti-canary attack Canary not updated on fork in server Attacker controls number of bytes overwritten ANRY BNRY CNRY DNRY ENRY FNRY search 2 32! search 4 2 8 Shadow return stack Suppose you have a safe place to store the canary Why not just store the return address there? Needs to be a separate stack Ultimate return address protection

Outline You may notice We re catching up with the readings Today: StackGuard, ASLR attacks Next time: CFI, Shacham ROP Pre-proposals due tonight Pre-proposals schedule note One PDF per group Submit via Moodle by 11:55pm Favorite meeting time: Mondays 2:30-3:00 Not everyone can have that time If your favorite time is popular, have more second choices Registering HW1 groups Outline Send list of members to geddes@cs.umn.edu Include names and UMN ids/login names We ll notify you when VMs are ready

Basic idea Code and data locations Address Space Layout Randomization Move memory areas around randomly so attackers can t predict addresses Keep internal structure unchanged E.g., whole stack moves together Execution of code depends on memory location E.g., on 32-bit x86: Direct jumps are relative Function pointers are absolute Data must be absolute Relocation (Windows) PIC/PIE (GNU/Linux) Extension of technique already used in compilation Keep table of absolute addresses, instructions on how to update Disadvantage: code modifications take time on load, prevent sharing Position-Independent Code / Executable Keep code unchanged, use register to point to data area Disadvantage: code complexity, register pressure hurt performance What s not covered Entropy limitations Main executable (Linux 32-bit PIC) Incompatible DLLs (Windows) Relative locations within a module/area Intuitively, entropy measures amount of randomness, in bits Random 32-bit int: 32 bits of entropy ASLR page aligned, so at most 32-12 = 20 bits of entropy Other constraints further reduce possibilities

Leakage limitations GOT hijack (Müller) If an attacker learns the randomized base address, can reconstruct other locations Any stack address! stack unprotected, etc. Main program fixed, libc randomized PLT in main program used to call libc Rewire PLT to call attacker s favorite libc functions E.g., turn printf into system GOT hijack (Müller) ret2pop (Müller) printf@plt: jmp *0x8049678... system@plt: jmp *0x804967c... 0x8049678: <addr of printf in libc> 0x804967c: <addr of system in libc> Take advantage of shellcode pointer already present on stack Rewrite intervening stack to treat the shellcode pointer like a return address A long sequence of chained returns, one pop ret2pop (Müller) Outline

Basic idea Traditional shellcode must go in a memory area that is writable, so the shellcode can be inserted executable, so the shellcode can be executed But benign code usually does not need this combination W xor X, really :(W ^ X) Non-writable code, X! :W E.g., read-only.text section Has been standard for a while, especially on Unix Lets OS efficiently share code with multiple program instances Non-executable data, W! :X Implementing W X Prohibit execution of static data, stack, heap Not a problem for most programs Incompatible with some GCC features no one uses Non-executable stack opt-in on Linux, but now near-universal Page protection implemented by CPU Some architectures (e.g. SPARC) long supported W X x86 historically did not One bit controls both read and execute Partial stop-gap code segment limit Eventual obvious solution: add new bit NX (AMD), XD (Intel), XN (ARM) One important exception Counterattack: code reuse Remaining important use of self-modifying code: just-in-time (JIT) compilers E.g., all modern JavaScript engines Allow code to re-enable execution per-block mprotect, VirtualProtect Now a favorite target of attackers Attacker can t execute new code So, take advantage of instructions already in binary There are usually a lot of them And no need to obey original structure

Classic return-to-libc (1997) Overwrite stack with copies of: Pointer to libc s system function Pointer to "/bin/sh" string (also in libc) The system function is especially convenient Distinctive feature: return to entry point Chained return-to-libc Shellcode often wants a sequence of actions, e.g. Restore privileges Allow execution of memory area Overwrite system file, etc. Can put multiple fake frames on the stack Basic idea present in 1997, further refinements Beyond return-to-libc Outline Can we do more? Oh, yes. Classic academic approach: what s the most we could ask for? Here: Turing completeness How to do it: reading for Monday BCVS Makefile BCVS Makefile CFLAGS := -g -w -m32 \ -fno-stack-protector \ -z execstack -z norelro CFLAGS := -g -w -m32 \ -fno-stack-protector \ -z execstack -z norelro Standard non-security options

BCVS Makefile BCVS Makefile CFLAGS := -g -w -m32 \ -fno-stack-protector \ -z execstack -z norelro CFLAGS := -g -w -m32 \ -fno-stack-protector \ -z execstack -z norelro Turn off canaries Allow execution on stack BCVS Makefile BCVS unprotection, cont d CFLAGS := -g -w -m32 \ -fno-stack-protector \ -z execstack -z norelro Leave GOT writable Not in Makefile: disable ASLR Will be done system-wide in VM For pre-vm testing, can use setarch i386 -R Next time Return-oriented programming (ROP) And counter-defenses Control-flow integrity (CFI)