Preloader
Server Security

Tutorial: Xtream UI Protection with Fail2Ban

Secure your IPTV server by automatically banning malicious IPs attempting to exploit your panel.


Why Use Fail2Ban?

Xtream UI servers are often targets for brute-force attacks and scanners looking for vulnerabilities. Fail2Ban monitors your server logs (like Nginx access logs) for suspicious activity—such as repeated 404 errors or failed login attempts—and updates your firewall rules to ban those IP addresses automatically.

1Step 1: Install Fail2Ban

First, we need to install the Fail2Ban package on your Ubuntu server. Open your terminal (PuTTY) and run:

apt-get update apt-get install fail2ban -y

2Step 2: Define the Filter

We need to tell Fail2Ban what to look for. We will create a filter configuration file that defines the "bad behavior" using Regular Expressions (Regex).

Create a new file named xtream.conf:

nano /etc/fail2ban/filter.d/xtream.conf

Paste the following content into the file. This regex targets specific attack patterns often seen on Xtream UI servers:

[Definition] failregex = ^<HOST> -.* "GET \/portal\.php\?type=stb&action=(?:handshake&token=&prehash=0&JsHttpRequest=1\-xml|get_profile) HTTP\/1\.1" 200 .* ^<HOST> - .* 404 0 .* ^<HOST>.*"(GET|POST).*" (404|444|403|400) .*$ ignoreregex =

Press CTRL+X, then Y, then Enter to save.

3Step 3: Configure the Jail

Now we create a "Jail" that uses our filter. This tells Fail2Ban which log file to watch, how many failures are allowed, and how long to ban the IP.

Open or create jail.local:

nano /etc/fail2ban/jail.local

Add the following configuration block:

[xtream] enabled = true filter = xtream action = iptables-allports[protocol=all, blocktype=DROP] logpath = /home/xtreamcodes/iptv_xtream_codes/logs/main.access.log maxretry = 5 bantime = 3600 ignoreip = 127.0.0.1 YOUR_OWN_IP

Note: Change YOUR_OWN_IP to your actual home/office IP address to prevent locking yourself out.

4Step 4: Verify Nginx Logging

Fail2Ban relies on logs. You must ensure your Xtream UI Nginx configuration is actually writing to the log file we specified.

Check your Nginx config:

nano /home/xtreamcodes/iptv_xtream_codes/nginx/conf/nginx.conf

Make sure there is a line enabling the access log, similar to:

access_log /home/xtreamcodes/iptv_xtream_codes/logs/main.access.log;

5Step 5: Restart and Test

Finally, restart the Fail2Ban service to apply the changes.

service fail2ban restart

To check if it is working and see currently banned IPs, you can use:

fail2ban-client status xtream

Advanced: Log Rotation

To prevent your log file from getting too huge, you can add a cron job to clear it periodically. This keeps Fail2Ban efficient.

Add this to your crontab (crontab -e):

0 */1 * * * echo "" > /home/xtreamcodes/iptv_xtream_codes/logs/main.access.log

This empties the log file every hour.