--- name: HTML Injection Testing description: This skill should be used when the user asks to "test for HTML injection", "inject HTML into web pages", "perform HTML injection attacks", "deface web applications", or "test content injection vulnerabilities". It provides comprehensive HTML injection attack techniques and testing methodologies. version: 1.0.0 tags: [html-injection, web-security, injection, penetration-testing, content-injection] --- # HTML Injection Testing ## Purpose Identify and exploit HTML injection vulnerabilities that allow attackers to inject malicious HTML content into web applications. This vulnerability enables attackers to modify page appearance, create phishing pages, and steal user credentials through injected forms. ## Prerequisites ### Required Tools - Web browser with developer tools - Burp Suite or OWASP ZAP - Tamper Data or similar proxy - cURL for testing payloads ### Required Knowledge - HTML fundamentals - HTTP request/response structure - Web application input handling - Difference between HTML injection and XSS ## Outputs and Deliverables 1. **Vulnerability Report** - Identified injection points 2. **Exploitation Proof** - Demonstrated content manipulation 3. **Impact Assessment** - Potential phishing and defacement risks 4. **Remediation Guidance** - Input validation recommendations ## Core Workflow ### Phase 1: Understanding HTML Injection HTML injection occurs when user input is reflected in web pages without proper sanitization: ```html
Injected paragraph
Please login at portal.company.com
```
### Phase 7: Advanced Injection Techniques
#### CSS Injection
```html
');
```
```python
# Python: HTML escape
from html import escape
safe_output = escape(user_input)
# Python Flask: Auto-escaping
{{ user_input }} # Jinja2 escapes by default
{{ user_input | safe }} # Marks as safe (dangerous!)
```
```javascript
// JavaScript: Text content (safe)
element.textContent = userInput;
// JavaScript: innerHTML (dangerous!)
element.innerHTML = userInput; // Vulnerable!
// JavaScript: Sanitize
const clean = DOMPurify.sanitize(userInput);
element.innerHTML = clean;
```
Server-side protections:
- Input validation (whitelist allowed characters)
- Output encoding (context-aware escaping)
- Content Security Policy (CSP) headers
- Web Application Firewall (WAF) rules
## Quick Reference
### Common Test Payloads
| Payload | Purpose |
|---------|---------|
| `Test
` | Basic rendering test |
| `Bold` | Simple formatting |
| `Link` | Link injection |
| `` | Image tag test |
| `
test
` |
| Form field | POST with HTML payload |
| Cookie value | Inject via document.cookie |
| HTTP header | Inject in Referer/User-Agent |
| File upload | HTML file with malicious content |
### Encoding Types
| Type | Example |
|------|---------|
| URL encoding | `%3Ch1%3E` = `` |
| HTML entities | `<h1>` = `
` |
| Double encoding | `%253C` = `<` |
| Unicode | `\u003c` = `<` |
## Constraints and Limitations
### Attack Limitations
- Modern browsers may sanitize some injections
- CSP can prevent inline styles and scripts
- WAFs may block common payloads
- Some applications escape output properly
### Testing Considerations
- Distinguish between HTML injection and XSS
- Verify visual impact in browser
- Test in multiple browsers
- Check for stored vs reflected
### Severity Assessment
- Lower severity than XSS (no script execution)
- Higher impact when combined with phishing
- Consider defacement/reputation damage
- Evaluate credential theft potential
## Troubleshooting
### HTML Not Rendering
**Solutions:**
1. Check if output is HTML-encoded
2. Try different encoding methods
3. Test alternative tags
4. Verify injection point is in HTML context
### Payload Stripped
**Solutions:**
1. Use encoding variations
2. Try tag splitting
3. Test with null bytes
4. Use nested/malformed tags
### XSS Not Working (Only HTML)
**Causes:**
- JavaScript filtered but HTML allowed
- CSP blocking inline scripts
- Framework-level XSS protection
**Leverage HTML injection instead:**
- Create phishing forms
- Inject misleading content
- Redirect via meta refresh