SlideShare une entreprise Scribd logo
1  sur  48
Télécharger pour lire hors ligne
Practical Malware Analysis
Ch 8: Debugging
Rev. 9-11-18
Disassemblers v. Debuggers
• A disassembler like IDA Pro shows the state
of the program just before execution
begins
• Debuggers show
– Every memory location
– Register
– Argument to every function
• At any point during processing
– And let you change them
Two Debuggers
• Ollydbg
– Most popular for malware analysis
– User-mode debugging only
– IDA Pro has a built-in debugger, but it's not as
easy to use or powerful as Ollydbg
• Windbg
– Supports kernel-mode debugging
Source-Level v. Assembly-Level
Debuggers
• Source-level debugger
– Usually built into development platform
– Can set breakpoints (which stop at lines of code)
– Can step through program one line at a time
• Assembly-level debuggers (low-level)
– Operate on assembly code rather than source code
– Malware analysts are usually forced to use them,
because they don't have source code
Windows Crashes
• When an app
crashes,
Windows may
offer to open it
in a debugger
• Usually it uses
Windbg
• Links Ch 8c, 8d
Kernel v. User-Mode
Debugging
User Mode Debugging
• Debugger runs on the same system as the
code being analyzed
• Debugging a single executable
• Separated from other executables by the
OS
Kernel Mode Debugging
The Old Way
• Requires two computers, because there is only
one kernel per computer
• If the kernel is at a breakpoint, the system
stops
• One computer runs the code being debugged
• Other computer runs the debugger
• OS must be configured to allow kernel
debugging
• Two machines must be connected
Windows 7
Advanced
Boot Options
• Press F8
during
startup
• "Debugging
Mode"
Side-Effect of Debug Mode
• PrntScn key causes BSOD
• Created great suffering in S214 in previous
semesters
• Use Shift+PrntScn instead
Kernel Mode Debugging
The New Way
• Mark Russinovich's Livekd tool allows you
to debug the kernel with only one
computer!
• MUCH easier :)
• Tool has some limitations (Link Ch 8e)
12
How Livekd Works
• Link Ch 8f
Good Intro to OllyDbg
• Link Ch 8a
Using a Debugger
Two Ways
• Start the program with the debugger
– It stops running immediately prior to the
execution of its entry point
• Attach a debugger to a program that is
already running
– All its threads are paused
– Useful to debug a process that is affected by
malware
Single-Stepping
• Simple, but slow
• Don't get bogged down in details
Example
• This code
decodes the
string with XOR
Stepping-over v. Stepping-Into
• Single step executes one instruction
• Step-over call instructions
– Completes the call and returns without pausing
– Decreases the amount of code you need to analyze
– Might miss important functionality, especially if
the function never returns
• Step-into a call
– Moves into the function and stops at its first
command
Pausing Execution with Breakpoints
• A program that is paused at a breakpoint
is called broken
• Example
– You can't tell where this call is going
– Set a breakpoint at the call and see what's in
eax
• This code
calculates a
filename
and then
creates the
file
• Set a
breakpoint
at
CreateFileW
and look at
the stack to
see the
filename
WinDbg
Encrypted Data
• Suppose malware sends encrypted
network data
• Set a breakpoint before the data is
encrypted and view it
OllyDbg
Types of Breakpoints
• Software execution
• Hardware execution
• Conditional
Software Execution Breakpoints
• The default option for most debuggers
• Debugger overwrites the first byte of the
instruction with 0xCC
– The instruction for INT 3
– An interrupt designed for use with debuggers
– When the breakpoint is executed, the OS
generates an exception and transfers control
to the debugger
Memory Contents at a Breakpoint
• There's a breakpoint at the push
instruction
• Debugger says it's 0x55, but it's really
0xCC
When Software Execution Breakpoints
Fail
• If the 0xCC byte is changed during code
execution, the breakpoint won't occur
• If other code reads the memory
containing the breakpoint, it will read
0xCC instead of the original byte
• Code that verifies integrity will notice the
discrepancy
Hardware Execution Breakpoints
• Uses four hardware Debug Registers
– DR0 through DR3 – addresses of breakpoints
– DR7 stores control information
• The address to stop at is in a register
• Can break on access or execution
– Can set to break on read, write, or both
• No change in code bytes
Hardware Execution Breakpoints
• Running code can change the DR registers,
to interfere with debuggers
• General Detect flag in DR7
– Causes a breakpoint prior to any mov
instruction that would change the contents of
a Debug Register
– Does not detect other instructions, however
Conditional Breakpoints
• Breaks only if a condition is true
– Ex: Set a breakpoint on the GetProcAddress
function
– Only if parameter being passed in is
RegSetValue
• Implemented as software breakpoints
– The debugger always receives the break
– If the condition is not met, it resumes
execution without alerting the user
Conditional Breakpoints
• Conditional breakpoints take much longer
than ordinary instructions
• A conditional breakpoint on a frequently-
accessed instruction can slow a program
down
• Sometimes so much that it never finishes
Exceptions
Exceptions
• Used by debuggers to gain control of a
running program
• Breakpoints generate exceptions
• Exceptions are also caused by
– Invalid memory access
– Division by zero
– Other conditions
First- and Second-Chance Exceptions
• When a exception occurs while a
debugger is attached
– The program stops executing
– The debugger is given first chance at control
– Debugger can either handle the exception, or
pass it on to the program
– If it's passed on, the program's exception
handler takes it
Second Chance
• If the application doesn't handle the
exception
• The debugger is given a second chance to
handle it
– This means the program would have crashed if
the debugger were not attached
• In malware analysis, first-chance exceptions
can usually be ignored
• Second-chance exceptions cannot be ignored
– They usually mean that the malware doesn't like
the environment in which it is running
Common Exceptions
• INT 3 (Software breakpoint)
• Single-stepping in a debugger is implemented
as an exception
– If the trap flag in the flags register is set,
– The processor executes one instruction and then
generates an exception
• Memory-access violation exception
– Code tries to access a location that it cannot
access, either because the address is invalid or
because of access-control protections
Common Exceptions
• Violating Privilege Rules
– Attempt to execute privileged instruction
with outside privileged mode
– In other words, attempt to execute a kernel
mode instruction in user mode
– Or, attempt to execute Ring 0 instruction
from Ring 3
List of Exceptions
• Link Ch 8b
Modifying Execution with a
Debugger
Skipping a Function
• You can change control flags, the
instruction pointer, or the code itself
• You could avoid a function call by setting
a breakpoint where at the call, and then
changing the instruction pointer to the
instruction after it
– This may cause the program to crash or
malfunction, or course
Testing a Function
• You could run a function directly, without
waiting for the main code to use it
– You will have to set the parameters
– This destroys a program's stack
– The program won't run properly when the
function completes
Modifying Program Execution
in Practice
Example (A Real Virus)
• Operation depends on language setting of
a computer
– Simplified Chinese
• Uninstalls itself & does no harm
– English
• Display pop-up "Your luck's no good"
– Japanese or Indonesian
• Overwrite the hard drive with random data
Break at 1; Change Return Value
CNIT 126: 8: Debugging

Contenu connexe

Tendances

Practical Malware Analysis Ch12
Practical Malware Analysis Ch12Practical Malware Analysis Ch12
Practical Malware Analysis Ch12Sam Bowne
 
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly Sam Bowne
 
CNIT 126 11. Malware Behavior
CNIT 126 11. Malware BehaviorCNIT 126 11. Malware Behavior
CNIT 126 11. Malware BehaviorSam Bowne
 
Practical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA ProPractical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA ProSam Bowne
 
Practical Malware Analysis Ch 14: Malware-Focused Network Signatures
Practical Malware Analysis Ch 14: Malware-Focused Network SignaturesPractical Malware Analysis Ch 14: Malware-Focused Network Signatures
Practical Malware Analysis Ch 14: Malware-Focused Network SignaturesSam Bowne
 
CNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgCNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgSam Bowne
 
CNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static Techniques
CNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static TechniquesCNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static Techniques
CNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static TechniquesSam Bowne
 
Practical Malware Analysis: Ch 11: Malware Behavior
Practical Malware Analysis: Ch 11: Malware BehaviorPractical Malware Analysis: Ch 11: Malware Behavior
Practical Malware Analysis: Ch 11: Malware BehaviorSam Bowne
 
CNIT 126 5: IDA Pro
CNIT 126 5: IDA Pro CNIT 126 5: IDA Pro
CNIT 126 5: IDA Pro Sam Bowne
 
CNIT 126: Ch 2 & 3
CNIT 126: Ch 2 & 3CNIT 126: Ch 2 & 3
CNIT 126: Ch 2 & 3Sam Bowne
 
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in Assembly
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in AssemblyPractical Malware Analysis: Ch 6: Recognizing C Code Constructs in Assembly
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in AssemblySam Bowne
 
CNIT 126 4: A Crash Course in x86 Disassembly
CNIT 126 4: A Crash Course in x86 DisassemblyCNIT 126 4: A Crash Course in x86 Disassembly
CNIT 126 4: A Crash Course in x86 DisassemblySam Bowne
 
CNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginCNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginSam Bowne
 
Practical Malware Analysis Ch13
Practical Malware Analysis Ch13Practical Malware Analysis Ch13
Practical Malware Analysis Ch13Sam Bowne
 
Practical Windows Kernel Exploitation
Practical Windows Kernel ExploitationPractical Windows Kernel Exploitation
Practical Windows Kernel ExploitationzeroSteiner
 
CNIT 126 Ch 9: OllyDbg
CNIT 126 Ch 9: OllyDbgCNIT 126 Ch 9: OllyDbg
CNIT 126 Ch 9: OllyDbgSam Bowne
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeCNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeSam Bowne
 
127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on LinuxSam Bowne
 
Practical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbgPractical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbgSam Bowne
 
CNIT 141: 4. Block Ciphers
CNIT 141: 4. Block CiphersCNIT 141: 4. Block Ciphers
CNIT 141: 4. Block CiphersSam Bowne
 

Tendances (20)

Practical Malware Analysis Ch12
Practical Malware Analysis Ch12Practical Malware Analysis Ch12
Practical Malware Analysis Ch12
 
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
 
CNIT 126 11. Malware Behavior
CNIT 126 11. Malware BehaviorCNIT 126 11. Malware Behavior
CNIT 126 11. Malware Behavior
 
Practical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA ProPractical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA Pro
 
Practical Malware Analysis Ch 14: Malware-Focused Network Signatures
Practical Malware Analysis Ch 14: Malware-Focused Network SignaturesPractical Malware Analysis Ch 14: Malware-Focused Network Signatures
Practical Malware Analysis Ch 14: Malware-Focused Network Signatures
 
CNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgCNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbg
 
CNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static Techniques
CNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static TechniquesCNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static Techniques
CNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static Techniques
 
Practical Malware Analysis: Ch 11: Malware Behavior
Practical Malware Analysis: Ch 11: Malware BehaviorPractical Malware Analysis: Ch 11: Malware Behavior
Practical Malware Analysis: Ch 11: Malware Behavior
 
CNIT 126 5: IDA Pro
CNIT 126 5: IDA Pro CNIT 126 5: IDA Pro
CNIT 126 5: IDA Pro
 
CNIT 126: Ch 2 & 3
CNIT 126: Ch 2 & 3CNIT 126: Ch 2 & 3
CNIT 126: Ch 2 & 3
 
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in Assembly
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in AssemblyPractical Malware Analysis: Ch 6: Recognizing C Code Constructs in Assembly
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in Assembly
 
CNIT 126 4: A Crash Course in x86 Disassembly
CNIT 126 4: A Crash Course in x86 DisassemblyCNIT 126 4: A Crash Course in x86 Disassembly
CNIT 126 4: A Crash Course in x86 Disassembly
 
CNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginCNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you Begin
 
Practical Malware Analysis Ch13
Practical Malware Analysis Ch13Practical Malware Analysis Ch13
Practical Malware Analysis Ch13
 
Practical Windows Kernel Exploitation
Practical Windows Kernel ExploitationPractical Windows Kernel Exploitation
Practical Windows Kernel Exploitation
 
CNIT 126 Ch 9: OllyDbg
CNIT 126 Ch 9: OllyDbgCNIT 126 Ch 9: OllyDbg
CNIT 126 Ch 9: OllyDbg
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeCNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: Shellcode
 
127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux
 
Practical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbgPractical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbg
 
CNIT 141: 4. Block Ciphers
CNIT 141: 4. Block CiphersCNIT 141: 4. Block Ciphers
CNIT 141: 4. Block Ciphers
 

Similaire à CNIT 126: 8: Debugging

CNIT 126 8: Debugging
CNIT 126 8: DebuggingCNIT 126 8: Debugging
CNIT 126 8: DebuggingSam Bowne
 
Cloud Foundry Summit 2015: 12 Factor Apps For Operations
Cloud Foundry Summit 2015: 12 Factor Apps For OperationsCloud Foundry Summit 2015: 12 Factor Apps For Operations
Cloud Foundry Summit 2015: 12 Factor Apps For OperationsVMware Tanzu
 
CNIT 126 9: OllyDbg
CNIT 126 9: OllyDbgCNIT 126 9: OllyDbg
CNIT 126 9: OllyDbgSam Bowne
 
Ch 16 & 17 Fault Injection & Fuzzing
Ch 16 & 17 Fault Injection & FuzzingCh 16 & 17 Fault Injection & Fuzzing
Ch 16 & 17 Fault Injection & FuzzingSam Bowne
 
Software coding & testing, software engineering
Software coding & testing, software engineeringSoftware coding & testing, software engineering
Software coding & testing, software engineeringRupesh Vaishnav
 
Java: Finding Bugs, Fixing Bugs in IBM Domino Designer and XPages
Java: Finding Bugs, Fixing Bugs in IBM Domino Designer and XPagesJava: Finding Bugs, Fixing Bugs in IBM Domino Designer and XPages
Java: Finding Bugs, Fixing Bugs in IBM Domino Designer and XPagespanagenda
 
Java Code Quality Tools
Java Code Quality ToolsJava Code Quality Tools
Java Code Quality ToolsAnju ML
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your codePascal Larocque
 
TechGIG_Memory leaks in_java_webnair_26th_july_2012
TechGIG_Memory leaks in_java_webnair_26th_july_2012TechGIG_Memory leaks in_java_webnair_26th_july_2012
TechGIG_Memory leaks in_java_webnair_26th_july_2012Ashish Bhasin
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010Clay Helberg
 
19-reliabilitytesting.ppt
19-reliabilitytesting.ppt19-reliabilitytesting.ppt
19-reliabilitytesting.pptAnilteaser
 
Captain Hook: Pirating AVs to Bypass Exploit Mitigations
Captain Hook: Pirating AVs to Bypass Exploit MitigationsCaptain Hook: Pirating AVs to Bypass Exploit Mitigations
Captain Hook: Pirating AVs to Bypass Exploit MitigationsenSilo
 
Piratng Avs to bypass exploit mitigation
Piratng Avs to bypass exploit mitigationPiratng Avs to bypass exploit mitigation
Piratng Avs to bypass exploit mitigationPriyanka Aash
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem slovingMani Kandan
 
Gearman - Northeast PHP 2012
Gearman - Northeast PHP 2012Gearman - Northeast PHP 2012
Gearman - Northeast PHP 2012Mike Willbanks
 
Compilers and interpreters
Compilers and interpretersCompilers and interpreters
Compilers and interpretersRAJU KATHI
 

Similaire à CNIT 126: 8: Debugging (20)

CNIT 126 8: Debugging
CNIT 126 8: DebuggingCNIT 126 8: Debugging
CNIT 126 8: Debugging
 
Cloud Foundry Summit 2015: 12 Factor Apps For Operations
Cloud Foundry Summit 2015: 12 Factor Apps For OperationsCloud Foundry Summit 2015: 12 Factor Apps For Operations
Cloud Foundry Summit 2015: 12 Factor Apps For Operations
 
CNIT 126 9: OllyDbg
CNIT 126 9: OllyDbgCNIT 126 9: OllyDbg
CNIT 126 9: OllyDbg
 
Exception handling
Exception handlingException handling
Exception handling
 
PHP - Introduction to PHP Bugs - Debugging
PHP -  Introduction to  PHP Bugs - DebuggingPHP -  Introduction to  PHP Bugs - Debugging
PHP - Introduction to PHP Bugs - Debugging
 
Ch 16 & 17 Fault Injection & Fuzzing
Ch 16 & 17 Fault Injection & FuzzingCh 16 & 17 Fault Injection & Fuzzing
Ch 16 & 17 Fault Injection & Fuzzing
 
Software coding & testing, software engineering
Software coding & testing, software engineeringSoftware coding & testing, software engineering
Software coding & testing, software engineering
 
Java: Finding Bugs, Fixing Bugs in IBM Domino Designer and XPages
Java: Finding Bugs, Fixing Bugs in IBM Domino Designer and XPagesJava: Finding Bugs, Fixing Bugs in IBM Domino Designer and XPages
Java: Finding Bugs, Fixing Bugs in IBM Domino Designer and XPages
 
Java Code Quality Tools
Java Code Quality ToolsJava Code Quality Tools
Java Code Quality Tools
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
 
TechGIG_Memory leaks in_java_webnair_26th_july_2012
TechGIG_Memory leaks in_java_webnair_26th_july_2012TechGIG_Memory leaks in_java_webnair_26th_july_2012
TechGIG_Memory leaks in_java_webnair_26th_july_2012
 
Anti Debugging
Anti DebuggingAnti Debugging
Anti Debugging
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
 
19-reliabilitytesting.ppt
19-reliabilitytesting.ppt19-reliabilitytesting.ppt
19-reliabilitytesting.ppt
 
Captain Hook: Pirating AVs to Bypass Exploit Mitigations
Captain Hook: Pirating AVs to Bypass Exploit MitigationsCaptain Hook: Pirating AVs to Bypass Exploit Mitigations
Captain Hook: Pirating AVs to Bypass Exploit Mitigations
 
Piratng Avs to bypass exploit mitigation
Piratng Avs to bypass exploit mitigationPiratng Avs to bypass exploit mitigation
Piratng Avs to bypass exploit mitigation
 
Plc by Mohamed Al-Emam, Session3
Plc by Mohamed Al-Emam, Session3Plc by Mohamed Al-Emam, Session3
Plc by Mohamed Al-Emam, Session3
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem sloving
 
Gearman - Northeast PHP 2012
Gearman - Northeast PHP 2012Gearman - Northeast PHP 2012
Gearman - Northeast PHP 2012
 
Compilers and interpreters
Compilers and interpretersCompilers and interpreters
Compilers and interpreters
 

Plus de Sam Bowne

3: DNS vulnerabilities
3: DNS vulnerabilities 3: DNS vulnerabilities
3: DNS vulnerabilities Sam Bowne
 
8. Software Development Security
8. Software Development Security8. Software Development Security
8. Software Development SecuritySam Bowne
 
4 Mapping the Application
4 Mapping the Application4 Mapping the Application
4 Mapping the ApplicationSam Bowne
 
3. Attacking iOS Applications (Part 2)
 3. Attacking iOS Applications (Part 2) 3. Attacking iOS Applications (Part 2)
3. Attacking iOS Applications (Part 2)Sam Bowne
 
12 Elliptic Curves
12 Elliptic Curves12 Elliptic Curves
12 Elliptic CurvesSam Bowne
 
11. Diffie-Hellman
11. Diffie-Hellman11. Diffie-Hellman
11. Diffie-HellmanSam Bowne
 
2a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 12a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 1Sam Bowne
 
9 Writing Secure Android Applications
9 Writing Secure Android Applications9 Writing Secure Android Applications
9 Writing Secure Android ApplicationsSam Bowne
 
12 Investigating Windows Systems (Part 2 of 3)
12 Investigating Windows Systems (Part 2 of 3)12 Investigating Windows Systems (Part 2 of 3)
12 Investigating Windows Systems (Part 2 of 3)Sam Bowne
 
12 Investigating Windows Systems (Part 1 of 3
12 Investigating Windows Systems (Part 1 of 312 Investigating Windows Systems (Part 1 of 3
12 Investigating Windows Systems (Part 1 of 3Sam Bowne
 
9. Hard Problems
9. Hard Problems9. Hard Problems
9. Hard ProblemsSam Bowne
 
8 Android Implementation Issues (Part 1)
8 Android Implementation Issues (Part 1)8 Android Implementation Issues (Part 1)
8 Android Implementation Issues (Part 1)Sam Bowne
 
11 Analysis Methodology
11 Analysis Methodology11 Analysis Methodology
11 Analysis MethodologySam Bowne
 
8. Authenticated Encryption
8. Authenticated Encryption8. Authenticated Encryption
8. Authenticated EncryptionSam Bowne
 
7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)Sam Bowne
 
7. Attacking Android Applications (Part 1)
7. Attacking Android Applications (Part 1)7. Attacking Android Applications (Part 1)
7. Attacking Android Applications (Part 1)Sam Bowne
 
5. Stream Ciphers
5. Stream Ciphers5. Stream Ciphers
5. Stream CiphersSam Bowne
 
6 Scope & 7 Live Data Collection
6 Scope & 7 Live Data Collection6 Scope & 7 Live Data Collection
6 Scope & 7 Live Data CollectionSam Bowne
 

Plus de Sam Bowne (20)

Cyberwar
CyberwarCyberwar
Cyberwar
 
3: DNS vulnerabilities
3: DNS vulnerabilities 3: DNS vulnerabilities
3: DNS vulnerabilities
 
8. Software Development Security
8. Software Development Security8. Software Development Security
8. Software Development Security
 
4 Mapping the Application
4 Mapping the Application4 Mapping the Application
4 Mapping the Application
 
3. Attacking iOS Applications (Part 2)
 3. Attacking iOS Applications (Part 2) 3. Attacking iOS Applications (Part 2)
3. Attacking iOS Applications (Part 2)
 
12 Elliptic Curves
12 Elliptic Curves12 Elliptic Curves
12 Elliptic Curves
 
11. Diffie-Hellman
11. Diffie-Hellman11. Diffie-Hellman
11. Diffie-Hellman
 
2a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 12a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 1
 
9 Writing Secure Android Applications
9 Writing Secure Android Applications9 Writing Secure Android Applications
9 Writing Secure Android Applications
 
12 Investigating Windows Systems (Part 2 of 3)
12 Investigating Windows Systems (Part 2 of 3)12 Investigating Windows Systems (Part 2 of 3)
12 Investigating Windows Systems (Part 2 of 3)
 
10 RSA
10 RSA10 RSA
10 RSA
 
12 Investigating Windows Systems (Part 1 of 3
12 Investigating Windows Systems (Part 1 of 312 Investigating Windows Systems (Part 1 of 3
12 Investigating Windows Systems (Part 1 of 3
 
9. Hard Problems
9. Hard Problems9. Hard Problems
9. Hard Problems
 
8 Android Implementation Issues (Part 1)
8 Android Implementation Issues (Part 1)8 Android Implementation Issues (Part 1)
8 Android Implementation Issues (Part 1)
 
11 Analysis Methodology
11 Analysis Methodology11 Analysis Methodology
11 Analysis Methodology
 
8. Authenticated Encryption
8. Authenticated Encryption8. Authenticated Encryption
8. Authenticated Encryption
 
7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)
 
7. Attacking Android Applications (Part 1)
7. Attacking Android Applications (Part 1)7. Attacking Android Applications (Part 1)
7. Attacking Android Applications (Part 1)
 
5. Stream Ciphers
5. Stream Ciphers5. Stream Ciphers
5. Stream Ciphers
 
6 Scope & 7 Live Data Collection
6 Scope & 7 Live Data Collection6 Scope & 7 Live Data Collection
6 Scope & 7 Live Data Collection
 

Dernier

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Dernier (20)

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

CNIT 126: 8: Debugging

  • 1. Practical Malware Analysis Ch 8: Debugging Rev. 9-11-18
  • 2. Disassemblers v. Debuggers • A disassembler like IDA Pro shows the state of the program just before execution begins • Debuggers show – Every memory location – Register – Argument to every function • At any point during processing – And let you change them
  • 3. Two Debuggers • Ollydbg – Most popular for malware analysis – User-mode debugging only – IDA Pro has a built-in debugger, but it's not as easy to use or powerful as Ollydbg • Windbg – Supports kernel-mode debugging
  • 4. Source-Level v. Assembly-Level Debuggers • Source-level debugger – Usually built into development platform – Can set breakpoints (which stop at lines of code) – Can step through program one line at a time • Assembly-level debuggers (low-level) – Operate on assembly code rather than source code – Malware analysts are usually forced to use them, because they don't have source code
  • 5. Windows Crashes • When an app crashes, Windows may offer to open it in a debugger • Usually it uses Windbg • Links Ch 8c, 8d
  • 7. User Mode Debugging • Debugger runs on the same system as the code being analyzed • Debugging a single executable • Separated from other executables by the OS
  • 8. Kernel Mode Debugging The Old Way • Requires two computers, because there is only one kernel per computer • If the kernel is at a breakpoint, the system stops • One computer runs the code being debugged • Other computer runs the debugger • OS must be configured to allow kernel debugging • Two machines must be connected
  • 9. Windows 7 Advanced Boot Options • Press F8 during startup • "Debugging Mode"
  • 10. Side-Effect of Debug Mode • PrntScn key causes BSOD • Created great suffering in S214 in previous semesters • Use Shift+PrntScn instead
  • 11. Kernel Mode Debugging The New Way • Mark Russinovich's Livekd tool allows you to debug the kernel with only one computer! • MUCH easier :) • Tool has some limitations (Link Ch 8e)
  • 13. Good Intro to OllyDbg • Link Ch 8a
  • 14.
  • 16. Two Ways • Start the program with the debugger – It stops running immediately prior to the execution of its entry point • Attach a debugger to a program that is already running – All its threads are paused – Useful to debug a process that is affected by malware
  • 17. Single-Stepping • Simple, but slow • Don't get bogged down in details
  • 18. Example • This code decodes the string with XOR
  • 19. Stepping-over v. Stepping-Into • Single step executes one instruction • Step-over call instructions – Completes the call and returns without pausing – Decreases the amount of code you need to analyze – Might miss important functionality, especially if the function never returns • Step-into a call – Moves into the function and stops at its first command
  • 20. Pausing Execution with Breakpoints • A program that is paused at a breakpoint is called broken • Example – You can't tell where this call is going – Set a breakpoint at the call and see what's in eax
  • 21. • This code calculates a filename and then creates the file • Set a breakpoint at CreateFileW and look at the stack to see the filename
  • 23. Encrypted Data • Suppose malware sends encrypted network data • Set a breakpoint before the data is encrypted and view it
  • 24.
  • 26. Types of Breakpoints • Software execution • Hardware execution • Conditional
  • 27. Software Execution Breakpoints • The default option for most debuggers • Debugger overwrites the first byte of the instruction with 0xCC – The instruction for INT 3 – An interrupt designed for use with debuggers – When the breakpoint is executed, the OS generates an exception and transfers control to the debugger
  • 28. Memory Contents at a Breakpoint • There's a breakpoint at the push instruction • Debugger says it's 0x55, but it's really 0xCC
  • 29. When Software Execution Breakpoints Fail • If the 0xCC byte is changed during code execution, the breakpoint won't occur • If other code reads the memory containing the breakpoint, it will read 0xCC instead of the original byte • Code that verifies integrity will notice the discrepancy
  • 30. Hardware Execution Breakpoints • Uses four hardware Debug Registers – DR0 through DR3 – addresses of breakpoints – DR7 stores control information • The address to stop at is in a register • Can break on access or execution – Can set to break on read, write, or both • No change in code bytes
  • 31. Hardware Execution Breakpoints • Running code can change the DR registers, to interfere with debuggers • General Detect flag in DR7 – Causes a breakpoint prior to any mov instruction that would change the contents of a Debug Register – Does not detect other instructions, however
  • 32. Conditional Breakpoints • Breaks only if a condition is true – Ex: Set a breakpoint on the GetProcAddress function – Only if parameter being passed in is RegSetValue • Implemented as software breakpoints – The debugger always receives the break – If the condition is not met, it resumes execution without alerting the user
  • 33. Conditional Breakpoints • Conditional breakpoints take much longer than ordinary instructions • A conditional breakpoint on a frequently- accessed instruction can slow a program down • Sometimes so much that it never finishes
  • 34.
  • 36. Exceptions • Used by debuggers to gain control of a running program • Breakpoints generate exceptions • Exceptions are also caused by – Invalid memory access – Division by zero – Other conditions
  • 37. First- and Second-Chance Exceptions • When a exception occurs while a debugger is attached – The program stops executing – The debugger is given first chance at control – Debugger can either handle the exception, or pass it on to the program – If it's passed on, the program's exception handler takes it
  • 38. Second Chance • If the application doesn't handle the exception • The debugger is given a second chance to handle it – This means the program would have crashed if the debugger were not attached • In malware analysis, first-chance exceptions can usually be ignored • Second-chance exceptions cannot be ignored – They usually mean that the malware doesn't like the environment in which it is running
  • 39. Common Exceptions • INT 3 (Software breakpoint) • Single-stepping in a debugger is implemented as an exception – If the trap flag in the flags register is set, – The processor executes one instruction and then generates an exception • Memory-access violation exception – Code tries to access a location that it cannot access, either because the address is invalid or because of access-control protections
  • 40. Common Exceptions • Violating Privilege Rules – Attempt to execute privileged instruction with outside privileged mode – In other words, attempt to execute a kernel mode instruction in user mode – Or, attempt to execute Ring 0 instruction from Ring 3
  • 43. Skipping a Function • You can change control flags, the instruction pointer, or the code itself • You could avoid a function call by setting a breakpoint where at the call, and then changing the instruction pointer to the instruction after it – This may cause the program to crash or malfunction, or course
  • 44. Testing a Function • You could run a function directly, without waiting for the main code to use it – You will have to set the parameters – This destroys a program's stack – The program won't run properly when the function completes
  • 46. Example (A Real Virus) • Operation depends on language setting of a computer – Simplified Chinese • Uninstalls itself & does no harm – English • Display pop-up "Your luck's no good" – Japanese or Indonesian • Overwrite the hard drive with random data
  • 47. Break at 1; Change Return Value