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?

HackTheBox Writeup:Chemistry

Posted at

はじめに

本記事はHackTheBoxのWriteupです。

Machineは、Chemistryです。

Chemistryでは、Pythonのライブラリに関する脆弱性について学びます。

スキャニング

はじめにポートスキャンを実行します。

以下では事前に用意したシェルを介してポートスキャンを実行しています。

##################
# Port scan tool #
##################
 *Detailed scan :1
 *Full scan     :2


 ***Select scanning method by number***
1
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-10-27 23:30 JST
Nmap scan report for 10.10.11.38
Host is up (0.25s latency).

PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.11 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 b6:fc:20:ae:9d:1d:45:1d:0b:ce:d9:d0:20:f2:6f:dc (RSA)
|   256 f1:ae:1c:3e:1d:ea:55:44:6c:2f:f2:56:8d:62:3c:2b (ECDSA)
|_  256 94:42:1b:78:f2:51:87:07:3e:97:26:c9:a2:5c:0a:26 (ED25519)
5000/tcp open  upnp?
| fingerprint-strings: 
|   GetRequest: 
|     HTTP/1.1 200 OK
|     Server: Werkzeug/3.0.3 Python/3.9.5
|     Date: Sun, 27 Oct 2024 14:30:54 GMT
|     Content-Type: text/html; charset=utf-8
|     Content-Length: 719
|     Vary: Cookie
|     Connection: close
|     <!DOCTYPE html>
|     <html lang="en">
|     <head>
|     <meta charset="UTF-8">
|     <meta name="viewport" content="width=device-width, initial-scale=1.0">
|     <title>Chemistry - Home</title>
|     <link rel="stylesheet" href="/static/styles.css">
|     </head>
|     <body>
|     <div class="container">
|     class="title">Chemistry CIF Analyzer</h1>
|     <p>Welcome to the Chemistry CIF Analyzer. This tool allows you to upload a CIF (Crystallographic Information File) and analyze the structural data contained within.</p>
|     <div class="buttons">
|     <center><a href="/login" class="btn">Login</a>
|     href="/register" class="btn">Register</a></center>
|     </div>
|     </div>
|     </body>
|   RTSPRequest: 
|     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|     "http://www.w3.org/TR/html4/strict.dtd">
|     <html>
|     <head>
|     <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|     <title>Error response</title>
|     </head>
|     <body>
|     <h1>Error response</h1>
|     <p>Error code: 400</p>
|     <p>Message: Bad request version ('RTSP/1.0').</p>
|     <p>Error code explanation: HTTPStatus.BAD_REQUEST - Bad request syntax or unsupported method.</p>
|     </body>
|_    </html>
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port5000-TCP:V=7.94SVN%I=7%D=10/27%Time=671E4E9D%P=x86_64-pc-linux-gnu%
SF:r(GetRequest,38A,"HTTP/1\.1\x20200\x20OK\r\nServer:\x20Werkzeug/3\.0\.3
SF:\x20Python/3\.9\.5\r\nDate:\x20Sun,\x2027\x20Oct\x202024\x2014:30:54\x2
SF:0GMT\r\nContent-Type:\x20text/html;\x20charset=utf-8\r\nContent-Length:
SF:\x20719\r\nVary:\x20Cookie\r\nConnection:\x20close\r\n\r\n<!DOCTYPE\x20
SF:html>\n<html\x20lang=\"en\">\n<head>\n\x20\x20\x20\x20<meta\x20charset=
SF:\"UTF-8\">\n\x20\x20\x20\x20<meta\x20name=\"viewport\"\x20content=\"wid
SF:th=device-width,\x20initial-scale=1\.0\">\n\x20\x20\x20\x20<title>Chemi
SF:stry\x20-\x20Home</title>\n\x20\x20\x20\x20<link\x20rel=\"stylesheet\"\
SF:x20href=\"/static/styles\.css\">\n</head>\n<body>\n\x20\x20\x20\x20\n\x
SF:20\x20\x20\x20\x20\x20\n\x20\x20\x20\x20\n\x20\x20\x20\x20<div\x20class
SF:=\"container\">\n\x20\x20\x20\x20\x20\x20\x20\x20<h1\x20class=\"title\"
SF:>Chemistry\x20CIF\x20Analyzer</h1>\n\x20\x20\x20\x20\x20\x20\x20\x20<p>
SF:Welcome\x20to\x20the\x20Chemistry\x20CIF\x20Analyzer\.\x20This\x20tool\
SF:x20allows\x20you\x20to\x20upload\x20a\x20CIF\x20\(Crystallographic\x20I
SF:nformation\x20File\)\x20and\x20analyze\x20the\x20structural\x20data\x20
SF:contained\x20within\.</p>\n\x20\x20\x20\x20\x20\x20\x20\x20<div\x20clas
SF:s=\"buttons\">\n\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<center
SF:><a\x20href=\"/login\"\x20class=\"btn\">Login</a>\n\x20\x20\x20\x20\x20
SF:\x20\x20\x20\x20\x20\x20\x20<a\x20href=\"/register\"\x20class=\"btn\">R
SF:egister</a></center>\n\x20\x20\x20\x20\x20\x20\x20\x20</div>\n\x20\x20\
SF:x20\x20</div>\n</body>\n<")%r(RTSPRequest,1F4,"<!DOCTYPE\x20HTML\x20PUB
SF:LIC\x20\"-//W3C//DTD\x20HTML\x204\.01//EN\"\n\x20\x20\x20\x20\x20\x20\x
SF:20\x20\"http://www\.w3\.org/TR/html4/strict\.dtd\">\n<html>\n\x20\x20\x
SF:20\x20<head>\n\x20\x20\x20\x20\x20\x20\x20\x20<meta\x20http-equiv=\"Con
SF:tent-Type\"\x20content=\"text/html;charset=utf-8\">\n\x20\x20\x20\x20\x
SF:20\x20\x20\x20<title>Error\x20response</title>\n\x20\x20\x20\x20</head>
SF:\n\x20\x20\x20\x20<body>\n\x20\x20\x20\x20\x20\x20\x20\x20<h1>Error\x20
SF:response</h1>\n\x20\x20\x20\x20\x20\x20\x20\x20<p>Error\x20code:\x20400
SF:</p>\n\x20\x20\x20\x20\x20\x20\x20\x20<p>Message:\x20Bad\x20request\x20
SF:version\x20\('RTSP/1\.0'\)\.</p>\n\x20\x20\x20\x20\x20\x20\x20\x20<p>Er
SF:ror\x20code\x20explanation:\x20HTTPStatus\.BAD_REQUEST\x20-\x20Bad\x20r
SF:equest\x20syntax\x20or\x20unsupported\x20method\.</p>\n\x20\x20\x20\x20
SF:</body>\n</html>\n");
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 118.82 seconds
Scan completed

上記ポートスキャンの結果を基に調査を行います。

列挙

ポートスキャンの結果を踏まえて、5000番ポートにアクセスすると、以下の様な画面が表示されます。

スクリーンショット 2024-10-27 23.37.51.png

Chemistry CIF Analyzerのアプリケーションを使用するにはアカウントの登録が必要なため、アカウントの登録を行います。

スクリーンショット 2024-10-27 23.38.00.png

アカウント登録後、Dashboardの画面に遷移します。

スクリーンショット 2024-10-27 23.42.05.png
Dashboardの画面ではCIFのファイルをアップロードすることができます。

Crystallographic Information File (CIF) は、国際結晶学連合(IUCr)によって策定された結晶構造を記述するための標準的なファイルフォーマットです。

PythonではCIFの解析に便利なライブラリがあります。

  • ASE (Atomic Simulation Environment)
  • PyCifRW
  • pymatgen (Python Materials Genomics)

脆弱性分析

GoogleでCIF EXPLOITなどのワードで検索すると、pymatgenのPoCが見つかります。

pymatgenで使用されているJonesFaithfulTransformation.from_transformation_str()メソッドは、入力処理にeval()を安全に使用していないため、信頼できない入力を解析する際に任意のコードを実行することができるCVE-2024-23346の脆弱性が存在しています。

システムハッキング

上記PoCを参考にしながら足場を作ります。

アクセスの獲得

リバースシェルを組み込んだCIFファイルを作成してアップロードします。

スクリーンショット 2024-10-27 23.49.00.png

CIFファイルをアップロード後、リスナーを用意した状態で「View」のボタンを押します。

スクリーンショット 2024-10-27 23.49.14.png

リバースシェルが取得できます。

listening on [any] 4444 ...
connect to [<Your IP address>] from (UNKNOWN) [10.10.11.38] 57002
sh: 0: can't access tty; job control turned off
$ 

ユーザーフラグ

カレントディレクトリは、/home/appディレクトリです。

水平展開を行うにあたり/homeディレクトリ配下のユーザーを確認します。

total 16
drwxr-xr-x  4 root root 4096 Jun 16 23:10 ./
drwxr-xr-x 19 root root 4096 Oct 11 11:17 ../
drwxr-xr-x  8 app  app  4096 Oct 28 13:38 app/
drwxr-xr-x  6 rosa rosa 4096 Oct 28 13:36 rosa/

上記結果を踏まえて、rosaユーザーの認証情報を探索します。カレントディレクトリ配下のinstanceディレクトリを確認すると、SQLiteで使用していると思われるdatabase.dbファイルを発見しました。

total 28
drwx------ 2 app app  4096 Oct 28 13:36 ./
drwxr-xr-x 8 app app  4096 Oct 28 13:33 ../
-rwx------ 1 app app 20480 Oct 28 13:36 database.db*

以下のコマンドを実行して、データベースに接続します。

sqlite3 database.db

SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.

テーブル情報を確認します。

sqlite> .tables
structure  user

SQLの実行結果が見やすい様にヘッダーなどを設定します。

sqlite> .header on
sqlite> .mode column

userテーブルを確認すると、パスワードはmd5で暗号化されていることが分かります。

sqlite> select * from user;
id          username    password                        
----------  ----------  --------------------------------
1           admin       2861debaf8d99436a10ed6f75a252abf
2           app         197865e46b878d9e74a0346b6d59886a
3           rosa        [REDACTED]
4           robert      02fcf7cfc10adc37959fb21f06c6b467
5           jobert      3dec299e06f7ed187bac06bd3b670ab2
6           carlos      9ad48828b0955513f7cf0f7f6510c8f8
7           peter       6845c17d298d95aa942127bdad2ceb9b
8           victoria    c3601ad2286a4293868ec2a4bc606ba3
9           tania       a4aa55e816205dc0389591c9f82f43bb
10          eusebio     6cad48078d0241cca9a7b322ecd073b3
11          gelacia     4af70c80b68267012ecdac9a7e916d18
12          fabian      4e5d71f53fdd2eabdbabb233113b5dc0
13          axel        9347f9724ca083b17e39555c36fd9007
14          kristel     6896ba7b11a62cacffbdaded457c6d92
15          abc123      195423df846dfabbd53e78e770bc9700
16          aaa         08f8e0260c64418510cefb2b06eee5cd
17          test        098f6bcd4621d373cade4e832627b4f6
18          pzt         4cd738ebc0a1305998b9619ad36a68d8

上記結果よりrosaユーザーのパスワードを解析します。

スクリーンショット 2024-10-28 22.42.34.png

解析したパスワードを用いてSSHの接続を行います。

$ ssh rosa@<IP address>

ユーザーフラグが確認できます。

total 36
drwxr-xr-x 5 rosa rosa 4096 Oct 28 13:47 ./
drwxr-xr-x 4 root root 4096 Jun 16 23:10 ../
lrwxrwxrwx 1 root root    9 Jun 17 01:50 .bash_history -> /dev/null
-rw-r--r-- 1 rosa rosa  220 Feb 25  2020 .bash_logout
-rw-r--r-- 1 rosa rosa 3771 Feb 25  2020 .bashrc
drwx------ 2 rosa rosa 4096 Jun 15 20:38 .cache/
drwxrwxr-x 4 rosa rosa 4096 Jun 16 16:04 .local/
-rw-r--r-- 1 rosa rosa  807 Feb 25  2020 .profile
lrwxrwxrwx 1 root root    9 Jun 17 01:51 .sqlite_history -> /dev/null
drwx------ 2 rosa rosa 4096 Jun 15 18:24 .ssh/
-rw-r--r-- 1 rosa rosa    0 Jun 15 20:43 .sudo_as_admin_successful
-rw-r----- 1 root rosa   33 Oct 28 13:32 user.txt

ルートフラグ

ルートフラグを取得するためには、権限昇格が必要です。

更に列挙を行うためssコマンドを実行すると、ローカルの8080番で稼働しているサービスが見つかりました。

ss -aln -t4

State             Recv-Q            Send-Q                       Local Address:Port                         Peer Address:Port            Process            
LISTEN            0                 128                              127.0.0.1:8080                              0.0.0.0:*                                  
LISTEN            0                 4096                         127.0.0.53%lo:53                                0.0.0.0:*                                  
LISTEN            0                 128                                0.0.0.0:22                                0.0.0.0:*                                  
LISTEN            0                 128                                0.0.0.0:5000                              0.0.0.0:*   

以下のコマンドを実行して、ポートフォワーディングを行ないます。

$ ssh -L 8080:localhost:8080 rosa@<IP address>

ローカルの8080番ポートにアクセスすると、以下の様なページが表示されます。

スクリーンショット 2024-10-28 22.51.20.png

ページ内を見ても他にヒントは得られなかったため、gobusterを用いてコンテンツ探索を行います。

$ gobuster dir -u http://localhost:8080 -w /usr/share/wordlists/dirb/common.txt

===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://localhost:8080
[+] Method:                  GET
[+] Threads:                 10
[+] Wordlist:                /usr/share/wordlists/dirb/common.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.6
[+] Timeout:                 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/assets               (Status: 403) [Size: 14]
Progress: 4614 / 4615 (99.98%)
===============================================================
Finished
===============================================================

上記結果より/assetsディレクトリを発見しました。

/assetsディレクトリを利用して、アクセス及びルートフラグを取得するためには、CVE-2024-23334の脆弱性を利用します。

おわりに

タイトル回収が面白いMachineでした。

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?