Zabbix. Task. Iptables monitoring, which uses as Honeypot
At Honeypot server (Centos 7)
Redirect particular logs to the separated Log-file
yum install epel-release
systemctl disable firewalld
systemctl stop firewalld
yum install -y iptables-services
systemctl enable --now iptables
iptables -F -t filter
iptables -F -t nat
Catching input connections 5060/udp with log-prefix "Attack_SIP: "
iptables -A INPUT -p udp --dport 5060 -j LOG --log-level info --log-prefix "Attack_SIP: "
iptables -A INPUT -p tcp --dport 5060 -j LOG --log-level info --log-prefix "Attack_SIP: "
service iptables save
systemctl restart iptables
Show
iptables -L -v -n -t filter
Rsyslog configuring for log redirection into the file
nano /etc/rsyslog.d/iptables.conf
:msg, contains, "Attack_SIP: " -/var/log/honeypot/iptables/iptables-honeypot.log & ~
mkdir -p /var/log/honeypot/iptables/
chown -R nobody:nobody /var/log/honeypot/iptables/
nano /etc/rsyslog.conf
... $umask 0000 $FileCreateMode 0644
systemctl restart rsyslog
Zabbix-agent
yum install zabbix40-agent
nano /etc/zabbix_agentd.conf
... Server=192.168.166.149 ... ServerActive=192.168.166.149 ... Hostname=sar_honeypot01_166-52 # This host in Zabbix-server must have EXACTLY such name. HOSTNAME of this system (hostnamectl set-hostname <hostname>) may have another name. ...
systemctl enable zabbix-agent
systemctl restart zabbix-agent
# НЕОБЯЗАТЕЛЬНО ЕСЛИ ИСПОЛЬЗУЕТСЯ ТАКАЯ КОНСТРУКЦИЯ ТРИГГЕРА:
- Expression: {sar_honeypot01_166-52:log[/var/log/ssh-honeypot.log].regexp("([0-9]{1,3}[\.]){3}[0-9]{1,3}",5m)}=1 and {sar_honeypot01_166-52:log[/var/log/ssh-honeypot.log].nodata(5m)}=0
- каждый час добавляем в лог строку-разделитель,
- она нужна чтобы забикс сервер корректно обновлял информацию из логов
- и отключал триггер согласно настройкам
crontab -e
0 0 * * * logrotate -f /etc/logrotate.conf 0 */1 * * * echo `date +\%Y-\%m-\%d_\%H-\%M` "devider" >> /var/log/honeypot/iptables/iptables-honeypot.log
At Zabbix-server
Create a host with name "sar_honeypot01_166-52" # This name must be in the zabbix-agent configuration at the Honeypot server.
Create Item
Name: "port_scan_log"
Type: Zabbix agent (active)
Key: log[/var/log/honeypot/iptables/iptables-honeypot.log]
Type of information: logrotate
Update interval: 1s
Create Trigger
The trigger will trigger if there will be a line with IP-address in the logs
Name: Попытка получить доступ по SSH на Honeypot сервер. Возможно, Brute force. Смотрите историю элемента данных "port_scan_log".
# за последние 5 минут в логах есть IP-адрес, если в логах через 5 минут после срабатывания триггера больше ничего не появилось - триггер пропадает
Expression: {sar_honeypot01_166-52:log[/var/log/ssh-honeypot.log].regexp("([0-9]{1,3}[\.]){3}[0-9]{1,3}",5m)}=1 and {sar_honeypot01_166-52:log[/var/log/ssh-honeypot.log].nodata(5m)}=0
Check
На любой другой машине
nmap -sU <адрес_машины_с_iptables> -p5060
После этого на машине Honeypot с iptables
cat /var/log/honeypot/iptables/iptables-honeypot.log
... Jul 20 17:22:18 centos7-honeypot01 kernel: Attack SIP: IN=ens160 OUT= MAC=00:50:56:ba:6b:50:00:50:56:83:24:e2:08:00 SRC=192.168.17.250 DST=192.168.166.52 LEN=28 TOS=0x00 PREC=0x00 TTL=51 ID=9330 PROTO=UDP SPT=47791 DPT=5060 LEN=8 ...
На забикс сервере должен обновиться лог в Item history "port_scan_log" и сработать триггер