Introduction to Bedside:

In this writeup, we will explore the “Bedside” machine from Hack The Box, categorized as an Medium difficulty challenge. This walkthrough will cover the reconnaissance, exploitation, and privilege escalation steps required to capture the flag.
Objective on Bedside machine:
The goal of this walkthrough is to complete the “Bedside” machine from Hack The Box by achieving the following objectives:
User Flag
Enumeration revealed two web services, including research.bedside.htb, which hosted a file-upload portal powered by pdfminer.six. Further analysis uncovered a server-side deserialization flaw that provided access as datawrangler inside a Docker container. Container enumeration then exposed an internal service on port 3000 with a path traversal vulnerability. The issue revealed the developer user’s private SSH key, which I used to connect to the host as developer and retrieve the user flag.
Root Flag
The developer account had passwordless sudo access to bedside_trainer.py. Since the script used MONAI and PyTorch to load checkpoints from a writable datastore directory, I investigated its checkpoint-handling process. By examining how the trainer processed serialized model files and triggering the privileged workflow, I eventually gained root access and retrieved the root flag.
Enumerating the Bedside Machine
Reconnaissance:
Nmap Scan:
Begin with a network scan to identify open ports and running services on the target machine.
nmap -Pn -sC -sV 10.129.84.199 -oA initialNmap Output:
┌─[dark@parrot]─[~/Documents/htb/bedside]
└──╼ $nmap -Pn -sC -sV 10.129.84.199 -oA initial
Starting Nmap 7.95 ( https://nmap.org ) at 2026-12-03 06:11 EST
Warning: 10.129.84.199 giving up on port because retransmission cap hit (6).
Stats: 0:03:35 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 99.99% done; ETC: 06:14 (0:00:00 remaining)
Nmap scan report for 10.129.84.199
Host is up, received user-set (2.3s latency).
Not shown: 65526 closed tcp ports (reset)
PORT STATE SERVICE REASON VERSION
22/tcp open ssh syn-ack ttl 63 OpenSSH 10.0p2 Debian 7+deb13u4 (protocol 2.0)
80/tcp open http syn-ack ttl 63 Apache httpd 2.4.68
|_http-title: Did not follow redirect to http://bedside.htb/
|_http-server-header: Apache/2.4.68 (Debian)
Service Info: Host: default; OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 305.40 secondsAnalysis:
- Port 22 (SSH): OpenSSH 10.0p2 running on Debian.
- Port 80 (HTTP): Apache 2.4.68 running on Debian, redirecting to
bedside.htb.
Web Enumeration on Bedside machine

Visiting http://bedside.htb revealed a medical-themed landing page for Bedside Clinic, promoting AI-powered heart health services. The page featured navigation links for About Us, Treatments, AI Innovations, and Contact, alongside a prominent consultation button. However, no interactive features or user input fields were immediately apparent.
Virtual Host Discovery on Bedside machine

Gobuster also performed a virtual host scan using the same wordlist while excluding common error codes.

Using ffuf with a large subdomain wordlist and response-size filtering revealed research.bedside.htb as a valid virtual host, returning HTTP 200 with a response size of 3152 bytes.
Research Portal Analysis

The research.bedside.htb virtual host displayed the Bedside Research Portal, where staff could upload medical images and documents for AI model training. The upload form supported JPEG, PNG, BMP, TIFF, DCM, PDF, and archive formats.
Exploiting pdfminer.six Deserialization

Intercepting a request to the research portal revealed the custom X-Powered-By: pdfminer.six header. This suggests that the backend uses Python’s pdfminer.six library to parse uploaded PDFs on the server.

Further research into pdfminer.six reveals an arbitrary code execution vulnerability caused by insecure pickle deserialization. An attacker can exploit this behavior by supplying a compressed pickle file containing malicious code. When pdfminer.six processes the PDF, the deserialization process executes that code automatically.
Technical Analysis of CVE-2025-64512 in pdfminer.six
CVE-2025-64512 affects pdfminer.six and allows arbitrary code execution through insecure pickle deserialization. The vulnerable CMapDB._load_data() function uses pickle.loads() to load compressed CMap files. By crafting a PDF that references a malicious .pickle.gz file, an attacker can trigger code execution when the application processes the document.
Preparing the Malicious Pickle Payload

The proof of concept uses a pickle gadget to trigger os.system during deserialization and initiate a reverse shell. It then compresses the payload with gzip and saves it as Evil.pickle.gz for upload testing.
Creating the PDF Trigger

Python generated a minimal PDF from scratch with a simple Catalog, Pages, and Page object structure. This template provided a starting point for subsequent deserialization testing.

To verify the workflow, I created a test pickle containing a basic object, compressed it with gzip, and successfully loaded it again.

The resulting malicious.pickle.gz passed gzip validation and contained a 68-byte pickle stream. The archive was ready for testing through the research portal’s PDF processing workflow.

Running the custom pdf.py script successfully generated malicious.pdf. This minimal PDF serves as a container for subsequent deserialization testing.
Uploading the Malicious PDF

A multipart POST request sent the gzip-compressed pickle file to the research portal. The server responded with HTTP 200 and the X-Powered-By: pdfminer.six header, indicating that it accepted the upload without immediate rejection.

The browser shows malicious.pickle.gz selected in the upload form. Although .gz does not appear in the explicitly supported formats, the application still accepts the file, possibly because it treats it as an archive.

Netcat listened on port 9007 for an incoming connection during the payload-processing test.

The upload form displays malicious.pdf as the selected file, preparing the next stage, in which the backend processes the PDF through pdfminer.six.

A multipart request submitted the crafted PDF to the research portal. The server returned HTTP 200 with the pdfminer.six header, indicating that it accepted the file for processing.
Obtaining a Shell as datawrangler

After uploading the trigger PDF, a reverse shell connects back to the listener on port 9007. The session lands as the low-privileged datawrangler user inside the /app directory of the container.
Container Enumeration

Standard networking utilities (netstat and ss) are not present on the system. Alternative methods such as reading /proc/net/tcp will be required for further enumeration of listening services.

Reading /proc/net/tcp reveals several established and listening sockets. Notable entries include local ports in the 0x0016 (22) and 0x0050 (80) ranges, as well as multiple connections from the container’s internal IP, confirming active services and outbound traffic.
Discovering Internal Services

Inside /datastore the directories checkpoints, logs, models, processed, raw and a recently modified staging folder are visible.

Listing the root filesystem shows a typical container environment. Of particular interest are the writable datastore directory owned by datawrangler:dataops

The empty .dockerenv file is highlighted, reinforcing that the current shell is running inside a Docker container. This suggests potential container-escape or lateral-movement opportunities.

A path-traversal request against an internal service on port 3000 successfully reads /etc/passwd. The response reveals several users, including developer (uid 1000) and the current datawrangler account, providing useful information for further privilege escalation.

Inside /app only two files are present: pdf_watcher.py (the main processing script) and a short requirements.txt. The watcher script is the component responsible for monitoring uploads and invoking pdfminer.six.

The source of pdf_watcher.py shows that it continuously monitors the upload directory, performs basic filename sanitization, and moves processed files into /datastore/staging. The hard-coded paths and limited validation help explain the earlier deserialization vector.

A world-readable portscan.sh script was discovered in /tmp, providing another lead for further enumeration.

Although portscan.sh lacked execute permissions, its contents could still be accessed through the Bash interpreter.

Running the script via bash /tmp/portscan.sh displays its usage syntax, confirming it expects a target IP or hostname and an optional concurrency parameter.

Executing the port scanner against 127.0.0.1 reveals three open ports: 22 (SSH), 80 (HTTP), and 3000 (the internal service previously abused for path traversal).

A path-traversal request against the service on port 3000 successfully retrieves the private SSH key belonging to the developer user (/home/developer/.ssh/id_rsa).

On the attack host the same private key is saved as id_rsa and its permissions are restricted to 600.
Developer SSH Access

Using the stolen private key, an SSH connection is established to developer@bedside.htb. The login succeeds and presents the Bedside Clinic banner, dropping into a shell as the developer user on the host.

The user.txt flag is immediately readable in the developer’s home directory.
Escalate to Root Privileges Access on Bedside machine
Privilege Escalation:

sudo -l reveals that the developer user can execute /usr/bin/python3 /opt/trainer/bedside_trainer.py as root without a password. This script becomes the next privilege-escalation target.
Analyzing the Training Script

The privileged script /opt/trainer/bedside_trainer.py is examined. It is a MONAI-based training utility that loads data from the datastore directories, builds a model, and accepts optional arguments for epochs, batch size, learning rate, and a hardware scanner device.
Testing the Initial SUID Payload

A short Python script is written that defines a malicious class whose __reduce__ method executes a command chain to copy /bin/bash to /usr/local/bin/root, change ownership to root, and set the SUID bit. The object is then serialized with torch.save into exploit.pt.

Running the exploit script produces the file exploit.pt containing the pickled payload.

A listing of /tmp shows several systemd-private directories and a VMware-related file, confirming the host environment.

Both exploit.pt and its generator script were placed in /tmp, ready for transfer.

Port 8888 hosted a Python HTTP server to serve the model file to the container.

From the earlier datawrangler shell, the file is fetched via curl and saved into /datastore/checkpoints/exploit.pt, a location the trainer is expected to load from.

The attacker’s HTTP server logs confirm that the container successfully retrieved exploit.pt twice.
Understanding the SUID Restriction

Running the trainer with elevated privileges triggered file promotion and data loading before MONAI/PyTorch raised an exception in the DataLoader code. The traceback showed that the checkpoint reached the model-loading stage.

A background cleanup loop monitored the processed and staging directories, removing unexpected .txt files to prevent interference with subsequent trainer runs.

After generating the checkpoint, I inspected /bin/bash using ls -la. The output showed that the binary still had its original permissions, indicating that the intended permission change had not taken effect at this stage.

I modified the payload to target /usr/local/bin/root, then generated root.pt and packaged it into root.zip. Finally, I uploaded the archive to the research web application using a multipart HTTP request to its file upload endpoint.

After switching to the datawrangler account, I extracted root.pt from the uploaded archive into /datastore/checkpoints/. I also created a placeholder image under /datastore/processed/ using Base64 decoding. This prepared the files for the application’s checkpoint processing workflow.

Back in the developer account, I used its sudo permission to run the trainer. The command also attempted to execute /usr/local/bin/root to verify the execution context and retrieve the root flag. However, the attempt failed because that binary did not exist at the specified path.
Preparing the Sudoers Payload

Although the initial payload successfully executed, the system neutralized SUID privileges. To bypass this restriction, a malicious PyTorch checkpoint uses a custom class that overrides __reduce__() to execute a system command during deserialization. This command adds the developer account to /etc/sudoers.d/developer, granting passwordless sudo access. Finally, torch.save() writes the payload to /tmp/root.pt.

Running the Python script generates the malicious checkpoint at /tmp/root.pt.

A temporary HTTP server was started on port 4444, bound to 127.0.0.1.

From the datawrangler account, remove any existing checkpoint files. Then, use curl to download root.pt into /datastore/checkpoints/ as zzz_root.pt. Finally, create a small PNG file in /datastore/processed/ to trigger the training pipeline and make it process the uploaded checkpoint.
Triggering the Training Pipeline

Obtaining Root Access on Bedside machine

The sudo permission opened a Bash shell without requesting an interactive password. The prompt changed to root@bedside, confirming root-level access. From the root shell, I retrieved the flag from /root/root.txt.



