进入题目,注意到url是
http://9a3ac4d3-ee63-44c3-a2a4-b2168576598d.node3.buuoj.cn/index.php?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd=
而中间的img参数的内容看起来像base64,先解码试试。
经过两次base64解码加上一次hex解码,得到555.png。
那么接下来尝试获取index.php的内容:
<?phperror_reporting(E_ALL || ~ E_NOTICE);header('content-type:text/html;charset=utf-8');$cmd = $_GET['cmd'];if (!isset($_GET['img']) || !isset($_GET['cmd']))header('Refresh:0;url=./index.php?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd=');$file = hex2bin(base64_decode(base64_decode($_GET['img'])));$file = preg_replace("/[^a-zA-Z0-9.]+/", "", $file);if (preg_match("/flag/i", $file)) {echo '<img src ="./ctf3.jpeg">';die("xixi~ no flag");} else {$txt = base64_encode(file_get_contents($file));echo "<img src='data:image/gif;base64," . $txt . "'></img>";echo "<br>";}echo $cmd;echo "<br>";if (preg_match("/ls|bash|tac|nl|more|less|head|wget|tail|vi|cat|od|grep|sed|bzmore|bzless|pcre|paste|diff|file|echo|sh|\'|\"|\`|;|,|\*|\?|\\|\\\\|\n|\t|\r|\xA0|\{|\}|\(|\)|\&[^\d]|@|\||\\$|\[|\]|{|}|\(|\)|-|<|>/i", $cmd)) {echo("forbid ~");echo "<br>";} else {if ((string)$_POST['a'] !== (string)$_POST['b'] && md5($_POST['a']) === md5($_POST['b'])) {echo `$cmd`;} else {echo ("md5 is funny ~");}}?><html><style>body{background:url(./bj.png) no-repeat center center;background-size:cover;background-attachment:fixed;background-color:#CCCCCC;}</style><body></body></html>
主要看下面的echo$cmd`部分,如果想要执行这一句需要绕过前面两个过滤。<br />禁用了很多读取文件常用的命令,比如tac、nl、more、head、tail、cat、echo、vi等被ban了,单引号、@、分号、逗号、$、{、}等构造符号也被禁了。<br />首先用dir查看当前目录文件和根目录下面的文件,找到flag位置:/flag<br />接着想办法绕过过滤读取flag。<br />本来程序里是有过滤掉`:
但是发现还是可以使用\来绕过过滤,所以
ca\t /flag
除了\,还可以使用sort命令:
Linux sort命令用于将文本文件内容加以排序。 sort可针对文本文件的内容,以行为单位来排序。
sort /flag

