Part 3: Advanced Dynamic Analysis Chapter 8: Debugging.

Slides:



Advertisements
Similar presentations
Computer-System Structures Er.Harsimran Singh
Advertisements

Memory Protection: Kernel and User Address Spaces  Background  Address binding  How memory protection is achieved.
Secure In-VM Monitoring Using Hardware Virtualization Monirul Sharif, Wenke Lee, Weidong Cui, and Andrea Lanzi Presented by Tyler Bletsch.
Utilizing the GDB debugger to analyze programs Background and application.
Operating System Security : David Phillips A Study of Windows Rootkits.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
RIVERSIDE RESEARCH INSTITUTE Helikaon Linux Debugger: A Stealthy Custom Debugger For Linux Jason Raber, Team Lead - Reverse Engineer.
Nullcon Goa 2010http://nullcon.net Intelligent Debugging and in-memory Fuzzers By Vishwas Sharma Amandeep Bharti Rohan Thakur.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Chapter 4 H1 Assembly Language: Part 2. Direct instruction Contains the absolute address of the memory location it accesses. ld instruction:
Introduction to Interrupts
OllyDbg Debuger.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
System Calls 1.
Trying to like a boss… REVERSE ENGINEERING. WHAT EVEN IS… REVERSE ENGINEERING?? Reverse engineering is the process of disassembling and analyzing a particular.
Practical Malware Analysis Ch 8: Debugging Rev
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Protection and the Kernel: Mode, Space, and Context.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
CCS APPS CODE COVERAGE. CCS APPS Code Coverage Definition: –The amount of code within a program that is exercised Uses: –Important for discovering code.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
CS533 Concepts of Operating Systems Jonathan Walpole.
29th ACSAC (December, 2013) SPIDER: Stealthy Binary Program Instrumentation and Debugging via Hardware Virtualization Zhui Deng, Xiangyu Zhang, and Dongyan.
Memory Management 3 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
CIS 450 – Network Security Chapter 7 – Buffer Overflow Attacks.
Replay Compilation: Improving Debuggability of a Just-in Time Complier Presenter: Jun Tao.
UBI >> Contents Chapter 2 Software Development tools Code Composer Essentials v3: Code Debugging Texas Instruments Incorporated University of Beira Interior.
Christopher Kruegel University of California Engin Kirda Institute Eurecom Clemens Kolbitsch Thorsten Holz Secure Systems Lab Vienna University of Technology.
MICHALIS POLYCHRONAKIS(COLUMBIA UNIVERSITY,USA), KOSTAS G. ANAGNOSTAKIS(NIOMETRICS, SINGAPORE), EVANGELOS P. MARKATOS(FORTH-ICS, GREECE) ACSAC,2010 Comprehensive.
Module 6: Debugging a Windows CE Image.  Overview Debug Zones IDE Debug Setup IDE Debug Commands Platform Builder Integrated Kernel Debugger Other Debugging.
Buffer Overflow Proofing of Code Binaries By Ramya Reguramalingam Graduate Student, Computer Science Advisor: Dr. Gopal Gupta.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 9: Virtual Memory.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
Disclaimer The Content, Demonstration, Source Code and Programs presented here is "AS IS" without any warranty or conditions.
Homework tar file Download your course tarball from web page – Named using your PSU ID – Chapter labeled for each binary.
Processes and Virtual Memory
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.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Lecture 5 Rootkits Hoglund/Butler (Chapters 1-3).
Lecture 11 Example Rootkit. Intel internship Intel CTG (Corporate Technology Group) –Advanced research & development –System integrity services using.
CNIT 127: Exploit Development Ch 8: Windows Overflows Part 1.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Lecture 10 Anti-debugger techniques. Anti-debuggers Making reverse-engineering and disassembly painful –Polymorphism –Encryption –Interrupt disabling.
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
Chapter 6 Limited Direct Execution Chien-Chung Shen CIS/UD
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
CSNB334 Advanced Operating Systems 3. Kernel Structure and Organization Lecturer: Abdul Rahim Ahmad.
Lab assignments Follow each lab walkthrough in textbook
Introduction to Operating Systems
Live Phishing Attack Authentication Activity from a Foreign Address.
Dynamic Analysis ddaa.
Threads CSSE 332 Operating Systems Rose-Hulman Institute of Technology
Malware Incident Response  Dynamic Analysis - 2
Module: Handling Exceptions
Part 3: Advanced Dynamic Analysis
Chapter 9 :: Subroutines and Control Abstraction
Introduction to Operating Systems
Chapter 9: Virtual-Memory Management
Machine Independent Features
Lab assignments Follow each lab walkthrough in textbook
Memory Management Tasks
Reverse engineering through full system simulations
Module 6: Debugging a Windows CE Image
Outline Operating System Organization Operating System Examples
Virtual Memory Lecture notes from MKP and S. Yalamanchili.
Following Malware Execution in IDA
Presentation transcript:

Part 3: Advanced Dynamic Analysis Chapter 8: Debugging

Debugger Hardware or software used to examine execution of another program Disassembler: static snapshot of what code looks like before execution Debugger: dynamic snapshot of what code does during execution

Types of debuggers Source-level Debug while coding Map machine execution to corresponding source code lines Allow setting of breakpoints at source-code lines Assembly-level Strictly operate at machine instruction level Main debugger used for malware

Kernel mode v. user mode User mode Debug one program via another program all in user space Examples: OlllyDbg Kernel mode Debugging a kernel requires a second machine Must configure target OS to allow kernel debugging Examples: WinDbg

Debugging functions Single stepping One machine instruction or source line at a time Stepping-over: call functions executed all at once before control returned to debugger Stepping-into: call functions followed and callee executed one machine instruction at a time Stepping-out: some debuggers allow you to return to calling function Replay Some VMs allow record/replay to “undo” execution

Debugging functions Software execution breakpoints Virtual address or source line Examine the state of the machine at critical execution points File creation (Listing 8-4, Figure 8-1) Encryption (Listing 8-5, Figure 8-2) Implemented by overwriting INT 3 (0xcc) into opcode of instruction (Table 8-1) Debugger restores overwritten byte upon continue Replay Some VMs allow record/replay to “undo” execution

Debugging functions Hardware execution breakpoints Dedicated registers that store virtual addresses Can be set to break on access, rather than on execution Memory watchpoints on data (reads or writes) 4 hardware registers (DR0-DR3) Can be modified by running program! Malware can disable them Counter-measure is “General Detect” flag in DR7 that triggers a breakpoint on any mov involving debug registers

Debugging functions Conditional software execution breakpoints Break only if a certain condition is met Example Break on GetProcAddress function only if address parameter is RegSetValue Implemented as normal software breakpoint, but debugger checks condition and automatically continues if not met

Exceptions Used by debugger to gain control of program INT 3, Trap flag in FLAGS register, Division by 0, invalid memory access First-chance and second-chance exceptions Debugger (if attached) gets first-chance control over exceptions If debugger does not want it, program allowed to handle exception If program does not handle exception and would crash, debugger gets a second-chance to handle exception Malware may intentionally trigger first-chance exceptions to determine environment

Modifying execution Via debugger Skip functions by changing EIP directly Invoke functions directly on arguments you choose Use in metamorphic malware Malware programmed to behave differently under different circumstances Debugger can be set to trace branches of metamorphic code (Listing 8-6)

Advanced Dynamic Analysis Chapter 9: OllyDbg

OllyDbg Developed by Oleh Yuschuk Debugger of choice for malware analysis *and* exploit developers Bought by Immunity and rebranded as ImmDbg Python API support added Many still use OllyDbg 1.1 (OllyDbg 2.0 not widely used yet in 2012)

Loading code in OllyDbg Open executable from within OllyDbg Launch executable and attach In-class exercise Recreate Figure 9-2 for notepad.exe 4 main windows of OllyDbg Disassembler, Registers, Stack, Memory dump Launch notepad.exe from OllyDbg Attach OllyDbg to running notepad Recreate Figures 9-3, 9-4 for notepad.exe

Rebasing Memory locations of Figure 9-4 dynamic Relocatable code allows libraries to be rebased Enables libraries to be written independent of each other Absolute address references modified at load time via.reloc information in PE header Supports ASLR to thwart malware In-class exercise Note the location of notepad's.text section Relaunch OllyDbg on notepad again What is the location now?

Threads Most programs and malware multi-threaded In-class exercise Launch Internet Explorer Attach OllyDbg View threads via View>Threads How many threads are there?

Executing code Debug menu Run Restarts process until next breakpoint reached Breakpoint=>Run to selection Continue execution until specified instruction Debug=>Execute till Return Runs until next return hit Debug=>Execute till User Code Run until user program code is reached Pulls out of library calls In-class: MyExample.exe strncmp Step into, step over

Executing code Malware making a mess out of step-over P. 187 Step over a “call” instruction sets breakpoint to next instruction after call Malware might never return Could be a “get EIP” trick as well – call followed by a pop

Breakpoints View=>Breakpoints to list Right-click instruction to find sub-menu to set Software breakpoint (Toggle) Sets execution breakpoint at instruction See string decoder in Listing 9-2 Hardware breakpoint (on execution) Memory (on access) Memory (on write)

Breakpoints Right-click instruction to find sub-menu to set Conditional breakpoint Checks condition to see if debugger should break Poison Ivy example – Backdoor that reads shellcode commands from socket and executes them – Uses a call to VirtualAlloc to store command – Typical call to VirtualAlloc (Figure 9-7) – Want to break only on large allocations indicative of a batch of commands (> 100bytes) » Size parameter at [ESP+8] » Set breakpoint at VirtualAlloc entry point if condition [ESP+8] > 100 » Breakpoint=>Conditional » Figure 9-8

Loading DLLs Malware often delivered as DLLs to be injected into other processes OllyDbg uses loaddll.exe as dummy program Calls into DllMain function of target DLL Hit play to initialize DLL Debug=>Call DLL export to call a particular exported function with custom parameters Follow in disassembler to see code Figure 9-10 In-class exercise Open Lab03-02.dll (only on 32-bit win7, restart olly)

Tracing Recording execution Standard Back Trace Execution recorded when single stepping + and – take you forward and backward in execution Call Stack Trace View the function call path that has led to your current execution point In-class: MyExample.exe strncmp

Tracing Recording execution Run Trace OllyDbg saves every executed instruction and all changes to registers and flags Highlight code to trace – Run Trace=>Add Selection – Execute – View=>Run Trace – - and + to navigate trace and see changes – In-class: MyExample.exe and strncmp Or use “Trace Into” and “Trace Over” options to run trace until next breakpoint – Take care to limit size of trace

Tracing Poison Ivy backdoor example VirtualAlloc to store commands from C&C server Stored in heap memory EIP executes from heap locations Goal: Find out mechanism for execution Step #1: Set condition to pause on EIP outside of program segment (Figure 9-11) Step #2: Trace Into to execute until condition met Step #3: Use – key to backup execution to see where entry into shellcode occurred

Exceptions Exceptions that occur while debugger attached transfer control to debugger User options Step into exception Step over exception Run exception handler Can also set in Debugging Options to ignore all exceptions (immediately transfer control back to program)

Patching Modifying program instructions to change behavior Binary=>Edit In class In OllyDbg, modify conditional branch within MyExample.exe to *always* hit OK branch Copy modifications to new executable

Dumping Create new binary upon unpacking program OllyDump plug-in Find entry point after unpacking and decryption operations of malware performed Creates a new executable that can be analyzed within IDA Pro Figure 9-16

In-class exercise Lab 9-2 In OllyDbg, perform the Follow in Dump step to display 1qaz2wsx and ocl.exe Generate Listing 9-6L in IDA Pro. In OllyDbg, set a breakpoint at the strcmp and identify the strings being compared In IDA Pro, show where the network calls are located Change the name of the file to enable the malware to execute Step through and show the DNS name as it is being decoded Within Wireshark, show the connect and its result