Today we are going to cover the use of SQLMap in bug bounty and web pentest. This tool has been around for years and proved to be the top choice. When you test websites for SQLi, you often start manually with known payloads and then move to your tools. Although there are a few tools available out there, this one is the most capable. So itβs a good idea to start with it.
This article will teach you how to work with flags and options. Since all the heavy lifting is done by the tool, itβs enough for you to start finding bugs and report them. SQLi is considered to be a critical vulnerability, as it may lead to RCE or a full website compromise. That really depends on the database management system (DBMS). We had a case during a pentest where an adminβs IP was whitelisted in the MySQL database. That same IP also had SSH open, and credential reuse got us into that server too. You never know what youβre going to run into once youβre inside a database. Sometimes one finding can lead to the next. Thatβs why this vulnerability is critical.
OWASP Top 10
Although the injections moved down the list, theyβre still out there and very much exploitable. There are many gov websites that are vulnerable to it. Sometimes youβll come across a time-based injection thatβs pretty slow to work with. Other times, you might get a union-based injection that will let you dump entire databases fast and clean. Error-based injections are common and easy to spot. And finally, there are boolean-based injections.
Itβs not always obvious that a website is vulnerable to an injection. It might look totally outdated but give you nothing. And on the other hand, solid looking websites can leak everything with just one payload.
Simple payload
Letβs start with the basics. Often, you donβt need to go overboard as SQLMap can handle most of it for you. You can stick with simple payloads and only then get into complex ones. The complexity of the payload doesnβt always increase the chance of a successful SQLi. Even changing parameters like βrisk or βlevel too early can make your payload fail.
Letβs take a Russian ISP website as an example. The one-liner here is simple. Below you can see an intercepted POST request that we saved from Burp. It had random login credentials for the test.Β
kali > sudo sqlmap -r website.ru.txt --risk=3 --level=4 --batch --random-agent
You can play with levels and risks, but be careful as some websites may have WAF, so try to keep it low in the beginning.
Now letβs try dumping their data with βdump. We are interested in the billing database (-D billing) and users11 table (-T users11). At the end of the line we will add βcolumns to enumerate the columns.
You can also use βusers and βpasswords to dump credentials of database admins.
βusers extracts database management users. Here you will see all the whitelisted IPs, but sometimes you will come across localhost, which wonβt let you connect to the DB externally. βpasswords will dump password hashes if available. If you succeed, it opens up a new attack vector, as mentioned before.
Letβs now test a second example where higher risk and level work just fine and actually give better results.Β
Here is a furniture shop in Moscow. Even though the website seems pretty modern, the id= parameter is injectable.
We will go with βlevel=4 and βrisk=3 again this time. The asterisk (*) points at the parameter that needs to be tested. You can also use -p for that.
It worked. Now we dump the users table with usernames and hashes. But keep in mind, not all hashes can be cracked by SQLMap. If it fails, donβt be surprised. Just export them and use Hashcat or John the Ripper.
Once cracked, we can log into the website. If someone cracks an adminβs hash, they can cause real damage to the website.
That was easy. Letβs look at a different challenge.
Tampers
This is a gov.ru website. Itβs different compared to the previous ones, because regular SQLMap payloads fail here. Itβs protected by a WAF that filters suspicious requests. For this reason we will use tampers. There are many of them and random isa popular choice. It randomizes the casing of your payload, which can help bypass WAFs.
Another flag you might notice is βno-cast. This tells SQLMap not to cast data types. It can be useful after you find a working injection. Before that, it might get in your way.
There are tons of tamper scripts designed for different firewalls. If you find out what firewall is running, youβll have a better chance of picking the right one.
Columns
Here is another government-associated website for the city of Khabarovsk. Khabarovsk is a major city in the Russian Far East, close to China. Itβs known for its military importance and some sketchy biological programs during the Soviet era. This website looks like a city archive. Letβs dig into it.
Look at the search functions. It shows results in a table format. Thatβs your clue. We need to know how many columns are returned. If your union payload uses the wrong number of columns, it wonβt work.
As you can see above, there are four of them. So we will go with βunion-col=4
Using a union character (a random string or ID) can sometimes help stabilize your payload and avoid false positives. Donβt forget to add tamper scripts. You can even stack them, just make sure they donβt conflict with each other.Β
Conclusion
Thatβs it for Part 1. Weβve laid the foundation in this chapter showing you the real use of SQLMap and its functions. As it was mentioned previously, SQLi are critical vulnerabilities and itβs always a good idea to test them during your Web App Hacking or Bug Bounty. We have training on each, where we give you the needed skills to start finding your first bugs or land a job as a pentesters, as many companies require these skills.Β
Just wrapped up another Hack The Box machine: Fries (Hard).
TThis machine provided a realistic attack path that started with source code review in Gitea, where leaked credentials in a Git commit led to authenticated PostgreSQL RCE through pgAdmin. From there, I pivoted through the internal Docker network using Ligolo-ng, abused an exposed NFS share and debugfs to gain host access, then exploited PWM configuration weaknesses to capture LDAP credentials. The final stage involved Active Directory enumeration and AD CS (ESC6/ESC7) abuse to obtain an administrator certificate and compromise the domain. A great lab for practising web exploitation, Docker security, Linux privilege escalation, internal pivoting, and Active Directory attacks.