Worm enabling exploits Cyber Security Lab Spring ‘10.

Slides:



Advertisements
Similar presentations
Buffer Overflows Nick Feamster CS 6262 Spring 2009 (credit to Vitaly S. from UT for slides)
Advertisements

Smashing the Stack for Fun and Profit
Defenses. Preventing hijacking attacks 1. Fix bugs: – Audit software Automated tools: Coverity, Prefast/Prefix. – Rewrite software in a type safe languange.
Exploring Security Vulnerabilities by Exploiting Buffer Overflow using the MIPS ISA Andrew T. Phillips Jack S. E. Tan Department of Computer Science University.
Communications of the ACM (CACM), Vol. 32, No. 6, June 1989
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.
Foundations of Network and Computer Security J J ohn Black Lecture #30 Nov 26 th 2007 CSCI 6268/TLEN 5831, Fall 2007.
Stack-Based Buffer Overflows Attacker – Can take over a system remotely across a network. local malicious users – To elevate their privileges and gain.
Netprog: Buffer Overflow1 Buffer Overflow Exploits Taken shamelessly from: netprog/overflow.ppt.
Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Maziéres, Dan Boneh
Control hijacking attacks Attacker’s goal: – Take over target machine (e.g. web server) Execute arbitrary code on target by hijacking application control.
Lecture 16 Buffer Overflow
Buffer Overflow Attacks. Memory plays a key part in many computer system functions. It’s a critical component to many internal operations. From mother.
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.
Lecture 6: Buffer Overflow CS 436/636/736 Spring 2014 Nitesh Saxena *Adopted from a previous lecture by Aleph One (Smashing the Stack for Fun and Profit)
Exploiting Buffer Overflows on AIX/PowerPC HP-UX/PA-RISC Solaris/SPARC.
University of Washington Today Memory layout Buffer overflow, worms, and viruses 1.
Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and.
Buffer Overflows : An In-depth Analysis. Introduction Buffer overflows were understood as early as 1972 The legendary Morris Worm made use of a Buffer.
Overview What is a worm? What is a worm? Origin? Origin? How does it propagate? How does it propagate? How does it take up resources of an infected node?
Mitigation of Buffer Overflow Attacks
CIS 450 – Network Security Chapter 7 – Buffer Overflow Attacks.
Lecture slides prepared for “Computer Security: Principles and Practice”, 3/e, by William Stallings and Lawrie Brown, Chapter 10 “Buffer Overflow”.
CNIT 127: Exploit Development Ch 4: Introduction to Format String Bugs.
1 CSE 451 Section 2: Interrupts, Syscalls, Virtual Machines, and Project 1.
Distributed Denial of Service Attacks Shankar Saxena Veer Vivek Kaushik.
Buffer Overflow CS461/ECE422 Spring Reading Material Based on Chapter 11 of the text.
Smashing the Stack Overview The Stack Region Buffer Overflow
Buffer Overflow. Introduction On many C implementations, it is possible to corrupt the execution stack by writing past the end of an array. Known as smash.
Overflows & Exploits. In the beginning 11/02/1988 Robert Morris, Jr., a graduate student in Computer Science at Cornell, wrote an experimental, self-replicating,
Lecture 8: Buffer Overflow CS 436/636/736 Spring 2013 Nitesh Saxena *Adopted from a previous lecture by Aleph One (Smashing the Stack for Fun and Profit)
Hacking Windows 9X/ME. Hacking framework Initial access physical access brute force trojans Privilege escalation Administrator, root privileges Consolidation.
Buffer Overflow Group 7Group 8 Nathaniel CrowellDerek Edwards Punna ChalasaniAxel Abellard Steven Studniarz.
Buffer Overflow Attack Proofing of Code Binary Gopal Gupta, Parag Doshi, R. Reghuramalingam, Doug Harris The University of Texas at Dallas.
Lecture 9: Buffer Ovefflows and ROP EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer Engineering Spring 2014,
A Tool for Pro-active Defense Against the Buffer Overrun Attack D. Bruschi, E. Rosti, R. Banfi Presented By: Warshavsky Alex.
Buffer overflow and stack smashing attacks Principles of application software security.
Sairajiv Burugapalli. This chapter covers three main categories of classic software vulnerability: Buffer overflows Integer vulnerabilities Format string.
Buffer Overflows Taught by Scott Coté.-. _ _.-. / \.-. ((___)).-. / \ /.ooM \ / \.-. [ x x ].-. / \ /.ooM \ -/ \ /-----\-----/---\--\ /--/---\-----/-----\ / \-
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.
Foundations of Network and Computer Security J J ohn Black CSCI 6268/TLEN 5550, Spring 2013.
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.
VM: Chapter 7 Buffer Overflows. csci5233 computer security & integrity (VM: Ch. 7) 2 Outline Impact of buffer overflows What is a buffer overflow? Types.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
1 Introduction to Information Security , Spring 2016 Lecture 2: Control Hijacking (2/2) Avishai Wool.
CS703 - Advanced Operating Systems By Mr. Farhan Zaidi.
@Yuan Xue Worm Attack Yuan Xue Fall 2012.
Shellcode COSC 480 Presentation Alison Buben.
Refs: rootshell, antionline, your favorite hacker site…
Mitigation against Buffer Overflow Attacks
Buffer Overflow Buffer overflows are possible because C doesn’t check array boundaries Buffer overflows are dangerous because buffers for user input are.
Protecting Memory What is there to protect in memory?
The Hardware/Software Interface CSE351 Winter 2013
Protecting Memory What is there to protect in memory?
Protecting Memory What is there to protect in memory?
CMSC 414 Computer and Network Security Lecture 21
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Software Security Lesson Introduction
Format String.
CSC 495/583 Topics of Software Security Format String Bug (2) & Heap
Format String Vulnerability
Overflows, Injection, & Memory Safety
Return-to-libc Attacks
Presentation transcript:

Worm enabling exploits Cyber Security Lab Spring ‘10

Background reading Worm Anatomy and Model – Smashing the Stack for Fun and Profit – &id=14&mode=txthttp:// &id=14&mode=txt The Shellcoder’s Handbook –At the library

More Reading Steve Hanna’s Shellcode page – Once Upon a Free() – =9&mode=txthttp:// =9&mode=txt

Outline Review worm structure Examine exploited vulnerabilities –Buffer Overflow –Return to Libc –Format String exploits –Heap Overflow

What is a Worm? An autonomous process that can cause a copy of itself (or a variant) to execute on a remote machine. Various Goals –Install trojan’s for later access –Install zombies for later DDoS or other activities –Install spies for information gathering –Personal fame Generally varies from a virus in that it propagates independently. –A virus needs a host program to propagate. –But otherwise, many of the issues between worms and virus are the same

Life Cycle of a Worm Initialization: –Install software, understand the local machine configuration Payload Activation: –Activate the worm on the current host Network Propagation: –Identify new targets and propagate itself –The cycle starts all over on the newly infected devices

Network Propagation in More Detail Target Acquisition: Identify hosts to attack. –Random address scans (Code Red) or locality biased (Nimda) –Code Red v2 effectiveness changed based on good seeding Network Reconnaissance: Determine if the target is available and what is running on it Attack: Attempt to gain root access on the target –Traditionally this has been buffer overflow –Can also attack other weaknesses like weak passwords Infection: Leverage root access to start the Initialization phase on the new host

Example Worm: LION Active around 2001 Three versions Not a particularly effective worm –Uses a BIND exploit that attacks the “named” daemon Not activated on default RedHat 6.2 installations Administrator would have to explicitly add to inetd table and run as root Variant of the earlier worms –ADMworm, Millenium Worm, Ramen worm

Lion Life Cycle Attempts connection to TCP port 53 on candidate target hosts –Selects random class B network blocks to scan If target responds, send malformed UDP IQUERY packet to UDP port 53 –Used to determine if target is running vulnerable version of Linux running BIND 8 If vulnerable, send overflow packet –Attack code walks file descriptor table of exploited process to find FD of initial TCP connection –Duplicates FD to stdin, stdout, stderr –Spawn /bin/sh running at root

Lion Life Cycle Continued Now can use original TCP connection as control channel to send shell commands –Download and install software Versions 1 and 2 download from fixed site Version 3 uses Ramen distribution code to download from infecting host –Send password files to central location for later analysis –Cover tracks. Erase logs and temporary files

Buffer Overflow Exploits Write too much data into a stack buffer –Replace return address on the stack with address of attack code –Generally attack code attempts to start a shell If process is SetUID root, shell will be root Attack code is often in the buffer

Stack Structure Function Arguments (a) Return Address Saved Frame Ptr void func(char *a) { char buffer[512]; strcpy(buffer, a); …. } High address Low address Previous frames Buffer[512] Stack Ptr Frame Ptr

Shell Code Insert code to spawn a shell Phrack article discusses how to do this from first principles –Create assembly code to exec /bin/sh –Use GDB to get hex of machine code –Rework assembly as necessary to avoid internal 0’s Could break attack if strcpy is used by attack target Will result in a hex string like: –“\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x 46\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\ x80\x31\xdb\x89\xd8\x40\xcd\x80\xe8\xdc\xff\xff\xff/bi n/sh”

Structure of Buffer Buffer more than 512 bytes will replace other information on the stack (like return address) Problem is determining absolute address in buffer to jump to and ensuring you replace the return address –Pad with leading NOPs and trailing return addresses –Then your guesses on the stack structure do not need to be exact NOPsShell CodeReturn Address Replacements

Copied Stack Function Arguments Return Address Saved Frame Ptr Previous frames Buffer[512] N copies of Address X Previous frames NOPs Shell Code Address X

Calculating New Return Address If you have source –Use GDB to find stack address at appropriate invocation GDB reporting may not be accurate, might take several guesses –Use Eggshell program Approximate target program Takes buffer size and offset arguments Computes candidate buffers Emits buffers in environment variable named EGG Creates new shell on the way out so EGG is available after program has completed If you don’t have source –Brute force? –Examination of core files or other dumps

Return to libc Make stack non-executable to protect from buffer overflow –Newer windows feature –Feature in some flavors of Unix/Linux Adapt by setting the return address to a known library –Libc is home to nice functions like system, which we can use to spawn a shell.

Return to Libc Stack Function Arguments Return Address Saved Frame Ptr Previous frames Buffer[512] Y X – new frame ptr Previous frames Buffer[512] Libc Segement system() exit() X Z – new return ptr to /bin/sh Y Z Frame Ptr

Protections No execute bit Address space randomization Canaries Use type safe languages Avoid known bad libraries

Address Space Randomization Vary the base stack address with each execution –Stack smashing must have absolute address to over write function return address –Enabled by default in some linuxes (e.g., FC3) Wastes some address space –Less of an issue once we have 64 bit address space Not absolute –Try many times and get lucky Does not help return to libc or heap overflows

Tools for Buffer Overflow Protection LibSafe – –Intercept calls to functions with known problems and perform extra checks –Source is not necessary StackGuard and SSP/ProPolice –Place “canary” values at key places on stack smashing_protectionhttp://en.wikipedia.org/wiki/Stack- smashing_protection –Terminator (fixed) or random values –ProPolice patch to gcc

LibSafe Function Arguments Return Address Saved Frame Ptr Previous frames Buffer[512] Frame Pointer Uses LD_PRELOAD to intercept all “dangerous” calls. Use Frame pointer and buffer address to detect corruption of stack Target Buffer

Canary Values Function Arguments Return Address Saved Frame Ptr Previous frames Buffer[512] N copies of Address X Previous frames NOPs Shell Code Address X Canary

Non-Executable Stack Set page as non-executable –Supported by newer AMD and x86 chips –Supported by some OS’s Does not protect against return to libc or heap attacks.

Format String Errors What is a format string? –printf(“Foo 0x%x %d\n”, addr, count); What happens if the arguments are missing? –printf(“Foo 0x%x, %d\n”); What if the end user can specify his own format string? –printf(fmtstring)

Information Disclosure By specifying arbitrary %x’s (or %d’s) you can read the stack –Made easier by direct parameter access –“%128\$x” – print the 128’th argument as a hex Looking at the stack you can see the address to your own format string

Reading arbitrary addresses You can load an address into the first 4 bytes of your format string If you know the offset of the format string on the stack, use %s to read the string starting at that address –formatstr = $’\x55\x4d\x06\x08%272$s’; –printf(formatstr) So, we leak information, but printf is read only, right?

Writing data with printf The %n parameter writes the number of bytes written so far by printf to the corresponding int * pointer Kind of awkward, but does enable the dedicated fiddler to write arbitrary data at arbitrary locations –Only writes one byte at a time Likely targets –Return addresses –Data, like terminating passwords we are checking –Global Offset Table (GOT) – library function pointer table

Format string errors easily avoided Never accept raw format strings from end user –Never allow printf(buf) –Instead do printf(“%s”, buf);

Heap overflows Gain control by overflowing heap allocated buffer Heap imposes additional structure on large blocks of memory given by OS Control structures intermingled with user data in heap memory –Specific attacks very dependent on details of particular malloc implementation

Example Structure 0 Cur size + flag Data Returned Ptr to mem Allocated Chunk Cur size + flag Unused Space Returned Ptr to mem Freed Chunk Prev size Next Ptr Prev Ptr

Control Memory Through Free 0 Cur size + flag Data 0 Cur size + flag Data buf2 buf1 0 Cur size + flag Data 0xFFFFFFF 0xFFFFFF0 buf2 buf1 fd bk

Exploiting Heap Control Structure Overwrite into the next “free” block Set or unset low bit of size to control path through free –Unlink will use the first two words in the memory to remove itself from linked list. –You can put any memory address there, e.g. Stack return location, and control broader execution flow.

Poison buffer Jmp, 2paddingShell code 0xFFFFFF FC Retloc - 12Retaddr Chunk Boundary Retaddr

Heap attack protections Randomization could help use here too. –DieHard (DH) Memory Allocator – age=diehardhttp://prisms.cs.umass.edu/emery/index.php?p age=diehard

Summary Worms rely on exploits of networked services –Goal: get a shell started at high privilege –Even shell at low privilege gives attacker a foothold to attack locally Exploits need to write specific data and specific addresses –Trick data structures –Use mechanisms in unexpected ways