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

What's hot (20)

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

Similar to Fuzzing - Part 2 (20)

PDF
Fuzzing - Part 1
UTD Computer Security Group
 
PPT
nullcon 2010 - Intelligent debugging and in memory fuzzing
n|u - The Open Security Community
 
PPTX
Advanced malware analysis training session5 reversing automation
Cysinfo Cyber Security Community
 
PDF
FuzzyDebugger.pdf
ritviktanksalkar1
 
PDF
DEF CON 27 - KYLE GWINNUP - next generation process emulation with binee
Felipe Prado
 
PPTX
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
Peter Hlavaty
 
PDF
CNIT 126 8: Debugging
Sam Bowne
 
PDF
CNIT 126: 8: Debugging
Sam Bowne
 
PPTX
Ropython-windbg-python-extensions
Alin Gabriel Serdean
 
PPTX
EhTrace -- RoP Hooks
Shane Macaulay
 
PPTX
Driver Debugging Basics
Bala Subra
 
PDF
Practical Malware Analysis: Ch 8: Debugging
Sam Bowne
 
PPTX
Advanced malware analysis training session4 anti-analysis techniques
Cysinfo Cyber Security Community
 
PDF
Dmitriy D1g1 Evdokimov - DBI Intro
DefconRussia
 
PPTX
Taint scope
geeksec80
 
PDF
Rainbow Over the Windows: More Colors Than You Could Expect
Peter Hlavaty
 
PDF
Zone IDA Proc
Tzung-Bi Shih
 
PDF
FuzzyDbg_Report.pdf
ritviktanksalkar1
 
PDF
Debugging of (C)Python applications
Roman Podoliaka
 
Fuzzing - Part 1
UTD Computer Security Group
 
nullcon 2010 - Intelligent debugging and in memory fuzzing
n|u - The Open Security Community
 
Advanced malware analysis training session5 reversing automation
Cysinfo Cyber Security Community
 
FuzzyDebugger.pdf
ritviktanksalkar1
 
DEF CON 27 - KYLE GWINNUP - next generation process emulation with binee
Felipe Prado
 
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
Peter Hlavaty
 
CNIT 126 8: Debugging
Sam Bowne
 
CNIT 126: 8: Debugging
Sam Bowne
 
Ropython-windbg-python-extensions
Alin Gabriel Serdean
 
EhTrace -- RoP Hooks
Shane Macaulay
 
Driver Debugging Basics
Bala Subra
 
Practical Malware Analysis: Ch 8: Debugging
Sam Bowne
 
Advanced malware analysis training session4 anti-analysis techniques
Cysinfo Cyber Security Community
 
Dmitriy D1g1 Evdokimov - DBI Intro
DefconRussia
 
Taint scope
geeksec80
 
Rainbow Over the Windows: More Colors Than You Could Expect
Peter Hlavaty
 
Zone IDA Proc
Tzung-Bi Shih
 
FuzzyDbg_Report.pdf
ritviktanksalkar1
 
Debugging of (C)Python applications
Roman Podoliaka
 
Ad

More from UTD Computer Security Group (20)

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

Recently uploaded (20)

PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 

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/