Hacking Techniques & Intrusion Detection Ali Al-Shemery arabnix [at] gmail.

Slides:



Advertisements
Similar presentations
Hacking Techniques & Intrusion Detection Ali Al-Shemery arabnix [at] gmail.
Advertisements

Slide 1CPU Emulator Tutorial This program is part of the software suite that accompanies the book The Digital Core, by Noam Nisan and Shimon Schocken 2003,
Hacking Techniques & Intrusion Detection Ali Al-Shemery arabnix [at] gmail.
Utilizing the GDB debugger to analyze programs Background and application.
RIVERSIDE RESEARCH INSTITUTE Helikaon Linux Debugger: A Stealthy Custom Debugger For Linux Jason Raber, Team Lead - Reverse Engineer.
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
Hacking Techniques & Intrusion Detection Ali Al-Shemery arabnix [at] gmail.
Hacking Techniques & Intrusion Detection Ali Al-Shemery arabnix [at] gmail.
Memory & Storage Architecture Seoul National University Computer Architecture “ Bomb Lab Hints” 2nd semester, 2014 Modified version : The original.
, Spring 2005 Debugging with gdb ???mber ??, 200? class03.ppt David I. Murray , Fall 2005.
OllyDbg Debuger.
Homework Reading –Finish K&R Chapter 1 (if not done yet) –Start K&R Chapter 2 for next time. Programming Assignments –DON’T USE and string library functions,
Debugging techniques in Linux Debugging Techniques in Linux Chetan Kumar S Wipro Technologies.
1 ENG236: ENG236: C++ Programming Environment (2) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY.
F13 Forensic tool analysis Dr. John P. Abraham Professor UTPA.
Gdb is the GNU debugger on our CS machines. gdb is most effective when it is debugging a program that has debugging symbols linked in to it. With gcc and.
Homework Reading Programming Assignments
Debugging Cluster Programs using symbolic debuggers.
Trying to like a boss… REVERSE ENGINEERING. WHAT EVEN IS… REVERSE ENGINEERING?? Reverse engineering is the process of disassembling and analyzing a particular.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
Application Security Tom Chothia Computer Security, Lecture 14.
Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
Memory & Storage Architecture Seoul National University GDB commands Hyeon-gyu School of Computer Science and Engineering.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2011.
Part 3: Advanced Dynamic Analysis Chapter 8: Debugging.
Binary Auditing Geller Bedoya Michael Wozniak. Background  Binary auditing is a technique used to test the security and discover the inner workings of.
Compiling & Debugging Quick tutorial. What is gcc? Gcc is the GNU Project C compiler A command-line program Gcc takes C source files as input Outputs.
Goals: To gain an understanding of assembly To get your hands dirty in GDB.
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
Module 6: Debugging a Windows CE Image.  Overview Debug Zones IDE Debug Setup IDE Debug Commands Platform Builder Integrated Kernel Debugger Other Debugging.
A Tutorial on Introduction to gdb By Sasanka Madiraju Graduate Assistant Center for Computation and Technology.
CNIT 127: Exploit Development Ch 3: Shellcode. Topics Protection rings Syscalls Shellcode nasm Assembler ld GNU Linker objdump to see contents of object.
1 SEEM3460 Tutorial Compiling and Debugging C programs.
CSE 351 GDB Introduction. Lab 1 Status? How is Lab 1 going? I’ll be available at the end of class to answer questions There are office hours later today.
Disclaimer The Content, Demonstration, Source Code and Programs presented here is "AS IS" without any warranty or conditions.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
Introduction to Information Security ROP – Recitation 5.
Debugging 1/6/2016. Debugging 1/6/2016 Debugging  Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a program.
Unit - V. Debugging GNU Debugger helps you in getting information about the following: 1.If a core dump happened, then what statement or expression did.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.
Lab 9 Department of Computer Science and Information Engineering National Taiwan University Lab9 - Debugging I 2014/11/4/ 28 1.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
1 ENERGY 211 / CME 211 Lecture 14 October 22, 2008.
GDB Introduction And Lab 2
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
Using the GNU Debugger (GDB)‏ Techzemplary Pvt.Ltd February 24 th 2008 Pranav Peshwe.
Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Institute of Radio Physics and Electronics and Indian GNU/Linux Users Group Kolkata.
DEBUG.
Instructions for test_function
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Static and dynamic analysis of binaries
Dynamic Analysis ddaa.
CSE 374 Programming Concepts & Tools
Debugging with gdb gdb is the GNU debugger on our CS machines.
Malware Incident Response  Dynamic Analysis - 2
gdb gdb is the GNU debugger on our CS machines.
Introduction to Computer Systems
Computer Architecture “Bomb Lab Hints”
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science
GNU DEBUGGER TOOL. What is the GDB ? GNU Debugger It Works for several languages – including C/C++ [Assembly, Fortran,Go,Objective-C,Pascal]
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
CSC235 - Visual Studio Tutorial
Week 2: Buffer Overflow Part 2.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
Debugging.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2013.
By Hugues Leger / Intro to GDB debugger By Hugues Leger / 11/16/2019.
Presentation transcript:

Hacking Techniques & Intrusion Detection Ali Al-Shemery arabnix [at] gmail

All materials is licensed under a Creative Commons “Share Alike” license. 2

# whoami Ali Al-Shemery Ph.D., MS.c., and BS.c., Jordan More than 14 years of Technical Background (mainly Linux/Unix and Infosec) Technical Instructor for more than 10 years (Infosec, and Linux Courses) Hold more than 15 well known Technical Certificates Infosec & Linux are my main Interests 3

Software Exploitation Prepared by: Dr. Ali Al-Shemery Mr. Shadi Naif

Debugging Fundamentals for Pentesters

Outline – Part 2 Debugger – GDB – Immunity Debugger Debuggers Offer? Popular Debuggers? Which to use? Example: Debugging auth.c using gdb 6

Debugger A computer program that lets you run your program, line by line and examine the values of variables or look at values passed into functions and let you figure out why it isn't running the way you expected it to. 7

Debuggers Offer? Debuggers offer sophisticated functions such as: – Running a program step by step (single-stepping mode), – Stopping (breaking) (pausing the program to examine the current state) at some event or specified instruction by means of a breakpoint, – Tracking the values of variables, – Tracking the values of CPU registers, – Attach to a process, – View the process’s Memory map, – Load memory dump (post-mortem debugging), – Disassemble program instructions, – Change values at runtime, – Continue execution at a different location in the program to bypass a crash or logical error. 8

Popular Debuggers? GNU Debugger (GDB) Microsoft Windows Debugger (Windbg) OllyDbg Immunity Debugger Microsoft Visual Studio Debugger Interactive Disassembler (IDA Pro) 9

Immunity Debugger A powerful new way to write exploits, analyze malware, and reverse engineer binary files. It builds on a solid user interface with function graphing, and a large and well supported Python API for easy extensibility. Did you read that? Python 10

Immunity Debugger 11

Which to use? IMO there is no exact answer to this question, it’s a matter of comfort! Choose the debugger comfortable for you and helps you with your debugging process. 12

Example – Auth.c What does auth.c do? – It takes the first argument from the command line, – It then passes this argument to a basic authentication function for checking, – If the argument is the correct password, it prints a success message, – If the argument isn’t the correct password, it prints a failure message. There is a bug in the code! Let’s try to discover it. 13

Auth.c using gdb gdb is a command line debugger, not very user friendly, but very powerful. First we need to compile auth.c, then run auth from within gdb. Use gcc: – gcc –ggdb –O0 auth.c -o auth 14

Auth.c using gdb - Cont. Start auth from within gdb: – gdb auth Run it with no arguments (gdb) run This will give us a Segmentation fault. The program now crashes! Let’s find what made the program crash. 15

Auth.c using gdb - Cont. We need to reconstruct the frames on the stack. The frames will show us the function calling sequence. Use the gdb command “backtrace” (gdb) backtrace If you examine the output of the command you will find that the crash happened after calling the auth() function (frame #1)! 16

Auth.c using gdb - Cont. We need to check the instructions in the code where it has crashed. EIP points to the last instruction executed. We need to examine the memory and EIP: To do that we will use the “x” to display memory contents: (gdb) x/5i $eip What does all that do???? 17

Auth.c using gdb - Cont. “x” is used to display memory content in various formats, “i” is used for displaying instructions (disassembly), “5” is the number of instructions to display. Check next slide for “x” formats. 18

“x” – Examine Memory FormatDescription xhexadecimal ddecimal ooctal tbinary iinstructions sstring ccharacter uunsigned UnitDescription bbytes wwords (4 bytes) x / 19

Auth.c using gdb - Cont. The fault occurred at this instruction: (gdb) x/10i $eip cmp al, BYTE PTR [edx] cmp al, BYTE PTR [edx] compares al with the byte at the memory address stored within edx. There doesn’t seem to be an error here! Wait, let’s inspect the register edx and see what does it hold? 20

Auth.c using gdb - Cont. Let’s inspect the local variables and arguments. We can use the gdb “info locals” and “info args” commands: (gdb) info locals No symbol table info availabe (gdb) info args No symbol table info availabe 21

Auth.c using gdb - Cont. That means there is no debugging information. (Re-compile to resolve!) Quit gdb: (gdb) q Recompile with debugging information enabled: gcc –g auth.c –o auth The –g informs the compile to include symbolic debugging information within the compiled binary. 22

Auth.c using gdb - Cont. Let’s load auth in gdb again: $ gdb auth Now we can list the program code which is available from the debugging information. For that we use the gdb “list” command: (gdb) list – Press Enter if not all the code is shown. 23

Auth.c using gdb - Cont. If you remember the program crashed when calling the auth() function. Let us setup a break point. We can use the gdb “break” command: – (gdb) break 13 Now run the program: – (gdb) run The process execution is suspended when it reaches our breakpoint. This is how we made gdb control the execution process! 24

Auth.c using gdb - Cont. Let us check the arguments values. We can use the gdb “print” command for inspecting variables. – (gdb) print argv[1] argv[1] is the argument passed to the auth function. And as you can see it’s value is 0x0 which is a NULL pointer! Continue the execution with the gdb command “continue”: – (gdb) continue 25

Auth.c using gdb - Cont. Now if we inspect the registers using the gdb command “info registers” we see that edx is holding 0x0 (the NULL pointer). – (gdb) info registers – (gdb) x/5i $eip This is what is causing the crash, as the program is comparing to a NULL pointer! 26

Auth.c using gdb – Summary Using gdb we managed to discover the bug in our code. All we need to do to solve this problem is check for the number of given arguments before calling the auth() function! as simple as that! 27

Load Configurations Tired of always setting your GDB configurations? Use the -x file Add your configurations to a file such as gdb.config and then: – gdb –x gdb.config auth 28

Quit GDB Debugging Just press ‘q’ ! 29

References (1) Papers/Presentations/Links: – ShellCode, – Introduction to win32 shellcoding, Corelan, part-9-introduction-to-win32-shellcodeing/ part-9-introduction-to-win32-shellcodeing/ – Hacking/Shellcode/Alphanumeric/x64 printable opcodes, 64_printable_opcodes 64_printable_opcodes – Learning Assembly Through Writing Shellcode, through-writing-shellcode/ through-writing-shellcode/ – Shellcoding for Linux and Windows Tutorial, – Unix Assembly Codes Development, – Win32 Assembly Components,

References (2) Papers/Presentations/Links: – 64-bit Linux Shellcode, linux-shellcode/ linux-shellcode/ – Writing shellcode for Linux and *BSD, panic.it/security/shellcode/index.htmlhttp:// panic.it/security/shellcode/index.html – Understanding Windows’s Shellcode (Matt Miller’s, aka skape) – Metasploit’s Meterpreter (Matt Miller, aka skape) – Syscall Proxying fun and applications, uberwall.org – X86 Opcode and Instruction Reference, – Shellcode: the assembly cocktail, by Samy Bahra,

References (3) Books: – Grayhat Hacking: The Ethical Hacker’s Handbook, 3 rd Edition – The Shellcoders Handbook, – The Art of Exploitation, 2 nd Edition, Shellcode Repositories: – Exploit-DB: – Shell Storm: Tools: – BETA3 - Multi-format shellcode encoding tool, – X86 Opcode and Instruction Reference, – bin2shell, content/uploads/2012/06/bin2shell.tar.gz 32