Team Write-up
In this write-up, we tackle the "Team" room from TryHackMe. This challenge involves web enumeration, exploiting Local File Inclusion (LFI) to steal SSH keys, lateral movement between users, and finally escalating privileges to root via LXD containers.
Room URL: https://tryhackme.com/room/teamcw
1. Reconnaissance
We start with a standard Nmap scan to identify open ports and services.
sudo nmap -T4 10.82.165.94

The scan reveals three open ports:
- 21/tcp: FTP
- 22/tcp: SSH
- 80/tcp: HTTP
I first tried to access the FTP server using anonymous login, but it failed.

2. Web Enumeration
Moving to port 80, I accessed the website via IP address. It displayed the default Apache2 Ubuntu page. However, inspecting the page source revealed a critical hint in the title tag.

The title said: If you see this add 'team.thm' to your hosts!. I added this entry to my /etc/hosts file to properly resolve the domain name.
Visiting http://team.thm revealed a new website.

I checked robots.txt and found a potential username: dale.

I continued enumeration with Gobuster to find hidden directories.
gobuster dir -u [http://team.thm/scripts](http://team.thm/scripts) -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x php,txt,js,html

Gobuster found /scripts/script.txt. Reading it, I noticed a comment saying the old version of the script had credentials in it and was renamed.

Following this lead, I tried accessing script.old and found FTP credentials inside!

3. FTP Access
With the credentials found (ftpuser), I logged into the FTP server.

I found a file named New_site.txt. It contained information about a new development site under a subdomain and mentioned that SSH keys (id_rsa) are placed in config files.

The note mentioned a subdomain. I added it to /etc/hosts and accessed it.
4. LFI Exploitation
The dev site had a link that looked suspicious: script.php?page=.... This is a classic indicator of Local File Inclusion (LFI) vulnerability.
I confirmed the LFI by reading /etc/passwd.

I also verified I could read /home/dale/user.txt directly via LFI.

Now the goal was to find the SSH private key mentioned earlier. The note said it's in a "config file". I created a wordlist of common config file locations and used Ffuf to fuzz the LFI parameter.

Ffuf found a hit for /etc/ssh/sshd_config. Usually keys aren't there, but this is a CTF. Reading that file via LFI revealed the private SSH key for the user dale at the bottom of the config!

5. SSH & User Flag
I copied the key to my machine, set correct permissions (chmod 600), and logged in as Dale. Remember to remove # from the key.
ssh dale@10.82.165.94 -i id_rsa

I checked sudo -l to see what Dale can do.

Dale can run a script /home/gyles/admin_checks as the user gyles without a password. I analyzed the script. It reads user input into a variable $error and executes it! This is a command injection vulnerability.

I exploited this by inputting /bin/sh -i when prompted for the date. This spawned a shell as gyles.

6. Privilege Escalation
Now as Gyles, I transferred linpeas.sh to enumerate further.

LinPEAS highlighted that Gyles belongs to the lxd group.

Being in the LXD group allows a user to create a privileged container and mount the host's root filesystem into it.

To exploit this, I first needed to build a compatible Alpine Linux image on my attacker machine:
git clone [https://github.com/saghul/lxd-alpine-builder.git](https://github.com/saghul/lxd-alpine-builder.git)
cd lxd-alpine-builder
sudo ./build-alpine
After building it, I transferred the .tar.gz file to the target machine using a Python HTTP server. Then, I executed the following commands on the target machine to import the image and initialize the container:
lxc image import ./alpine-v3.13-x86_64-*.tar.gz --alias myimage
lxd init # (accepted defaults)
lxc init myimage mycontainer -c security.privileged=true
lxc config device add mycontainer mydevice disk source=/ path=/mnt/root recursive=true
lxc start mycontainer
lxc exec mycontainer /bin/sh

Inside the container, I navigated to /mnt/root/root and successfully read the final flag!

Root Flag: THM{[REDACTED]}