SlideShare a Scribd company logo
Control Hijacking Attacks
Table of Contents
• Attacker’s Intentions
• Buffer Overflow Attacks
 Basic Stack Exploit
 Heap based buffer overflow attack
 Defense Against Buffer Overflow Attack
 Integer Overflow Attack
 Format String Attack
 Prevention of Control Hijacking Attacks
 Runtime Checking: Stackguard
Attacker’s Intentions
Take control of the victim’s machine
 Hijack the execution flow of a running program
 Execute arbitrary code
Requirements
 Inject attack code or attack parameters
 Abuse vulnerability and modify memory such that control flow is redirected
Attacker’s Intentions (Contd)
Examples
 Buffer Overflow attack
 Integer overflow attack
 Format string vulnerabilities
• What is needed by attacker?
 Understanding C functions, the stack, and the heap.
 Know how system calls are made
 The exec() system call
 Attacker needs to know which CPU and OS used on the target machine:
Buffer Overflow Attack
• Result from mistakes done while writing code
 Coding flaws because of
• unfamiliarity with language
• Ignorance about security issues
• unwillingness to take extra effort
• Often related to particular programming language
• Buffer overflows
 mostly relevant for C / C++ programs
 not in languages with automatic memory management
Buffer Overflow Attack (Contd.)
• dynamic bounds checks (e.g., Java)
• automatic resizing of buffers (e.g., Perl)
• One of the most used attack techniques
• What is needed to understand buffer overflow attack?
 Understanding C functions and the stack
 Some familiarity with machine code
 Know how systems calls are made
 The exec() system call
Stack Frame
Parameters
Return address
Stack Frame Pointer
Local variables
SP
Stack
Growth
What are buffer overflows?
• Suppose a web server contains a function:
void func (char *str) {
char buf [128];
strcpy (buf, str);
do-something (buf);
}
• When the function is invoked the stack looks like:
• What if *str is 136 bytes long? After strcpy:
strret-addrsfpbuf
Top
of
stack
str
Top
of
stack
*str ret
Exploiting buffer overflows
• Suppose web server calls func() with given URL.
 Attacker sends a 200 byte URL. Gets shell on web server
• Some complications:
 Program P should not contain the ‘0’ character.
 Overflow should not crash program before func() exists.
• Sample remote buffer overflows of this type:
 (2005) Overflow in MIME type field in MS Outlook.
 (2005) Overflow in Symantec Virus Detection
Set test = CreateObject ("Symantec.SymVAFileQuery.1")
test.GetPrivateProfileString "file", [long string]
Basic stack exploit
• Problem: no range checking in strcpy().
• Suppose *str is such that after strcpy stack looks like:
• When func() exits, the user will be given a shell !
• Note: attack code runs in stack.
• To determine ret guess position of stack when func() is called
Top
of
stack*str ret Code for P
Program P: exec( “/bin/sh” )
(exact shell code by Aleph One)
Stack-based attacks: many variants
• Return address clobbering
• Overwriting function pointers (e.g. PHP 4.0.2, MediaPlayer, BMP).
• Overwriting exception-handler pointers (C++).
 Need to cause an exception afterwards
• Overwriting longjmp buffers (e.g. Perl 5.003)
 Mechanism for error handling in C
• Overwriting saved frame pointer (SFP)
 Off-by-one error is enough: one byte buffer overflow!
 First return (leave) sets SP to overwritten SFP.
 Second return (ret) jumps to fake top of stack
Heap
or
stack
buf[128] FuncPtr
Control Hijacking Opportunities
• Stack smashing attack:
 Override return address in stack activation record by overflowing a local buffer
variable.
• Function pointers: (e.g. PHP 4.0.2, MS Media Player Bitmaps)
 Overflowing buf will override function pointer.
• Longjmp buffers: longjmp (pos) (e.g. Perl 5.003)
 Overflowing buf next to pos overrides value of pos.
Heap
or
stackbuf[128] FuncPtr
Heap-based control hijacking
• Compiler generated function pointers (e.g. C++ code)
• Suppose vtable is on the heap next to a string object:
ptr
data
Object T
FP1
FP2
FP3
vtable
method #1
method #2
method #3
ptr
buf[256]
data
object T
vtable
Heap-based control hijacking
• Compiler generated function pointers (e.g. C++ code)
• After overflow of buf we have:
ptr
data
Object T
FP1
FP2
FP3
vtable
method #1
method #2
method #3
ptr
buf[256]
data
object T
vtable
shell
code
Defense Against Buffer Overflow Attack
• Programming language choice is crucial
• The language
 should be strongly typed
 Should do automatic bound checks.
 Should do automatic memory management.
Integer Overflow Attack
• Integer overflows: e.g. MS DirectX MIDI Lib, Phrack60
void func(int a, char v)
{
char buf[128];
init(buf);
buf[a] = v;
}
• Problem: a can point to `ret-addr’ on stack.
• Double free: double free space on heap.
 Can cause mem mgr to write data to specific location
 Examples: CVS server
An Example
void func( char *buf1, *buf2, unsigned int len1, len2) {
char temp[256];
if (len1 + len2 > 256) {return -1} //lengthcheck
memcpy(temp, buf1, len1); // cat buffers
memcpy(temp+len1, buf2, len2);
do-something(temp); // do stuff
}
What if len1 = 0x80, len2 = 0xffffff80?
⇒ len1+len2 = 0
Second memcpy () will overflow heap
Format String Attack
Int func(char *user) {
fprintf( stderr, user);
}
Problem: what if user = “%s%s%s%s%s%s%s” ??
 Most likely program will crash: DoS.
 If not, program will print memory contents. Privacy?
 Full exploit using user = “%n”
• Correct form:
int func(char *user) {
fprintf( stdout, “%s”, user);
}
Vulnerable functions
• Any function using a format string.
• Printing:
 printf, fprintf, sprintf, …
 vprintf, vfprintf, vsprintf, …
• Logging:
syslog, err, warn
Exploit
• Dumping arbitrary memory:
 Walk up stack until desired pointer is found.
 printf( “%08x.%08x.%08x.%08x|%s|”)
• Writing to arbitrary memory:
 printf( “hello %n”, &temp) -- writes ‘6’ into temp.
 printf( “%08x.%08x.%08x.%08x.%n”)
Control Hijacking
Preventing hijacking attacks
• Fix bugs:
 Audit software
 Automated tools: Coverity, Prefast/ Prefix.
 Rewrite software in a type safe language (Java, ML)
• Difficult for existing (legacy) code ...
• Concede overflow, but prevent code execution
• Add runtime code to detect overflows exploits
 Halt process when overflow exploit detected
 StackGuard, LibSafe, ...
Run time checking: StackGuard
• StackGuard
 Run time tests for stack integrity.
 Embed “canaries” in stack frames and verify their
 integrity prior to function return.
• Canary Types
 Random canary:
• Choose random string at program startup.
• Insert canary string into every stack frame.
• Verify canary before returning from function.
• To corrupt random canary, attacker must learn current random string.
Canary (Contd)
• Terminator canary:
 Canary = 0, newline, linefeed, EOF
• String functions will not copy beyond terminator.
• Attacker cannot use string functions to corrupt stack.
• StackGuard implemented as a GCC patch.
 Program must be recompiled.
• Minimal performance effects: 8% for Apache.
• Note: Canaries don’t offer fullproof protection.
 Some stack smashing attacks leave canaries unchanged
• Heap protection: PointGuard
 Protects function pointers and setjmp buffers by encrypting them: XOR
with random cookie
 Less effective, more noticeable performance effects
• .

More Related Content

What's hot

Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
Ritu Ranjan Shrivastwa
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
Virtual memory
Virtual memoryVirtual memory
Virtual memoryAnuj Modi
 
Memory Organization
Memory OrganizationMemory Organization
Memory Organization
Kamal Acharya
 
Operating Systems - "Chapter 4: Multithreaded Programming"
Operating Systems - "Chapter 4:  Multithreaded Programming"Operating Systems - "Chapter 4:  Multithreaded Programming"
Operating Systems - "Chapter 4: Multithreaded Programming"
Ra'Fat Al-Msie'deen
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
Instruction format
Instruction formatInstruction format
Instruction format
Sanjeev Patel
 
Micro program example
Micro program exampleMicro program example
Micro program example
rajshreemuthiah
 
Computer Organisation & Architecture (chapter 1)
Computer Organisation & Architecture (chapter 1) Computer Organisation & Architecture (chapter 1)
Computer Organisation & Architecture (chapter 1)
Subhasis Dash
 
System calls
System callsSystem calls
System calls
Bernard Senam
 
Two pass Assembler
Two pass AssemblerTwo pass Assembler
Two pass Assembler
Satyamevjayte Haxor
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
Thooyavan Venkatachalam
 
Accessing I/O Devices
Accessing I/O DevicesAccessing I/O Devices
Accessing I/O DevicesSlideshare
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
JavaTpoint.Com
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Thrashing allocation frames.43
Thrashing allocation frames.43Thrashing allocation frames.43
Thrashing allocation frames.43myrajendra
 
Registers
RegistersRegisters
Registers
Sahil Bansal
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
Dr. C.V. Suresh Babu
 
Linker and Loader
Linker and Loader Linker and Loader
Linker and Loader
sonalikharade3
 

What's hot (20)

Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Memory Organization
Memory OrganizationMemory Organization
Memory Organization
 
Operating Systems - "Chapter 4: Multithreaded Programming"
Operating Systems - "Chapter 4:  Multithreaded Programming"Operating Systems - "Chapter 4:  Multithreaded Programming"
Operating Systems - "Chapter 4: Multithreaded Programming"
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Instruction format
Instruction formatInstruction format
Instruction format
 
Micro program example
Micro program exampleMicro program example
Micro program example
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Computer Organisation & Architecture (chapter 1)
Computer Organisation & Architecture (chapter 1) Computer Organisation & Architecture (chapter 1)
Computer Organisation & Architecture (chapter 1)
 
System calls
System callsSystem calls
System calls
 
Two pass Assembler
Two pass AssemblerTwo pass Assembler
Two pass Assembler
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
Accessing I/O Devices
Accessing I/O DevicesAccessing I/O Devices
Accessing I/O Devices
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Thrashing allocation frames.43
Thrashing allocation frames.43Thrashing allocation frames.43
Thrashing allocation frames.43
 
Registers
RegistersRegisters
Registers
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Linker and Loader
Linker and Loader Linker and Loader
Linker and Loader
 

Similar to Control hijacking

Buffer Overflow Countermeasures, DEP, Security Assessment
Buffer Overflow Countermeasures, DEP, Security AssessmentBuffer Overflow Countermeasures, DEP, Security Assessment
Buffer Overflow Countermeasures, DEP, Security Assessment
Amar Myana
 
Embedded c & working with avr studio
Embedded c & working with avr studioEmbedded c & working with avr studio
Embedded c & working with avr studioNitesh Singh
 
Buffer Overflows
Buffer OverflowsBuffer Overflows
Buffer OverflowsSumit Kumar
 
2.Format Strings
2.Format Strings2.Format Strings
2.Format Stringsphanleson
 
0100_Embeded_C_CompilationProcess.pdf
0100_Embeded_C_CompilationProcess.pdf0100_Embeded_C_CompilationProcess.pdf
0100_Embeded_C_CompilationProcess.pdf
KhaledIbrahim10923
 
0-Slot14-15-16-Libraries.pdf
0-Slot14-15-16-Libraries.pdf0-Slot14-15-16-Libraries.pdf
0-Slot14-15-16-Libraries.pdf
ssusere19c741
 
C for Engineers
C for EngineersC for Engineers
C for Engineers
Julie Iskander
 
A Peek into TFRT
A Peek into TFRTA Peek into TFRT
A Peek into TFRT
Koan-Sin Tan
 
Buffer overflow
Buffer overflowBuffer overflow
Buffer overflow
Evgeni Tsonev
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)
SURBHI SAROHA
 
Ceh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflowCeh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflow
Vi Tính Hoàng Nam
 
Os lectures
Os lecturesOs lectures
Os lectures
Adnan Ghafoor
 
Ch 18: Source Code Auditing
Ch 18: Source Code AuditingCh 18: Source Code Auditing
Ch 18: Source Code Auditing
Sam Bowne
 
Dive into exploit development
Dive into exploit developmentDive into exploit development
Dive into exploit development
Payampardaz
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CanSecWest
 
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
OpenEBS
 
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
Sam Bowne
 
Secure Coding Practices for Middleware
Secure Coding Practices for MiddlewareSecure Coding Practices for Middleware
Secure Coding Practices for MiddlewareManuel Brugnoli
 
C format string vulnerability
C format string vulnerabilityC format string vulnerability
C format string vulnerability
sluge
 

Similar to Control hijacking (20)

Buffer Overflow Countermeasures, DEP, Security Assessment
Buffer Overflow Countermeasures, DEP, Security AssessmentBuffer Overflow Countermeasures, DEP, Security Assessment
Buffer Overflow Countermeasures, DEP, Security Assessment
 
Buffer Overflow Attacks
Buffer Overflow AttacksBuffer Overflow Attacks
Buffer Overflow Attacks
 
Embedded c & working with avr studio
Embedded c & working with avr studioEmbedded c & working with avr studio
Embedded c & working with avr studio
 
Buffer Overflows
Buffer OverflowsBuffer Overflows
Buffer Overflows
 
2.Format Strings
2.Format Strings2.Format Strings
2.Format Strings
 
0100_Embeded_C_CompilationProcess.pdf
0100_Embeded_C_CompilationProcess.pdf0100_Embeded_C_CompilationProcess.pdf
0100_Embeded_C_CompilationProcess.pdf
 
0-Slot14-15-16-Libraries.pdf
0-Slot14-15-16-Libraries.pdf0-Slot14-15-16-Libraries.pdf
0-Slot14-15-16-Libraries.pdf
 
C for Engineers
C for EngineersC for Engineers
C for Engineers
 
A Peek into TFRT
A Peek into TFRTA Peek into TFRT
A Peek into TFRT
 
Buffer overflow
Buffer overflowBuffer overflow
Buffer overflow
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)
 
Ceh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflowCeh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflow
 
Os lectures
Os lecturesOs lectures
Os lectures
 
Ch 18: Source Code Auditing
Ch 18: Source Code AuditingCh 18: Source Code Auditing
Ch 18: Source Code Auditing
 
Dive into exploit development
Dive into exploit developmentDive into exploit development
Dive into exploit development
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
 
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
 
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
 
Secure Coding Practices for Middleware
Secure Coding Practices for MiddlewareSecure Coding Practices for Middleware
Secure Coding Practices for Middleware
 
C format string vulnerability
C format string vulnerabilityC format string vulnerability
C format string vulnerability
 

More from G Prachi

The trusted computing architecture
The trusted computing architectureThe trusted computing architecture
The trusted computing architecture
G Prachi
 
Security risk management
Security risk managementSecurity risk management
Security risk management
G Prachi
 
Mobile platform security models
Mobile platform security modelsMobile platform security models
Mobile platform security models
G Prachi
 
Malicious software and software security
Malicious software and software  securityMalicious software and software  security
Malicious software and software security
G Prachi
 
Network defenses
Network defensesNetwork defenses
Network defenses
G Prachi
 
Network protocols and vulnerabilities
Network protocols and vulnerabilitiesNetwork protocols and vulnerabilities
Network protocols and vulnerabilities
G Prachi
 
Web application security part 02
Web application security part 02Web application security part 02
Web application security part 02
G Prachi
 
Web application security part 01
Web application security part 01Web application security part 01
Web application security part 01
G Prachi
 
Basic web security model
Basic web security modelBasic web security model
Basic web security model
G Prachi
 
Least privilege, access control, operating system security
Least privilege, access control, operating system securityLeast privilege, access control, operating system security
Least privilege, access control, operating system security
G Prachi
 
Dealing with legacy code
Dealing with legacy codeDealing with legacy code
Dealing with legacy code
G Prachi
 
Exploitation techniques and fuzzing
Exploitation techniques and fuzzingExploitation techniques and fuzzing
Exploitation techniques and fuzzing
G Prachi
 
Computer security concepts
Computer security conceptsComputer security concepts
Computer security concepts
G Prachi
 
Administering security
Administering securityAdministering security
Administering security
G Prachi
 
Database security and security in networks
Database security and security in networksDatabase security and security in networks
Database security and security in networks
G Prachi
 
Protection in general purpose operating system
Protection in general purpose operating systemProtection in general purpose operating system
Protection in general purpose operating system
G Prachi
 
Program security
Program securityProgram security
Program security
G Prachi
 
Elementary cryptography
Elementary cryptographyElementary cryptography
Elementary cryptography
G Prachi
 
Information security introduction
Information security introductionInformation security introduction
Information security introduction
G Prachi
 
Technology, policy, privacy and freedom
Technology, policy, privacy and freedomTechnology, policy, privacy and freedom
Technology, policy, privacy and freedom
G Prachi
 

More from G Prachi (20)

The trusted computing architecture
The trusted computing architectureThe trusted computing architecture
The trusted computing architecture
 
Security risk management
Security risk managementSecurity risk management
Security risk management
 
Mobile platform security models
Mobile platform security modelsMobile platform security models
Mobile platform security models
 
Malicious software and software security
Malicious software and software  securityMalicious software and software  security
Malicious software and software security
 
Network defenses
Network defensesNetwork defenses
Network defenses
 
Network protocols and vulnerabilities
Network protocols and vulnerabilitiesNetwork protocols and vulnerabilities
Network protocols and vulnerabilities
 
Web application security part 02
Web application security part 02Web application security part 02
Web application security part 02
 
Web application security part 01
Web application security part 01Web application security part 01
Web application security part 01
 
Basic web security model
Basic web security modelBasic web security model
Basic web security model
 
Least privilege, access control, operating system security
Least privilege, access control, operating system securityLeast privilege, access control, operating system security
Least privilege, access control, operating system security
 
Dealing with legacy code
Dealing with legacy codeDealing with legacy code
Dealing with legacy code
 
Exploitation techniques and fuzzing
Exploitation techniques and fuzzingExploitation techniques and fuzzing
Exploitation techniques and fuzzing
 
Computer security concepts
Computer security conceptsComputer security concepts
Computer security concepts
 
Administering security
Administering securityAdministering security
Administering security
 
Database security and security in networks
Database security and security in networksDatabase security and security in networks
Database security and security in networks
 
Protection in general purpose operating system
Protection in general purpose operating systemProtection in general purpose operating system
Protection in general purpose operating system
 
Program security
Program securityProgram security
Program security
 
Elementary cryptography
Elementary cryptographyElementary cryptography
Elementary cryptography
 
Information security introduction
Information security introductionInformation security introduction
Information security introduction
 
Technology, policy, privacy and freedom
Technology, policy, privacy and freedomTechnology, policy, privacy and freedom
Technology, policy, privacy and freedom
 

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 

Control hijacking

  • 2. Table of Contents • Attacker’s Intentions • Buffer Overflow Attacks  Basic Stack Exploit  Heap based buffer overflow attack  Defense Against Buffer Overflow Attack  Integer Overflow Attack  Format String Attack  Prevention of Control Hijacking Attacks  Runtime Checking: Stackguard
  • 3. Attacker’s Intentions Take control of the victim’s machine  Hijack the execution flow of a running program  Execute arbitrary code Requirements  Inject attack code or attack parameters  Abuse vulnerability and modify memory such that control flow is redirected
  • 4. Attacker’s Intentions (Contd) Examples  Buffer Overflow attack  Integer overflow attack  Format string vulnerabilities • What is needed by attacker?  Understanding C functions, the stack, and the heap.  Know how system calls are made  The exec() system call  Attacker needs to know which CPU and OS used on the target machine:
  • 5. Buffer Overflow Attack • Result from mistakes done while writing code  Coding flaws because of • unfamiliarity with language • Ignorance about security issues • unwillingness to take extra effort • Often related to particular programming language • Buffer overflows  mostly relevant for C / C++ programs  not in languages with automatic memory management
  • 6. Buffer Overflow Attack (Contd.) • dynamic bounds checks (e.g., Java) • automatic resizing of buffers (e.g., Perl) • One of the most used attack techniques • What is needed to understand buffer overflow attack?  Understanding C functions and the stack  Some familiarity with machine code  Know how systems calls are made  The exec() system call
  • 7. Stack Frame Parameters Return address Stack Frame Pointer Local variables SP Stack Growth
  • 8. What are buffer overflows? • Suppose a web server contains a function: void func (char *str) { char buf [128]; strcpy (buf, str); do-something (buf); } • When the function is invoked the stack looks like: • What if *str is 136 bytes long? After strcpy: strret-addrsfpbuf Top of stack str Top of stack *str ret
  • 9. Exploiting buffer overflows • Suppose web server calls func() with given URL.  Attacker sends a 200 byte URL. Gets shell on web server • Some complications:  Program P should not contain the ‘0’ character.  Overflow should not crash program before func() exists. • Sample remote buffer overflows of this type:  (2005) Overflow in MIME type field in MS Outlook.  (2005) Overflow in Symantec Virus Detection Set test = CreateObject ("Symantec.SymVAFileQuery.1") test.GetPrivateProfileString "file", [long string]
  • 10. Basic stack exploit • Problem: no range checking in strcpy(). • Suppose *str is such that after strcpy stack looks like: • When func() exits, the user will be given a shell ! • Note: attack code runs in stack. • To determine ret guess position of stack when func() is called Top of stack*str ret Code for P Program P: exec( “/bin/sh” ) (exact shell code by Aleph One)
  • 11. Stack-based attacks: many variants • Return address clobbering • Overwriting function pointers (e.g. PHP 4.0.2, MediaPlayer, BMP). • Overwriting exception-handler pointers (C++).  Need to cause an exception afterwards • Overwriting longjmp buffers (e.g. Perl 5.003)  Mechanism for error handling in C • Overwriting saved frame pointer (SFP)  Off-by-one error is enough: one byte buffer overflow!  First return (leave) sets SP to overwritten SFP.  Second return (ret) jumps to fake top of stack Heap or stack buf[128] FuncPtr
  • 12. Control Hijacking Opportunities • Stack smashing attack:  Override return address in stack activation record by overflowing a local buffer variable. • Function pointers: (e.g. PHP 4.0.2, MS Media Player Bitmaps)  Overflowing buf will override function pointer. • Longjmp buffers: longjmp (pos) (e.g. Perl 5.003)  Overflowing buf next to pos overrides value of pos. Heap or stackbuf[128] FuncPtr
  • 13. Heap-based control hijacking • Compiler generated function pointers (e.g. C++ code) • Suppose vtable is on the heap next to a string object: ptr data Object T FP1 FP2 FP3 vtable method #1 method #2 method #3 ptr buf[256] data object T vtable
  • 14. Heap-based control hijacking • Compiler generated function pointers (e.g. C++ code) • After overflow of buf we have: ptr data Object T FP1 FP2 FP3 vtable method #1 method #2 method #3 ptr buf[256] data object T vtable shell code
  • 15. Defense Against Buffer Overflow Attack • Programming language choice is crucial • The language  should be strongly typed  Should do automatic bound checks.  Should do automatic memory management.
  • 16. Integer Overflow Attack • Integer overflows: e.g. MS DirectX MIDI Lib, Phrack60 void func(int a, char v) { char buf[128]; init(buf); buf[a] = v; } • Problem: a can point to `ret-addr’ on stack. • Double free: double free space on heap.  Can cause mem mgr to write data to specific location  Examples: CVS server
  • 17. An Example void func( char *buf1, *buf2, unsigned int len1, len2) { char temp[256]; if (len1 + len2 > 256) {return -1} //lengthcheck memcpy(temp, buf1, len1); // cat buffers memcpy(temp+len1, buf2, len2); do-something(temp); // do stuff } What if len1 = 0x80, len2 = 0xffffff80? ⇒ len1+len2 = 0 Second memcpy () will overflow heap
  • 18. Format String Attack Int func(char *user) { fprintf( stderr, user); } Problem: what if user = “%s%s%s%s%s%s%s” ??  Most likely program will crash: DoS.  If not, program will print memory contents. Privacy?  Full exploit using user = “%n” • Correct form: int func(char *user) { fprintf( stdout, “%s”, user); }
  • 19. Vulnerable functions • Any function using a format string. • Printing:  printf, fprintf, sprintf, …  vprintf, vfprintf, vsprintf, … • Logging: syslog, err, warn
  • 20. Exploit • Dumping arbitrary memory:  Walk up stack until desired pointer is found.  printf( “%08x.%08x.%08x.%08x|%s|”) • Writing to arbitrary memory:  printf( “hello %n”, &temp) -- writes ‘6’ into temp.  printf( “%08x.%08x.%08x.%08x.%n”)
  • 21. Control Hijacking Preventing hijacking attacks • Fix bugs:  Audit software  Automated tools: Coverity, Prefast/ Prefix.  Rewrite software in a type safe language (Java, ML) • Difficult for existing (legacy) code ... • Concede overflow, but prevent code execution • Add runtime code to detect overflows exploits  Halt process when overflow exploit detected  StackGuard, LibSafe, ...
  • 22. Run time checking: StackGuard • StackGuard  Run time tests for stack integrity.  Embed “canaries” in stack frames and verify their  integrity prior to function return. • Canary Types  Random canary: • Choose random string at program startup. • Insert canary string into every stack frame. • Verify canary before returning from function. • To corrupt random canary, attacker must learn current random string.
  • 23. Canary (Contd) • Terminator canary:  Canary = 0, newline, linefeed, EOF • String functions will not copy beyond terminator. • Attacker cannot use string functions to corrupt stack. • StackGuard implemented as a GCC patch.  Program must be recompiled. • Minimal performance effects: 8% for Apache. • Note: Canaries don’t offer fullproof protection.  Some stack smashing attacks leave canaries unchanged • Heap protection: PointGuard  Protects function pointers and setjmp buffers by encrypting them: XOR with random cookie  Less effective, more noticeable performance effects • .

Editor's Notes

  1. A control-hijacking attack overwrites some data structures in a victim program that affect its control flow, and eventually hijacks the control of the program and possibly the underlying system.
  2. A data structure that can affect the control flow of a program is called a control-sensitive data structure, examples of which include return address, function pointer, global offset table/import table, C++ virtual functions table pointer, etc. Once an attacker grabs control of the victim program, she can invoke any operation to which the victim program’s effective user is entitled.
  3. Buffer overflow attacks are known to be the most common type of attacks that allow attackers to hijack a remote system by sending a specially crafted packet to a vulnerable network application running on it.
  4. In a buffer-overflow attack, the extra data sometimes holds specific instructions for actions intended by a hacker or malicious user; for example, the data could trigger a response that damages files, changes data or unveils private information.
  5. A buffer is a temporary area for data storage. When more data (than was originally allocated to be stored) gets placed by a program or system process, the extra data overflows. It causes some of that data to leak out into other buffers, which can corrupt or overwrite whatever data they were holding.
  6. The canonical method for exploiting a stack based buffer overflow is to overwrite the function return address with a pointer to attacker-controlled data (usually on the stack itself).
  7. Stack buffer overflow can be caused deliberately as part of an attack known as stack smashing. n software, a stack buffer overflow or stack buffer overrun occurs when a program writes to a memory address on the program's call stack outside of the intended data structure, which is usually a fixed-length buffer. Stack buffer overflow bugs are caused when a program writes more data to a buffer located on the stack than what is actually allocated for that buffer.
  8. Windows media player bitmaps (skins) – heap overflow, Feb. 2006 setjmp – used for exception handling (jump to global error handling code in case of error)
  9. Difficult to make this exploit work. A reliable method called “heap spraying” is described at the end of the presentation.
  10. Approaches to detect buffer over flow attacks can be divided into two groups: static techniques that detect potential buffer overruns by examining program’s source code and dynamic techniques that protect programs at run-time. Wilander et. al. [1, 2] present a comprehensive overview of tools of both types. [1] . Wilander and M. Kamkar. A comparison of publicly available tools for static intrusion prevention. In Proc. Of 7th Nordic Workshop on Secure IT Systems , 2002. [2] J. Wilander and M. Kamkar. A comparison of publicly available tools for dynamic buffer overflow prevention. In Proc. of 10th Network and Distributed System Security. Symposium , 2003.
  11. An Integer Overflow is the condition that occurs when the result of an arithmetic operation, such as multiplication or addition, exceeds the maximum size of the integer type used to store it.
  12. Integer overflow is what occurs when a numeric variable exceeds its maximum capacity. Generally what happens, due to two's complement arithmetic, is that the variable wraps to the opposite end of the spectrum. So for a signed variable, a negative value too large to fit would become a large positive value.
  13. The Format String exploit occurs when the submitted data of an input string is evaluated as a command by the application. In this way, the attacker could execute code, read the stack, or cause a segmentation fault in the running application, causing new behaviors that could compromise the security or the stability of the system.
  14. Most vulnerabilities in C are related to buffer overflows and string manipulation. In most cases, this would result in a segmentation fault, but specially crafted malicious input values, adapted to the architecture and environment could yield to arbitrary code execution. gets: The stdio gets() function does not check for buffer length and always results in a vulnerability. Strcpy: The strcpy built-in function does not check buffer lengths and may very well overwrite memory zone contiguous to the intended destination. In fact, the whole family of functions is similarly vulnerable: strcpy, strcat and strcmp. Sprintf: Just as the previous functions, sprintf does not check the buffer boundaries and is vulnerable to overflows. printf and friends: One other vulnerability category is concerned with string formatting attacks , those can cause information leakage, overwriting of memory, … This error can be exploited in any of the following functions: printf, fprintf, sprintf and snprintf, i.e. all functions that take a “format string” as argument.