SlideShare a Scribd company logo
1 of 28
Download to read offline
FUZZING – PART 1
Mitchell Adair
utdcsg.org
#utdcsg – irc.oftc.net
9/5/2012
Before we begin
• Almost all the material is coming from
this book.
• Awesome book, by some of the
godfathers of fuzzing
• Buy it…
http://www.amazon.com/gp/product/032
1446119
What is fuzzing?
• The process of sending specific data to an application, in hope
to elicit certain responses.
• specific?
• Mutated data, edge cases, etc.
• certain?
• Crashes, errors, etc.
• Wikipedia
• “Fuzz testing or fuzzing is a software testing technique, often
automated or semi-automated, that involves providing invalid,
unexpected, or random data to the inputs of a computer program. The
program is then monitored for exceptions such as crashes, or failing
built-in code assertions or for finding potential memory leaks. Fuzzing
is commonly used to test for security problems in software or computer
systems.”
Why?
• Used often in
• Software testing (SDL)
• Google, Mozilla, Microsoft and others are huge on this
• Bug hunting  our focus
• Good and bad guys, contractors, etc.
• Looking for fame, profit, etc.
Finding vulnerabilities
• Three primary methods
• Code auditing
• Requires source code 
• Reversing
• No need for source code, focus on binary applications
• Very time consuming, higher skill degree required
• Fuzzing
• Lots of frameworks available
• Can quickly spin up a custom one yourself (Part 2)
• Binary, source, etc. unimportant
• Can be as simple or complex as you like
*After getting used to fuzzing, the problem isn’t finding
bugs, it’s figuring out which bugs are exploitable.
2 days later…
1 libqt4_plugin.dll:0xxxxxxxxx mov ecx,[edx+0x30]
1 msvcrt.dll:0xxxxxxxxx rep stosd
1 ntdll.dll:0xxxxxxxxx mov ecx,[ecx+0x4]
2 libqt4_plugin.dll:0xxxxxxxxx arpl [ecx+0x63],sp
2 libqt4_plugin.dll:0xxxxxxxxx mov eax,[eax+0x18]
2 libqt4_plugin.dll:0xxxxxxxxx or byte [eax+0x10],0x1
3 libqt4_plugin.dll:0xxxxxxxxx mov [eax+0x8],ebx
4 libpacketizer_dirac_plugin.dll:0xxxxxxxxx mov dword [eax+0x20],0x0
4 libpacketizer_dirac_plugin.dll:0xxxxxxxxx mov eax,[edx+0x4]
5 libqt4_plugin.dll:0xxxxxxxxx mov dword [eax],0x1
10 libqt4_plugin.dll:0xxxxxxxxx mov [ebx+0x8],eax
13 libpacketizer_dirac_plugin.dll:0xxxxxxxxx mov edx,[eax+0x8]
2 days later… cont
1 [INVALID]:00000001
1 [INVALID]:00000040
1 [INVALID]:00350000
1 [INVALID]:0057001b
1 [INVALID]:008dac24
1 [INVALID]:0135f5d0
1 [INVALID]:0172d090
1 [INVALID]:01bffba8
1 [INVALID]:01c2fcc8
1 [INVALID]:01c9fc7c
1 [INVALID]:01cc5198
1 [INVALID]:0239f068
1 [INVALID]:0310d678
1 [INVALID]:06040002
1 [INVALID]:2f04002b
1 [INVALID]:338dac24
1 [INVALID]:7351eb81
1 [INVALID]:ff2677c4
2 [INVALID]:40000060
5 [INVALID]:76630000
• 32 unique crashes ?
• The ones labeled INVALID, where EIP was
invalid look particularly interesting
• 0x00000001 and 0x00000040 especially 
Fuzzing phases
1.
2.
3.
4.
5.
6.
• We’re going to focus on steps 3 through 5
Types of values
• So.. what type of data do I want to send to an application?
• Integer values
• Border cases :
• 0, 0xffffffff (2^32)
• Leverage +n / -n cases
• malloc( … + 1)
• Ranges :
• MAX32 – 16 <= MAX32 <= MAX32 + 16
• MAX32 / 2 – 16 <= MAX32 / 2 <= MAX32 / 2 + 16
• MAX32 / 3 – 16 <= MAX32 / 3 <= MAX32 / 3 + 16
• MAX32 / 4 – 16 <= MAX32 / 4 <= MAX32 / 4 + 16
• MAX16 – 16 <= MAX16 <= MAX16 + 16
• MAX16 / 2 – 16 <= MAX16 / 2 <= MAX16 / 2 + 16
• MAX16 / 3 – 16 <= MAX16 / 3 <= MAX16 / 3 + 16
• MAX16 / 4 – 16 <= MAX16 / 4 <= MAX16 / 4 + 16
• MAX8 – 16 <= MAX8 <= MAX8 + 16
• MAX8 / 2 – 16 <= MAX8 / 2 <= MAX8 / 2 + 16
• MAX8 / 3 – 16 <= MAX8 / 3 <= MAX8 / 3 + 16
• MAX8 / 4 – 16 <= MAX8 / 4 <= MAX8 / 4 + 16
Try to influence sign /
unsigned values : char,
short, int, etc.
Unsigned value:
2^Y
Signed value:
2^Y / 2
Types of values… cont
• String repetions
• A*100, A*1000, A*10000
• Not just A, B makes a difference on the heap, and in hard coded
checks!
• Delimiters
• !@#$%^&*()-_=+{}|;:’”,<.>/?~`
• Varying length strings separated by delimiters
• Increasing the length of delimiters is important as well
• User::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::password
• Format strings
• %s and %n have greatest chance to trigger a fault
• %s dereferences a stack value
• %n writes to a pointer (another dereference)
• Should include long sequences
Types of values… cont
• Character translations
• 0xfe and 0xff are expanded into 4 characters under utf16
• Directory traversal
• If targeting web apps or network daemons
• ../../ and .... etc.
• Command injection
• If targeting web apps, cgi scripts, network daemons
• &&, ; and | characters
Types of targets
• Environment variables
• Positional arguments, flags, etc.
• File formats
• Network protocols
• Web apps
• Etc.
Targeting environment variables
• Focus on *nix because of concept of super user / privilege
escalation
• Finding targets
• We want setuid or setguid files
• Find / -type f –perm -4000 –o –perm -2000
• setuid is column 4, value 4
• setguid is column 4, value 2
• So setuid and getuid to a normal 640 file would become 6640
Enumerating environment variables
• From GDB, we can hook getenv and show all requests
• gdb –q ./myprogram
• break getenv
• (say yes if it asks about setting a deffered breakpoint)
• commands
• These will get executed after the breakpoint is hit
• silent
• x/s *(char **)($ebp+8)
• Treat $ebp+8 as a pointer to a character pointer
• Dereference the above, leaves a character pointer
• x/s = examine the string of, a character pointer
• Print the string of $ebp+8
• end
• cont
Enumerating environment variables...
Preloading
• LD_PRELOAD
• “The dynamic linker can be influenced into modifying its behavior
during either the program's execution or the program's linking… A
typical modification of this behavior is the use of the
LD_LIBRARY_PATH and LD_PRELOAD environment variables.
These variables adjust the runtime linking process by searching for
shared libraries at alternate locations and by forcibly loading and
linking libraries that would otherwise not be, respectively.” - Wikipedia
Preloading…
• Creating a substitute for getenv
#define BUFFSIZE 20000
char *getenv(char *variable)
{
char buff[BUFFSIZE];
memset(buff,’A’,BUFFSIZE);
buff[BUFFSIZE-1] = 0x0;
return buff;
}
• Compiling and running
$ gcc -shared -fPIC -o my_getenv.so my_getenv.c
• Create the shared library, my_getenv.so
$ LD_PRELOAD=./my_getenv.so /usr/bin/target
• Set the LD_PRELOAD environment varaible and run the application
Preloading…
• When the application makes a call to getenv, our shared
library replacement to getenv will get called instead.
Detecting problems
• The poor man’s way
• Check return code of the application
• If application terminated due to unhandled signal, return 128 +
signal #
• SIGSEV = 11
• SIGILL = 4
• Return values of 132 and 139 should be flagged as possible crashes
• In the previous slide, “echo $?” echoes the return value
• 139 would be SIGSEV
Detecting problems…
• Better way
• Use wait or waitpid function
• fork with an execve in the child and wait or waitpid in the parent
• can check if child crashed by return value of wait(pid)
Detecting problems…
• The poor man’s (better) way
Detecting problems…
• Best
• Use debugging libraries
• PyDBG, winappdbg, ptrace, etc.
• Can catch any signals of interest during execution
• handle_signal could log important information
• Register contents, stack values, backtrace, etc.
Targeting file formats (or parsers)
• About half of the
local exploits on
exploit-db.com
are file related
• Common
targets include
media players,
document
readers, etc.
Targeting file formats (or parsers)
• What exactly are we trying to exploit with file fuzzing?
• Format assumptions
• Length field ABC is supposed to be in the range 0-100, surely no one
would put 999999…
• Surely no one would put a negative value…
• etc.
• Signed bugs
• Length field XYZ is 4 bytes, and represents the length of the following
field
• ie : [….|4 byte size| data of 4 byte size|….]
int n = (int)read(…); // convert the next 4 bytes into an int
If( n > MAX_SIZE) // make sure the value is < MAX_SIZE
error() // error if it’s not
strncpy(dest, source, n) // we’re safe to copy
Targeting file formats (or parsers)
• Signed bugs…
• If n is a signed value (0x80000000 – 0xffffffff), the length check will
be bypassed, and *huge* value will be read… overflow
• Parsers
• Looping over data, expecting to find delimiters
while(*ptr != ‘;’)
*buff++ = *ptr++;
Types of file fuzzers
• Brute force / mutation-based
• “dumb”
• Given a set of good files, mutate them, and run them
• Very fast and easy to start doing
• Generation-based
• “intelligent”
• Based off a very specific file format
• Requires learning the format, and coding the fuzzer to fuzz specific
fields following the format
• 4 byte length, 2 byte version, string delimited by a ‘;’, etc…
• Can be more fruitful, but requires more up-front effort
Popular file fuzzers
• Peach
• De facto file fuzzer, very popular, very powerfull
• http://peachfuzzer.com/
• SPIKEfile
• notSPIKEfile
• iFUZZ
• etc.
• Each have their own pros and cons. We’ll be going into
Peach in Part 2.
Pffft… but I have Python
• Tools are great… but we’re going to make our own ;)
Part 2 – Creating a mutation based file fuzzer,
and a “how-to” for Peach file fuzzing.
https://github.com/rmadair/fuzzer
Feel free to get a head start and check it out. I
highly encourage everyone to fork it, make changes,
etc. 

More Related Content

What's hot

Learn To Test Like A Grumpy Programmer - 3 hour workshop
Learn To Test Like A Grumpy Programmer - 3 hour workshopLearn To Test Like A Grumpy Programmer - 3 hour workshop
Learn To Test Like A Grumpy Programmer - 3 hour workshopchartjes
 
DEF CON 27 - AMIT WAISEL and HILA COHEN - malproxy
DEF CON 27 - AMIT WAISEL and HILA COHEN - malproxyDEF CON 27 - AMIT WAISEL and HILA COHEN - malproxy
DEF CON 27 - AMIT WAISEL and HILA COHEN - malproxyFelipe Prado
 
José Miguel Esparza - Obfuscation and (non-)detection of malicious PDF files ...
José Miguel Esparza - Obfuscation and (non-)detection of malicious PDF files ...José Miguel Esparza - Obfuscation and (non-)detection of malicious PDF files ...
José Miguel Esparza - Obfuscation and (non-)detection of malicious PDF files ...RootedCON
 
Specialized Compiler for Hash Cracking
Specialized Compiler for Hash CrackingSpecialized Compiler for Hash Cracking
Specialized Compiler for Hash CrackingPositive Hack Days
 
Github.com anton terekhov-orientdb-php
Github.com anton terekhov-orientdb-phpGithub.com anton terekhov-orientdb-php
Github.com anton terekhov-orientdb-phpSan jay
 
Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...
Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...
Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...RootedCON
 
EuroPython 2016 - Do I Need To Switch To Golang
EuroPython 2016 - Do I Need To Switch To GolangEuroPython 2016 - Do I Need To Switch To Golang
EuroPython 2016 - Do I Need To Switch To GolangMax Tepkeev
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MoreMatt Harrison
 
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]RootedCON
 
Static Code Analysis and Cppcheck
Static Code Analysis and CppcheckStatic Code Analysis and Cppcheck
Static Code Analysis and CppcheckZachary Blair
 
Cs1123 11 pointers
Cs1123 11 pointersCs1123 11 pointers
Cs1123 11 pointersTAlha MAlik
 
Introduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsPhoenix
 
Static Code Analysis and AutoLint
Static Code Analysis and AutoLintStatic Code Analysis and AutoLint
Static Code Analysis and AutoLintLeander Hasty
 
Java Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvJava Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvAnton Arhipov
 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java ProgrammersMike Bowler
 

What's hot (20)

Learn To Test Like A Grumpy Programmer - 3 hour workshop
Learn To Test Like A Grumpy Programmer - 3 hour workshopLearn To Test Like A Grumpy Programmer - 3 hour workshop
Learn To Test Like A Grumpy Programmer - 3 hour workshop
 
Python in 90 minutes
Python in 90 minutesPython in 90 minutes
Python in 90 minutes
 
DEF CON 27 - AMIT WAISEL and HILA COHEN - malproxy
DEF CON 27 - AMIT WAISEL and HILA COHEN - malproxyDEF CON 27 - AMIT WAISEL and HILA COHEN - malproxy
DEF CON 27 - AMIT WAISEL and HILA COHEN - malproxy
 
José Miguel Esparza - Obfuscation and (non-)detection of malicious PDF files ...
José Miguel Esparza - Obfuscation and (non-)detection of malicious PDF files ...José Miguel Esparza - Obfuscation and (non-)detection of malicious PDF files ...
José Miguel Esparza - Obfuscation and (non-)detection of malicious PDF files ...
 
Specialized Compiler for Hash Cracking
Specialized Compiler for Hash CrackingSpecialized Compiler for Hash Cracking
Specialized Compiler for Hash Cracking
 
Hacking with hhvm
Hacking with hhvmHacking with hhvm
Hacking with hhvm
 
Python
PythonPython
Python
 
Github.com anton terekhov-orientdb-php
Github.com anton terekhov-orientdb-phpGithub.com anton terekhov-orientdb-php
Github.com anton terekhov-orientdb-php
 
Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...
Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...
Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...
 
EuroPython 2016 - Do I Need To Switch To Golang
EuroPython 2016 - Do I Need To Switch To GolangEuroPython 2016 - Do I Need To Switch To Golang
EuroPython 2016 - Do I Need To Switch To Golang
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and More
 
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]
 
Static Code Analysis and Cppcheck
Static Code Analysis and CppcheckStatic Code Analysis and Cppcheck
Static Code Analysis and Cppcheck
 
Cs1123 11 pointers
Cs1123 11 pointersCs1123 11 pointers
Cs1123 11 pointers
 
Phpconf2008 Sphinx En
Phpconf2008 Sphinx EnPhpconf2008 Sphinx En
Phpconf2008 Sphinx En
 
Introduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data Analytics
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
Static Code Analysis and AutoLint
Static Code Analysis and AutoLintStatic Code Analysis and AutoLint
Static Code Analysis and AutoLint
 
Java Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvJava Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lv
 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java Programmers
 

Similar to Fuzzing - Part 1

Yihan Lian & Zhibin Hu - Smarter Peach: Add Eyes to Peach Fuzzer [rooted2017]
Yihan Lian &  Zhibin Hu - Smarter Peach: Add Eyes to Peach Fuzzer [rooted2017]Yihan Lian &  Zhibin Hu - Smarter Peach: Add Eyes to Peach Fuzzer [rooted2017]
Yihan Lian & Zhibin Hu - Smarter Peach: Add Eyes to Peach Fuzzer [rooted2017]RootedCON
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxsandeshshahapur
 
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...Alexandre Moneger
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programmingChetan Giridhar
 
FooCodeChu - Services for Software Analysis, Malware Detection, and Vulnerabi...
FooCodeChu - Services for Software Analysis, Malware Detection, and Vulnerabi...FooCodeChu - Services for Software Analysis, Malware Detection, and Vulnerabi...
FooCodeChu - Services for Software Analysis, Malware Detection, and Vulnerabi...Silvio Cesare
 
Javascript done right - Open Web Camp III
Javascript done right - Open Web Camp IIIJavascript done right - Open Web Camp III
Javascript done right - Open Web Camp IIIDirk Ginader
 
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon YangPractical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon YangLyon Yang
 
Next-generation sequencing data format and visualization with ngs.plot 2015
Next-generation sequencing data format and visualization with ngs.plot 2015Next-generation sequencing data format and visualization with ngs.plot 2015
Next-generation sequencing data format and visualization with ngs.plot 2015Li Shen
 
Speed geeking-lotusscript
Speed geeking-lotusscriptSpeed geeking-lotusscript
Speed geeking-lotusscriptBill Buchan
 
Data types and Operators
Data types and OperatorsData types and Operators
Data types and Operatorsraksharao
 
Automatic tool for static analysis
Automatic tool for static analysisAutomatic tool for static analysis
Automatic tool for static analysisChong-Kuan Chen
 
CNIT 127: Ch 18: Source Code Auditing
CNIT 127: Ch 18: Source Code AuditingCNIT 127: Ch 18: Source Code Auditing
CNIT 127: Ch 18: Source Code AuditingSam Bowne
 
C_and_C++_notes.pdf
C_and_C++_notes.pdfC_and_C++_notes.pdf
C_and_C++_notes.pdfTigabu Yaya
 
Intro to React
Intro to ReactIntro to React
Intro to ReactTroy Miles
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go ProgrammingLin Yo-An
 

Similar to Fuzzing - Part 1 (20)

Yihan Lian & Zhibin Hu - Smarter Peach: Add Eyes to Peach Fuzzer [rooted2017]
Yihan Lian &  Zhibin Hu - Smarter Peach: Add Eyes to Peach Fuzzer [rooted2017]Yihan Lian &  Zhibin Hu - Smarter Peach: Add Eyes to Peach Fuzzer [rooted2017]
Yihan Lian & Zhibin Hu - Smarter Peach: Add Eyes to Peach Fuzzer [rooted2017]
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptx
 
C language
C languageC language
C language
 
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
FooCodeChu - Services for Software Analysis, Malware Detection, and Vulnerabi...
FooCodeChu - Services for Software Analysis, Malware Detection, and Vulnerabi...FooCodeChu - Services for Software Analysis, Malware Detection, and Vulnerabi...
FooCodeChu - Services for Software Analysis, Malware Detection, and Vulnerabi...
 
Javascript done right - Open Web Camp III
Javascript done right - Open Web Camp IIIJavascript done right - Open Web Camp III
Javascript done right - Open Web Camp III
 
C language
C languageC language
C language
 
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon YangPractical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
 
Next-generation sequencing data format and visualization with ngs.plot 2015
Next-generation sequencing data format and visualization with ngs.plot 2015Next-generation sequencing data format and visualization with ngs.plot 2015
Next-generation sequencing data format and visualization with ngs.plot 2015
 
Speed geeking-lotusscript
Speed geeking-lotusscriptSpeed geeking-lotusscript
Speed geeking-lotusscript
 
Data types and Operators
Data types and OperatorsData types and Operators
Data types and Operators
 
Automatic tool for static analysis
Automatic tool for static analysisAutomatic tool for static analysis
Automatic tool for static analysis
 
CNIT 127: Ch 18: Source Code Auditing
CNIT 127: Ch 18: Source Code AuditingCNIT 127: Ch 18: Source Code Auditing
CNIT 127: Ch 18: Source Code Auditing
 
C
CC
C
 
.NET Deserialization Attacks
.NET Deserialization Attacks.NET Deserialization Attacks
.NET Deserialization Attacks
 
C_and_C++_notes.pdf
C_and_C++_notes.pdfC_and_C++_notes.pdf
C_and_C++_notes.pdf
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go Programming
 

More from UTD Computer Security Group

UTD Computer Security Group - Cracking the domain
UTD Computer Security Group - Cracking the domainUTD Computer Security Group - Cracking the domain
UTD Computer Security Group - Cracking the domainUTD Computer Security Group
 

More from UTD Computer Security Group (20)

Py jail talk
Py jail talkPy jail talk
Py jail talk
 
22S kickoff 2.0 (kickoff + anonymity talk)
22S kickoff 2.0 (kickoff + anonymity talk)22S kickoff 2.0 (kickoff + anonymity talk)
22S kickoff 2.0 (kickoff + anonymity talk)
 
Cloud talk
Cloud talkCloud talk
Cloud talk
 
UTD Computer Security Group - Cracking the domain
UTD Computer Security Group - Cracking the domainUTD Computer Security Group - Cracking the domain
UTD Computer Security Group - Cracking the domain
 
Forensics audio and video
Forensics   audio and videoForensics   audio and video
Forensics audio and video
 
Computer networks and network security
Computer networks and network securityComputer networks and network security
Computer networks and network security
 
Intro to python
Intro to pythonIntro to python
Intro to python
 
Powershell crash course
Powershell crash coursePowershell crash course
Powershell crash course
 
Intro to cybersecurity
Intro to cybersecurityIntro to cybersecurity
Intro to cybersecurity
 
Intro to Bash
Intro to BashIntro to Bash
Intro to Bash
 
Web Exploitation
Web ExploitationWeb Exploitation
Web Exploitation
 
Network Exploitation
Network ExploitationNetwork Exploitation
Network Exploitation
 
Penetration Testing: Celestial
Penetration Testing: CelestialPenetration Testing: Celestial
Penetration Testing: Celestial
 
Introduction to Exploitation
Introduction to ExploitationIntroduction to Exploitation
Introduction to Exploitation
 
Cryptography Crash Course
Cryptography Crash CourseCryptography Crash Course
Cryptography Crash Course
 
Fuzzing - Part 2
Fuzzing - Part 2Fuzzing - Part 2
Fuzzing - Part 2
 
Exploitation Crash Course
Exploitation Crash CourseExploitation Crash Course
Exploitation Crash Course
 
Protostar VM - Heap3
Protostar VM - Heap3Protostar VM - Heap3
Protostar VM - Heap3
 
Heap Base Exploitation
Heap Base ExploitationHeap Base Exploitation
Heap Base Exploitation
 
Return Oriented Programming
Return Oriented ProgrammingReturn Oriented Programming
Return Oriented Programming
 

Recently uploaded

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 

Recently uploaded (20)

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 

Fuzzing - Part 1

  • 1. FUZZING – PART 1 Mitchell Adair utdcsg.org #utdcsg – irc.oftc.net 9/5/2012
  • 2. Before we begin • Almost all the material is coming from this book. • Awesome book, by some of the godfathers of fuzzing • Buy it… http://www.amazon.com/gp/product/032 1446119
  • 3. What is fuzzing? • The process of sending specific data to an application, in hope to elicit certain responses. • specific? • Mutated data, edge cases, etc. • certain? • Crashes, errors, etc. • Wikipedia • “Fuzz testing or fuzzing is a software testing technique, often automated or semi-automated, that involves providing invalid, unexpected, or random data to the inputs of a computer program. The program is then monitored for exceptions such as crashes, or failing built-in code assertions or for finding potential memory leaks. Fuzzing is commonly used to test for security problems in software or computer systems.”
  • 4. Why? • Used often in • Software testing (SDL) • Google, Mozilla, Microsoft and others are huge on this • Bug hunting  our focus • Good and bad guys, contractors, etc. • Looking for fame, profit, etc.
  • 5. Finding vulnerabilities • Three primary methods • Code auditing • Requires source code  • Reversing • No need for source code, focus on binary applications • Very time consuming, higher skill degree required • Fuzzing • Lots of frameworks available • Can quickly spin up a custom one yourself (Part 2) • Binary, source, etc. unimportant • Can be as simple or complex as you like *After getting used to fuzzing, the problem isn’t finding bugs, it’s figuring out which bugs are exploitable.
  • 6. 2 days later… 1 libqt4_plugin.dll:0xxxxxxxxx mov ecx,[edx+0x30] 1 msvcrt.dll:0xxxxxxxxx rep stosd 1 ntdll.dll:0xxxxxxxxx mov ecx,[ecx+0x4] 2 libqt4_plugin.dll:0xxxxxxxxx arpl [ecx+0x63],sp 2 libqt4_plugin.dll:0xxxxxxxxx mov eax,[eax+0x18] 2 libqt4_plugin.dll:0xxxxxxxxx or byte [eax+0x10],0x1 3 libqt4_plugin.dll:0xxxxxxxxx mov [eax+0x8],ebx 4 libpacketizer_dirac_plugin.dll:0xxxxxxxxx mov dword [eax+0x20],0x0 4 libpacketizer_dirac_plugin.dll:0xxxxxxxxx mov eax,[edx+0x4] 5 libqt4_plugin.dll:0xxxxxxxxx mov dword [eax],0x1 10 libqt4_plugin.dll:0xxxxxxxxx mov [ebx+0x8],eax 13 libpacketizer_dirac_plugin.dll:0xxxxxxxxx mov edx,[eax+0x8]
  • 7. 2 days later… cont 1 [INVALID]:00000001 1 [INVALID]:00000040 1 [INVALID]:00350000 1 [INVALID]:0057001b 1 [INVALID]:008dac24 1 [INVALID]:0135f5d0 1 [INVALID]:0172d090 1 [INVALID]:01bffba8 1 [INVALID]:01c2fcc8 1 [INVALID]:01c9fc7c 1 [INVALID]:01cc5198 1 [INVALID]:0239f068 1 [INVALID]:0310d678 1 [INVALID]:06040002 1 [INVALID]:2f04002b 1 [INVALID]:338dac24 1 [INVALID]:7351eb81 1 [INVALID]:ff2677c4 2 [INVALID]:40000060 5 [INVALID]:76630000 • 32 unique crashes ? • The ones labeled INVALID, where EIP was invalid look particularly interesting • 0x00000001 and 0x00000040 especially 
  • 8. Fuzzing phases 1. 2. 3. 4. 5. 6. • We’re going to focus on steps 3 through 5
  • 9. Types of values • So.. what type of data do I want to send to an application? • Integer values • Border cases : • 0, 0xffffffff (2^32) • Leverage +n / -n cases • malloc( … + 1) • Ranges : • MAX32 – 16 <= MAX32 <= MAX32 + 16 • MAX32 / 2 – 16 <= MAX32 / 2 <= MAX32 / 2 + 16 • MAX32 / 3 – 16 <= MAX32 / 3 <= MAX32 / 3 + 16 • MAX32 / 4 – 16 <= MAX32 / 4 <= MAX32 / 4 + 16 • MAX16 – 16 <= MAX16 <= MAX16 + 16 • MAX16 / 2 – 16 <= MAX16 / 2 <= MAX16 / 2 + 16 • MAX16 / 3 – 16 <= MAX16 / 3 <= MAX16 / 3 + 16 • MAX16 / 4 – 16 <= MAX16 / 4 <= MAX16 / 4 + 16 • MAX8 – 16 <= MAX8 <= MAX8 + 16 • MAX8 / 2 – 16 <= MAX8 / 2 <= MAX8 / 2 + 16 • MAX8 / 3 – 16 <= MAX8 / 3 <= MAX8 / 3 + 16 • MAX8 / 4 – 16 <= MAX8 / 4 <= MAX8 / 4 + 16 Try to influence sign / unsigned values : char, short, int, etc. Unsigned value: 2^Y Signed value: 2^Y / 2
  • 10. Types of values… cont • String repetions • A*100, A*1000, A*10000 • Not just A, B makes a difference on the heap, and in hard coded checks! • Delimiters • !@#$%^&*()-_=+{}|;:’”,<.>/?~` • Varying length strings separated by delimiters • Increasing the length of delimiters is important as well • User::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::password • Format strings • %s and %n have greatest chance to trigger a fault • %s dereferences a stack value • %n writes to a pointer (another dereference) • Should include long sequences
  • 11. Types of values… cont • Character translations • 0xfe and 0xff are expanded into 4 characters under utf16 • Directory traversal • If targeting web apps or network daemons • ../../ and .... etc. • Command injection • If targeting web apps, cgi scripts, network daemons • &&, ; and | characters
  • 12. Types of targets • Environment variables • Positional arguments, flags, etc. • File formats • Network protocols • Web apps • Etc.
  • 13. Targeting environment variables • Focus on *nix because of concept of super user / privilege escalation • Finding targets • We want setuid or setguid files • Find / -type f –perm -4000 –o –perm -2000 • setuid is column 4, value 4 • setguid is column 4, value 2 • So setuid and getuid to a normal 640 file would become 6640
  • 14. Enumerating environment variables • From GDB, we can hook getenv and show all requests • gdb –q ./myprogram • break getenv • (say yes if it asks about setting a deffered breakpoint) • commands • These will get executed after the breakpoint is hit • silent • x/s *(char **)($ebp+8) • Treat $ebp+8 as a pointer to a character pointer • Dereference the above, leaves a character pointer • x/s = examine the string of, a character pointer • Print the string of $ebp+8 • end • cont
  • 16. Preloading • LD_PRELOAD • “The dynamic linker can be influenced into modifying its behavior during either the program's execution or the program's linking… A typical modification of this behavior is the use of the LD_LIBRARY_PATH and LD_PRELOAD environment variables. These variables adjust the runtime linking process by searching for shared libraries at alternate locations and by forcibly loading and linking libraries that would otherwise not be, respectively.” - Wikipedia
  • 17. Preloading… • Creating a substitute for getenv #define BUFFSIZE 20000 char *getenv(char *variable) { char buff[BUFFSIZE]; memset(buff,’A’,BUFFSIZE); buff[BUFFSIZE-1] = 0x0; return buff; } • Compiling and running $ gcc -shared -fPIC -o my_getenv.so my_getenv.c • Create the shared library, my_getenv.so $ LD_PRELOAD=./my_getenv.so /usr/bin/target • Set the LD_PRELOAD environment varaible and run the application
  • 18. Preloading… • When the application makes a call to getenv, our shared library replacement to getenv will get called instead.
  • 19. Detecting problems • The poor man’s way • Check return code of the application • If application terminated due to unhandled signal, return 128 + signal # • SIGSEV = 11 • SIGILL = 4 • Return values of 132 and 139 should be flagged as possible crashes • In the previous slide, “echo $?” echoes the return value • 139 would be SIGSEV
  • 20. Detecting problems… • Better way • Use wait or waitpid function • fork with an execve in the child and wait or waitpid in the parent • can check if child crashed by return value of wait(pid)
  • 21. Detecting problems… • The poor man’s (better) way
  • 22. Detecting problems… • Best • Use debugging libraries • PyDBG, winappdbg, ptrace, etc. • Can catch any signals of interest during execution • handle_signal could log important information • Register contents, stack values, backtrace, etc.
  • 23. Targeting file formats (or parsers) • About half of the local exploits on exploit-db.com are file related • Common targets include media players, document readers, etc.
  • 24. Targeting file formats (or parsers) • What exactly are we trying to exploit with file fuzzing? • Format assumptions • Length field ABC is supposed to be in the range 0-100, surely no one would put 999999… • Surely no one would put a negative value… • etc. • Signed bugs • Length field XYZ is 4 bytes, and represents the length of the following field • ie : [….|4 byte size| data of 4 byte size|….] int n = (int)read(…); // convert the next 4 bytes into an int If( n > MAX_SIZE) // make sure the value is < MAX_SIZE error() // error if it’s not strncpy(dest, source, n) // we’re safe to copy
  • 25. Targeting file formats (or parsers) • Signed bugs… • If n is a signed value (0x80000000 – 0xffffffff), the length check will be bypassed, and *huge* value will be read… overflow • Parsers • Looping over data, expecting to find delimiters while(*ptr != ‘;’) *buff++ = *ptr++;
  • 26. Types of file fuzzers • Brute force / mutation-based • “dumb” • Given a set of good files, mutate them, and run them • Very fast and easy to start doing • Generation-based • “intelligent” • Based off a very specific file format • Requires learning the format, and coding the fuzzer to fuzz specific fields following the format • 4 byte length, 2 byte version, string delimited by a ‘;’, etc… • Can be more fruitful, but requires more up-front effort
  • 27. Popular file fuzzers • Peach • De facto file fuzzer, very popular, very powerfull • http://peachfuzzer.com/ • SPIKEfile • notSPIKEfile • iFUZZ • etc. • Each have their own pros and cons. We’ll be going into Peach in Part 2.
  • 28. Pffft… but I have Python • Tools are great… but we’re going to make our own ;) Part 2 – Creating a mutation based file fuzzer, and a “how-to” for Peach file fuzzing. https://github.com/rmadair/fuzzer Feel free to get a head start and check it out. I highly encourage everyone to fork it, make changes, etc. 