SlideShare una empresa de Scribd logo
1 de 51
Descargar para leer sin conexión
CNIT 127: Exploit Development

Ch 8: Windows Overflows

Part 2
Updated
10-27-18
Topics
• Stack Protection
• Heap-Based Buffer Overflows
• Other Overflows
Stack Protector in gcc
An Early Linux Project
Compile in Two Ways
• Compile without and with a stack
protector
• Two slightly different executable sizes
Disassemble test_pw
• Added code in prologue
• Copies a value from %gs:0x14 to the
bottom of the stack frame
Disassemble test_pw
• Added code in epilogue
• Won't ret if cookie check fails
Stack Protector in Windows
Use Visual Studio and C++
Compile in Two Ways
• Compile
without
and with a
stack
protector
• Two slightly
different
executable
sizes
Disassemble with IDA Free
• See security_cookie code
Stack Protection
Windows Stack Protections
• Microsoft Visual C++ .NET provides
– /GS compiler flag is on by default
– Tells compiler to place security cookies on
the stack to guard the saved return address
– Equivalent of a canary
– 4-byte value (dword) placed on the stack after
a procedure call
– Checked before procedure return
– Protects saved return address and EBP
How is the Cookie Generated?
• When a process starts, Windows combines
these values with XOR
– DateTime (a 64-bit integer counting time
intervals of 100 nanoseconds)
– Process ID
– Thread ID
– TickCount (number of milliseconds since the
system started up)
– Performance Counter (number of CPU cycles)
Predicting the Cookie
• If an attacker can run a process on the
target to get system time values
• Some bits of the cookie can be predicted
Effectively 17 bits of Randomness
How Good is 17 Bits?
• 2^17 = 131,072
• So an attacker would have to run an
attack 100,000 times or so to win by
guessing the cookie
Prologue Modification
• __security_cookie value placed in the
stack at a carefully calculated position
• To protect the EBP and Return value
– From link Ch 8m
Epilogue Modification
• Epilogue to a function now includes these
instructions
– From link Ch 8m
__security_check_cookie
• Current cookie value is in ecx
• Compared to authoritative value stored in
the .data section of the image file of the
procedure
• If the check fails, it calls a security handler,
using a pointer stored in the .data section
Parameter Order
• Before the /GS flag (added in Windows
Server 2003), local variables were placed
on the stack in the order of their
declaration in the C++ source code
• Now all arrays are moved to the bottom of
the list, closest to the saved return address
• This prevents buffer overflows in the
arrays from changing the non-array
variables
Overwriting Parameters
Overwriting Parameters
• We've changed the cookie, but if the
parameters are used in a write operation
before the function returns, we could
– Overwrite the authoritative cookie value in
the .data section, so the cookie check passes
– Overwrite the handler pointer to the security
handler, and let the cookie check fail
• Handler could point to injected code
• Or set handler to zero and overwrite the default
exception handler value
Heap-Based Buffer Overflows
Purpose of the Heap
• Consider a Web server
• HTTP requests vary in length
• May vary from 20 to 20,000 bytes or
longer (in principle)
• Once processed, the request can be
discarded, freeing memory for re-use
• For efficiency, such data is best stored on
the heap
The Process Heap
• Every process running on Win32 has a
process heap
• The C function GetProcessHeap() returns a
handle to the process heap
• A pointer to the process heap is also
stored in the Process Environment Block
The Process Heap
• This code returns that pointer in eax
• Many of the underlying functions of the
Windows API use this default process heap
Dynamic Heaps
• A process can create as many dynamic
heaps as required
• All inside the default process heap
• Created with the HeapCreate() function
• From link Ch 8o
Working with the Heap
• Application uses HeapAllocate() to borrow
a chunk of memory on the heap
– Legacy functions left from Win16 are
LocalAlloc() & GlobalAlloc(), but they do the
same thing—there's no difference in Win32
• When the application is done with the
memory, if calls HeapFree()
– Or LocalFree() or GlobalFree()
How the Heap Works
• The stack grows downwards, towards
address 0x00000000
• The heap grows upwards
• Heap starts with 128 LIST_ENTRY
structures that keep track of free blocks
Vulnerable Heap Operations
• When a chunk is freed, forward and
backward pointers must be updated
• This enables us to control a write
operation, to write to arbitrary RAM
locations
– Image from mathyvanhoef.com, link Ch 5b
Details
• There is a lot more to it, involving these
structures
– Segment list
– Virtual Allocation list
– Free list
– Lookaside list
• For details, see link Ch8o
Exploiting Heap-Based Overflows:

Three Techniques
• Overwrite the pointer to the exception
handler
• Overwrite the pointer to the Unhandled
Exception Filter
• Overwrite a pointer in the PEB
Overwrite a Pointer in the PEB
• RtlEnterCriticalSection, called by
RtlAcquirePebLock() and RtlReleasePebLock()
• Called whenever a process exits with
ExitProcess()
• PEB location is fixed for all versions of Win
NT
• Your code should restore this pointer, and
you may also need to repair the heap
Win 2003 Server
• Does not use these pointers in the PEB
• But there are Ldr* functions that call
pointers we can control
– Including LdrUnloadDll()
Vectored Exception Handling
• Introduced with Windows XP
• Traditional frame-based exception
handling stores exception registration
records on the stack
• Vectored exception handling stores
information about handlers on the heap
• A heap overflow can change them
Overwrite a Pointer to the Unhandled
Exception Filter
• First proposed by Halvar Flake at Blackhat
Amsterdam (2001)
• An application can set this value using
SetUnhandledExceptionFilter()
– Disassemble that function to find the pointer
Repairing the Heap
• The overflow corrupts the heap
• Shellcode will probably cause an access
violation
• Simplest repair process is to just make the
heap look like a fresh, empty heap
– With the one block we are using on it
Restore the Exception Handler you
Abused
• Otherwise, you could create an endless
loop
• If your shellcode causes an exception
COM Objects and the Heap
• Component Object Model (COM) Objects
– An object that can be created when needed
by another program
– It has methods that can be called to perform
a task
– It also has attributes (stored data)
• COM objects are created on the heap
Vtable in Heap
• All COM classes
have one or more
interfaces, which
are used to connect
them to a program
– Figure from link Ch
8p
COM Objects Contain Data
• If the programmer doesn't check, these
data fields could be overflowed, into the
next object's vtable
– Image from link Ch 8q
• Vunerable COM objects are often not fixed
• Just added to the "killbit" list
• Which can be circumvented
• From link Ch 8qq; Image on next slide from link
Ch 8r
Other Overflows
Overflows in the .data Section
• If a buffer is placed before function pointers in
the .data section
• Overflowing the buffer can change the pointers
TEB/PEB Overflows
• In principle, buffers in the TEB used for
converting ASCII to Unicode could be
overflowed
• Changing pointers
• There are no public examples of this type
of exploit
CNIT 127: 8: Windows overflows (Part 2)

Más contenido relacionado

La actualidad más candente

Ch 5: Introduction to heap overflows
Ch 5: Introduction to heap overflowsCh 5: Introduction to heap overflows
Ch 5: Introduction to heap overflowsSam Bowne
 
CNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgCNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgSam Bowne
 
CNIT 127 Ch 5: Introduction to heap overflows
CNIT 127 Ch 5: Introduction to heap overflowsCNIT 127 Ch 5: Introduction to heap overflows
CNIT 127 Ch 5: Introduction to heap overflowsSam Bowne
 
Ruxcon 2014 - Stefan Esser - iOS8 Containers, Sandboxes and Entitlements
Ruxcon 2014 - Stefan Esser - iOS8 Containers, Sandboxes and EntitlementsRuxcon 2014 - Stefan Esser - iOS8 Containers, Sandboxes and Entitlements
Ruxcon 2014 - Stefan Esser - iOS8 Containers, Sandboxes and EntitlementsStefan Esser
 
Malware Analysis - x86 Disassembly
Malware Analysis - x86 DisassemblyMalware Analysis - x86 Disassembly
Malware Analysis - x86 DisassemblyNatraj G
 
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
 
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...Sam Bowne
 
CNIT 129S Ch 4: Mapping the Application
CNIT 129S Ch 4: Mapping the ApplicationCNIT 129S Ch 4: Mapping the Application
CNIT 129S Ch 4: Mapping the ApplicationSam Bowne
 
CNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic Analysis
CNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic AnalysisCNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic Analysis
CNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic AnalysisSam Bowne
 
Sisteme de Operare: Analiza executabilelor și proceselor
Sisteme de Operare: Analiza executabilelor și proceselorSisteme de Operare: Analiza executabilelor și proceselor
Sisteme de Operare: Analiza executabilelor și proceselorAlexandru Radovici
 
Reliable Windows Heap Exploits
Reliable Windows Heap ExploitsReliable Windows Heap Exploits
Reliable Windows Heap Exploitsamiable_indian
 
CNIT 126 6: Recognizing C Code Constructs in Assembly
CNIT 126 6: Recognizing C Code Constructs in Assembly CNIT 126 6: Recognizing C Code Constructs in Assembly
CNIT 126 6: Recognizing C Code Constructs in Assembly Sam Bowne
 
Play with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit TechniquePlay with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit TechniqueAngel Boy
 
Practical Malware Analysis Ch 14: Malware-Focused Network Signatures
Practical Malware Analysis Ch 14: Malware-Focused Network SignaturesPractical Malware Analysis Ch 14: Malware-Focused Network Signatures
Practical Malware Analysis Ch 14: Malware-Focused Network SignaturesSam Bowne
 
Linux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend ProgramingLinux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend ProgramingAngel Boy
 
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly Sam Bowne
 
Writing Metasploit Plugins
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Pluginsamiable_indian
 

La actualidad más candente (20)

Ch 5: Introduction to heap overflows
Ch 5: Introduction to heap overflowsCh 5: Introduction to heap overflows
Ch 5: Introduction to heap overflows
 
CNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgCNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbg
 
CNIT 127 Ch 5: Introduction to heap overflows
CNIT 127 Ch 5: Introduction to heap overflowsCNIT 127 Ch 5: Introduction to heap overflows
CNIT 127 Ch 5: Introduction to heap overflows
 
Ruxcon 2014 - Stefan Esser - iOS8 Containers, Sandboxes and Entitlements
Ruxcon 2014 - Stefan Esser - iOS8 Containers, Sandboxes and EntitlementsRuxcon 2014 - Stefan Esser - iOS8 Containers, Sandboxes and Entitlements
Ruxcon 2014 - Stefan Esser - iOS8 Containers, Sandboxes and Entitlements
 
Malware Analysis - x86 Disassembly
Malware Analysis - x86 DisassemblyMalware Analysis - x86 Disassembly
Malware Analysis - x86 Disassembly
 
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
 
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
 
CNIT 129S Ch 4: Mapping the Application
CNIT 129S Ch 4: Mapping the ApplicationCNIT 129S Ch 4: Mapping the Application
CNIT 129S Ch 4: Mapping the Application
 
CNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic Analysis
CNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic AnalysisCNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic Analysis
CNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic Analysis
 
Sisteme de Operare: Analiza executabilelor și proceselor
Sisteme de Operare: Analiza executabilelor și proceselorSisteme de Operare: Analiza executabilelor și proceselor
Sisteme de Operare: Analiza executabilelor și proceselor
 
Reliable Windows Heap Exploits
Reliable Windows Heap ExploitsReliable Windows Heap Exploits
Reliable Windows Heap Exploits
 
CNIT 126 6: Recognizing C Code Constructs in Assembly
CNIT 126 6: Recognizing C Code Constructs in Assembly CNIT 126 6: Recognizing C Code Constructs in Assembly
CNIT 126 6: Recognizing C Code Constructs in Assembly
 
Play with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit TechniquePlay with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit Technique
 
Buffer overflow
Buffer overflowBuffer overflow
Buffer overflow
 
9: OllyDbg
9: OllyDbg9: OllyDbg
9: OllyDbg
 
Practical Malware Analysis Ch 14: Malware-Focused Network Signatures
Practical Malware Analysis Ch 14: Malware-Focused Network SignaturesPractical Malware Analysis Ch 14: Malware-Focused Network Signatures
Practical Malware Analysis Ch 14: Malware-Focused Network Signatures
 
Ethical Hacking
Ethical HackingEthical Hacking
Ethical Hacking
 
Linux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend ProgramingLinux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend Programing
 
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
 
Writing Metasploit Plugins
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Plugins
 

Similar a CNIT 127: 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)
CNIT 127: Ch 8: Windows overflows (Part 2)Sam Bowne
 
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...gree_tech
 
CNIT 127 14: Protection Mechanisms
CNIT 127 14: Protection MechanismsCNIT 127 14: Protection Mechanisms
CNIT 127 14: Protection MechanismsSam Bowne
 
Magento performance feat. core Hacks
Magento performance feat. core HacksMagento performance feat. core Hacks
Magento performance feat. core HacksDaniel Niedergesäß
 
python_development.pptx
python_development.pptxpython_development.pptx
python_development.pptxLemonReddy1
 
AOUG_11Nov2016_Challenges_with_EBS12_2
AOUG_11Nov2016_Challenges_with_EBS12_2AOUG_11Nov2016_Challenges_with_EBS12_2
AOUG_11Nov2016_Challenges_with_EBS12_2Sean Braymen
 
Monomi: Practical Analytical Query Processing over Encrypted Data
Monomi: Practical Analytical Query Processing over Encrypted DataMonomi: Practical Analytical Query Processing over Encrypted Data
Monomi: Practical Analytical Query Processing over Encrypted DataMostafa Arjmand
 
A GitOps model for High Availability and Disaster Recovery on EKS
A GitOps model for High Availability and Disaster Recovery on EKSA GitOps model for High Availability and Disaster Recovery on EKS
A GitOps model for High Availability and Disaster Recovery on EKSWeaveworks
 
Adding Support for Networking and Web Technologies to an Embedded System
Adding Support for Networking and Web Technologies to an Embedded SystemAdding Support for Networking and Web Technologies to an Embedded System
Adding Support for Networking and Web Technologies to an Embedded SystemJohn Efstathiades
 
Building Complex Business Processes 3.7
Building Complex Business Processes 3.7Building Complex Business Processes 3.7
Building Complex Business Processes 3.7StephenKardian
 
Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2Iffat Anjum
 
Valgrind tutorial
Valgrind tutorialValgrind tutorial
Valgrind tutorialSatabdi Das
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Openstack meetup lyon_2017-09-28
Openstack meetup lyon_2017-09-28Openstack meetup lyon_2017-09-28
Openstack meetup lyon_2017-09-28Xavier Lucas
 
Apache Airflow (incubating) NL HUG Meetup 2016-07-19
Apache Airflow (incubating) NL HUG Meetup 2016-07-19Apache Airflow (incubating) NL HUG Meetup 2016-07-19
Apache Airflow (incubating) NL HUG Meetup 2016-07-19Bolke de Bruin
 
Vulnerabilities on Various Data Processing Levels
Vulnerabilities on Various Data Processing LevelsVulnerabilities on Various Data Processing Levels
Vulnerabilities on Various Data Processing LevelsPositive Hack Days
 
KACE Agent Architecture and Troubleshooting Overview
KACE Agent Architecture and Troubleshooting OverviewKACE Agent Architecture and Troubleshooting Overview
KACE Agent Architecture and Troubleshooting OverviewDell World
 
Practical Experience with Automation Tools by Tim Walsh (Archivematica Camp B...
Practical Experience with Automation Tools by Tim Walsh (Archivematica Camp B...Practical Experience with Automation Tools by Tim Walsh (Archivematica Camp B...
Practical Experience with Automation Tools by Tim Walsh (Archivematica Camp B...Artefactual Systems - Archivematica
 
Chapter Seven(2)
Chapter Seven(2)Chapter Seven(2)
Chapter Seven(2)bolovv
 

Similar a CNIT 127: 8: Windows overflows (Part 2) (20)

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)
 
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
 
CNIT 127 14: Protection Mechanisms
CNIT 127 14: Protection MechanismsCNIT 127 14: Protection Mechanisms
CNIT 127 14: Protection Mechanisms
 
Magento performance feat. core Hacks
Magento performance feat. core HacksMagento performance feat. core Hacks
Magento performance feat. core Hacks
 
python_development.pptx
python_development.pptxpython_development.pptx
python_development.pptx
 
AOUG_11Nov2016_Challenges_with_EBS12_2
AOUG_11Nov2016_Challenges_with_EBS12_2AOUG_11Nov2016_Challenges_with_EBS12_2
AOUG_11Nov2016_Challenges_with_EBS12_2
 
Monomi: Practical Analytical Query Processing over Encrypted Data
Monomi: Practical Analytical Query Processing over Encrypted DataMonomi: Practical Analytical Query Processing over Encrypted Data
Monomi: Practical Analytical Query Processing over Encrypted Data
 
A GitOps model for High Availability and Disaster Recovery on EKS
A GitOps model for High Availability and Disaster Recovery on EKSA GitOps model for High Availability and Disaster Recovery on EKS
A GitOps model for High Availability and Disaster Recovery on EKS
 
Adding Support for Networking and Web Technologies to an Embedded System
Adding Support for Networking and Web Technologies to an Embedded SystemAdding Support for Networking and Web Technologies to an Embedded System
Adding Support for Networking and Web Technologies to an Embedded System
 
Building Complex Business Processes 3.7
Building Complex Business Processes 3.7Building Complex Business Processes 3.7
Building Complex Business Processes 3.7
 
Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2
 
Valgrind tutorial
Valgrind tutorialValgrind tutorial
Valgrind tutorial
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Openstack meetup lyon_2017-09-28
Openstack meetup lyon_2017-09-28Openstack meetup lyon_2017-09-28
Openstack meetup lyon_2017-09-28
 
Apache Airflow (incubating) NL HUG Meetup 2016-07-19
Apache Airflow (incubating) NL HUG Meetup 2016-07-19Apache Airflow (incubating) NL HUG Meetup 2016-07-19
Apache Airflow (incubating) NL HUG Meetup 2016-07-19
 
Vulnerabilities on Various Data Processing Levels
Vulnerabilities on Various Data Processing LevelsVulnerabilities on Various Data Processing Levels
Vulnerabilities on Various Data Processing Levels
 
KACE Agent Architecture and Troubleshooting Overview
KACE Agent Architecture and Troubleshooting OverviewKACE Agent Architecture and Troubleshooting Overview
KACE Agent Architecture and Troubleshooting Overview
 
Practical Experience with Automation Tools by Tim Walsh (Archivematica Camp B...
Practical Experience with Automation Tools by Tim Walsh (Archivematica Camp B...Practical Experience with Automation Tools by Tim Walsh (Archivematica Camp B...
Practical Experience with Automation Tools by Tim Walsh (Archivematica Camp B...
 
Chapter Seven(2)
Chapter Seven(2)Chapter Seven(2)
Chapter Seven(2)
 

Más de Sam Bowne

3: DNS vulnerabilities
3: DNS vulnerabilities 3: DNS vulnerabilities
3: DNS vulnerabilities Sam Bowne
 
8. Software Development Security
8. Software Development Security8. Software Development Security
8. Software Development SecuritySam Bowne
 
4 Mapping the Application
4 Mapping the Application4 Mapping the Application
4 Mapping the ApplicationSam Bowne
 
3. Attacking iOS Applications (Part 2)
 3. Attacking iOS Applications (Part 2) 3. Attacking iOS Applications (Part 2)
3. Attacking iOS Applications (Part 2)Sam Bowne
 
12 Elliptic Curves
12 Elliptic Curves12 Elliptic Curves
12 Elliptic CurvesSam Bowne
 
11. Diffie-Hellman
11. Diffie-Hellman11. Diffie-Hellman
11. Diffie-HellmanSam Bowne
 
2a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 12a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 1Sam Bowne
 
9 Writing Secure Android Applications
9 Writing Secure Android Applications9 Writing Secure Android Applications
9 Writing Secure Android ApplicationsSam Bowne
 
12 Investigating Windows Systems (Part 2 of 3)
12 Investigating Windows Systems (Part 2 of 3)12 Investigating Windows Systems (Part 2 of 3)
12 Investigating Windows Systems (Part 2 of 3)Sam Bowne
 
12 Investigating Windows Systems (Part 1 of 3
12 Investigating Windows Systems (Part 1 of 312 Investigating Windows Systems (Part 1 of 3
12 Investigating Windows Systems (Part 1 of 3Sam Bowne
 
9. Hard Problems
9. Hard Problems9. Hard Problems
9. Hard ProblemsSam Bowne
 
8 Android Implementation Issues (Part 1)
8 Android Implementation Issues (Part 1)8 Android Implementation Issues (Part 1)
8 Android Implementation Issues (Part 1)Sam Bowne
 
11 Analysis Methodology
11 Analysis Methodology11 Analysis Methodology
11 Analysis MethodologySam Bowne
 
8. Authenticated Encryption
8. Authenticated Encryption8. Authenticated Encryption
8. Authenticated EncryptionSam Bowne
 
7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)Sam Bowne
 
7. Attacking Android Applications (Part 1)
7. Attacking Android Applications (Part 1)7. Attacking Android Applications (Part 1)
7. Attacking Android Applications (Part 1)Sam Bowne
 
5. Stream Ciphers
5. Stream Ciphers5. Stream Ciphers
5. Stream CiphersSam Bowne
 
6 Scope & 7 Live Data Collection
6 Scope & 7 Live Data Collection6 Scope & 7 Live Data Collection
6 Scope & 7 Live Data CollectionSam Bowne
 

Más de Sam Bowne (20)

Cyberwar
CyberwarCyberwar
Cyberwar
 
3: DNS vulnerabilities
3: DNS vulnerabilities 3: DNS vulnerabilities
3: DNS vulnerabilities
 
8. Software Development Security
8. Software Development Security8. Software Development Security
8. Software Development Security
 
4 Mapping the Application
4 Mapping the Application4 Mapping the Application
4 Mapping the Application
 
3. Attacking iOS Applications (Part 2)
 3. Attacking iOS Applications (Part 2) 3. Attacking iOS Applications (Part 2)
3. Attacking iOS Applications (Part 2)
 
12 Elliptic Curves
12 Elliptic Curves12 Elliptic Curves
12 Elliptic Curves
 
11. Diffie-Hellman
11. Diffie-Hellman11. Diffie-Hellman
11. Diffie-Hellman
 
2a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 12a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 1
 
9 Writing Secure Android Applications
9 Writing Secure Android Applications9 Writing Secure Android Applications
9 Writing Secure Android Applications
 
12 Investigating Windows Systems (Part 2 of 3)
12 Investigating Windows Systems (Part 2 of 3)12 Investigating Windows Systems (Part 2 of 3)
12 Investigating Windows Systems (Part 2 of 3)
 
10 RSA
10 RSA10 RSA
10 RSA
 
12 Investigating Windows Systems (Part 1 of 3
12 Investigating Windows Systems (Part 1 of 312 Investigating Windows Systems (Part 1 of 3
12 Investigating Windows Systems (Part 1 of 3
 
9. Hard Problems
9. Hard Problems9. Hard Problems
9. Hard Problems
 
8 Android Implementation Issues (Part 1)
8 Android Implementation Issues (Part 1)8 Android Implementation Issues (Part 1)
8 Android Implementation Issues (Part 1)
 
11 Analysis Methodology
11 Analysis Methodology11 Analysis Methodology
11 Analysis Methodology
 
8. Authenticated Encryption
8. Authenticated Encryption8. Authenticated Encryption
8. Authenticated Encryption
 
7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)
 
7. Attacking Android Applications (Part 1)
7. Attacking Android Applications (Part 1)7. Attacking Android Applications (Part 1)
7. Attacking Android Applications (Part 1)
 
5. Stream Ciphers
5. Stream Ciphers5. Stream Ciphers
5. Stream Ciphers
 
6 Scope & 7 Live Data Collection
6 Scope & 7 Live Data Collection6 Scope & 7 Live Data Collection
6 Scope & 7 Live Data Collection
 

Último

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 

Último (20)

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

CNIT 127: 8: Windows overflows (Part 2)

  • 1. CNIT 127: Exploit Development
 Ch 8: Windows Overflows
 Part 2 Updated 10-27-18
  • 2. Topics • Stack Protection • Heap-Based Buffer Overflows • Other Overflows
  • 4. An Early Linux Project
  • 5. Compile in Two Ways • Compile without and with a stack protector • Two slightly different executable sizes
  • 6. Disassemble test_pw • Added code in prologue • Copies a value from %gs:0x14 to the bottom of the stack frame
  • 7. Disassemble test_pw • Added code in epilogue • Won't ret if cookie check fails
  • 10. Compile in Two Ways • Compile without and with a stack protector • Two slightly different executable sizes
  • 11. Disassemble with IDA Free • See security_cookie code
  • 13. Windows Stack Protections • Microsoft Visual C++ .NET provides – /GS compiler flag is on by default – Tells compiler to place security cookies on the stack to guard the saved return address – Equivalent of a canary – 4-byte value (dword) placed on the stack after a procedure call – Checked before procedure return – Protects saved return address and EBP
  • 14.
  • 15. How is the Cookie Generated? • When a process starts, Windows combines these values with XOR – DateTime (a 64-bit integer counting time intervals of 100 nanoseconds) – Process ID – Thread ID – TickCount (number of milliseconds since the system started up) – Performance Counter (number of CPU cycles)
  • 16. Predicting the Cookie • If an attacker can run a process on the target to get system time values • Some bits of the cookie can be predicted
  • 17. Effectively 17 bits of Randomness
  • 18. How Good is 17 Bits? • 2^17 = 131,072 • So an attacker would have to run an attack 100,000 times or so to win by guessing the cookie
  • 19. Prologue Modification • __security_cookie value placed in the stack at a carefully calculated position • To protect the EBP and Return value – From link Ch 8m
  • 20. Epilogue Modification • Epilogue to a function now includes these instructions – From link Ch 8m
  • 21. __security_check_cookie • Current cookie value is in ecx • Compared to authoritative value stored in the .data section of the image file of the procedure • If the check fails, it calls a security handler, using a pointer stored in the .data section
  • 22. Parameter Order • Before the /GS flag (added in Windows Server 2003), local variables were placed on the stack in the order of their declaration in the C++ source code • Now all arrays are moved to the bottom of the list, closest to the saved return address • This prevents buffer overflows in the arrays from changing the non-array variables
  • 23.
  • 25. Overwriting Parameters • We've changed the cookie, but if the parameters are used in a write operation before the function returns, we could – Overwrite the authoritative cookie value in the .data section, so the cookie check passes – Overwrite the handler pointer to the security handler, and let the cookie check fail • Handler could point to injected code • Or set handler to zero and overwrite the default exception handler value
  • 27. Purpose of the Heap • Consider a Web server • HTTP requests vary in length • May vary from 20 to 20,000 bytes or longer (in principle) • Once processed, the request can be discarded, freeing memory for re-use • For efficiency, such data is best stored on the heap
  • 28. The Process Heap • Every process running on Win32 has a process heap • The C function GetProcessHeap() returns a handle to the process heap • A pointer to the process heap is also stored in the Process Environment Block
  • 29. The Process Heap • This code returns that pointer in eax • Many of the underlying functions of the Windows API use this default process heap
  • 30. Dynamic Heaps • A process can create as many dynamic heaps as required • All inside the default process heap • Created with the HeapCreate() function
  • 31. • From link Ch 8o
  • 32. Working with the Heap • Application uses HeapAllocate() to borrow a chunk of memory on the heap – Legacy functions left from Win16 are LocalAlloc() & GlobalAlloc(), but they do the same thing—there's no difference in Win32 • When the application is done with the memory, if calls HeapFree() – Or LocalFree() or GlobalFree()
  • 33. How the Heap Works • The stack grows downwards, towards address 0x00000000 • The heap grows upwards • Heap starts with 128 LIST_ENTRY structures that keep track of free blocks
  • 34. Vulnerable Heap Operations • When a chunk is freed, forward and backward pointers must be updated • This enables us to control a write operation, to write to arbitrary RAM locations – Image from mathyvanhoef.com, link Ch 5b
  • 35. Details • There is a lot more to it, involving these structures – Segment list – Virtual Allocation list – Free list – Lookaside list • For details, see link Ch8o
  • 36. Exploiting Heap-Based Overflows:
 Three Techniques • Overwrite the pointer to the exception handler • Overwrite the pointer to the Unhandled Exception Filter • Overwrite a pointer in the PEB
  • 37. Overwrite a Pointer in the PEB • RtlEnterCriticalSection, called by RtlAcquirePebLock() and RtlReleasePebLock() • Called whenever a process exits with ExitProcess() • PEB location is fixed for all versions of Win NT • Your code should restore this pointer, and you may also need to repair the heap
  • 38. Win 2003 Server • Does not use these pointers in the PEB • But there are Ldr* functions that call pointers we can control – Including LdrUnloadDll()
  • 39. Vectored Exception Handling • Introduced with Windows XP • Traditional frame-based exception handling stores exception registration records on the stack • Vectored exception handling stores information about handlers on the heap • A heap overflow can change them
  • 40. Overwrite a Pointer to the Unhandled Exception Filter • First proposed by Halvar Flake at Blackhat Amsterdam (2001) • An application can set this value using SetUnhandledExceptionFilter() – Disassemble that function to find the pointer
  • 41. Repairing the Heap • The overflow corrupts the heap • Shellcode will probably cause an access violation • Simplest repair process is to just make the heap look like a fresh, empty heap – With the one block we are using on it
  • 42. Restore the Exception Handler you Abused • Otherwise, you could create an endless loop • If your shellcode causes an exception
  • 43. COM Objects and the Heap • Component Object Model (COM) Objects – An object that can be created when needed by another program – It has methods that can be called to perform a task – It also has attributes (stored data) • COM objects are created on the heap
  • 44. Vtable in Heap • All COM classes have one or more interfaces, which are used to connect them to a program – Figure from link Ch 8p
  • 45. COM Objects Contain Data • If the programmer doesn't check, these data fields could be overflowed, into the next object's vtable – Image from link Ch 8q
  • 46. • Vunerable COM objects are often not fixed • Just added to the "killbit" list • Which can be circumvented • From link Ch 8qq; Image on next slide from link Ch 8r
  • 47.
  • 49. Overflows in the .data Section • If a buffer is placed before function pointers in the .data section • Overflowing the buffer can change the pointers
  • 50. TEB/PEB Overflows • In principle, buffers in the TEB used for converting ASCII to Unicode could be overflowed • Changing pointers • There are no public examples of this type of exploit