Exploitation Of Windows Buffer Overflows. What is a Buffer Overflow A buffer overflow is when memory is copied to a location that is outside of its allocated.

Slides:



Advertisements
Similar presentations
Practical Malware Analysis
Advertisements

Smashing the Stack for Fun and Profit
1 CHAPTER 8 BUFFER OVERFLOW. 2 Introduction One of the more advanced attack techniques is the buffer overflow attack Buffer Overflows occurs when software.
Stack buffer overflow
Memory Image of Running Programs Executable file on disk, running program in memory, activation record, C-style and Pascal-style parameter passing.
1 Function Calls Professor Jennifer Rexford COS 217 Reading: Chapter 4 of “Programming From the Ground Up” (available online from the course Web site)
Practical Session 3. The Stack The stack is an area in memory that its purpose is to provide a space for temporary storage of addresses and data items.
Accessing parameters from the stack and calling functions.
Practical Session 3. The Stack The stack is an area in memory that its purpose is to provide a space for temporary storage of addresses and data items.
1 Homework Reading –PAL, pp , Machine Projects –Finish mp2warmup Questions? –Start mp2 as soon as possible Labs –Continue labs with your.
Assembly תרגול 8 פונקציות והתקפת buffer.. Procedures (Functions) A procedure call involves passing both data and control from one part of the code to.
September 22, 2014 Pengju (Jimmy) Jin Section E
Attacks Using Stack Buffer Overflow Boxuan Gu
University of Washington CSE 351 : The Hardware/Software Interface Section 5 Structs as parameters, buffer overflows, and lab 3.
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2011.
Dr. José M. Reyes Álamo 1.  The 80x86 memory addressing modes provide flexible access to memory, allowing you to easily access ◦ Variables ◦ Arrays ◦
Exploiting Buffer Overflows on AIX/PowerPC HP-UX/PA-RISC Solaris/SPARC.
More Network Security Threats Worm = a stand-alone program that can replicate itself and spread Worms can also contain manipulation routines to perform.
Variables, Functions & Parameter Passing CSci 588 Fall 2013 All material not from online sources copyright © Travis Desell, 2011.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
Introduction: Exploiting Linux. Basic Concepts Vulnerability A flaw in a system that allows an attacker to do something the designer did not intend,
Practical Session 4. Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _,
Mitigation of Buffer Overflow Attacks
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)
CNIT 127: Exploit Development Ch 3: Shellcode. Topics Protection rings Syscalls Shellcode nasm Assembler ld GNU Linker objdump to see contents of object.
Overflows & Exploits. In the beginning 11/02/1988 Robert Morris, Jr., a graduate student in Computer Science at Cornell, wrote an experimental, self-replicating,
CNIT 127: Exploit Development Ch 1: Before you begin.
Stack-based buffer overflows Yves Younan DistriNet, Department of Computer Science Katholieke Universiteit Leuven Belgium
What is exactly Exploit writing?  Writing a piece of code which is capable of exploit the vulnerability in the target software.
Shellcode Development -Femi Oloyede -Pallavi Murudkar.
JMU GenCyber Boot Camp Summer, Introduction to Penetration Testing Elevating privileges – Getting code run in a privileged context Exploiting misconfigurations.
CS 155 Section 1 PP1 Eu-Jin Goh. Setting up Environment Demo.
1 Getting Started with C++ Part 2 Linux. 2 Getting Started on Linux Now we will look at Linux. See how to copy files between Windows and Linux Compile.
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.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015.
Practical Session 4. GNU Linker Links object files together Used as the last step in the compilation We will use ld to link together compiled assembly.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
Practical Session 4. GNU Linker Links object files together Used as the last step in the compilation We will use ld to link together compiled assembly.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
Practical Session 3.
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.
Stack Operations Dr. Hadi AL Saadi.
Recitation 5: Attack Lab
Introduction to Information Security
Computer Architecture and Assembly Language
Recitation: Attack Lab
Exploiting & Defense Day 2 Recap
Recitation: Attack Lab
Popping Items Off a Stack Lesson xx
Assembly Language Programming II: C Compiler Calling Sequences
Practical Session 4.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
Multi-modules programming
Week 2: Buffer Overflow Part 2.
X86 Assembly Review.
Computer Architecture and System Programming Laboratory
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2013.
System and Cyber Security
FIGURE Illustration of Stack Buffer Overflow
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Presentation transcript:

Exploitation Of Windows Buffer Overflows

What is a Buffer Overflow A buffer overflow is when memory is copied to a location that is outside of its allocated space This is bad because it will override data that has been stored to control the flow of the data and other stored values Exploitation could (and does) lead to the process giving a cracker access to your system remotely

What is Shellcode Shellcode in the strictest definition is a program that will bring up a shell terminal from a remote location In the more practical since shell code is any program which is injected into another program for some malicious purpose

How a Buffer Overflow Works While windows is running it protects the code portion of the executable file from being written to So to get a buffer overflow a cracker must write to the stack where all of the temporary data is stored

Example of Buffer Overflow (part 1) #include using std::cin; using std::cout; using std::endl; void function() { char buffer1[10]; char buffer2[10]; cin >> buffer1; strcpy(buffer2, buffer1); cout << buffer2 << endl; } int main() { function(); cout << "if you see this then you didn't overflow the buffer“ << endl; return 0; }

Example of Buffer Overflow (part 2) Return Address 123\0 ABCDEFGHIJ Return Address Buffer1 Buffer2 With this code the stack would normally look like this But if we enter the string ABCDEF GHIJ123

Example of Buffer Overflow (part 3) If a long enough string was inserted into the buffer it could override the Return Address which could jump to the beginning of a program and overrun the process

How to Locate Functions in the Kernel32.dll Download a program to disassemble the dll file. (I used disasm.exe from Take the disassembled file and do a search for the file that you are looking for You will find the address in a line that looks like this Addr:7C80BC69 Ord: 830 (033Eh) Name: SizeofResource Addr:7C Ord: 831 (033Fh) Name: Sleep Addr:7C80239C Ord: 832 (0340h) Name: SleepEx

Basics of x86 Assembly (Part 1) Because of the simplicity of most shellcode the simplest and most useful assembly code will be discussed in this section One thing that should be noted is that because Shellcode is injected as a string it CANNOT HAVE ANY NULL CHARACTERS IN IT!!!!

Basics of x86 Assembly (Part 2) Registers EAX – EDX are 32-bit general purpose registers AX – DX access the lower 16-bit of the general purpose registers AL – DLaccess the lower 8-bit of the general purpose registers Assembler Code STRING_LABLE db ‘string$’ - declares a string and assigns it to STRING_LABLE. In c++ this would look like STRING_LABLE = ‘string$’. The string needs to end with a $ or any other symbol because a NULL character will have to be placed into it later. jmp short LABLE – jump a short distance to the section of code designated by LABLE: push/pop REGISTER – place what is in REGISTER onto the top of the stack / remove what is on the top of the stack and place it into REGISTER

Basics of x86 Assembly (Part 3) call LABLE db ‘string$’ – jumps to location LABLE and places string$ onto the stack call REGISTER – calls whatever function address is sitting in the register Because some functions have arguments that need to be passed to them you will need to place then onto the stack in reverse order. Ex.) foo(int x, int y, int z) push edx;place z push ecx;place y push ebx;place x call eax;eax has the address of foo which pulls x, ;y and z off of the stack mov Dest, Source – place what is in the register Source into the register Dest xor REG, REG – A good way to clear out a register is to xor the register with itself

Example of a way to place a NULL at the end of a string jmp short START ADD_NULL: pop ecx;move the address of the string ;‘Hey Man$’ into ecx xor edx, edx;clear edx mov [ecx + 8], dl;ecx now has the ;address of the string ‘Hey Man\0’ START: call ADD_NULL db ‘Hey Man$’

Example of how to exit the process without alerting the parent process xor eax, eax push eax mov eax 0xFFFFFFFF;address of ExitProcess function – note ;FFFFFFFFF is not its address call eax

Turning Assembly to Shellcode Create an assembly file on a *nix machine which contains the whole shellcode (it should not be to long) Run the on a *nix box command: nasm –f elf SHCODE.asm; ld –o SHCODE SHCODE.o; objdump –d SHCODE What will pop up on your screen is the hex interpretation of your assembly code Take out all of the hex numbers and add a \x before each pair of them You should end up with something like this - \xe5\xf4\x04\x22 – if not longer. This is your shellcode. If any part of it equals \x00 you screwed up!

Testing the Shellcode This c file was written by Steve Hanna who wrote Shellcoding for Linux and Windows Tutorial /*shellcodetest.c*/ char code[] = "bytecode will go here!"; Int main(int argc, char **argv) { int (*func)(); func = (int (*)()) code; (int)(*func)(); }

Source Steve Hanna - Shellcoding for Linux and Windows Tutorial - hellcode.html hellcode.html Honestly this is the best place to begin trying to learn. His examples are fast and simple.