Java File Audit logo

Java File Audit

OrganizationPopular
wgpsec
java-file-audit

Java 源码文件操作类漏洞审计。当在 Java 白盒审计中需要检测文件相关漏洞时触发。 覆盖 5 类文件风险: 任意文件上传(MultipartFile/Servlet Part/类型绕过)、任意文件读取(NIO/IO流/路径穿越)、 任意文件写入(覆盖配置/WebShell落地)、归档提取漏洞(ZipInputStream/Zip Slip)、文件删除/重命名竞争。 需要 java-audit-pipeline 提供的数据流证据。

Overview

Publisherwgpsec
RepositoryAboutSecurity
Skill namejava-file-audit
Stars
1.7K
Forks
242
Bundled files
1
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by wgpsec on GitHub. Read the source before you install it.

Installation

Install the Java File Audit AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/wgpsec/AboutSecurity.git /tmp/AboutSecurity
mkdir -p .claude/skills
cp -r /tmp/AboutSecurity/skills/code-audit/java/java-file-audit .claude/skills/java-file-audit
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Java File Audit in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Java File Audit on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Java File Audit is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Java 文件操作类漏洞源码审计

本 skill 聚焦源码层面判断"文件操作漏洞是否成立",核心是验证路径可控性、文件名可控性和内容可控性。构造上传绕过 payload、目录穿越利用链等运行时利用技术属于对应黑盒 exploit skill 范畴。

深入参考


Sink 分类决策树

根据遇到的 Sink 函数类型,进入不同审计分支:

Sink 函数分支典型严重度
MultipartFile.transferTo() / Part.write()文件上传Critical-High
FileInputStream / Files.readAllBytes() / new File(path) / ClassLoader.getResourceAsStream()文件读取High-Medium
FileOutputStream / Files.write() / FileWriter文件写入Critical-High
ZipInputStream.getNextEntry() / ZipFile.entries()归档提取High
File.delete() / Files.delete()文件删除Medium

文件上传审计要点

上传漏洞本质是三要素同时满足: 可执行扩展名 + Web 可达存储路径 + 未被重命名/内容清洗。

  • MultipartFile: file.transferTo(new File(dir + file.getOriginalFilename()))getOriginalFilename() 返回客户端原始文件名,可含 ../ 路径穿越或恶意扩展名
  • Servlet Part: part.write(uploadPath + fileName) — 检查 fileName 是否来自 part.getSubmittedFileName() 且未净化
  • ContentType 校验 vs 扩展名校验: file.getContentType() 来自客户端 HTTP 头,完全可伪造;扩展名白名单更可靠但需 toLowerCase() 处理
  • 存储路径可控性: 文件名中的 ../ 跳出上传目录,Paths.get(dir, fileName).normalize() 后需验证前缀
  • Spring multipart-config: spring.servlet.multipart.location / max-file-size / max-request-size 配置影响上传行为,检查是否限制合理
  • 文件头 Magic bytes 校验: 真实类型检测需读取文件头字节(如 ImageIO.read() 或 Apache Tika),而非信任 Content-Type

文件读取审计要点

路径穿越是文件读取漏洞的核心,../ 及其变体可跳出预期目录:

  • 路径穿越 ../: new FileInputStream("/data/" + userPath) — 用户输入 ../../etc/passwd 读取任意文件
  • NIO 安全模式: Path resolved = baseDir.resolve(userInput).normalize(); if (!resolved.startsWith(baseDir)) throw ...normalize() 消除 ../startsWith() 校验前缀
  • URL 编码绕过: %2e%2e%2f../)、双重编码 %252e%252e%252f — 检查框架是否自动解码后再传入路径
  • ClassLoader.getResourceAsStream: 类路径读取受 ClassLoader 沙箱限制,通常不可穿越到文件系统任意路径,但可读取 classpath 内敏感配置
  • Spring Resource 路径: classpath: 协议限于类路径内,file: 协议可访问文件系统 — 检查协议是否用户可切换

文件写入审计要点

写入漏洞需要: 路径可控 + 内容可控 + 写入路径可被 Web 容器执行。

  • WebShell 写入: Files.write(Paths.get(dir + filename), content.getBytes()) — 路径和内容同时可控时,写入 .jsp 到 Web 根即获得 RCE
  • 配置文件覆盖: 覆写 application.yml / application.properties 修改数据源、重定向等配置;覆写 web.xml 添加恶意 Servlet 映射
  • 日志注入写马: 日志框架记录用户输入 → 日志文件路径可预测 → 配合文件包含或直接写入 JSP 内容到日志
  • 模板文件覆盖: Thymeleaf / FreeMarker 模板目录可写 → 覆盖模板注入 SSTI payload → 下次渲染时触发
  • 安全模式: 路径白名单 + 内容类型校验 + 文件存储到 Web 根外 + 写入权限最小化

归档提取审计要点

Zip Slip 是归档提取最经典的漏洞,恶意归档条目名含 ../ 导致任意路径写入:

  • ZipEntry.getName() 含 ../: new File(destDir, entry.getName()) — 条目名如 ../../webapps/ROOT/shell.jsp 直接写入 Web 目录
  • 安全模式 (Canonical Path 校验): 解压前获取 file.getCanonicalPath()destDir.getCanonicalPath(),验证文件路径以目标目录为前缀
  • TarInputStream / GzipInputStream: 类似风险,tar 条目名同样可含路径穿越
  • 文件覆盖: 即使不穿越目录,恶意归档可覆盖同目录下已有文件(配置文件、库文件)

文件删除审计要点

  • 路径穿越删除: new File(dir + userInput).delete() — 用户输入 ../../important.conf 删除关键文件
  • TOCTOU 竞争: 检查权限 → 执行删除之间的时间窗口,攻击者可替换目标为符号链接指向敏感文件
  • 符号链接跟随: Files.delete(path) 删除链接目标而非链接本身(取决于实现),File.delete() 仅删除链接

检测清单

  • 所有文件类 EVID_* 证据点已逐一审查
  • 上传功能的文件名净化方式已确认(UUID 重命名 vs 原始文件名 vs 白名单扩展名)
  • 上传存储路径是否在 Web 根内、是否可直接通过 URL 访问已验证
  • ContentType 校验 vs 文件头 Magic bytes 校验方式已区分
  • 文件读取路径的穿越防护已检查(normalize + startsWith 模式)
  • 文件写入的路径和内容来源已追踪,是否可写入可执行位置已确认
  • 归档解压函数的条目名称校验已检查(Canonical Path 验证)
  • 文件删除操作的路径校验和符号链接风险已评估
  • 过滤不充分的点已给出绕过思路或标"待验证"
  • 严重度评分使用了统一公式,与 pipeline 一致

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Java File Audit AI skill do?

Java 源码文件操作类漏洞审计。当在 Java 白盒审计中需要检测文件相关漏洞时触发。 覆盖 5 类文件风险: 任意文件上传(MultipartFile/Servlet Part/类型绕过)、任意文件读取(NIO/IO流/路径穿越)、 任意文件写入(覆盖配置/WebShell落地)、归档提取漏洞(ZipInputStream/Zip Slip)、文件删除/重命名竞争。 需要 java-audit-pipeline 提供的数据流证据。

Why use Java File Audit on TypingMind?

Because you install it once and use it with any model. Java File Audit is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Java File Audit in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/wgpsec/AboutSecurity/tree/master/skills/code-audit/java/java-file-audit. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Java File Audit?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Java File Audit?

As many as you like. As long as a model supports skills, you can use Java File Audit with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Java File Audit AI skill free?

It is published on GitHub by wgpsec. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇