<?php
/*//設置open_basedir
ini_set("open_basedir", "/home/shawn/www/index/");
*/
if (isset($_GET['file'])) {
$file = trim($_GET['file']);
} else {
$file = "main.html";
}
// disallow ip
if (preg_match('/^(http:\/\/)+([^\/]+)/i', $file, $domain)) {
$domain = $domain[2];
if (stripos($domain, ".") !== false) {
die("Hacker");
}
}
if( @file_get_contents($file)!=''){
echo file_get_contents($file);
}else{
$str=<<<EOF
如上引用了XDCTF的一道題目的源碼,此題需要get提交file變量,並且正則匹配file變量中的ip地址,點號被過濾。
第一種繞過方式:
file=php://filter/resource=http://127.0.0.1/(這是針對這道題的正則匹配來繞過,觀察正則表達式,是從file變量開始匹配,如此構造payload匹配不到ip地址巧妙繞過)
第二種繞過方式:
轉ip地址為整型或者十六進制
第三種繞過方式:
因為https://i.cnblogs.com@127.0.0.1與http://127.0.0.1的請求是一樣的。那么便可構造payload繞過。
這道題讀取/etc/hosts 或者 /proc/net/arp
然后在內網的一台服務器主頁可以找到flag 比較坑的是頁面內容是404 但是響應碼是200 長度又和別的ip的404頁面一模一樣。
更多關於ssrf可以到http://bobao.360.cn/learning/detail/240.html學習。
