NMAP – User Agent – How to Set Your Own, Permanently!
By default Nmap comes fully bundled with NSE (Nmap Scripting-Engine) a fully integrated scripting engine with many useful libraries.
The http library is very commonly used, however many people dont realise they are using the user-agent
Mozilla/5.0 (compatible; Nmap Scripting Engine; http://nmap.org/book/nse.html)
This is obviously a value you wouldn’t like to be used when pen-testing, as it would give your presence away on the battlefield, as they say. Additionally, it is easily detected and blocked (Unique to Nmap’s NSE http library).
Furthermore, Mod Security, and many other WAF’s (Web Application Firewalls) etc will quickly catch on to what you’re up to.
For example a ModSecurity rule that detects and blocks this default user agent is:
SecRule REQUEST_HEADERS:User-Agent "@streq Mozilla/5.0 (compatible; Nmap Scripting Engine; http://nmap.org/book/nse.html)" deny
With a good Sec setup on the server using ModSecurity, fail2ban etc would more than likely kick in, dropping your scanner’s connections.
According to the NMAP development team this value is left by “design” and that if you want to change it you have to use
--script-args http.useragent="some ua" when launching your Nmap scans. The problem is that this is burdensome to add (and remember) everytime you need it.
NMAP How to change user agent:
You can find the default value in
/usr/share/nmap/nselib/http.lua (At the beginning of the file, a couple of lines after the comments)
local USER_AGENT = stdnse.get_script_args('http.useragent') or "Mozilla/5.0 (compatible; Nmap Scripting Engine; http://nmap.org/book/nse.html)"
Here’s an example of a user agent that should be used in a default setting
local USER_AGENT = stdnse.get_script_args('http.useragent') or "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"
You can set it to whatever you like, stealth is key, change it periodically etc.
Anyway, we shall leave it at that, for now.
Check out more of our guides here
Suggest an edit to this article
Go to Cybersecurity Knowledge Base
Got to the Latest Cybersecurity News
Stay informed of the latest Cybersecurity trends, threats and developments. Sign up for our Weekly Cybersecurity Newsletter Today.
Remember, CyberSecurity Starts With You!
- Globally, 30,000 websites are hacked daily.
- 64% of companies worldwide have experienced at least one form of a cyber attack.
- There were 20M breached records in March 2021.
- In 2020, ransomware cases grew by 150%.
- Email is responsible for around 94% of all malware.
- Every 39 seconds, there is a new attack somewhere on the web.
- An average of around 24,000 malicious mobile apps are blocked daily on the internet.