Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)

Slides:



Advertisements
Similar presentations
Practical Malware Analysis
Advertisements

Smashing the Stack for Fun and Profit
Introduction to Information Security ROP – Recitation 5 nirkrako at post.tau.ac.il itamarg at post.tau.ac.il.
Utilizing the GDB debugger to analyze programs Background and application.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Accessing parameters from the stack and calling functions.
1 Homework Reading –PAL, pp , Machine Projects –Finish mp2warmup Questions? –Start mp2 as soon as possible Labs –Continue labs with your.
September 22, 2014 Pengju (Jimmy) Jin Section E
Recitation: Bomb Lab June 5, 2015 Dipayan Bhattacharya.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
CS162B: Assembly and C Jacob T. Chan. Objectives ▪ System calls ▪ Relation of System calls to Assembly and C ▪ Special System Calls (exit, write, print,
Application Security Tom Chothia Computer Security, Lecture 14.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 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)
Carnegie Mellon Introduction to Computer Systems /18-243, spring 2009 Recitation, Jan. 14 th.
Buffer Overflows : An In-depth Analysis. Introduction Buffer overflows were understood as early as 1972 The legendary Morris Worm made use of a Buffer.
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, _,
Goals: To gain an understanding of assembly To get your hands dirty in GDB.
Introduction to Information Security מרצים : Dr. Eran Tromer: Prof. Avishai Wool: מתרגלים : Itamar Gilad
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.
Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
CET 3510 Microcomputer Systems Tech. Lecture 2 Professor: Dr. José M. Reyes Álamo.
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.
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.
CNIT 127: Exploit Development Ch 1: Before you begin.
A Tool for Pro-active Defense Against the Buffer Overrun Attack D. Bruschi, E. Rosti, R. Banfi Presented By: Warshavsky Alex.
Shellcode Development -Femi Oloyede -Pallavi Murudkar.
Introduction to Information Security ROP – Recitation 5.
Compiler Construction Code Generation Activation Records
Reminder Bomb lab is due tomorrow! Attack lab is released tomorrow!!
Introduction to Information Security מרצים : Dr. Eran Tromer: Prof. Avishai Wool: מתרגלים : Itamar Gilad
EXPLOITATION CRASH COURSE – FALL 2013 UTD Computer Security Group – Andrew Folloder csg.utdallas.edu (credit: Scott Hand)
Introduction to InfoSec – Recitation 3 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (infosec15 at modprobe.net)
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.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Practical Session 3.
Exploiting & Defense Day 1 Recap
Introduction to Information Security
Instruction Set Architecture
Computer Architecture and Assembly Language
Introduction to Information Security
Static and dynamic analysis of binaries
Computer Architecture and Assembly Language
Debugging with gdb gdb is the GNU debugger on our CS machines.
Introduction to Information Security
Homework Reading Machine Projects Labs PAL, pp ,
Exploiting & Defense Day 2 Recap
Introduction to Compilers Tim Teitelbaum
Recitation: Attack Lab
Assembly Language Programming II: C Compiler Calling Sequences
Practical Session 4.
Lecture 9: Buffer Overflow*
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
CNT4704: Analysis of Computer Communication Network Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Fall 2011.
Week 2: Buffer Overflow Part 1.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2013.
System and Cyber Security
Exploitation Part 1.
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Return-to-libc Attacks
Presentation transcript:

Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)

Today More assembly tips Binary Patching o Tools Review of the stack Stack overflows Implementation o Tools

Little vs Big Endian Endian-ity is the definition of how numbers are represented in memory (or on a data bus) In the x86 architecture 0x would be represented in memory: o Intel Architecture is little endian. (we are using little) However the same number in Big Endian would be: o (we don’t see the bit reordering because our minimum working unit is a byte)

Registers Common uses: Eax – used usually for fast calculations / system call numbers /used to pass the return value or self class in c++. Ecx – used as a counter frequently. Ebp – used to store the stack frame pointer Esp – used to store the stack pointer edi/esi – used for string/buffer manipulations Ip – used to store the current instruction pointer – can not be accessed directly!

x86 There are lots of assembly instructions with varying sizes, and they can be used alternative to fit certain constraints. Examples: o MOV EAX, 0 o Alternatively: o XOR EAX,EAX There are also 8 bit commands to access partial registers o MOV AL, 5 There are 16 bit commands o Mov ax, 65535

Binary Patching Motivation: o Change the behavior of a program o Disable software protections for further analysis Examples: o Bypass checks in the program o Adding new functionality o Blocking weak/vulnerable functionality Process: o Find relevant code to modify o Understand code using reverse engineering o Find hook point in the code o Find location to insert new code without damaging the original operation or file structure as much as possible. o Divert flow from the hook point to the inserted code o Write the needed new functionality o Return the point of origin, or other appropriate point in the original code.

Example 1 Pre patched code: o Load input strings to compare to existing o CALL strcmp o ADD ESP,8 o TEST EAX,EAX o JZ end_of_function o LEA EBX, [address to user input command ] o PUSH EBX o LEA EBX, [address to user parameter] o CALL execv o ADD ESP,4 end_of_function: o LEAVE o RET

Example 1-Identify Pre patched code: o Load input strings to compare to existing o CALL strcmp o ADD ESP,8 o TEST EAX,EAX o JZ end_of_function o LEA EBX, [address to user input command ] o PUSH EBX o LEA EBX, [address to user parameter] o CALL execv o ADD ESP,4 end_of_function: o LEAVE o RET

Example 1-Patched Patched code: o Load input strings to compare to existing o CALL strcmp o ADD ESP,8 o TEST EAX,EAX o NOP o LEA EBX, [address to user input command ] o PUSH EBX o LEA EBX, [address to user parameter] o CALL execv o ADD ESP,4 end_of_function: o LEAVE o RET Why 2 NOPs ?

patch_util_gcc.py Compiles assembly and patches input binary into output binary. Parameters: o Original binary that will be patched o Output binary, this will be patch o Address.patch – code in assembly that will be compiled by gcc and put in the new binary in address which is the same as the patch. o Address2.patch – another patch Don’t forget to “chmod +x [output binary]” after creation. Running “patch_util_gcc.py empty.bin shellcode.bin 0.patch” – can be used to write shellcode.

va_to_offset.py Reads the FL structure and converts virtual addresses given at process startup (as shown in IDA). To the actual location in the file. An alternative solution is to search for the original code with ghex and patch it with the hex editor.

Example 2 Binary_patching_example_verify We will override the verification of the login, by seeking the appropriate point, which will be most easy. Create a patch and apply, verify that everything is well with IDA. Run and test and hope for the best.

Buffer’Os History: o First documented buffer overflows were thought of in 1972 COMPUTER SECURITY TECHNOLOGY PLANNING STUDY (Page 61)COMPUTER SECURITY TECHNOLOGY PLANNING STUDY o The first buffer overflows known in the wild were Stack’Os o Stack Overflows were widely introduced by Aleph One Phrack Magazine Issue 49 on November 8, 1996 o Title: Smashing the stack for fun and profit o Purpose: o Like when patching, we re-route the code to new code which adds new functionility. o We modify the behavior of a program without modifying the binary, and only by controlling the input! o Therefore we can subvert the original functionality of the code to any purpose.

Where does it get really interesting When the program input is from a remote connection o Example: telnet When the program has higher privileges o Example: su

Process Memory Abstract / \ lower | | memory | Text | addresses | | | | | (Initialized) | | Data | | (Uninitialized) | | | | | | Stack | higher | | memory \ / addresses

Example1.c void function(int a, int b, int c) { char buffer1[5]; char buffer2[10]; } void main() { function(1,2,3); }

Stack Structure bottom of top of memory memory buffer2 buffer1 sfp ret a b c < [ ][ ][ ][ ][ ][ ][ ] top of bottom of stack stack

Tools List gdb – GNU Debugger o Core dumping: gdb –core=core.dump o Ollydbg – (for windows) which we will not cover in the course. IDA o va_to_offset.py – easy program to get offset of code in orig file. gcc – the gnu compiler o For the course we have prepared an easy utility for compiling small assembly bits: patch_util_gcc.py ghex – can be used to patch the binary : o Once we have a search string to find the binary code, we can modify it Other common tools for linux debugging: o ltrace – library tracing o strace – system call tracing o Objdump – dump elf file and symbol information shellcode

shellcode example with interrupt calls jmp call_start # jump to the end of the code to /bin/sh start_shellcode: # label to jump back pop ebx # put point to /bin/sh in ebx xor eax,eax # zero eax, but dont use mov, because it include \x00 mov al, 0xb # system call 0xb, - execve xor ecx, ecx # clear pointer to envp int 0x80 # call a system call! xor eax,eax # ignore return and reset to zero. mov al, 0x1 # call exit system call int 0x80 call_start: call start_shellcode.string "/bin/sh"

GDB Quick browse si, ni – step instruction s, n – step info reg – print all registers dump memory filename startaddress stopaddress x/i address – disassemble at this address p (char *) 0x – print at this address as if it was a c- string. x/bx address – print hex starting from this address c – continue r arg1 arg2 – runs the file with the specified arguments b somefunction – sets a breakpoint

The end