-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
Describe the bug
SQLMap modifies the Host header from saved request files by appending the explicit port number (e.g., :80), which breaks virtual host resolution on web servers configured to match exact hostnames without ports. This causes the target server to return 302 redirects instead of the expected responses, preventing SQLMap from detecting or exploiting vulnerabilities.
To Reproduce
- This is how the request looks like in BurpSuite Community with
Host: metapress.htb(without port, for obvious reasons):
POST /wp-admin/admin-ajax.php HTTP/1.1
Host: metapress.htb
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded
Content-Length: 112
Origin: http://metapress.htb
DNT: 1
Connection: keep-alive
Referer: http://metapress.htb/events/
Cookie: PHPSESSID=l2ve5br129sggimqop44241kg0
Priority: u=0
action=bookingpress_front_get_category_services&category_id=1&total_service=&_wpnonce=1a518999a4&total_service=1Right-click and "Save item". Saved to unauth-sqli.req
-
Add to
/etc/hosts:10.129.228.95 metapress.htb -
Run:
python3 sqlmap.py -r unauth-sqli.req --dbms mysql -t 20 --risk 3 --level 5 --technique U --proxy http://127.0.0.1:8080 -p total_service -
Observe through proxy (Burp Suite) that SQLMap sends
Host: metapress.htb:80instead ofHost: metapress.htb
Expected behavior
SQLMap should preserve the Host header exactly as provided in the request file (Host: metapress.htb), not append the port number.
Screenshots
Original request (works - returns 200 OK):
SQLMap's modified request (fails - returns 302 redirect):
Response difference:
- With
Host: metapress.htb:HTTP/1.1 200 OKwith JSON application data - With
Host: metapress.htb:80:HTTP/1.1 302 Moved Temporarilywith redirect to homepage
Running environment:
- sqlmap version: dev branch (1.9.11.3#dev)
- Installation method: git clone
- Operating system: Debian Linux
- Python version: 3.11.2
Target details:
- DBMS: MySQL
- SQLi techniques found by sqlmap: None (prevented by Host header issue causing 302 redirects)
- WAF/IPS: None
- Relevant console output: SQLMap receives 302 redirects instead of application responses, preventing vulnerability detection
- Exception traceback: None - no errors, just incorrect behavior
The root cause appears to be SQLMap reconstructing the Host header from parsed components rather than preserving the original value from the -r request file.
A suggested fix would be to preserve the exact Host header from the request file, or add a command-line option like --preserve-host-header to prevent modification.