fail2ban Privilege Escalation
The user michael could restart the fail2ban service as root and had write access to the action.d configuration folder. By editing an action file to run a command when an IP is banned, the attacker could execute arbitrary commands as root and escalate privileges.
Published on infosecwriteups.com
It is an Intrusion Prevention System (IPS), that could be installed on Linux systems in order to protect them from attacks like port scan or brute force. Imagine that you have the ssh service on your Linux machine, which can be accessed through the Internet.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the sudoers rule allowed the user to restart fail2ban as root, and the action.d directory was writable by a group the user belonged to, so the user could inject commands that fail2ban executed with root privileges.
Impact
An attacker with the user's access could execute arbitrary commands as root, leading to full system compromise.
What the attacker needed
Shell access as user michael; sudo permission to restart fail2ban; write access to action.d folder
How it was found
- Check what commands the user can run with sudo and find that fail2ban can be restarted as root.
- Confirm that the user can write to the action.d folder.
- Edit the iptables-multiport.conf action file to add a command that sets the setuid bit on /bin/bash.
- Restart the fail2ban service with sudo.
- Trigger a ban so that fail2ban runs the action and sets the setuid bit.
- Run bash -p to get a root shell.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Fail2ban is a tool that watches log files and blocks IP addresses that look like attackers. Here, a normal user was allowed to restart that tool as the all-powerful root user and could also change the files that tell fail2ban what to do when it blocks someone. So the user made fail2ban run their own command as root, which gave them full control of the machine.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.