SlideShare a Scribd company logo
Vulnerability, Exploit to
                            Metasploit




balgan@ptcoresec.eu
Before we start

• Some slides might seem like they have too much text, the reason this happens is that I
  want you to be able to get home after this presentation and start messing around with
  the stuff you will learn about here. To do that there is a lot of text you need as a reference
  that even though it is on the slides I might not read.

• Also this presentation will be compiled in a package, with all the software, notes and
  cheat sheets that you need to hack away as soon as you are out of here.
Who Am I ?
                                      Team Leader of these guise
•    Tiago Henriques
•    @balgan
•    23
•    BSc
•    MSc
•    CEH       Which
•    CHFI      Means
                                 file:///C:/Users/balga
               You
                                 n/Downloads/11545_
•   CISSP      Should
                                 192585389754_51359
•   MCSA       Probably
                                 9754_3020198_33334
•   CISA       Leave
                                 9_n.jpg
•   CISM       Because
                                           Currently employed
•   CPT        I will
                                           by these guise
•   CCNA       Talk shit
               Amirite?

• OSCP
                  Next project
What we are going to (try) to cover today
Terminology

• Vulnerability - Security hole in a piece of software, or hardware and can provide a
  potential vector to attack a system. It can go from something simple like a weak password
  to something more complex like buffer overflow, or SQL injection.

• Exploit – A program whose only reason is to take advantage of a vulnerability. Exploits
  often deliver payloads to a target system.

• Payload – Piece of software that allows an attacker to control the exploited system.

• DEP – Data Execution Prevention – First introduced in Win XP SP2 – Used to mark certain
  parts of the stack as non-executable.

• ASLR – Address Space Layout Randomization – Windows Vista onwards – Randomizes the
  base addresses of executables, dll’s, stack and heap.
Step 1 - Vulnerability
Where can I find one? Why should I look for one ?What am I looking for?
Why do I want to look for
                                vulnerabilities?
• There are plenty of reasons why you would want to look for vulnerabilities:


1. Fame – Who doesn’t know people like Charlie Miller, Dino Dai Zovi, and Alex


   Sotirov?


2. Money – You can make a living out of this! ZDI and other programs buy vulns and

   depending on how critical it is you can get quite a lot of money for it!


3. Technical knowledge – You can learn a lot more by digging into the internals of

   software/hardware then just using it normally.
How to find one?

• Multiple techniques exist to find vulnerabilities but we will mention only these three main
  ones:

    • Static analysis – Analyse the programs without running them, reading source code or
      using tools for static analysis. Analyse how the program flow works and how data
      enters the software.

    • Potentially vulnerable Code Locations – Look at specific parts of source code, mainly
      at “unsafe” locations, such as strcpy() and strcat() which are amazing for buffer
      overflows.

    • Fuzzing – Fuzzing is a completely different approach to finding vulnerabilities, it’s a
      dynamic analysis that consists of testing the application by throwing malformed or
      unexpected data as input. Though its easy to automate, the problem with this
      approach is that you can crash an application 70000 times and out of those you get
      10 vulns and only 2 are exploitable.


    … and messing around with the aplication.
More theory
• Every windows application uses memory! The process memory has 3 major components:
         • Code segment – Instructions that the CPU executes – EIP keeps track of next
             instruction (!very important!)
         • Data segment – used for variables, dynamic buffers
         • Stack segment – used to pass data /arguments to functions.
• If you want to access the stack memory directly, you can use the ESP (Stack Pointer) which
  points at the top (lowest memory address ) of the stack.
• The CPU’s general purpose registers (Intel, x86) are :
         •   EAX : accumulator : used for performing calculations, and used to store return values from
             function calls. Basic operations such as add, subtract, compare use this general-purpose
             register
         •   EBX : base (does not have anything to do with base pointer). It has no general purpose and
             can be used to store data.
         •   ECX : counter : used for iterations. ECX counts downward.
         •   EDX : data : this is an extension of the EAX register. It allows for more complex calculations
             (multiply, divide) by allowing extra data to be stored to facilitate those calculations.
         •   ESP : stack pointer
         •   EBP : base pointer
         •   ESI : source index : holds location of input data
         •   EDI : destination index : points to location of where result of data operation is stored
         •   EIP : instruction pointer

 For more information on this check the notes for extra links.
Tools

• So we are now going to crash our first application.
    • Application name: Free MP3 CD Ripper
    • Type of Vulnerability: Buffer Overflow
    • Tools of Trade: ImmunityDebugger, Mona.py, Python, Notepad++
• ImmunityDebugger – Variant of OllyDbg easily scriptable since its python compatible!

• Mona.py – Amazing script created by Corelan Team that integrates with
  ImmunityDebugger and provides lots of functionality for finding vulns and writing
  exploits

• Python – Best scripting language ever for fast prototyping and testing shit.

• Notepad++ - Pretty colors on notepad ftw! 
• Virtual Machines -
Mona.py

• Installing mona – Copy mona.py to the PyCommands folder.
• Useful inicial commands:
    • !mona help
    • !mona update –t trunk
    • !mona config –set workingfolder c:logs%p

                     Constructor code
DEMO 1 - CRASHAPP
Vulnerability, exploit to metasploit
DEMO 2 - Crash-
  EIPControl
Vulnerability, exploit to metasploit
Step 2 - Exploit
Developing a working exploit and Integration into Metasploit framework using mona
Quick recap




• Where are we at the moment:
   • We can crash the app
   • We sort of know how much we have to pass onto it to crash it (5k A’s)
   • We know we control the EIP! (41414141)

• What do we need:
   • Know exactly how much “junk” we have to pass onto it
   • Get proper shellcode and pointers without bad characters
Getting IT!




• Know exactly how much “junk” we have to pass onto it – Mona can do this for us,
We need to turn our A’s into a cyclic pattern :
        !mona pc 5000

• Get proper shellcode and pointers without bad characters – null pointers are bad!
        !mona suggest –cpb ‘x00x0ax0d’
DEMO 3 - Generate
  Cyclic Pattern
Cyclic Patterns
• !mona pc 5000 - Generates cyclic pattern with 5000 characters and
insert them into our constructor script.
DEMO 4 - Mona-
   suggest
Exploit.rb




Now let’s analyse the file created by mona.py - exploit.rb




Also and more important, does it work ?
DEMO 5 - Exploit -
  metasploit -
  exploitation
Quick Recap

• So the process goes likes this:


 1. Manage to crash an app using the normal constructors

 2. Confirm that we control the registers

 3. Create a cyclic pattern and replace it on the constructors

 4. Use mona.py suggest to generate the exploit.rb

 5. Check if it works out of the box by copying it to correct folder and trying it

 6. Fix it if needed

 7. Done.


 8. (Optional) – Submit module to metasploit development and have it
 implemented onto the framework.
Step 3 - Metasploit
Learning a bit about metasploit, why you want your exploits integrated and and use it.
Metasploit Quick Background

•   Exploitation framework
•   Is made of lots of different
    modules and tools that work
    together
•   First written in PERL
•   Then changed to Ruby (HELL
    YEAH!)
•   4 Versions – Pro, Express ,
    Community (Free), Development
    (Free)
•   On the last year more then 1
    million downloads were made
•   Open sauce
Metasploit Architecture




Mad Paint Skillz
Metasploit




• There is a world of functionality within metasploit, however today we will focus only on
  meterpreter and a bit of metasm!

• If I was to talk of all the funcionality within metasploit I would need at least a 2 hour slot
  only to grasp the top features of this amazing framework.
Meterpreter
• Meterpreter is what you could call Shell Ultimate Gold Over 9000 level edition!

• The best way in my opinion to show you the power of meterpreter is to do a demo!

                          Explaining this Francisco Guerreiro style
DEMO 6 - Payload Generation - Normal




  DEMO 6.1 - Session established



   DEMO 6.2 - Meterpreter First
Meterpreter




• This is all really cool ! However not a real scenario, so lets up the stakes a bit!
DEMO 7 - METASM SHIZZLE




DEMO 7.1 - Meterpreter windows 7
Meterpreter

  • There are a few other things about meterpreter I didn’t show you:

  •   post/windows/gather/smart_hashdump – This module sumps local accounts from SAM Database, if
      the target is a Domain Controller it will dump the Domain Account Database.

  •   post/windows/gather/screen_spy – Get your popcorn, this module makes an almost real time movie
      of the targets screen.

  •   post/windows/gather/enum_shares – This script will enumerate all the shares that are currently
      configured on the target

  •   post/windows/gather/enum_services – This script will enumerate all the services that are currently
      configured on the target

  •   post/windows/gather/enum_computers – This script will enumerate all the computers that are
      included in the primary Domain
                                                 And my favourites:

post/windows/gather/bitcoin_jacker – Downloads any Bitcoin wallet.dat on the target system.


post/windows/manage/autoroute - Allows you to attack other machines via our first compromised machine (PIVOTING).
Wrapping things up
 Typical questions
F.A.Q.

• Want to attack: Windows ?

                 Linux ?
F.A.Q.

• Want to attack: Solaris?




                  FreeBSD?



                                      Want to attack virtualization stuff?
                                      Vmauthd_version
           Scada? Yup!                Esx_fingerprint
           OS X ? Yup!                Vmauthd_login
           Netware? Yup               Vmware_enum_users
           Irix? Yup                  Vmware_enum_vms
                                      Poweroff_vm /Poweron_vm
F.A.Q.
• IPv6 Fully Compatible

• And most important….
F.A.Q.
How does Mona deal with:

ASLR:
Mona will, by default, only query non-ASLR and non-rebase modules.
If you can find a memory leak, you can still query ASLR/rebase modules .

For partial overwrite : say you need to overwrite half of the saved return pointer and make
it point to jmp eax from module1.dll, which has base 0xAABB0000, then you could search
for these pointers using

!mona find –type instr –s “jmp eax” –b 0xAABB0000 -t 0xAABBFFFF

This will get you all pointers from that memory region, so you can use the last 2 bytes in the
partial overwrite
F.A.Q.
How does Mona deal with:

DEP:

Mona will attempt to automatically generate ROP chains

Also, Usually, people only think about bad chars when creating payload… but especially in
case of ROP chains, a lot of the payload may be pointers
So… when using mona, you can use for example –cpb ‘x00x0ax0dx20’ to exclude
pointers that have those bad chars
(this option is available for any command)

Mona will also create a stackpivot file, which you can use in case of SEH overwrite
Becoming a vuln researcher

1st – Corelan.be – Read through the exploit development tutorial - Learn a scripting
language and ASM

2nd – Read “ A Bug Hunter’s diary” – Side by side: Learn how to use tools of the trade such
as: Immunity Dbg, Scapy, WinDbg, IDA.

3rd – Read Metasploit book

4th – Proceed to learn about fuzzing and other techniques.




For extra directions go to: http://myne-us.blogspot.com/2010/08/from-0x90-to-0x4c454554-journey-into.html
References



1. Corelan.be – AMAZING Team and you can learn so much on their website and IRC chan


2. https://www.corelan.be/index.php/2011/07/14/mona-py-the-manual/ - Mona stuff


3. www.metasploit.com/modules/


4. http://www.offensive-security.com/metasploit-unleashed/

More Related Content

PDF
Metasploit for Penetration Testing: Beginner Class
PPTX
Metasploit For Beginners
PDF
Metasploit Humla for Beginner
PPTX
Metasploit for Web Workshop
PDF
Pen-Testing with Metasploit
PDF
Metasploit - The Exploit Learning Tree
PPTX
Penetration testing using metasploit
PPTX
Finalppt metasploit
Metasploit for Penetration Testing: Beginner Class
Metasploit For Beginners
Metasploit Humla for Beginner
Metasploit for Web Workshop
Pen-Testing with Metasploit
Metasploit - The Exploit Learning Tree
Penetration testing using metasploit
Finalppt metasploit

What's hot (20)

PPT
Hacking Fundamentals - Jen Johnson , Miria Grunick
PPT
Laboratory exercise - Network security - Penetration testing
ODP
Stealthy, Hypervisor-based Malware Analysis
PPTX
Vulnerability desing patterns
PDF
Mem forensic
PDF
Modern Evasion Techniques
PDF
Pitfalls and limits of dynamic malware analysis
PDF
Масштабируемый и эффективный фаззинг Google Chrome
PDF
Penetration Testing Resource Guide
PDF
Veil-PowerView - NovaHackers
PDF
CheckPlease: Payload-Agnostic Targeted Malware
PDF
Defcon 22-colby-moore-patrick-wardle-synack-drop cam
PPTX
Introducing PS>Attack: An offensive PowerShell toolkit
PDF
About linux-english
PDF
Inside the Matrix,How to Build Transparent Sandbox for Malware Analysis
PPTX
Metasploit & Windows Kernel Exploitation
PPTX
Introduction of ShinoBOT (Black Hat USA 2013 Arsenal)
Hacking Fundamentals - Jen Johnson , Miria Grunick
Laboratory exercise - Network security - Penetration testing
Stealthy, Hypervisor-based Malware Analysis
Vulnerability desing patterns
Mem forensic
Modern Evasion Techniques
Pitfalls and limits of dynamic malware analysis
Масштабируемый и эффективный фаззинг Google Chrome
Penetration Testing Resource Guide
Veil-PowerView - NovaHackers
CheckPlease: Payload-Agnostic Targeted Malware
Defcon 22-colby-moore-patrick-wardle-synack-drop cam
Introducing PS>Attack: An offensive PowerShell toolkit
About linux-english
Inside the Matrix,How to Build Transparent Sandbox for Malware Analysis
Metasploit & Windows Kernel Exploitation
Introduction of ShinoBOT (Black Hat USA 2013 Arsenal)
Ad

Viewers also liked (20)

PDF
Metasploit
ODP
Bilgi Sistemleri Güvenliği Metasploit
PDF
SynFlood DDOS Saldırıları ve Korunma Yolları
PPTX
BTRisk Android Uygulamalara Malware Yerleştirme Sunumu
PDF
Web Sunucularına Yönelik DDoS Saldırıları
PDF
Kablosuz Ağlara Yapılan Saldırılar
PDF
Tcpdump ile Trafik Analizi(Sniffing)
PDF
Uygulamalı Ağ Güvenliği Eğitimi Lab Çalışmaları
PDF
Beyaz Şapkalı Hacker (CEH) Lab Kitabı
PPTX
Beyaz Şapkalı Hacker CEH Eğitimi - Bölüm 1, 2, 3
PDF
Metasploit Framework Eğitimi
PDF
Zararlı Yazılım Analizi Eğitimi Lab Kitabı
PDF
İleri Seviye Ağ Güvenliği Lab Kitabı
PPTX
Beyaz Şapkalı Hacker CEH Eğitimi - Bölüm 19
PPTX
Beyaz Şapkalı Hacker CEH Eğitimi - Bölüm 4, 5, 6
PPTX
Beyaz Şapkalı Hacker CEH Eğitimi - Bölüm 7, 8, 9
PDF
Kablosuz Ağlarda Adli Analiz
PPTX
Beyaz Şapkalı Hacker CEH Eğitimi - Bölüm 10, 11, 12
Metasploit
Bilgi Sistemleri Güvenliği Metasploit
SynFlood DDOS Saldırıları ve Korunma Yolları
BTRisk Android Uygulamalara Malware Yerleştirme Sunumu
Web Sunucularına Yönelik DDoS Saldırıları
Kablosuz Ağlara Yapılan Saldırılar
Tcpdump ile Trafik Analizi(Sniffing)
Uygulamalı Ağ Güvenliği Eğitimi Lab Çalışmaları
Beyaz Şapkalı Hacker (CEH) Lab Kitabı
Beyaz Şapkalı Hacker CEH Eğitimi - Bölüm 1, 2, 3
Metasploit Framework Eğitimi
Zararlı Yazılım Analizi Eğitimi Lab Kitabı
İleri Seviye Ağ Güvenliği Lab Kitabı
Beyaz Şapkalı Hacker CEH Eğitimi - Bölüm 19
Beyaz Şapkalı Hacker CEH Eğitimi - Bölüm 4, 5, 6
Beyaz Şapkalı Hacker CEH Eğitimi - Bölüm 7, 8, 9
Kablosuz Ağlarda Adli Analiz
Beyaz Şapkalı Hacker CEH Eğitimi - Bölüm 10, 11, 12
Ad

Similar to Vulnerability, exploit to metasploit (20)

PDF
Hacking school computers for fun profit and better grades short
PDF
Dive into exploit development
PPTX
Reversing malware analysis training part10 exploit development basics
PPTX
BSides Algiers - Reversing Win32 applications - Yacine Hebbal
PDF
Louisville Infosec - Metasploit Class - Fuzzing and Exploit Development with ...
PDF
Metasploitation part-1 (murtuja)
PPT
Writing Metasploit Plugins
PDF
Fuzzing: Finding Your Own Bugs and 0days! at Arab Security Conference
PPT
Software security
PPTX
20101017 program analysis_for_security_livshits_lecture03_security
PDF
24 33 -_metasploit
PDF
Basic buffer overflow part1
PPTX
Anatomy of a Buffer Overflow Attack
PDF
Thick Application Penetration Testing: Crash Course
PPT
B-Sides Seattle 2012 Offensive Defense
PDF
Writing simple buffer_overflow_exploits
PPTX
Malware 101 by saurabh chaudhary
PPTX
Metasploit
PDF
Exploitation and State Machines
PDF
Hack Attack! An Introduction to Penetration Testing
Hacking school computers for fun profit and better grades short
Dive into exploit development
Reversing malware analysis training part10 exploit development basics
BSides Algiers - Reversing Win32 applications - Yacine Hebbal
Louisville Infosec - Metasploit Class - Fuzzing and Exploit Development with ...
Metasploitation part-1 (murtuja)
Writing Metasploit Plugins
Fuzzing: Finding Your Own Bugs and 0days! at Arab Security Conference
Software security
20101017 program analysis_for_security_livshits_lecture03_security
24 33 -_metasploit
Basic buffer overflow part1
Anatomy of a Buffer Overflow Attack
Thick Application Penetration Testing: Crash Course
B-Sides Seattle 2012 Offensive Defense
Writing simple buffer_overflow_exploits
Malware 101 by saurabh chaudhary
Metasploit
Exploitation and State Machines
Hack Attack! An Introduction to Penetration Testing

More from Tiago Henriques (20)

PDF
BSides Lisbon 2023 - AI in Cybersecurity.pdf
PDF
Pixels Camp 2017 - Stories from the trenches of building a data architecture
PDF
Pixels Camp 2017 - Stranger Things the internet version
PDF
The state of cybersecurity in Switzerland - FinTechDay 2017
PDF
Webzurich - The State of Web Security in Switzerland
PDF
BSides Lisbon - Data science, machine learning and cybersecurity
PDF
I FOR ONE WELCOME OUR NEW CYBER OVERLORDS! AN INTRODUCTION TO THE USE OF MACH...
PDF
BinaryEdge - Security Data Metrics and Measurements at Scale - BSidesLisbon 2015
PDF
Codebits 2014 - Secure Coding - Gamification and automation for the win
PPTX
Presentation Brucon - Anubisnetworks and PTCoresec
PPTX
Hardware hacking 101
PPTX
Workshop
PPTX
PPTX
Confraria 28-feb-2013 mesa redonda
PPTX
Preso fcul
PPTX
How to dominate a country
PPTX
Country domination - Causing chaos and wrecking havoc
PDF
(Mis)trusting and (ab)using ssh
PPTX
Secure coding - Balgan - Tiago Henriques
PPTX
Practical exploitation and social engineering
BSides Lisbon 2023 - AI in Cybersecurity.pdf
Pixels Camp 2017 - Stories from the trenches of building a data architecture
Pixels Camp 2017 - Stranger Things the internet version
The state of cybersecurity in Switzerland - FinTechDay 2017
Webzurich - The State of Web Security in Switzerland
BSides Lisbon - Data science, machine learning and cybersecurity
I FOR ONE WELCOME OUR NEW CYBER OVERLORDS! AN INTRODUCTION TO THE USE OF MACH...
BinaryEdge - Security Data Metrics and Measurements at Scale - BSidesLisbon 2015
Codebits 2014 - Secure Coding - Gamification and automation for the win
Presentation Brucon - Anubisnetworks and PTCoresec
Hardware hacking 101
Workshop
Confraria 28-feb-2013 mesa redonda
Preso fcul
How to dominate a country
Country domination - Causing chaos and wrecking havoc
(Mis)trusting and (ab)using ssh
Secure coding - Balgan - Tiago Henriques
Practical exploitation and social engineering

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Big Data Technologies - Introduction.pptx
PPT
Teaching material agriculture food technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Sensors and Actuators in IoT Systems using pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Chapter 2 Digital Image Fundamentals.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
Modernizing your data center with Dell and AMD
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Big Data Technologies - Introduction.pptx
Teaching material agriculture food technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Spectral efficient network and resource selection model in 5G networks
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Sensors and Actuators in IoT Systems using pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
NewMind AI Weekly Chronicles - August'25 Week I
Chapter 2 Digital Image Fundamentals.pdf
cuic standard and advanced reporting.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Transforming Manufacturing operations through Intelligent Integrations
Modernizing your data center with Dell and AMD
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
madgavkar20181017ppt McKinsey Presentation.pdf
Advanced methodologies resolving dimensionality complications for autism neur...

Vulnerability, exploit to metasploit

  • 2. Before we start • Some slides might seem like they have too much text, the reason this happens is that I want you to be able to get home after this presentation and start messing around with the stuff you will learn about here. To do that there is a lot of text you need as a reference that even though it is on the slides I might not read. • Also this presentation will be compiled in a package, with all the software, notes and cheat sheets that you need to hack away as soon as you are out of here.
  • 3. Who Am I ? Team Leader of these guise • Tiago Henriques • @balgan • 23 • BSc • MSc • CEH Which • CHFI Means file:///C:/Users/balga You n/Downloads/11545_ • CISSP Should 192585389754_51359 • MCSA Probably 9754_3020198_33334 • CISA Leave 9_n.jpg • CISM Because Currently employed • CPT I will by these guise • CCNA Talk shit Amirite? • OSCP Next project
  • 4. What we are going to (try) to cover today
  • 5. Terminology • Vulnerability - Security hole in a piece of software, or hardware and can provide a potential vector to attack a system. It can go from something simple like a weak password to something more complex like buffer overflow, or SQL injection. • Exploit – A program whose only reason is to take advantage of a vulnerability. Exploits often deliver payloads to a target system. • Payload – Piece of software that allows an attacker to control the exploited system. • DEP – Data Execution Prevention – First introduced in Win XP SP2 – Used to mark certain parts of the stack as non-executable. • ASLR – Address Space Layout Randomization – Windows Vista onwards – Randomizes the base addresses of executables, dll’s, stack and heap.
  • 6. Step 1 - Vulnerability Where can I find one? Why should I look for one ?What am I looking for?
  • 7. Why do I want to look for vulnerabilities? • There are plenty of reasons why you would want to look for vulnerabilities: 1. Fame – Who doesn’t know people like Charlie Miller, Dino Dai Zovi, and Alex Sotirov? 2. Money – You can make a living out of this! ZDI and other programs buy vulns and depending on how critical it is you can get quite a lot of money for it! 3. Technical knowledge – You can learn a lot more by digging into the internals of software/hardware then just using it normally.
  • 8. How to find one? • Multiple techniques exist to find vulnerabilities but we will mention only these three main ones: • Static analysis – Analyse the programs without running them, reading source code or using tools for static analysis. Analyse how the program flow works and how data enters the software. • Potentially vulnerable Code Locations – Look at specific parts of source code, mainly at “unsafe” locations, such as strcpy() and strcat() which are amazing for buffer overflows. • Fuzzing – Fuzzing is a completely different approach to finding vulnerabilities, it’s a dynamic analysis that consists of testing the application by throwing malformed or unexpected data as input. Though its easy to automate, the problem with this approach is that you can crash an application 70000 times and out of those you get 10 vulns and only 2 are exploitable. … and messing around with the aplication.
  • 9. More theory • Every windows application uses memory! The process memory has 3 major components: • Code segment – Instructions that the CPU executes – EIP keeps track of next instruction (!very important!) • Data segment – used for variables, dynamic buffers • Stack segment – used to pass data /arguments to functions. • If you want to access the stack memory directly, you can use the ESP (Stack Pointer) which points at the top (lowest memory address ) of the stack. • The CPU’s general purpose registers (Intel, x86) are : • EAX : accumulator : used for performing calculations, and used to store return values from function calls. Basic operations such as add, subtract, compare use this general-purpose register • EBX : base (does not have anything to do with base pointer). It has no general purpose and can be used to store data. • ECX : counter : used for iterations. ECX counts downward. • EDX : data : this is an extension of the EAX register. It allows for more complex calculations (multiply, divide) by allowing extra data to be stored to facilitate those calculations. • ESP : stack pointer • EBP : base pointer • ESI : source index : holds location of input data • EDI : destination index : points to location of where result of data operation is stored • EIP : instruction pointer For more information on this check the notes for extra links.
  • 10. Tools • So we are now going to crash our first application. • Application name: Free MP3 CD Ripper • Type of Vulnerability: Buffer Overflow • Tools of Trade: ImmunityDebugger, Mona.py, Python, Notepad++ • ImmunityDebugger – Variant of OllyDbg easily scriptable since its python compatible! • Mona.py – Amazing script created by Corelan Team that integrates with ImmunityDebugger and provides lots of functionality for finding vulns and writing exploits • Python – Best scripting language ever for fast prototyping and testing shit. • Notepad++ - Pretty colors on notepad ftw!  • Virtual Machines -
  • 11. Mona.py • Installing mona – Copy mona.py to the PyCommands folder. • Useful inicial commands: • !mona help • !mona update –t trunk • !mona config –set workingfolder c:logs%p Constructor code
  • 12. DEMO 1 - CRASHAPP
  • 14. DEMO 2 - Crash- EIPControl
  • 16. Step 2 - Exploit Developing a working exploit and Integration into Metasploit framework using mona
  • 17. Quick recap • Where are we at the moment: • We can crash the app • We sort of know how much we have to pass onto it to crash it (5k A’s) • We know we control the EIP! (41414141) • What do we need: • Know exactly how much “junk” we have to pass onto it • Get proper shellcode and pointers without bad characters
  • 18. Getting IT! • Know exactly how much “junk” we have to pass onto it – Mona can do this for us, We need to turn our A’s into a cyclic pattern : !mona pc 5000 • Get proper shellcode and pointers without bad characters – null pointers are bad! !mona suggest –cpb ‘x00x0ax0d’
  • 19. DEMO 3 - Generate Cyclic Pattern
  • 20. Cyclic Patterns • !mona pc 5000 - Generates cyclic pattern with 5000 characters and insert them into our constructor script.
  • 21. DEMO 4 - Mona- suggest
  • 22. Exploit.rb Now let’s analyse the file created by mona.py - exploit.rb Also and more important, does it work ?
  • 23. DEMO 5 - Exploit - metasploit - exploitation
  • 24. Quick Recap • So the process goes likes this: 1. Manage to crash an app using the normal constructors 2. Confirm that we control the registers 3. Create a cyclic pattern and replace it on the constructors 4. Use mona.py suggest to generate the exploit.rb 5. Check if it works out of the box by copying it to correct folder and trying it 6. Fix it if needed 7. Done. 8. (Optional) – Submit module to metasploit development and have it implemented onto the framework.
  • 25. Step 3 - Metasploit Learning a bit about metasploit, why you want your exploits integrated and and use it.
  • 26. Metasploit Quick Background • Exploitation framework • Is made of lots of different modules and tools that work together • First written in PERL • Then changed to Ruby (HELL YEAH!) • 4 Versions – Pro, Express , Community (Free), Development (Free) • On the last year more then 1 million downloads were made • Open sauce
  • 28. Metasploit • There is a world of functionality within metasploit, however today we will focus only on meterpreter and a bit of metasm! • If I was to talk of all the funcionality within metasploit I would need at least a 2 hour slot only to grasp the top features of this amazing framework.
  • 29. Meterpreter • Meterpreter is what you could call Shell Ultimate Gold Over 9000 level edition! • The best way in my opinion to show you the power of meterpreter is to do a demo! Explaining this Francisco Guerreiro style
  • 30. DEMO 6 - Payload Generation - Normal DEMO 6.1 - Session established DEMO 6.2 - Meterpreter First
  • 31. Meterpreter • This is all really cool ! However not a real scenario, so lets up the stakes a bit!
  • 32. DEMO 7 - METASM SHIZZLE DEMO 7.1 - Meterpreter windows 7
  • 33. Meterpreter • There are a few other things about meterpreter I didn’t show you: • post/windows/gather/smart_hashdump – This module sumps local accounts from SAM Database, if the target is a Domain Controller it will dump the Domain Account Database. • post/windows/gather/screen_spy – Get your popcorn, this module makes an almost real time movie of the targets screen. • post/windows/gather/enum_shares – This script will enumerate all the shares that are currently configured on the target • post/windows/gather/enum_services – This script will enumerate all the services that are currently configured on the target • post/windows/gather/enum_computers – This script will enumerate all the computers that are included in the primary Domain And my favourites: post/windows/gather/bitcoin_jacker – Downloads any Bitcoin wallet.dat on the target system. post/windows/manage/autoroute - Allows you to attack other machines via our first compromised machine (PIVOTING).
  • 34. Wrapping things up Typical questions
  • 35. F.A.Q. • Want to attack: Windows ? Linux ?
  • 36. F.A.Q. • Want to attack: Solaris? FreeBSD? Want to attack virtualization stuff? Vmauthd_version Scada? Yup! Esx_fingerprint OS X ? Yup! Vmauthd_login Netware? Yup Vmware_enum_users Irix? Yup Vmware_enum_vms Poweroff_vm /Poweron_vm
  • 37. F.A.Q. • IPv6 Fully Compatible • And most important….
  • 38. F.A.Q. How does Mona deal with: ASLR: Mona will, by default, only query non-ASLR and non-rebase modules. If you can find a memory leak, you can still query ASLR/rebase modules . For partial overwrite : say you need to overwrite half of the saved return pointer and make it point to jmp eax from module1.dll, which has base 0xAABB0000, then you could search for these pointers using !mona find –type instr –s “jmp eax” –b 0xAABB0000 -t 0xAABBFFFF This will get you all pointers from that memory region, so you can use the last 2 bytes in the partial overwrite
  • 39. F.A.Q. How does Mona deal with: DEP: Mona will attempt to automatically generate ROP chains Also, Usually, people only think about bad chars when creating payload… but especially in case of ROP chains, a lot of the payload may be pointers So… when using mona, you can use for example –cpb ‘x00x0ax0dx20’ to exclude pointers that have those bad chars (this option is available for any command) Mona will also create a stackpivot file, which you can use in case of SEH overwrite
  • 40. Becoming a vuln researcher 1st – Corelan.be – Read through the exploit development tutorial - Learn a scripting language and ASM 2nd – Read “ A Bug Hunter’s diary” – Side by side: Learn how to use tools of the trade such as: Immunity Dbg, Scapy, WinDbg, IDA. 3rd – Read Metasploit book 4th – Proceed to learn about fuzzing and other techniques. For extra directions go to: http://myne-us.blogspot.com/2010/08/from-0x90-to-0x4c454554-journey-into.html
  • 41. References 1. Corelan.be – AMAZING Team and you can learn so much on their website and IRC chan 2. https://www.corelan.be/index.php/2011/07/14/mona-py-the-manual/ - Mona stuff 3. www.metasploit.com/modules/ 4. http://www.offensive-security.com/metasploit-unleashed/

Editor's Notes

  • #10: https://www.corelan.be/index.php/2009/07/19/exploit-writing-tutorial-part-1-stack-based-overflows/
  • #12: import osfilename = "2-n-half-k" + ".wav"buffer = "A" * 2500file = open(filename,"w")file.write(buffer)file.close()
  • #13: Simple demo of running multiple wav files built with constructors and app crashes on one of them
  • #15: DEMO2 - Crash-EIPControl
  • #20: DEMO 3 - Generate Cyclic Pattern
  • #22: DEMO4 - Mona-suggest
  • #24: DEMO5 - Exploit - metasploit - exploitation
  • #31: DEMO5 - Exploit - metasploit - exploitation
  • #40:  ROP is a generalization of the classic return-to-libc attack that involves leveraging small sequences of instructions, typically function epilogues, at known addresses to execute arbitrary code incrementally. This is achieved by controlling data pointed to by ESP, the stack pointer register, such that each ret instruction results in incrementing ESP and transferring execution to the next address chosen by the attacker.