User-Agent Spoofing

User-Agent Spoofing

One-liner: The technique of modifying the User-Agent HTTP header to impersonate a different client or bypass security controls.

🎯 What Is It?

The User-Agent header in HTTP Requests identifies the client software (browser, bot, tool) making the request. User-Agent spoofing is changing this header to appear as a different clientβ€”either to bypass restrictions, evade detection, or access content served differently based on the client type.

πŸ€” Why It Matters

πŸ”¬ How It Works

Default User-Agent Examples

# cURL default
User-Agent: curl/7.81.0

# Python requests
User-Agent: python-requests/2.28.0

# Chrome browser
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Spoofing with cURL

# Default request (may be blocked)
curl http://target.com/api

# Spoof as Chrome browser
curl -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0" http://target.com/api

# Custom/internal User-Agent
curl -A "internalcomputer" http://target.com/admin

# Empty User-Agent
curl -A "" http://target.com/api

Spoofing with Python

import requests

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0'
}
response = requests.get('http://target.com', headers=headers)

πŸ“Š Common Spoofing Scenarios

Scenario Original UA Spoofed UA Purpose
Bypass tool blocking curl/7.x Chrome/Firefox UA Access blocked endpoint
Internal access Browser UA internalscanner Access internal resources
Mobile content Desktop UA Mobile UA Access mobile version
Bot evasion python-requests Real browser UA Avoid bot detection
WAF bypass Known tool UA Legitimate browser Evade security rules

πŸ›‘οΈ Detection & Prevention

How to Detect (Blue Team)

How to Prevent / Mitigate

🚨 Security Implications

Risk Description
False sense of security Blocking by UA alone is easily bypassed
Evasion of logging Attackers hide tool signatures
Access control bypass Weak controls based on UA
Content differential attacks Accessing hidden content paths

🎀 Interview Angles

Common Questions

STAR Story

Situation: A web application blocked cURL and other security tools based on User-Agent header.
Task: Demonstrate that this security control was insufficient.
Action: Used cURL with -A flag to spoof a standard browser User-Agent, bypassing the block. Documented additional indicators (missing headers, request patterns) that could be used for better detection.
Result: Client implemented behavioral-based detection instead of User-Agent blocking, improving actual security posture.

βœ… Best Practices

❌ Common Misconceptions

πŸ“š References