This configuration for Openwrt x64 22.03.4
Install ethtool, snort3, kmod-nft-queue
opkg install kmod-nft-queue ethtool snort3
Check Offloading of wan interface and disable it.
root@OpenWrt:~# ethtool -k eth1 | grep receive-offload
generic-receive-offload: on
large-receive-offload: off [fixed]
root@OpenWrt:~# ethtool -K eth1 gro off lro off
Cannot change large-receive-offload
root@OpenWrt:~# ethtool -k eth1 | grep receive-offload
generic-receive-offload: off
large-receive-offload: off [fixed]
Add ntf rule for nfqueue
nft 'add chain inet fw4 IPS { type filter hook forward priority filter ; }'
nft insert rule inet fw4 IPS counter queue num 4 bypass
Note: On older verstion openwrt using iptables. The rule will not persist when you reboot device. Create file firewall.user and then add it into /etc/config/firewall.
Download snort rule and extract into /etc/snort/ then replace alert to block action in rules file:
for i in /etc/snort/rules/*.rules; do sed -i s'/^alert/block/' "$i"; done
Update RULE_PATH in /etc/snort/snort_default.lua
-- Path to your rules files (this can be a relative path)
RULE_PATH = '/etc/snort/rules'
BUILTIN_RULE_PATH = '/etc/snort/builtins'
PLUGIN_RULE_PATH = '/etc/snort/so_rules'
Update in file /etc/snort/snort.lua
Check ips with mode inline and add rules for IPS.
ips =
{
mode = inline,
variables = default_variables,
rules = [[
-- Update the rules here
include $RULE_PATH/snort3-server-web.rules
include $RULE_PATH/snort3-protocol-icmp.rules
]]
}
-- Add more section for daq nfq in snort.lua
daq = {
module_dirs = {'/usr/lib/daq'},
inputs = { '4' },
modules =
{
{
name = 'nfq',
mode = 'inline',
variables = { 'device=eth1' } -- eth1 is wan interface
}
}
}
Run the test:
> snort -c /etc/snort/snort.lua -Q -T
Update in file/etc/init.d/snort
> procd_set_param command $PROG -c "$config_dir/snort.lua" -A "$alert_module" -Q -M
Depend your hardware or your configurations, you can use -q instead of -M to do not show snort startup log in logread or syslog-ng.
Restart snort
> /etc/init.d/snort restart
Inlog:
> May 25 08:53:16 OpenWrt snort[31733]: Finished /etc/snort//snort.lua:
> May 25 08:53:16 OpenWrt snort: Loading ips.rules:
> May 25 08:53:16 OpenWrt snort: Loading /etc/snort/rules/snort3-protocol-icmp.rules:
> May 25 08:53:16 OpenWrt snort: Finished /etc/snort/rules/snort3-protocol-icmp.rules:
> May 25 08:53:16 OpenWrt snort: Finished ips.rules:
> May 25 08:53:16 OpenWrt snort: --------------------------------------------------
> May 25 08:53:16 OpenWrt snort: rule counts
> May 25 08:53:16 OpenWrt snort: total rules loaded: 149
> May 25 08:53:16 OpenWrt snort: text rules: 149
> May 25 08:53:16 OpenWrt snort: option chains: 149
> May 25 08:53:16 OpenWrt snort: chain headers: 4
> May 25 08:53:16 OpenWrt snort: --------------------------------------------------
> May 25 08:53:16 OpenWrt snort: port rule counts
> May 25 08:53:16 OpenWrt snort: tcp udp icmp ip
> May 25 08:53:16 OpenWrt snort: any 1 1 149 1
> May 25 08:53:16 OpenWrt snort: total 1 1 149 1
> May 25 08:53:16 OpenWrt snort: --------------------------------------------------
> May 25 08:53:16 OpenWrt snort: ips policies rule stats
> May 25 08:53:16 OpenWrt snort: id loaded shared enabled file
> May 25 08:53:16 OpenWrt snort: 0 149 0 149 /etc/snort//snort.lua
> May 25 08:53:16 OpenWrt snort: --------------------------------------------------
> May 25 08:53:16 OpenWrt snort: fast pattern port groups src dst any
> May 25 08:53:16 OpenWrt snort: packet: 0 0 4
> May 25 08:53:16 OpenWrt snort: --------------------------------------------------
> May 25 08:53:16 OpenWrt snort: search engine
> May 25 08:53:16 OpenWrt snort: instances: 4
> May 25 08:53:16 OpenWrt snort: patterns: 55
> May 25 08:53:16 OpenWrt snort: pattern chars: 721
> May 25 08:53:16 OpenWrt snort: num states: 544
> May 25 08:53:16 OpenWrt snort: num match states: 85
> May 25 08:53:16 OpenWrt snort: memory scale: KB
> May 25 08:53:16 OpenWrt snort: total memory: 21.8525
> May 25 08:53:16 OpenWrt snort: pattern memory: 2.84863
> May 25 08:53:16 OpenWrt snort: match list memory: 8.28125
> May 25 08:53:16 OpenWrt snort: transition memory: 10.2227
> May 25 08:53:16 OpenWrt snort: --------------------------------------------------
> May 25 08:53:16 OpenWrt snort: nfq DAQ configured to inline.
> May 25 08:53:16 OpenWrt snort: Commencing packet processing
Test with icmp rules..
Try to ping any server from client...
> May 25 08:56:15 OpenWrt snort: [1:366:11] "PROTOCOL-ICMP PING Unix" [Classification: Misc activity] [Priority: 3] {ICMP} 192.168.1.110 -> 8.8.8.8
> May 25 08:56:15 OpenWrt snort: [1:29456:3] "PROTOCOL-ICMP Unusual PING detected" [Classification: Information Leak] [Priority: 2] {ICMP} 192.168.1.110 -> 8.8.8.8
> May 25 08:56:15 OpenWrt snort: [1:384:8] "PROTOCOL-ICMP PING" [Classification: Misc activity] [Priority: 3] {ICMP} 192.168.1.110 -> 8.8.8.8