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

Ch 8: Windows Overflows

Part 1
Rev. 3-15-17
Topics
• Thread Environment Block and Process
Environment Block
• Stack-Based Buffer Overflows
• Defeating ASLR (Address Space Layout
Randomization)
• Frame-Based Exception Handlers
• SEH Protections
• Defenses in Server 2008 (not in textbook)
Thread Environment Block and
Process Environment Block
Thread Environment Block (TEB)
• Stores information about the currently
executing thread
• Also called the Thread Information Block
• Officially undocumented for Win 9x
• Partially documented for Win NT
• So many Win32 programs use
undocumented TEB fields that they are
effectively part of the API
Thread Environment Block (TEB)
• TEB can be used to get a lot of
information about a process without
calling the Win32 API
• Can get
• Last error
• Import Address Table
• Process startup arguments
• and more
Thread Environment Block (TEB)
• SEH pointer
• Info about the stack
– Much more (Link Ch 8a)
FS: and GS:
• Segment Registers
• Left over from very early operating
systems
• Not used much anymore for their original
purpose
• On Windows 32-bit x86, FS: is used to
point to the TEB
– Links Ch 8e, 8y
Process Environment Block (PEB)
• An opaque data structure
• Details are hidden from its users
• Values are only intended to be
manipulated by calling subroutines that
can access the hidden information
• Used by Win NT internally
• Most fields intended only for internal OS
use
Process Environment Block (PEB)
• Only a few fields are documented by
Microsoft
• Contains data structures that apply across
a whole process
Process Environment Block (PEB)
Stack-Based Buffer Overflows
Classic Technique
• Overwrite the saved return address
– With a value that points back into the stack
• When the function returns, it copies the
return address into EIP
• Return address points to NOP Sled
SEH Technique
• Overwrite the SEH
– With a value that points back into the stack
• Trigger an exception
• Modified exception handler points to NOP
Sled
Defeating ASLR (Address
Space Layout Randomization)
Using Return Value
• We're inside the
function
• ESP points to the
stack
• Find a JMP ESP and
insert its address
into the return
value
Using SEH
• Old Windows versions
left the address of
the SEH in EBX
• Newer versions clear
all registers
• But SEH address is at
ESP+8
• Find POP, POP, RET
and put its address in
SEH
Frame-Based Exception
Handlers
Exception Handler
• Code that deals with problems from
within a running process
– Such as access violation or divide by zero
• Frame-Based Exception Handler
– Associated with a particular procedure
– Each procedure sets up a new stack frame
• Every thread in a Win32 process has at
least one frame-based exception handler
EXCEPTION_REGISTRATION
• Each thread's TEB has the
address of the first
EXCEPTION_REGISTRATION
structure at fs:[0]
• When an exception occurs,
the OS walks through the
list until a suitable handler
is found
SEH

Example

Code
SEH Chain in Immunity
• View, SEH Chain
• This is Notepad's SEH Chain
Follow Address in Stack
Exceptions in Stack Overflows
• Suppose we overflow the stack to
overwrite the stored return address
• Unfortunately, we also overwrite other
variables by accident (collateral damage)
• Those may lead to exceptions, as other
instructions become invalid, before the
function returns
Overwriting EXCEPTION_REGISTRATION
• To gain control of exception handling
• On Windows 2000 and Win XP (before SP1)
– EBX points to the current
EXCEPTION_REGISTRATION structure
• On later Windows versions, all the
registers are zeroed when the SEH is
called
– In order to make exploitation more difficult
Old Windows Process
• At crash, EBX points to
EXCEPTION_REGISTRATION structure
• Overwrite 

With "JMP EBX"
Modern Windows Process
• Stack at crash
• 3rd value points

to EXCEPTION

_REGISTRATION 

structure
• Use POP, POP, RET
SEH Protections
Win 2003 Server
• Attempts to ensure that handler is valid
before using it, with these steps
1.If handler is on the stack -- INVALID
– According to the TEB's entries FS:[4] and FS:{8]
2.If handler is in any loaded EXE or DLL –
MAYBE
– Otherwise VALID
Win 2003 Server
3. If the module is marked as "not allowed –
INVALID
4. If a module has no "Load Configuration
Directory", or one with a small size: VALID
Three Ways to Exploit SEH on Windows
Server 2003
1. Abuse an existing handler
2. Use code in an address outside all
modules
3. Use code in a module without a "Load
Configuration Directory"
Defenses in Win Server 2008
Not in Book
Microsoft's Defenses
• Normal SEH attack (link Ch 8f)
SAFESEH
• Microsoft added this compiler switch to
Visual Studio 2003
• It creates a whitelist of exception handler
addresses
• BUT this depends on the developer using
the switch
– All legacy code must be recompiled
SEHOP
• Verifies that the exception handler is
intact before using it
• The pointer to the next handler comes
before the pointer to the registration
record
• So an exploit will usually damage the
*Next pointer
EXCEPTION_REGISTRATION_RECORD
How SEHOP Works
• Adds an extra registration record at the
end of the list
• Walks the exception handler list to ensure
that the added record can be reached
• Will detect corruption of *Next pointers
SEHOP

Windows Versions
• SEHOP is enabled by default in Windows
Server 2008
• Disabled by default in Windows Vista
– Because it breaks some legacy code
• Also disabled by default on Windows 7
– But it can be enabled in the Registry
– Link Ch 8k
CNIT 127: Ch 8: Windows overflows (Part 1)
CNIT 127: Ch 8: Windows overflows (Part 1)

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)
CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)
CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)
 
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 127 Ch Ch 1: Before you Begin
CNIT 127 Ch Ch 1: Before you BeginCNIT 127 Ch Ch 1: Before you Begin
CNIT 127 Ch Ch 1: Before you Begin
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeCNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: Shellcode
 
127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux
 
CNIT 127 Lecture 7: Intro to 64-Bit Assembler
CNIT 127 Lecture 7: Intro to 64-Bit AssemblerCNIT 127 Lecture 7: Intro to 64-Bit Assembler
CNIT 127 Lecture 7: Intro to 64-Bit Assembler
 
CNIT 127: Ch 2: Stack Overflows in Linux
CNIT 127: Ch 2: Stack Overflows in LinuxCNIT 127: Ch 2: Stack Overflows in Linux
CNIT 127: Ch 2: Stack Overflows in Linux
 
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
 
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 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxCNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on Linux
 
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
 
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 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeCNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: Shellcode
 
CNIT 126 Ch 7: Analyzing Malicious Windows Programs
CNIT 126 Ch 7: Analyzing Malicious Windows ProgramsCNIT 126 Ch 7: Analyzing Malicious Windows Programs
CNIT 126 Ch 7: Analyzing Malicious Windows Programs
 
CNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: ShellcodeCNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: Shellcode
 
CNIT 127 Ch 6: The Wild World of Windows
CNIT 127 Ch 6: The Wild World of WindowsCNIT 127 Ch 6: The Wild World of Windows
CNIT 127 Ch 6: The Wild World of Windows
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxCNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on Linux
 
CNIT 126 5: IDA Pro
CNIT 126 5: IDA ProCNIT 126 5: IDA Pro
CNIT 126 5: IDA Pro
 
CNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on LinuxCNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on Linux
 
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
 

Destacado

Destacado (20)

CNIT 128 Ch 6: Mobile services and mobile Web (part 2: SAML to end)
CNIT 128 Ch 6: Mobile services and mobile Web (part 2: SAML to end)CNIT 128 Ch 6: Mobile services and mobile Web (part 2: SAML to end)
CNIT 128 Ch 6: Mobile services and mobile Web (part 2: SAML to end)
 
CNIT 128: 6: Mobile services and mobile Web (part 1: Beginning Through OAuth)
CNIT 128: 6: Mobile services and mobile Web (part 1: Beginning Through OAuth)CNIT 128: 6: Mobile services and mobile Web (part 1: Beginning Through OAuth)
CNIT 128: 6: Mobile services and mobile Web (part 1: Beginning Through OAuth)
 
CNIT 128 5: Mobile malware
CNIT 128 5: Mobile malwareCNIT 128 5: Mobile malware
CNIT 128 5: Mobile malware
 
Ch 4: Footprinting and Social Engineering
Ch 4: Footprinting and Social EngineeringCh 4: Footprinting and Social Engineering
Ch 4: Footprinting and Social Engineering
 
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
 
CNIT 123 Ch 1: Ethical Hacking Overview
CNIT 123 Ch 1: Ethical Hacking OverviewCNIT 123 Ch 1: Ethical Hacking Overview
CNIT 123 Ch 1: Ethical Hacking Overview
 
Ch 8: Desktop and Server OS Vulnerabilites
Ch 8: Desktop and Server OS VulnerabilitesCh 8: Desktop and Server OS Vulnerabilites
Ch 8: Desktop and Server OS Vulnerabilites
 
Ch 9: Embedded Operating Systems: The Hidden Threat
Ch 9: Embedded Operating Systems: The Hidden ThreatCh 9: Embedded Operating Systems: The Hidden Threat
Ch 9: Embedded Operating Systems: The Hidden Threat
 
Ch 3: Network and Computer Attacks
Ch 3: Network and Computer AttacksCh 3: Network and Computer Attacks
Ch 3: Network and Computer Attacks
 
Ch 2: TCP/IP Concepts Review
Ch 2: TCP/IP Concepts ReviewCh 2: TCP/IP Concepts Review
Ch 2: TCP/IP Concepts Review
 
Ch 7: Programming for Security Professionals
Ch 7: Programming for Security ProfessionalsCh 7: Programming for Security Professionals
Ch 7: Programming for Security Professionals
 
Ch 6: Enumeration
Ch 6: EnumerationCh 6: Enumeration
Ch 6: Enumeration
 
CNIT 126 5: IDA Pro
CNIT 126 5: IDA Pro CNIT 126 5: IDA Pro
CNIT 126 5: IDA Pro
 
CISSP Prep: Ch 3. Asset Security
CISSP Prep: Ch 3. Asset SecurityCISSP Prep: Ch 3. Asset Security
CISSP Prep: Ch 3. Asset Security
 
Ch 12: Cryptography
Ch 12: CryptographyCh 12: Cryptography
Ch 12: Cryptography
 
CNIT 126 8: Debugging
CNIT 126 8: DebuggingCNIT 126 8: Debugging
CNIT 126 8: Debugging
 
Ch 13: Network Protection Systems
Ch 13: Network Protection SystemsCh 13: Network Protection Systems
Ch 13: Network Protection Systems
 
Ch 10: Hacking Web Servers
Ch 10: Hacking Web ServersCh 10: Hacking Web Servers
Ch 10: Hacking Web Servers
 
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
 
How to Prepare for the CISSP Exam
How to Prepare for the CISSP ExamHow to Prepare for the CISSP Exam
How to Prepare for the CISSP Exam
 

Similar a CNIT 127: Ch 8: Windows overflows (Part 1)

exploiting heap overflows
exploiting heap overflowsexploiting heap overflows
exploiting heap overflows
primelude
 
Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.
Positive Hack Days
 
SEH overwrite and its exploitability
SEH overwrite and its exploitabilitySEH overwrite and its exploitability
SEH overwrite and its exploitability
FFRI, Inc.
 

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

CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeCNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: Shellcode
 
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)
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeCNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: Shellcode
 
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
 
CNIT 126 4: A Crash Course in x86 Disassembly
CNIT 126 4: A Crash Course in x86 DisassemblyCNIT 126 4: A Crash Course in x86 Disassembly
CNIT 126 4: A Crash Course in x86 Disassembly
 
exploiting heap overflows
exploiting heap overflowsexploiting heap overflows
exploiting heap overflows
 
Basic buffer overflow part1
Basic buffer overflow part1Basic buffer overflow part1
Basic buffer overflow part1
 
Information and network security 26 aes decryption and implementational issues
Information and network security 26 aes decryption and implementational issuesInformation and network security 26 aes decryption and implementational issues
Information and network security 26 aes decryption and implementational issues
 
Introduction to ewasm
Introduction to ewasmIntroduction to ewasm
Introduction to ewasm
 
Shellcode mastering
Shellcode masteringShellcode mastering
Shellcode mastering
 
Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.
 
Ch 18: Source Code Auditing
Ch 18: Source Code AuditingCh 18: Source Code Auditing
Ch 18: Source Code Auditing
 
Elixir
ElixirElixir
Elixir
 
Reduced instruction set computers
Reduced instruction set computersReduced instruction set computers
Reduced instruction set computers
 
11_ InstructionSetsAddressingModes .pdf
11_ InstructionSetsAddressingModes .pdf11_ InstructionSetsAddressingModes .pdf
11_ InstructionSetsAddressingModes .pdf
 
SEH overwrite and its exploitability
SEH overwrite and its exploitabilitySEH overwrite and its exploitability
SEH overwrite and its exploitability
 
Taking Full Advantage of Galera Multi Master Cluster
Taking Full Advantage of Galera Multi Master ClusterTaking Full Advantage of Galera Multi Master Cluster
Taking Full Advantage of Galera Multi Master Cluster
 
Is That A Penguin In My Windows?
Is That A Penguin In My Windows?Is That A Penguin In My Windows?
Is That A Penguin In My Windows?
 
Structured Exception Handler Exploitation
Structured Exception Handler ExploitationStructured Exception Handler Exploitation
Structured Exception Handler Exploitation
 
Ch04 threads
Ch04 threadsCh04 threads
Ch04 threads
 

Más de Sam 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

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Último (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
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
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 

CNIT 127: Ch 8: Windows overflows (Part 1)

  • 1. CNIT 127: Exploit Development
 Ch 8: Windows Overflows
 Part 1 Rev. 3-15-17
  • 2. Topics • Thread Environment Block and Process Environment Block • Stack-Based Buffer Overflows • Defeating ASLR (Address Space Layout Randomization) • Frame-Based Exception Handlers • SEH Protections • Defenses in Server 2008 (not in textbook)
  • 3. Thread Environment Block and Process Environment Block
  • 4. Thread Environment Block (TEB) • Stores information about the currently executing thread • Also called the Thread Information Block • Officially undocumented for Win 9x • Partially documented for Win NT • So many Win32 programs use undocumented TEB fields that they are effectively part of the API
  • 5. Thread Environment Block (TEB) • TEB can be used to get a lot of information about a process without calling the Win32 API • Can get • Last error • Import Address Table • Process startup arguments • and more
  • 6. Thread Environment Block (TEB) • SEH pointer • Info about the stack – Much more (Link Ch 8a)
  • 7. FS: and GS: • Segment Registers • Left over from very early operating systems • Not used much anymore for their original purpose • On Windows 32-bit x86, FS: is used to point to the TEB – Links Ch 8e, 8y
  • 8. Process Environment Block (PEB) • An opaque data structure • Details are hidden from its users • Values are only intended to be manipulated by calling subroutines that can access the hidden information • Used by Win NT internally • Most fields intended only for internal OS use
  • 9. Process Environment Block (PEB) • Only a few fields are documented by Microsoft • Contains data structures that apply across a whole process
  • 12. Classic Technique • Overwrite the saved return address – With a value that points back into the stack • When the function returns, it copies the return address into EIP • Return address points to NOP Sled
  • 13.
  • 14. SEH Technique • Overwrite the SEH – With a value that points back into the stack • Trigger an exception • Modified exception handler points to NOP Sled
  • 15.
  • 16. Defeating ASLR (Address Space Layout Randomization)
  • 17.
  • 18. Using Return Value • We're inside the function • ESP points to the stack • Find a JMP ESP and insert its address into the return value
  • 19. Using SEH • Old Windows versions left the address of the SEH in EBX • Newer versions clear all registers • But SEH address is at ESP+8 • Find POP, POP, RET and put its address in SEH
  • 21. Exception Handler • Code that deals with problems from within a running process – Such as access violation or divide by zero • Frame-Based Exception Handler – Associated with a particular procedure – Each procedure sets up a new stack frame • Every thread in a Win32 process has at least one frame-based exception handler
  • 22. EXCEPTION_REGISTRATION • Each thread's TEB has the address of the first EXCEPTION_REGISTRATION structure at fs:[0] • When an exception occurs, the OS walks through the list until a suitable handler is found
  • 24. SEH Chain in Immunity • View, SEH Chain • This is Notepad's SEH Chain
  • 26. Exceptions in Stack Overflows • Suppose we overflow the stack to overwrite the stored return address • Unfortunately, we also overwrite other variables by accident (collateral damage) • Those may lead to exceptions, as other instructions become invalid, before the function returns
  • 27. Overwriting EXCEPTION_REGISTRATION • To gain control of exception handling • On Windows 2000 and Win XP (before SP1) – EBX points to the current EXCEPTION_REGISTRATION structure • On later Windows versions, all the registers are zeroed when the SEH is called – In order to make exploitation more difficult
  • 28. Old Windows Process • At crash, EBX points to EXCEPTION_REGISTRATION structure • Overwrite 
 With "JMP EBX"
  • 29. Modern Windows Process • Stack at crash • 3rd value points
 to EXCEPTION
 _REGISTRATION 
 structure • Use POP, POP, RET
  • 31. Win 2003 Server • Attempts to ensure that handler is valid before using it, with these steps 1.If handler is on the stack -- INVALID – According to the TEB's entries FS:[4] and FS:{8] 2.If handler is in any loaded EXE or DLL – MAYBE – Otherwise VALID
  • 32. Win 2003 Server 3. If the module is marked as "not allowed – INVALID 4. If a module has no "Load Configuration Directory", or one with a small size: VALID
  • 33. Three Ways to Exploit SEH on Windows Server 2003 1. Abuse an existing handler 2. Use code in an address outside all modules 3. Use code in a module without a "Load Configuration Directory"
  • 34. Defenses in Win Server 2008 Not in Book
  • 35. Microsoft's Defenses • Normal SEH attack (link Ch 8f)
  • 36. SAFESEH • Microsoft added this compiler switch to Visual Studio 2003 • It creates a whitelist of exception handler addresses • BUT this depends on the developer using the switch – All legacy code must be recompiled
  • 37. SEHOP • Verifies that the exception handler is intact before using it • The pointer to the next handler comes before the pointer to the registration record • So an exploit will usually damage the *Next pointer
  • 39. How SEHOP Works • Adds an extra registration record at the end of the list • Walks the exception handler list to ensure that the added record can be reached • Will detect corruption of *Next pointers
  • 41. Windows Versions • SEHOP is enabled by default in Windows Server 2008 • Disabled by default in Windows Vista – Because it breaks some legacy code • Also disabled by default on Windows 7 – But it can be enabled in the Registry – Link Ch 8k