SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
Structured Exception Handler
                                 EXPLOITATION




http://www.htbridge.ch/                                  Brian Mariani
What is an exception

•   An exception is an event that occurs during the execution of a program

•   Requires the execution of code outside the normal flow of control
Structured Exception Handling
•   Blocks of code are encapsulated, with each block having one or more associated
    handlers.

•   Each handler specifies some form of filter condition on the type of exception it
    handles

•   When an exception is raised by code in a protected block, the set of corresponding
    handlers is searched in order, and the first one with a matchingfilter condition is
    executed

•   A single method can have multiple structured exception handling blocks, and the
    blocks can also be nested within each other
Exception pointers structure (1)

•   Contains an exception record with a machine-independent description of an
    exception

•   A context record with a machine-dependent description of the processor context at
    the time of the exception
Exception pointers structure (2)
•   A pointer to the next exception registration structure

•   A pointer to the address of the actual code of the exception handler
Thread information block
•   The Thread Information Block (TIB) is a data structure in Win32 that stores
    information
    about the currently running thread

•   At the position FS:[0x00] we found the current exception handler
Dumping SEH chain in Inmunity debugger
How SEH works?


•   The exception handlers are linked to each other

•   They form a linked list chain on the stack, and sit relatively close to the bottom of the
    stack

•   When an exception occurs, Windows retrieves the head of the SEH chain walks
    through the list and tries to find the suitable handler to close the application properly
Abusing the SEH
•   When exploiting an SEH overwrite and attacker clobbers the handler attribute of the
    EXCEPTION_REGISTRATION_RECORD with the address of an instruction sequence
    similar to POP POP RET

•   When the exception occurs, this causes Windows to pass execution to this address,
    which subsequently returns to the location on the stack of the Next attribute of the

    EXCEPTION_REGISTRATION_RECORD

•   The Next attribute is also controlled by the attacker, but if we recall the stack layout
    from earlier, the Next attribute is below the Handler attribute

•   This limits the attacker to 4 bytes before running into the Handler address he
    previously supplied to originally obtain code execution

•   However, by overwriting the Next attribute with the instructions that jump the Handler
    attribute, the attacker typically has enough room for arbitrary shellcode, and this is
    exactly what happens
Overwriting the Next SEH record and SE
                handler
  •   To check a chain of exception handlers before and after an overflow we can use
      WinDbg !exchain command

  •   At the left we can see the SEH chain and the stack before the overflow occurs

  •   At the right we can see the pointers were successfully overwritten
What are we overwriting?


•   When we performs a regular stack based buffer overflow, we overwrite the return
    address of the Extended Instruction Pointer (EIP)

•   When doing a SEH overflow, we will continue overwriting the stack after overwriting
                       overflow
    EIP, so we can overwrite the default exception handler as well
    EIP
Viewing the SEH before the overflow
•   Before the overflow occurs we can see the stack and the SEH chain.

•   The SEH chain starts from 0x015fd044 down to 0x015fffdc which indicates the end of
    the SEH chain

•   Directly below 0x015fffe0, we see 0x7c839ad8, which is the address of the default SE
                    0x015fffe0          0x7c839ad8
    handler for this application. This address sits in the address space of kernel32.dll
Viewing the SEH after the overflow
•   Dumping the TIB confirms that the SEH was overwritten

•   Code execution is successfully passed to the injected address 0x61616161

•   Addresses 0x015fd044 and 0x015fd048 which were the Next SEH record and SE
    handler are now controlled.




                                  EIP point to 0x61616161,
                                  so we can control the flow
                                       of the program




                                             Pointer to the Next record
                                              and SEH handler was
                                                     overwritten




                                                                TIB dumping let us know
                                                                   the SEH chain was
                                                                sucessfully overwritten
See an exception analysis
•   The command !analyze –v in Windbg give us more details about the triggering of the
    exception
How SEH base exploit works
•   When the exception is triggered the program flow go to the SE Handler

•   All we need is just put some code to jump to our payload

•   Faking a second exception makes the application goes to the next SEH pointer

•   As the Next SEH pointer is before the SE handler we can overwrite the Next SEH

•   Since the shellcode sits after the Handler, we can trick the SE Handler to execute POP

    POP RET instructions so the address to the Next SEH will be placed in EIP, therefore
    executing the code in Next SEH

•   The code will basically jump over some bytes and execute the shellcode
Exploiting the application
•   We will exploit a vulnerability in Gogago Youtube Downloader Video ActiveX
    www.gogago.net/download/youtube_video_downloader_setup.exe

•   A buffer overflow is triggered after injecting more that 2230 bytes in the Download()
    function

•   This vulnerability could be exploited using a basic RET CALL technique

•   We will use SEH based exploitation which is also functioning in this particular case
Creating the POC
•   We craft an html page calling the method Download using the CLASSID

•   When we overflow the method with 2250 bytes with junk data we trigger an exception
Overwriting Next pointer and SE
                handler
•   To successfully overwrite the Next Pointer and SE Handler we must calculate the exact
            number of bytes to inject

•   You can use tools as pattern_create and pattern_search from Metasploit, or you can do
    it manually injecting buffers with different patterns
Finding POP POP RET instructions
•   Finding opcodes it’s not a difficult task you can use findjump or IDA

•   In this tutorial we will use WinDBG

•   We launch our prove of concept and we attach to Internet Explorer. After the overflow
                                                             Explorer
    occurs we search the base memory address of the Gogago module MDIEex.dll

•   Finally we can search for the opcodes using the s command
Building the exploit
•   After calculating the number of bytes to overwrite the Next pointer and SE handler we
       inject 4 bytes of code to jump to our shellcode this will replace the old SE handler
•
    Following the SE handler we inject the POP POP RET opcodes from the same module
    of the exploited application

•   Finally we inject our payload
Executing the exploit (1)
•   We place a breakpoint before entering in the vulnerable method. The SE handler that
    will be overwritten sits at 0x15fa79c, and corresponds to the jscript.dll module
                                0x15fa79c
Executing the exploit (2)
•   After the overflow occurs we successfully overwrites the old jscript SE handler later
    code execution will be redirected to our POP POP RET instructions
Redirect code execution
•   The code is redirected to our fake SE Handler address
Jumping to our payload
•   Jumping over 6 bytes to reach ou shellcode starting at address 0x015fa7a4
Shellcode execution
•   Time to dance 
Questions




brian.mariani@htbridge.ch
References
•   http://msdn.microsoft.com/en-us/library/ms680663%28v=VS.85%29.aspx

•   http://msdn.microsoft.com/en-us/library/c68xfk56%28v=vs.71%29.aspx

•   http://en.wikipedia.org/wiki/Win32_Thread_Information_Block

•   http://corelan.be

Contenu connexe

Tendances

CNIT 127 14: Protection Mechanisms
CNIT 127 14: Protection MechanismsCNIT 127 14: Protection Mechanisms
CNIT 127 14: Protection MechanismsSam Bowne
 
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
 
CNIT 127: 3: Shellcode
CNIT 127: 3: ShellcodeCNIT 127: 3: Shellcode
CNIT 127: 3: ShellcodeSam Bowne
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeCNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeSam Bowne
 
Practical Malware Analysis Ch13
Practical Malware Analysis Ch13Practical Malware Analysis Ch13
Practical Malware Analysis Ch13Sam Bowne
 
CNIT 126 8: Debugging
CNIT 126 8: DebuggingCNIT 126 8: Debugging
CNIT 126 8: DebuggingSam Bowne
 
CNIT 126 7: Analyzing Malicious Windows Programs
CNIT 126 7: Analyzing Malicious Windows ProgramsCNIT 126 7: Analyzing Malicious Windows Programs
CNIT 126 7: Analyzing Malicious Windows ProgramsSam Bowne
 
CNIT 127 Ch 4: Introduction to format string bugs
CNIT 127 Ch 4: Introduction to format string bugsCNIT 127 Ch 4: Introduction to format string bugs
CNIT 127 Ch 4: Introduction to format string bugsSam Bowne
 
CNIT 141 8. Authenticated Encryption
CNIT 141 8. Authenticated EncryptionCNIT 141 8. Authenticated Encryption
CNIT 141 8. Authenticated EncryptionSam Bowne
 
CNIT 141: 1. Encryption
CNIT 141: 1. EncryptionCNIT 141: 1. Encryption
CNIT 141: 1. EncryptionSam Bowne
 
CNIT 126: 13: Data Encoding
CNIT 126: 13: Data EncodingCNIT 126: 13: Data Encoding
CNIT 126: 13: Data EncodingSam Bowne
 
CNIT 141: 1. Encryption
CNIT 141: 1. EncryptionCNIT 141: 1. Encryption
CNIT 141: 1. EncryptionSam Bowne
 
CNIT 126 9: OllyDbg
CNIT 126 9: OllyDbgCNIT 126 9: OllyDbg
CNIT 126 9: OllyDbgSam Bowne
 
Introduction to Raft algorithm
Introduction to Raft algorithmIntroduction to Raft algorithm
Introduction to Raft algorithmmuayyad alsadi
 
CNIT 127: 8: Windows overflows (Part 2)
CNIT 127: 8: Windows overflows (Part 2)CNIT 127: 8: Windows overflows (Part 2)
CNIT 127: 8: Windows overflows (Part 2)Sam Bowne
 
Practical Malware Analysis Ch12
Practical Malware Analysis Ch12Practical Malware Analysis Ch12
Practical Malware Analysis Ch12Sam Bowne
 
CNIT 127 14: Protection Mechanisms
CNIT 127 14: Protection MechanismsCNIT 127 14: Protection Mechanisms
CNIT 127 14: Protection MechanismsSam Bowne
 
CNIT 126 13: Data Encoding
CNIT 126 13: Data EncodingCNIT 126 13: Data Encoding
CNIT 126 13: Data EncodingSam Bowne
 
CNIT 141: 4. Block Ciphers
CNIT 141: 4. Block CiphersCNIT 141: 4. Block Ciphers
CNIT 141: 4. Block CiphersSam Bowne
 

Tendances (20)

CNIT 127 14: Protection Mechanisms
CNIT 127 14: Protection MechanismsCNIT 127 14: Protection Mechanisms
CNIT 127 14: Protection Mechanisms
 
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
 
CNIT 127: 3: Shellcode
CNIT 127: 3: ShellcodeCNIT 127: 3: Shellcode
CNIT 127: 3: Shellcode
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeCNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: Shellcode
 
Practical Malware Analysis Ch13
Practical Malware Analysis Ch13Practical Malware Analysis Ch13
Practical Malware Analysis Ch13
 
CNIT 126 8: Debugging
CNIT 126 8: DebuggingCNIT 126 8: Debugging
CNIT 126 8: Debugging
 
CNIT 126 7: Analyzing Malicious Windows Programs
CNIT 126 7: Analyzing Malicious Windows ProgramsCNIT 126 7: Analyzing Malicious Windows Programs
CNIT 126 7: Analyzing Malicious Windows Programs
 
CNIT 127 Ch 4: Introduction to format string bugs
CNIT 127 Ch 4: Introduction to format string bugsCNIT 127 Ch 4: Introduction to format string bugs
CNIT 127 Ch 4: Introduction to format string bugs
 
CNIT 141 8. Authenticated Encryption
CNIT 141 8. Authenticated EncryptionCNIT 141 8. Authenticated Encryption
CNIT 141 8. Authenticated Encryption
 
CNIT 141: 1. Encryption
CNIT 141: 1. EncryptionCNIT 141: 1. Encryption
CNIT 141: 1. Encryption
 
CNIT 126: 13: Data Encoding
CNIT 126: 13: Data EncodingCNIT 126: 13: Data Encoding
CNIT 126: 13: Data Encoding
 
CNIT 141: 1. Encryption
CNIT 141: 1. EncryptionCNIT 141: 1. Encryption
CNIT 141: 1. Encryption
 
CNIT 126 9: OllyDbg
CNIT 126 9: OllyDbgCNIT 126 9: OllyDbg
CNIT 126 9: OllyDbg
 
Introduction to Raft algorithm
Introduction to Raft algorithmIntroduction to Raft algorithm
Introduction to Raft algorithm
 
CNIT 127: 8: Windows overflows (Part 2)
CNIT 127: 8: Windows overflows (Part 2)CNIT 127: 8: Windows overflows (Part 2)
CNIT 127: 8: Windows overflows (Part 2)
 
Practical Malware Analysis Ch12
Practical Malware Analysis Ch12Practical Malware Analysis Ch12
Practical Malware Analysis Ch12
 
CNIT 127 14: Protection Mechanisms
CNIT 127 14: Protection MechanismsCNIT 127 14: Protection Mechanisms
CNIT 127 14: Protection Mechanisms
 
CNIT 126 13: Data Encoding
CNIT 126 13: Data EncodingCNIT 126 13: Data Encoding
CNIT 126 13: Data Encoding
 
Raft presentation
Raft presentationRaft presentation
Raft presentation
 
CNIT 141: 4. Block Ciphers
CNIT 141: 4. Block CiphersCNIT 141: 4. Block Ciphers
CNIT 141: 4. Block Ciphers
 

En vedette

Human body is a holy temple
Human body is a holy templeHuman body is a holy temple
Human body is a holy templeBASKARAN P
 
Dallas partner meeting_8.07.12
Dallas partner meeting_8.07.12Dallas partner meeting_8.07.12
Dallas partner meeting_8.07.12bscisteam
 
Preliminary Evaluation
Preliminary Evaluation Preliminary Evaluation
Preliminary Evaluation nctcmedia12
 
Market snapshot report 19 12-2012
Market snapshot report 19 12-2012Market snapshot report 19 12-2012
Market snapshot report 19 12-2012Abhijit Mitra
 
職場生存之道:內向心理學(二)
職場生存之道:內向心理學(二)職場生存之道:內向心理學(二)
職場生存之道:內向心理學(二)Wan Jen Huang
 
Questionnaire results
Questionnaire resultsQuestionnaire results
Questionnaire resultsTyrrell
 
Projecte disseny gràfic 2013
Projecte disseny gràfic 2013Projecte disseny gràfic 2013
Projecte disseny gràfic 2013Epv Artistica
 
Task 10 formal proposal#
Task 10   formal proposal#Task 10   formal proposal#
Task 10 formal proposal#Tyrrell
 
Webinar Monitorización Proactiva con HPE AppPulse Active
Webinar Monitorización Proactiva con HPE AppPulse ActiveWebinar Monitorización Proactiva con HPE AppPulse Active
Webinar Monitorización Proactiva con HPE AppPulse ActiveGlobe Testing
 
MACHU PICCHU
MACHU PICCHUMACHU PICCHU
MACHU PICCHUlaucs1975
 
Recommendations for bettermeans.com
Recommendations for bettermeans.comRecommendations for bettermeans.com
Recommendations for bettermeans.comslideme52
 

En vedette (20)

Ebook drupal 7 vn
Ebook drupal 7 vnEbook drupal 7 vn
Ebook drupal 7 vn
 
Human body is a holy temple
Human body is a holy templeHuman body is a holy temple
Human body is a holy temple
 
Dallas partner meeting_8.07.12
Dallas partner meeting_8.07.12Dallas partner meeting_8.07.12
Dallas partner meeting_8.07.12
 
4 teknik dan bentuk instrumen
4 teknik dan bentuk instrumen4 teknik dan bentuk instrumen
4 teknik dan bentuk instrumen
 
Youth Perspectives 1999
Youth Perspectives 1999Youth Perspectives 1999
Youth Perspectives 1999
 
Preliminary Evaluation
Preliminary Evaluation Preliminary Evaluation
Preliminary Evaluation
 
Market snapshot report 19 12-2012
Market snapshot report 19 12-2012Market snapshot report 19 12-2012
Market snapshot report 19 12-2012
 
職場生存之道:內向心理學(二)
職場生存之道:內向心理學(二)職場生存之道:內向心理學(二)
職場生存之道:內向心理學(二)
 
Kontrak transaksi perkuliahan1516
Kontrak transaksi perkuliahan1516Kontrak transaksi perkuliahan1516
Kontrak transaksi perkuliahan1516
 
การสังเกต Sn
การสังเกต Snการสังเกต Sn
การสังเกต Sn
 
Gib
GibGib
Gib
 
Key Performance Indicators for Energy Efficient Asset Management in a Factory...
Key Performance Indicators for Energy Efficient Asset Management in a Factory...Key Performance Indicators for Energy Efficient Asset Management in a Factory...
Key Performance Indicators for Energy Efficient Asset Management in a Factory...
 
Questionnaire results
Questionnaire resultsQuestionnaire results
Questionnaire results
 
Projecte disseny gràfic 2013
Projecte disseny gràfic 2013Projecte disseny gràfic 2013
Projecte disseny gràfic 2013
 
Task 10 formal proposal#
Task 10   formal proposal#Task 10   formal proposal#
Task 10 formal proposal#
 
Cartas Proibidas
Cartas ProibidasCartas Proibidas
Cartas Proibidas
 
Uruguay
UruguayUruguay
Uruguay
 
Webinar Monitorización Proactiva con HPE AppPulse Active
Webinar Monitorización Proactiva con HPE AppPulse ActiveWebinar Monitorización Proactiva con HPE AppPulse Active
Webinar Monitorización Proactiva con HPE AppPulse Active
 
MACHU PICCHU
MACHU PICCHUMACHU PICCHU
MACHU PICCHU
 
Recommendations for bettermeans.com
Recommendations for bettermeans.comRecommendations for bettermeans.com
Recommendations for bettermeans.com
 

Similaire à Structured Exception Handler Exploitation

Anatomy of a Buffer Overflow Attack
Anatomy of a Buffer Overflow AttackAnatomy of a Buffer Overflow Attack
Anatomy of a Buffer Overflow AttackRob Gillen
 
Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1Cysinfo Cyber Security Community
 
Practical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbgPractical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbgSam Bowne
 
CNIT 127: Ch 8: Windows overflows (Part 2)
CNIT 127: Ch 8: Windows overflows (Part 2)CNIT 127: Ch 8: Windows overflows (Part 2)
CNIT 127: Ch 8: Windows overflows (Part 2)Sam Bowne
 
Steelcon 2014 - Process Injection with Python
Steelcon 2014 - Process Injection with PythonSteelcon 2014 - Process Injection with Python
Steelcon 2014 - Process Injection with Pythoninfodox
 
Elixir Programming Language 101
Elixir Programming Language 101Elixir Programming Language 101
Elixir Programming Language 101Around25
 
Pipiot - the double-architecture shellcode constructor
Pipiot - the double-architecture shellcode constructorPipiot - the double-architecture shellcode constructor
Pipiot - the double-architecture shellcode constructorMoshe Zioni
 
Developing Blockchain Applications
Developing Blockchain Applications Developing Blockchain Applications
Developing Blockchain Applications malikmayank
 
Advanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONAdvanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONLyon Yang
 
Ceh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflowCeh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflowVi Tính Hoàng Nam
 
Post-mortem Debugging of Windows Applications
Post-mortem Debugging of  Windows ApplicationsPost-mortem Debugging of  Windows Applications
Post-mortem Debugging of Windows ApplicationsGlobalLogic Ukraine
 
CNIT 127: Ch 8: Windows overflows (Part 1)
CNIT 127: Ch 8: Windows overflows (Part 1)CNIT 127: Ch 8: Windows overflows (Part 1)
CNIT 127: Ch 8: Windows overflows (Part 1)Sam Bowne
 
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
 
CNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginCNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginSam Bowne
 

Similaire à Structured Exception Handler Exploitation (20)

Tranning-2
Tranning-2Tranning-2
Tranning-2
 
Anatomy of a Buffer Overflow Attack
Anatomy of a Buffer Overflow AttackAnatomy of a Buffer Overflow Attack
Anatomy of a Buffer Overflow Attack
 
php.pptx
php.pptxphp.pptx
php.pptx
 
Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1
 
Practical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbgPractical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbg
 
CNIT 127: Ch 8: Windows overflows (Part 2)
CNIT 127: Ch 8: Windows overflows (Part 2)CNIT 127: Ch 8: Windows overflows (Part 2)
CNIT 127: Ch 8: Windows overflows (Part 2)
 
Abusing SEH For Fun
Abusing SEH For FunAbusing SEH For Fun
Abusing SEH For Fun
 
Eusecwest
EusecwestEusecwest
Eusecwest
 
Steelcon 2014 - Process Injection with Python
Steelcon 2014 - Process Injection with PythonSteelcon 2014 - Process Injection with Python
Steelcon 2014 - Process Injection with Python
 
Elixir Programming Language 101
Elixir Programming Language 101Elixir Programming Language 101
Elixir Programming Language 101
 
EhTrace -- RoP Hooks
EhTrace -- RoP HooksEhTrace -- RoP Hooks
EhTrace -- RoP Hooks
 
Pipiot - the double-architecture shellcode constructor
Pipiot - the double-architecture shellcode constructorPipiot - the double-architecture shellcode constructor
Pipiot - the double-architecture shellcode constructor
 
Developing Blockchain Applications
Developing Blockchain Applications Developing Blockchain Applications
Developing Blockchain Applications
 
Advanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONAdvanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCON
 
Ceh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflowCeh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflow
 
Post-mortem Debugging of Windows Applications
Post-mortem Debugging of  Windows ApplicationsPost-mortem Debugging of  Windows Applications
Post-mortem Debugging of Windows Applications
 
CNIT 127: Ch 8: Windows overflows (Part 1)
CNIT 127: Ch 8: Windows overflows (Part 1)CNIT 127: Ch 8: Windows overflows (Part 1)
CNIT 127: Ch 8: Windows overflows (Part 1)
 
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
 
9: OllyDbg
9: OllyDbg9: OllyDbg
9: OllyDbg
 
CNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginCNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you Begin
 

Plus de High-Tech Bridge SA (HTBridge)

Novell GroupWise Multiple Untrusted Pointer Dereferences Exploitation
Novell GroupWise Multiple Untrusted Pointer Dereferences ExploitationNovell GroupWise Multiple Untrusted Pointer Dereferences Exploitation
Novell GroupWise Multiple Untrusted Pointer Dereferences ExploitationHigh-Tech Bridge SA (HTBridge)
 
In-Memory Fuzzing with Java (Publication from High-Tech Bridge)
In-Memory Fuzzing with Java (Publication from High-Tech Bridge)In-Memory Fuzzing with Java (Publication from High-Tech Bridge)
In-Memory Fuzzing with Java (Publication from High-Tech Bridge)High-Tech Bridge SA (HTBridge)
 
CVE 2012-1889 Microsoft XML core services uninitialized memory vulnerability
CVE 2012-1889 Microsoft XML core services uninitialized memory vulnerabilityCVE 2012-1889 Microsoft XML core services uninitialized memory vulnerability
CVE 2012-1889 Microsoft XML core services uninitialized memory vulnerabilityHigh-Tech Bridge SA (HTBridge)
 
Cybercrime in nowadays businesses - A real case study of targeted attack
Cybercrime in nowadays businesses - A real case study of targeted attackCybercrime in nowadays businesses - A real case study of targeted attack
Cybercrime in nowadays businesses - A real case study of targeted attackHigh-Tech Bridge SA (HTBridge)
 
Frontal Attacks - From basic compromise to Advanced Persistent Threat
Frontal Attacks - From basic compromise to Advanced Persistent ThreatFrontal Attacks - From basic compromise to Advanced Persistent Threat
Frontal Attacks - From basic compromise to Advanced Persistent ThreatHigh-Tech Bridge SA (HTBridge)
 
Defeating Data Execution Prevention and ASLR in Windows
Defeating Data Execution Prevention and ASLR in WindowsDefeating Data Execution Prevention and ASLR in Windows
Defeating Data Execution Prevention and ASLR in WindowsHigh-Tech Bridge SA (HTBridge)
 
Become fully aware of the potential dangers of ActiveX attacks
Become fully aware of the potential dangers of ActiveX attacksBecome fully aware of the potential dangers of ActiveX attacks
Become fully aware of the potential dangers of ActiveX attacksHigh-Tech Bridge SA (HTBridge)
 
Client-side threats - Anatomy of Reverse Trojan attacks
Client-side threats - Anatomy of Reverse Trojan attacksClient-side threats - Anatomy of Reverse Trojan attacks
Client-side threats - Anatomy of Reverse Trojan attacksHigh-Tech Bridge SA (HTBridge)
 

Plus de High-Tech Bridge SA (HTBridge) (15)

Welcome in the World Wild Web
Welcome in the World Wild WebWelcome in the World Wild Web
Welcome in the World Wild Web
 
Fuzzing: An introduction to Sulley Framework
Fuzzing: An introduction to Sulley FrameworkFuzzing: An introduction to Sulley Framework
Fuzzing: An introduction to Sulley Framework
 
Novell GroupWise Multiple Untrusted Pointer Dereferences Exploitation
Novell GroupWise Multiple Untrusted Pointer Dereferences ExploitationNovell GroupWise Multiple Untrusted Pointer Dereferences Exploitation
Novell GroupWise Multiple Untrusted Pointer Dereferences Exploitation
 
Manipulating Memory for Fun & Profit
Manipulating Memory for Fun & ProfitManipulating Memory for Fun & Profit
Manipulating Memory for Fun & Profit
 
In-Memory Fuzzing with Java (Publication from High-Tech Bridge)
In-Memory Fuzzing with Java (Publication from High-Tech Bridge)In-Memory Fuzzing with Java (Publication from High-Tech Bridge)
In-Memory Fuzzing with Java (Publication from High-Tech Bridge)
 
CVE 2012-1889 Microsoft XML core services uninitialized memory vulnerability
CVE 2012-1889 Microsoft XML core services uninitialized memory vulnerabilityCVE 2012-1889 Microsoft XML core services uninitialized memory vulnerability
CVE 2012-1889 Microsoft XML core services uninitialized memory vulnerability
 
Cybercrime in nowadays businesses - A real case study of targeted attack
Cybercrime in nowadays businesses - A real case study of targeted attackCybercrime in nowadays businesses - A real case study of targeted attack
Cybercrime in nowadays businesses - A real case study of targeted attack
 
Spying Internet Explorer 8.0
Spying Internet Explorer 8.0Spying Internet Explorer 8.0
Spying Internet Explorer 8.0
 
Frontal Attacks - From basic compromise to Advanced Persistent Threat
Frontal Attacks - From basic compromise to Advanced Persistent ThreatFrontal Attacks - From basic compromise to Advanced Persistent Threat
Frontal Attacks - From basic compromise to Advanced Persistent Threat
 
Inline Hooking in Windows
Inline Hooking in WindowsInline Hooking in Windows
Inline Hooking in Windows
 
Userland Hooking in Windows
Userland Hooking in WindowsUserland Hooking in Windows
Userland Hooking in Windows
 
Defeating Data Execution Prevention and ASLR in Windows
Defeating Data Execution Prevention and ASLR in WindowsDefeating Data Execution Prevention and ASLR in Windows
Defeating Data Execution Prevention and ASLR in Windows
 
Fake malware and virus scanners
Fake malware and virus scannersFake malware and virus scanners
Fake malware and virus scanners
 
Become fully aware of the potential dangers of ActiveX attacks
Become fully aware of the potential dangers of ActiveX attacksBecome fully aware of the potential dangers of ActiveX attacks
Become fully aware of the potential dangers of ActiveX attacks
 
Client-side threats - Anatomy of Reverse Trojan attacks
Client-side threats - Anatomy of Reverse Trojan attacksClient-side threats - Anatomy of Reverse Trojan attacks
Client-side threats - Anatomy of Reverse Trojan attacks
 

Dernier

The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 

Dernier (20)

The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 

Structured Exception Handler Exploitation

  • 1. Structured Exception Handler EXPLOITATION http://www.htbridge.ch/ Brian Mariani
  • 2. What is an exception • An exception is an event that occurs during the execution of a program • Requires the execution of code outside the normal flow of control
  • 3. Structured Exception Handling • Blocks of code are encapsulated, with each block having one or more associated handlers. • Each handler specifies some form of filter condition on the type of exception it handles • When an exception is raised by code in a protected block, the set of corresponding handlers is searched in order, and the first one with a matchingfilter condition is executed • A single method can have multiple structured exception handling blocks, and the blocks can also be nested within each other
  • 4. Exception pointers structure (1) • Contains an exception record with a machine-independent description of an exception • A context record with a machine-dependent description of the processor context at the time of the exception
  • 5. Exception pointers structure (2) • A pointer to the next exception registration structure • A pointer to the address of the actual code of the exception handler
  • 6. Thread information block • The Thread Information Block (TIB) is a data structure in Win32 that stores information about the currently running thread • At the position FS:[0x00] we found the current exception handler
  • 7. Dumping SEH chain in Inmunity debugger
  • 8. How SEH works? • The exception handlers are linked to each other • They form a linked list chain on the stack, and sit relatively close to the bottom of the stack • When an exception occurs, Windows retrieves the head of the SEH chain walks through the list and tries to find the suitable handler to close the application properly
  • 9. Abusing the SEH • When exploiting an SEH overwrite and attacker clobbers the handler attribute of the EXCEPTION_REGISTRATION_RECORD with the address of an instruction sequence similar to POP POP RET • When the exception occurs, this causes Windows to pass execution to this address, which subsequently returns to the location on the stack of the Next attribute of the EXCEPTION_REGISTRATION_RECORD • The Next attribute is also controlled by the attacker, but if we recall the stack layout from earlier, the Next attribute is below the Handler attribute • This limits the attacker to 4 bytes before running into the Handler address he previously supplied to originally obtain code execution • However, by overwriting the Next attribute with the instructions that jump the Handler attribute, the attacker typically has enough room for arbitrary shellcode, and this is exactly what happens
  • 10. Overwriting the Next SEH record and SE handler • To check a chain of exception handlers before and after an overflow we can use WinDbg !exchain command • At the left we can see the SEH chain and the stack before the overflow occurs • At the right we can see the pointers were successfully overwritten
  • 11. What are we overwriting? • When we performs a regular stack based buffer overflow, we overwrite the return address of the Extended Instruction Pointer (EIP) • When doing a SEH overflow, we will continue overwriting the stack after overwriting overflow EIP, so we can overwrite the default exception handler as well EIP
  • 12. Viewing the SEH before the overflow • Before the overflow occurs we can see the stack and the SEH chain. • The SEH chain starts from 0x015fd044 down to 0x015fffdc which indicates the end of the SEH chain • Directly below 0x015fffe0, we see 0x7c839ad8, which is the address of the default SE 0x015fffe0 0x7c839ad8 handler for this application. This address sits in the address space of kernel32.dll
  • 13. Viewing the SEH after the overflow • Dumping the TIB confirms that the SEH was overwritten • Code execution is successfully passed to the injected address 0x61616161 • Addresses 0x015fd044 and 0x015fd048 which were the Next SEH record and SE handler are now controlled. EIP point to 0x61616161, so we can control the flow of the program Pointer to the Next record and SEH handler was overwritten TIB dumping let us know the SEH chain was sucessfully overwritten
  • 14. See an exception analysis • The command !analyze –v in Windbg give us more details about the triggering of the exception
  • 15. How SEH base exploit works • When the exception is triggered the program flow go to the SE Handler • All we need is just put some code to jump to our payload • Faking a second exception makes the application goes to the next SEH pointer • As the Next SEH pointer is before the SE handler we can overwrite the Next SEH • Since the shellcode sits after the Handler, we can trick the SE Handler to execute POP POP RET instructions so the address to the Next SEH will be placed in EIP, therefore executing the code in Next SEH • The code will basically jump over some bytes and execute the shellcode
  • 16. Exploiting the application • We will exploit a vulnerability in Gogago Youtube Downloader Video ActiveX www.gogago.net/download/youtube_video_downloader_setup.exe • A buffer overflow is triggered after injecting more that 2230 bytes in the Download() function • This vulnerability could be exploited using a basic RET CALL technique • We will use SEH based exploitation which is also functioning in this particular case
  • 17. Creating the POC • We craft an html page calling the method Download using the CLASSID • When we overflow the method with 2250 bytes with junk data we trigger an exception
  • 18. Overwriting Next pointer and SE handler • To successfully overwrite the Next Pointer and SE Handler we must calculate the exact number of bytes to inject • You can use tools as pattern_create and pattern_search from Metasploit, or you can do it manually injecting buffers with different patterns
  • 19. Finding POP POP RET instructions • Finding opcodes it’s not a difficult task you can use findjump or IDA • In this tutorial we will use WinDBG • We launch our prove of concept and we attach to Internet Explorer. After the overflow Explorer occurs we search the base memory address of the Gogago module MDIEex.dll • Finally we can search for the opcodes using the s command
  • 20. Building the exploit • After calculating the number of bytes to overwrite the Next pointer and SE handler we inject 4 bytes of code to jump to our shellcode this will replace the old SE handler • Following the SE handler we inject the POP POP RET opcodes from the same module of the exploited application • Finally we inject our payload
  • 21. Executing the exploit (1) • We place a breakpoint before entering in the vulnerable method. The SE handler that will be overwritten sits at 0x15fa79c, and corresponds to the jscript.dll module 0x15fa79c
  • 22. Executing the exploit (2) • After the overflow occurs we successfully overwrites the old jscript SE handler later code execution will be redirected to our POP POP RET instructions
  • 23. Redirect code execution • The code is redirected to our fake SE Handler address
  • 24. Jumping to our payload • Jumping over 6 bytes to reach ou shellcode starting at address 0x015fa7a4
  • 25. Shellcode execution • Time to dance 
  • 27. References • http://msdn.microsoft.com/en-us/library/ms680663%28v=VS.85%29.aspx • http://msdn.microsoft.com/en-us/library/c68xfk56%28v=vs.71%29.aspx • http://en.wikipedia.org/wiki/Win32_Thread_Information_Block • http://corelan.be