Overview
This challenge involves exploiting a web application (likely written in Go) that suffers from two critical vulnerabilities: predictable session ID generation and an insecure ZIP extraction process. By chaining these flaws, an attacker can predict an administrator's session file path, use a symlink attack to overwrite it with forged JSON data, and successfully hijack the admin account to retrieve the flag.
the login problem
We can llook the function login. As we can see this function had problems of Predictability ans Session pollution
Vulnerability Analysis
1. Insecure Session Generation (Cryptographic Flaw)
The application generates session IDs using a simple SHA-256 hash of the current Unix timestamp (in seconds). Because the precision is limited to a single second, the entropy is effectively zero if the attacker knows exactly when a session was created.
2. Arbitrary File Write via Symlink Following
The application features a file upload endpoint (/user/upload) that accepts ZIP archives and extracts them into a user-specific directory. While the extraction library likely protects against traditional "Zip Slip" directory traversal (e.g., blocking ../ in filenames), it fails to prevent symlink following. If a user uploads a symlink pointing to a sensitive system file, and then uploads a second regular file with the exact same name, the archiver will open the symlink and write the new file's contents directly into the targeted destination.
The Exploitation Chain
The attack requires precision timing and a multi-step upload process to bypass the extraction protections.
Step 1: Session Prediction & Forcing Creation
To hijack the admin session, the session file must actually exist on the disk. The exploit script first triggers a fake login attempt for the admin user (password: "passata di pomodoro"). Immediately after triggering this login, the script captures its own local timestamp and hashes it. Because the attacker controls the exact moment the server processes the login, the local hash matches the server's generated session ID. We trigger the login for run the function PrepareSession.
- Target Path:
/tmp/sessions/admin/<predicted_sha256_hash>
Step 2: The Two-Step Symlink Overwrite
With the target file path known, the exploit leverages the ZIP upload endpoint to overwrite the admin's session data.
- The Portal (Upload 1): A ZIP archive is uploaded containing a symbolic link with a randomized name (e.g.,
e3b0c442...). This link points directly to the predicted admin session file in/tmp/sessions/admin/. - The Payload (Upload 2): A second ZIP is uploaded containing a flat, regular file bearing the exact same randomized name. The contents of this file contain the forged JSON session data:
{ "username": "admin", "id": 2, "role": "admin" }
When the backend extracts the second archive, it attempts to write to the file. Finding the symlink created in Step 1, the operating system follows it and writes the forged JSON directly over the administrator's actual session file.
Step 3: Session Hijacking
Once the admin session file on the server has been overwritten with the payload, the final step is to switch the local session context. The script modifies the local username cookie to admin. When the request is sent to the /user/admin endpoint, the server reads the poisoned session file, deserializes the JSON into its Go struct, and grants administrative access, revealing the HTB{...} flag.
###Exploit Code