SlideShare a Scribd company logo
 
Mitchell Adair
utdcsg.org
 Debugging libraries (for Windows)
o WinAppDbg, PyDBG
• Examples
• Pros and con
 Fuzzer design
o Design concepts
o Fuzzer goals
o Github
o Future work

 PyDBG
o “A pure-python win32 debugger interface.”
o Part of the Paimei reverse engineering framework
• Awesome
o Created by Pedram Amini
• Badass, you should be following him on Twitter etc.
 https://github.com/OpenRCE/pydbg
 So… what can it do?
o Launch or attach to processes
o Breakpoints, step into, step over, etc.
o Get / set memory or register values
o Give you access to PEB
o Resolve functions
o Disassemble
o Set callbacks for signals, events, breakpoints, etc.
o Snapshots
o … (seriously)
 And… you can use it stand-alone, or from within IDA!
 How is this different from Immunity, OllyDBG, etc?
o It’s scriptable!
 How about automating…
o Unpacking
o Malware analysis
• General statistics, system calls of interest, etc.
o Crash analysis
• Trace my path, save operand values, etc.
o Fuzzing!
• Debug a process, set callbacks on signals of interest, log the run…
• In memory fuzzing with snapshots
 Let’s see some examples!
 Create a debugging object
 Load the target executable
 Run it
 Pretty painless
 From the interpreter
 The entire dbg object is passed to the callback handler
 Some sort of continue status is returned
 Let’s handle some signals. How about access violation
 On Microsoft Windows, a process that accesses invalid
memory receives the STATUS_ACCESS_VIOLATION exception.
o Wikipedia
Fuzzing - Part 2
 Why do we care about access violations?
o “invalid memory” = ?
o Virtual memory that does not map to physical memory
o Virtual memory marked with permissions, and the process does not
have permission to perform the operation
• Memory is read/write/executable
• Trying to perform a read on non-readable memory… access violation
 We are typically trying to influence pointers, influence
length values, overflow boundaries, etc.
 The above usually results in access violations
 Illegal instruction is another good signal (usually means we
messed with EIP and it now points to an invalid instruction)
 We can
o Launch or attach to an application
o Set our callback handlers
o Run the application
 But… we want to collect as much information as possible
from the access violation handler
 Paimei comes with the great util, crash_binning.py that will
record lots of useful information
 Just create a crash_binning object and record the crash
with the dbg object passed to the callback handler
 That’s a pretty powerful 16 lines of code…
 Sample output from
crash_binning
 Registers, assembly,
stack trace, SEH
 All with a function
call, so easy!
 Now import multiprocessing
 Mutate some files
 Launch the target application with the new files
 Find bugs 
 WinAppDbg
 “The WinAppDbg python module allows developers to
quickly code instrumentation scripts in Python under
a Windows environment.”
 “It uses ctypes to wrap many Win32 API calls related to
debugging…”
 “The intended audience are QA engineers and software
security auditors wishing to test or fuzz Windows
applications with quickly coded Python scripts.”
 http://winappdbg.sourceforge.net/
 Why not just stick with PyDBG?
o Rumor has it PyDBG development has become OSX focused
o It rocks, but it’s a little old and antiquated
o Might have to write some wrappers, depending on your usage
 WinAppDbg is *only* windows, but it has a *ton* of stuff to
work with
 If you’re doing heavy PE work WinAppDbg might be the way
to go
 The WinAppDbg site has some great examples
o http://winappdbg.sourceforge.net/ProgrammingGuide.html
o Instrumentation
• Enumerating processes, loading a DLL into a process, control windows
o Debugging
• Starting and attaching, handling events, breakpoints, etc.
o Win32 API wrappers
• Enumerating heap blocks, modules and device drivers
o Misc
• Dump process memory, find alphanumeric jump addresses, etc.
 We’ll compare WinAppDbg with our last PyDBG example,
then show one more interesting example
 Picking up where we left off with PyDBG
A custom event handler
is optional, but is an
easy way to catch any
signals of interest
 Hooking a
function,
wsprintfW
 Catch the
load_dll signal
 If it’s
user32.dll,
resolve
wsprintf, hook
it
 Print the args
 Hooking a
function,
wsprintfW
 Catch the
load_dll signal
 If it’s
user32.dll,
resolve
wsprintf, hook
it
 Print the args
1. Catch load_dll
signal
 Hooking a
function,
wsprintfW
 Catch the
load_dll signal
 If it’s
user32.dll,
resolve
wsprintf, hook
it
 Print the args
1. Catch load_dll
signal
2. If it’s user32.dll
 Hooking a
function,
wsprintfW
 Catch the
load_dll signal
 If it’s
user32.dll,
resolve
wsprintf, hook
it
 Print the args
1. Catch load_dll
signal
2. If it’s user32.dll
3. Resolve “wsprintfW”
 Hooking a
function,
wsprintfW
 Catch the
load_dll signal
 If it’s
user32.dll,
resolve
wsprintf, hook
it
 Print the args
1. Catch load_dll
signal
2. If it’s user32.dll
3. Resolve “wsprintfW”
4. Hook it
 Hooking a
function,
wsprintfW
 Catch the
load_dll signal
 If it’s
user32.dll,
resolve
wsprintf, hook
it
 Print the args
1. Catch load_dll
signal
2. If it’s user32.dll
3. Resolve “wsprintfW”
4. Hook it
5. wsprintf hit at run time
 Hooking a
function,
wsprintfW
 Catch the
load_dll signal
 If it’s
user32.dll,
resolve
wsprintf, hook
it
 Print the args
1. Catch load_dll
signal
2. If it’s user32.dll
3. Resolve “wsprintfW”
4. Hook it
5. wsprintf hit at run time
6. Dereference
format string
 Hooking a
function,
wsprintfW
 Catch the
load_dll signal
 If it’s
user32.dll,
resolve
wsprintf, hook
it
 Print the args
1. Catch load_dll
signal
2. If it’s user32.dll
3. Resolve “wsprintfW”
4. Hook it
5. wsprintf hit at run time
6. Dereference
format string
7. Count args
 Hooking a
function,
wsprintfW
 Catch the
load_dll signal
 If it’s
user32.dll,
resolve
wsprintf, hook
it
 Print the args
1. Catch load_dll
signal
2. If it’s user32.dll
3. Resolve “wsprintfW”
4. Hook it
5. wsprintf hit at run time
6. Dereference
format string
7. Count args
8. Read
off stack,
print args
 Way too many great examples on their site to go into
o Hooking functions
o Watching variables
o Watching buffers
o Etc… very powerfull
 If you want to automate anything PE related, this is a great
library to look into

 Design goals
o Modularity
• Ex: generator, executor, monitor
o Reusability
• A new target program or file type should make little to no difference
o Speed
• A large file might have hundreds of thousands of mutations
• Multiprocessing or a distributed architecture is helpful
o False negatives
• We don’t want to miss anything…
 What are the general tasks performed during fuzzing?
o Generating mutated data
o Launching the target application
o Sending the data to the application
o Monitoring the application for signals of interest
o Logging results
o …more?
Mutate Data
Launch
Application
Monitor
Application
Log Results
Mutate Data
Launch
Application
Monitor
Application
Log Results
Executor.py
Mutator.py
Fuzzer.py
?
 Part 1 discussed possible values you may want to try
 Yield is a nice python feature
 Sole job is to mutate the bytes, any changes in possible
values can easily be handled here
 My actual executor
 Continually check
queue for new jobs
 When one is
available, call
execute
 Create a new pydbg
instance, setup
callbacks, execute
 My actual executor
 Continually check
queue for new jobs
 When one is
available, call
execute
 Create a new pydbg
instance, setup
callbacks, execute
1. Establish timeout
and queues
 My actual executor
 Continually check
queue for new jobs
 When one is
available, call
execute
 Create a new pydbg
instance, setup
callbacks, execute
1. Establish timeout
and queues
2. Wait for new job
 My actual executor
 Continually check
queue for new jobs
 When one is
available, call
execute
 Create a new pydbg
instance, setup
callbacks, execute
1. Establish timeout
and queues
2. Wait for new job
3. Execute job
 My actual executor
 Continually check
queue for new jobs
 When one is
available, call
execute
 Create a new pydbg
instance, setup
callbacks, execute
1. Establish timeout
and queues
2. Wait for new job
3. Execute job
4. Check timeout
 My actual executor
 Continually check
queue for new jobs
 When one is
available, call
execute
 Create a new pydbg
instance, setup
callbacks, execute
1. Establish timeout
and queues
2. Wait for new job
3. Execute job
4. Check timeout
5. Handle av
 handle_av we’ve seen, uses crash_binning to
capture relevant data
 timeout_callback is a custom callback. Every
itteration of the main debugging loop, it gets called.
An easy way to implement a max timeout
Start the
consumers
Start the
monitor thread
When the
queue is empty,
put a new job
 Feel free to grab my *work in progress* from the above link
 (I will update the site after the presentation)
 Producer / Consumer model
 Multiprocessing
 All in about 260 lines of python
Fuzzer.py
Mutator.py
Executor nExecutor 2Executor 1
queue
…
Fuzzer.py
Mutator.py
Executor nExecutor 2Executor 1
queue
…
1. For each file
mutation in
mutator
Fuzzer.py
Mutator.py
Executor nExecutor 2Executor 1
queue
…
1. For each file
mutation in
mutator
2. Yield a new
mutated file
Fuzzer.py
Mutator.py
Executor nExecutor 2Executor 1
queue
…
1. For each file
mutation in
mutator
2. Yield a new
mutated file
3. Add the new job
to the in_queue
Fuzzer.py
Mutator.py
Executor nExecutor 2Executor 1
queue
…
1. For each file
mutation in
mutator
2. Yield a new
mutated file
3. Add the new job
to the in_queue
4. Execute, and
monitor the job
Fuzzer.py
Mutator.py
Executor nExecutor 2Executor 1
queue
…
1. For each file
mutation in
mutator
2. Yield a new
mutated file
3. Add the new job
to the in_queue
4. Execute, and
monitor the job
5. Return the results
to the out_queue
Fuzzer.py
Mutator.py
Executor nExecutor 2Executor 1
queue
…
1. For each file
mutation in
mutator
2. Yield a new
mutated file
3. Add the new job
to the in_queue
4. Execute, and
monitor the job
5. Return the results
to the out_queue
6. Log results
 There is actually an incoming queue and an outgoing queue
as shown in the fuzzer.py slide, but it took me long enough
to get that graphic, I’m not changing it ;)
 How can we improve our fuzzer, increase our odds?
 Code coverage would be a nice feature
o PyDBG and WinAppDbg both support process “stalking”
o Used to determine the first time a basic block or something specific
is hit
• Enumerate basic blocks ahead of time, count ones hit during execution
• Find common pitfalls, track code coverage, etc.
 Cluster instead of consumer producer?
 Support specific file format fields?
o Just use Peach ;)
 Where can I find some sample files?
o Google.com, with the filter “filetype:xyz”
o ie. “filetype:zip”
o http://samples.mplayerhq.hu/
o http://www.filecrop.com/
• Be careful!
 Gray Hat Python: Python Programming for Hackers and
Reverse Engineers
o http://www.amazon.com/Gray-Hat-Python-Programming-
Engineers/dp/1593271921
 Fuzzing: Brute Force Vulnerability Discovery
o http://fuzzing.org/

More Related Content

PDF
Web Exploitation
PDF
What Goes In Must Come Out: Egress-Assess and Data Exfiltration
PDF
Ruxmon feb 2013 what happened to rails
PPTX
Bsides tampa
PDF
Bug Bounty Hunter Methodology - Nullcon 2016
PDF
Node.js and Ruby
PPTX
Same-origin Policy (SOP)
PDF
Introducing OWASP OWTF Workshop BruCon 2012
Web Exploitation
What Goes In Must Come Out: Egress-Assess and Data Exfiltration
Ruxmon feb 2013 what happened to rails
Bsides tampa
Bug Bounty Hunter Methodology - Nullcon 2016
Node.js and Ruby
Same-origin Policy (SOP)
Introducing OWASP OWTF Workshop BruCon 2012

What's hot (20)

PDF
Entomology 101
PPTX
Hacking - Breaking Into It
PDF
CheckPlease: Payload-Agnostic Targeted Malware
PDF
Detecting secrets in code committed to gitlab (in real time)
PPTX
Find maximum bugs in limited time
PDF
Ever Present Persistence - Established Footholds Seen in the Wild
PPTX
VS Debugging Tricks
PDF
The State of the Veil Framework
PDF
Building a REST API with Node.js and MongoDB
PDF
Js deobfuscation with JStillery - bsides-roma 2018
PDF
An EyeWitness View into your Network
PDF
WAF protections and bypass resources
PDF
Egress-Assess and Owning Data Exfiltration
KEY
Getting Started with MongoDB and Node.js
PDF
Puppet Camp Boston 2014: Securely Managing Secrets with FreeIPA and Puppet (I...
PDF
MongoDB World 2019 Builder's Fest - Open source command line power tools for ...
PDF
Static analysis for beginners
PPTX
Owasp web application security trends
PDF
Use Node.js to create a REST API
PDF
Nightwatch.js (vodQA Shots - Pune 2017)
Entomology 101
Hacking - Breaking Into It
CheckPlease: Payload-Agnostic Targeted Malware
Detecting secrets in code committed to gitlab (in real time)
Find maximum bugs in limited time
Ever Present Persistence - Established Footholds Seen in the Wild
VS Debugging Tricks
The State of the Veil Framework
Building a REST API with Node.js and MongoDB
Js deobfuscation with JStillery - bsides-roma 2018
An EyeWitness View into your Network
WAF protections and bypass resources
Egress-Assess and Owning Data Exfiltration
Getting Started with MongoDB and Node.js
Puppet Camp Boston 2014: Securely Managing Secrets with FreeIPA and Puppet (I...
MongoDB World 2019 Builder's Fest - Open source command line power tools for ...
Static analysis for beginners
Owasp web application security trends
Use Node.js to create a REST API
Nightwatch.js (vodQA Shots - Pune 2017)
Ad

Similar to Fuzzing - Part 2 (20)

PDF
Fuzzing - Part 1
PPT
nullcon 2010 - Intelligent debugging and in memory fuzzing
PPTX
Advanced malware analysis training session5 reversing automation
PDF
FuzzyDebugger.pdf
PDF
DEF CON 27 - KYLE GWINNUP - next generation process emulation with binee
PPTX
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
PDF
CNIT 126 8: Debugging
PDF
CNIT 126: 8: Debugging
PPTX
Ropython-windbg-python-extensions
PPTX
EhTrace -- RoP Hooks
PPTX
Driver Debugging Basics
PDF
Practical Malware Analysis: Ch 8: Debugging
PPTX
Advanced malware analysis training session4 anti-analysis techniques
PDF
Dmitriy D1g1 Evdokimov - DBI Intro
PPTX
Taint scope
PDF
Rainbow Over the Windows: More Colors Than You Could Expect
PDF
Zone IDA Proc
PDF
FuzzyDbg_Report.pdf
PDF
Debugging of (C)Python applications
Fuzzing - Part 1
nullcon 2010 - Intelligent debugging and in memory fuzzing
Advanced malware analysis training session5 reversing automation
FuzzyDebugger.pdf
DEF CON 27 - KYLE GWINNUP - next generation process emulation with binee
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
CNIT 126 8: Debugging
CNIT 126: 8: Debugging
Ropython-windbg-python-extensions
EhTrace -- RoP Hooks
Driver Debugging Basics
Practical Malware Analysis: Ch 8: Debugging
Advanced malware analysis training session4 anti-analysis techniques
Dmitriy D1g1 Evdokimov - DBI Intro
Taint scope
Rainbow Over the Windows: More Colors Than You Could Expect
Zone IDA Proc
FuzzyDbg_Report.pdf
Debugging of (C)Python applications
Ad

More from UTD Computer Security Group (20)

PDF
22S kickoff 2.0 (kickoff + anonymity talk)
PPTX
UTD Computer Security Group - Cracking the domain
PPTX
Forensics audio and video
PPTX
Computer networks and network security
PPTX
PPTX
Powershell crash course
PPTX
Intro to cybersecurity
PPTX
PDF
Network Exploitation
PDF
Penetration Testing: Celestial
PDF
Introduction to Exploitation
PDF
Cryptography Crash Course
PDF
Exploitation Crash Course
PDF
Protostar VM - Heap3
PDF
Heap Base Exploitation
PDF
Return Oriented Programming
PDF
Advanced Windows Exploitation
PDF
Advanced Domain Hacking
22S kickoff 2.0 (kickoff + anonymity talk)
UTD Computer Security Group - Cracking the domain
Forensics audio and video
Computer networks and network security
Powershell crash course
Intro to cybersecurity
Network Exploitation
Penetration Testing: Celestial
Introduction to Exploitation
Cryptography Crash Course
Exploitation Crash Course
Protostar VM - Heap3
Heap Base Exploitation
Return Oriented Programming
Advanced Windows Exploitation
Advanced Domain Hacking

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Empathic Computing: Creating Shared Understanding
PDF
Approach and Philosophy of On baking technology
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Cloud computing and distributed systems.
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
KodekX | Application Modernization Development
PDF
Encapsulation_ Review paper, used for researhc scholars
PPT
Teaching material agriculture food technology
Big Data Technologies - Introduction.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
MYSQL Presentation for SQL database connectivity
Empathic Computing: Creating Shared Understanding
Approach and Philosophy of On baking technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Understanding_Digital_Forensics_Presentation.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Machine learning based COVID-19 study performance prediction
Cloud computing and distributed systems.
Chapter 3 Spatial Domain Image Processing.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Per capita expenditure prediction using model stacking based on satellite ima...
20250228 LYD VKU AI Blended-Learning.pptx
KodekX | Application Modernization Development
Encapsulation_ Review paper, used for researhc scholars
Teaching material agriculture food technology

Fuzzing - Part 2

  • 2.  Debugging libraries (for Windows) o WinAppDbg, PyDBG • Examples • Pros and con  Fuzzer design o Design concepts o Fuzzer goals o Github o Future work
  • 4.  PyDBG o “A pure-python win32 debugger interface.” o Part of the Paimei reverse engineering framework • Awesome o Created by Pedram Amini • Badass, you should be following him on Twitter etc.  https://github.com/OpenRCE/pydbg
  • 5.  So… what can it do? o Launch or attach to processes o Breakpoints, step into, step over, etc. o Get / set memory or register values o Give you access to PEB o Resolve functions o Disassemble o Set callbacks for signals, events, breakpoints, etc. o Snapshots o … (seriously)  And… you can use it stand-alone, or from within IDA!
  • 6.  How is this different from Immunity, OllyDBG, etc? o It’s scriptable!  How about automating… o Unpacking o Malware analysis • General statistics, system calls of interest, etc. o Crash analysis • Trace my path, save operand values, etc. o Fuzzing! • Debug a process, set callbacks on signals of interest, log the run… • In memory fuzzing with snapshots
  • 7.  Let’s see some examples!
  • 8.  Create a debugging object  Load the target executable  Run it  Pretty painless
  • 9.  From the interpreter  The entire dbg object is passed to the callback handler  Some sort of continue status is returned
  • 10.  Let’s handle some signals. How about access violation  On Microsoft Windows, a process that accesses invalid memory receives the STATUS_ACCESS_VIOLATION exception. o Wikipedia
  • 12.  Why do we care about access violations? o “invalid memory” = ? o Virtual memory that does not map to physical memory o Virtual memory marked with permissions, and the process does not have permission to perform the operation • Memory is read/write/executable • Trying to perform a read on non-readable memory… access violation  We are typically trying to influence pointers, influence length values, overflow boundaries, etc.  The above usually results in access violations  Illegal instruction is another good signal (usually means we messed with EIP and it now points to an invalid instruction)
  • 13.  We can o Launch or attach to an application o Set our callback handlers o Run the application  But… we want to collect as much information as possible from the access violation handler  Paimei comes with the great util, crash_binning.py that will record lots of useful information
  • 14.  Just create a crash_binning object and record the crash with the dbg object passed to the callback handler
  • 15.  That’s a pretty powerful 16 lines of code…
  • 16.  Sample output from crash_binning  Registers, assembly, stack trace, SEH  All with a function call, so easy!
  • 17.  Now import multiprocessing  Mutate some files  Launch the target application with the new files  Find bugs 
  • 18.  WinAppDbg  “The WinAppDbg python module allows developers to quickly code instrumentation scripts in Python under a Windows environment.”  “It uses ctypes to wrap many Win32 API calls related to debugging…”  “The intended audience are QA engineers and software security auditors wishing to test or fuzz Windows applications with quickly coded Python scripts.”  http://winappdbg.sourceforge.net/
  • 19.  Why not just stick with PyDBG? o Rumor has it PyDBG development has become OSX focused o It rocks, but it’s a little old and antiquated o Might have to write some wrappers, depending on your usage  WinAppDbg is *only* windows, but it has a *ton* of stuff to work with  If you’re doing heavy PE work WinAppDbg might be the way to go
  • 20.  The WinAppDbg site has some great examples o http://winappdbg.sourceforge.net/ProgrammingGuide.html o Instrumentation • Enumerating processes, loading a DLL into a process, control windows o Debugging • Starting and attaching, handling events, breakpoints, etc. o Win32 API wrappers • Enumerating heap blocks, modules and device drivers o Misc • Dump process memory, find alphanumeric jump addresses, etc.  We’ll compare WinAppDbg with our last PyDBG example, then show one more interesting example
  • 21.  Picking up where we left off with PyDBG A custom event handler is optional, but is an easy way to catch any signals of interest
  • 22.  Hooking a function, wsprintfW  Catch the load_dll signal  If it’s user32.dll, resolve wsprintf, hook it  Print the args
  • 23.  Hooking a function, wsprintfW  Catch the load_dll signal  If it’s user32.dll, resolve wsprintf, hook it  Print the args 1. Catch load_dll signal
  • 24.  Hooking a function, wsprintfW  Catch the load_dll signal  If it’s user32.dll, resolve wsprintf, hook it  Print the args 1. Catch load_dll signal 2. If it’s user32.dll
  • 25.  Hooking a function, wsprintfW  Catch the load_dll signal  If it’s user32.dll, resolve wsprintf, hook it  Print the args 1. Catch load_dll signal 2. If it’s user32.dll 3. Resolve “wsprintfW”
  • 26.  Hooking a function, wsprintfW  Catch the load_dll signal  If it’s user32.dll, resolve wsprintf, hook it  Print the args 1. Catch load_dll signal 2. If it’s user32.dll 3. Resolve “wsprintfW” 4. Hook it
  • 27.  Hooking a function, wsprintfW  Catch the load_dll signal  If it’s user32.dll, resolve wsprintf, hook it  Print the args 1. Catch load_dll signal 2. If it’s user32.dll 3. Resolve “wsprintfW” 4. Hook it 5. wsprintf hit at run time
  • 28.  Hooking a function, wsprintfW  Catch the load_dll signal  If it’s user32.dll, resolve wsprintf, hook it  Print the args 1. Catch load_dll signal 2. If it’s user32.dll 3. Resolve “wsprintfW” 4. Hook it 5. wsprintf hit at run time 6. Dereference format string
  • 29.  Hooking a function, wsprintfW  Catch the load_dll signal  If it’s user32.dll, resolve wsprintf, hook it  Print the args 1. Catch load_dll signal 2. If it’s user32.dll 3. Resolve “wsprintfW” 4. Hook it 5. wsprintf hit at run time 6. Dereference format string 7. Count args
  • 30.  Hooking a function, wsprintfW  Catch the load_dll signal  If it’s user32.dll, resolve wsprintf, hook it  Print the args 1. Catch load_dll signal 2. If it’s user32.dll 3. Resolve “wsprintfW” 4. Hook it 5. wsprintf hit at run time 6. Dereference format string 7. Count args 8. Read off stack, print args
  • 31.  Way too many great examples on their site to go into o Hooking functions o Watching variables o Watching buffers o Etc… very powerfull  If you want to automate anything PE related, this is a great library to look into
  • 33.  Design goals o Modularity • Ex: generator, executor, monitor o Reusability • A new target program or file type should make little to no difference o Speed • A large file might have hundreds of thousands of mutations • Multiprocessing or a distributed architecture is helpful o False negatives • We don’t want to miss anything…
  • 34.  What are the general tasks performed during fuzzing? o Generating mutated data o Launching the target application o Sending the data to the application o Monitoring the application for signals of interest o Logging results o …more?
  • 37.  Part 1 discussed possible values you may want to try  Yield is a nice python feature  Sole job is to mutate the bytes, any changes in possible values can easily be handled here
  • 38.  My actual executor  Continually check queue for new jobs  When one is available, call execute  Create a new pydbg instance, setup callbacks, execute
  • 39.  My actual executor  Continually check queue for new jobs  When one is available, call execute  Create a new pydbg instance, setup callbacks, execute 1. Establish timeout and queues
  • 40.  My actual executor  Continually check queue for new jobs  When one is available, call execute  Create a new pydbg instance, setup callbacks, execute 1. Establish timeout and queues 2. Wait for new job
  • 41.  My actual executor  Continually check queue for new jobs  When one is available, call execute  Create a new pydbg instance, setup callbacks, execute 1. Establish timeout and queues 2. Wait for new job 3. Execute job
  • 42.  My actual executor  Continually check queue for new jobs  When one is available, call execute  Create a new pydbg instance, setup callbacks, execute 1. Establish timeout and queues 2. Wait for new job 3. Execute job 4. Check timeout
  • 43.  My actual executor  Continually check queue for new jobs  When one is available, call execute  Create a new pydbg instance, setup callbacks, execute 1. Establish timeout and queues 2. Wait for new job 3. Execute job 4. Check timeout 5. Handle av
  • 44.  handle_av we’ve seen, uses crash_binning to capture relevant data  timeout_callback is a custom callback. Every itteration of the main debugging loop, it gets called. An easy way to implement a max timeout
  • 45. Start the consumers Start the monitor thread When the queue is empty, put a new job
  • 46.  Feel free to grab my *work in progress* from the above link  (I will update the site after the presentation)  Producer / Consumer model  Multiprocessing  All in about 260 lines of python
  • 48. Fuzzer.py Mutator.py Executor nExecutor 2Executor 1 queue … 1. For each file mutation in mutator
  • 49. Fuzzer.py Mutator.py Executor nExecutor 2Executor 1 queue … 1. For each file mutation in mutator 2. Yield a new mutated file
  • 50. Fuzzer.py Mutator.py Executor nExecutor 2Executor 1 queue … 1. For each file mutation in mutator 2. Yield a new mutated file 3. Add the new job to the in_queue
  • 51. Fuzzer.py Mutator.py Executor nExecutor 2Executor 1 queue … 1. For each file mutation in mutator 2. Yield a new mutated file 3. Add the new job to the in_queue 4. Execute, and monitor the job
  • 52. Fuzzer.py Mutator.py Executor nExecutor 2Executor 1 queue … 1. For each file mutation in mutator 2. Yield a new mutated file 3. Add the new job to the in_queue 4. Execute, and monitor the job 5. Return the results to the out_queue
  • 53. Fuzzer.py Mutator.py Executor nExecutor 2Executor 1 queue … 1. For each file mutation in mutator 2. Yield a new mutated file 3. Add the new job to the in_queue 4. Execute, and monitor the job 5. Return the results to the out_queue 6. Log results
  • 54.  There is actually an incoming queue and an outgoing queue as shown in the fuzzer.py slide, but it took me long enough to get that graphic, I’m not changing it ;)
  • 55.  How can we improve our fuzzer, increase our odds?  Code coverage would be a nice feature o PyDBG and WinAppDbg both support process “stalking” o Used to determine the first time a basic block or something specific is hit • Enumerate basic blocks ahead of time, count ones hit during execution • Find common pitfalls, track code coverage, etc.  Cluster instead of consumer producer?  Support specific file format fields? o Just use Peach ;)
  • 56.  Where can I find some sample files? o Google.com, with the filter “filetype:xyz” o ie. “filetype:zip” o http://samples.mplayerhq.hu/ o http://www.filecrop.com/ • Be careful!
  • 57.  Gray Hat Python: Python Programming for Hackers and Reverse Engineers o http://www.amazon.com/Gray-Hat-Python-Programming- Engineers/dp/1593271921  Fuzzing: Brute Force Vulnerability Discovery o http://fuzzing.org/