REGEXVAULTv2.0
Security/Network Security
Verified Safe

User-Agent String (Suspicious Patterns) Regex for PHP

/(?:sqlmap|nmap|masscan|nikto|nessus|openvas|nuclei|burpsuite|zap|dirbuster|gobuster|ffuf|wfuzz|hydra|metasploit|msfconsole|python-requests|curl|wget|libwww-perl|scrapy|mechanize|go-http-client|[Bb]ot|[Cc]rawler|[Ss]pider|[Ss]craper|PhantomJS|HeadlessChrome)(?:[/\s]|$)/i

What this pattern does

This page provides a comprehensive, battle-tested regular expression for matching user-agent string (suspicious patterns), ported and verified for PHP. In security-sensitive code, using an unverified regex can open the door to both false positives and denial-of-service attacks. The snippet below is ready to drop into your PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.

Php Implementation

Php
<?php
// User-Agent String (Suspicious Patterns)
// ReDoS-safe | RegexVault — Security > Network Security

define('USERAGENT_STRING_SUSPICIOUS_PATTERNS_PATTERN', '/(?:sqlmap|nmap|masscan|nikto|nessus|openvas|nuclei|burpsuite|zap|dirbuster|gobuster|ffuf|wfuzz|hydra|metasploit|msfconsole|python-requests|curl|wget|libwww-perl|scrapy|mechanize|go-http-client|[Bb]ot|[Cc]rawler|[Ss]pider|[Ss]craper|PhantomJS|HeadlessChrome)(?:[\/\s]|$)/');

function validate_useragent_string_suspicious_patterns(string $input): bool {
    return (bool) preg_match(USERAGENT_STRING_SUSPICIOUS_PATTERNS_PATTERN, $input);
}

// Example
var_dump(validate_useragent_string_suspicious_patterns("sqlmap/1.4.12")); // bool(true)

Test Cases

Matches (Valid)
Rejects (Invalid)
sqlmap/1.4.12Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
python-requests/2.28.0Safari/537.36
Nessus 6.5
Mozilla/5.0 HeadlessChrome/119

When to use this pattern

This pattern is drawn from the Security > Network Security category and carries a ReDoS-safe certification. That matters for PHP developers because especially relevant in PHP where PCRE backtracking limits can trigger silent failures on malicious input. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

Sophisticated attackers spoof User-Agent strings. UA-based blocking is a deterrent, not a security control. Complement with behavioral analysis (request rate, URL patterns) for meaningful bot detection.

Technical Notes

Detection pattern for WAF (Web Application Firewall) rules. Matches known scanner, pentesting tool, and automation library user agents. False positives: legitimate bots (Googlebot, Bingbot) are not included. Extend the list based on observed attack patterns in your logs.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern