Skip to content

D^3CTF2025 jtar(复现)

前言

题目所给附件为war,由于只有部分源码,加上本地tomcat+idea调试没搞好,这里就用springboot直接搭了一个

根据sq师傅的writeup复现,具体参考D^3CTF 2025 writeup by Mini-Venom

分析

Controller中给出三个路由

  • view

page可控,这里可以直接解析jsp文件

  • Upload

可以上传文件,但是有黑名单,过滤了jsp jspx这些

  • BackUp

打包和解压两个操作,deepseek生成的流程图:

image-20250602212632467

这里的文件上传没有问题,我们直接来看BackUp路由,跟进tarDirectory方法

image-20250602213802912

这里有putNextEntrynew TarEntry方法

image-20250602213831820

继续跟进putNextEntry方法

image-20250602214026456

这里调用了writeEntryHeader方法

image-20250602214159250

然后调用了TarHeader#getNameBytes方法

image-20250602214735308

(byte)name.charAt(i)这里存在强制类型转换,会把char强制转换成byte,也就是字符转换为字节数组

Java的char是16位Unicode字符,而byte[]是8位字节数组,这里的转换就相当于取字符的低八位

image-20250602215411370

那么思路就很明显了,我们只要构造低八位是0x70的Unicode字符,经过tar->untar就可以得到jsp文件

这里借用sq师傅的脚本

1
2
3
4
5
6
7
8
9
10
11
12
target_byte_value = 0x70  # 对应 ASCII 字符 'p'

matching_chars = []
for code_point in range(0x10000):
if (code_point & 0xFF) == target_byte_value:
try:
char = chr(code_point)
matching_chars.append((char, hex(code_point)))
except:
continue
for char, code_hex in matching_chars:
print(f"字符: {char} | Unicode: {code_hex}")

image-20250602215601809

生成了很多,我们随便选一个,构造exp.jsɰ

1
由于是本地测试,内容就不写了,一个回显马就行

上传

image-20250602215909329

打包解包后得到jsp文件

image-20250602220107448

About this Post

This post is written by p0l1st, licensed under CC BY-NC 4.0.

#CTF