SOC Lab 2, Snort 3 as an IPS
Stack: Snort 3 inline (afpacket), Filebeat, Logstash, Elasticsearch, Kibana Environment: Docker Part 2 of the SOC Lab series. Part 1 is SOC Lab 1, Snort 3 as an IDS, where Snort 3 watched a Docker bridge as a passive IDS and shipped alerts to an Elastic stack.
Part 1 [1] deployed Snort 3 beside the traffic. Every matched rule produced an alert event with "action" : "allow", because a passive sensor has nothing to enforce. This post puts the same binary, the same rules and the same alert format into the data path. One keyword in the rule file then decides what happens to the packet: alert passes it and logs the match, drop discards it silently, reject discards it and resets the connection.
The report is reproducible end to end. Everything runs in one disposable --privileged container from the same ciscotalos/snort3 image Part 1 used. Working files live under /root/lab inside the container. Outputs below are from the actual runs.
Roadmap
Eight stages, in the order they were run. Each one ends with the evidence it produced, so you can tell whether yours worked before moving on.
- What inline changes. The one structural difference from Part 1: the sensor now sits in the data path, so a rule action becomes a packet verdict.
- Build the rig. One
--privilegedcontainer, a bump-in-the-wire made from two veth pairs and two network namespaces, and checksum offload disabled on every leg. - Configure and start Snort inline.
snort.luaplus a single rule, launched with-Q --daq afpacketonsa:sv. The banner has to readafpacket DAQ configured to inline. - Test A:
alert. Ping passes end to end, three replies, six JSON events with"action" : "allow". - Test B:
drop. The same ping, 100% packet loss, zero packets on the victim,"action" : "drop". - Test C:
reject. A TCP connect refused with a reset rather than a silent drop,"action" : "reset". - Results. The three runs side by side: the JSON
actionfield is the only thing that changed. - Running an IPS in production. Availability, false positives that become outages, and placement as posture.
What inline changes
IDS and IPS are the same engine in two positions. As an IDS, Snort watches a copy of the traffic; as an IPS, traffic must pass through it:
1
2
3
4
5
6
IDS (detection) IPS (prevention)
attacker ──► victim attacker ──► [ Snort ] ──► victim
│ └── match → drop / reject the packet
└── Snort watches, (traffic flows *through* Snort)
match → alert
Out of the data path, drop and reject have nothing to stop, which is why a passive IDS uses alert. Inline, the same actions become enforceable [2][3]:
| action | behaviour inline | JSON action |
|---|---|---|
alert | log the match, let the packet through | allow |
drop | log the match, discard the packet silently | drop |
reject | log the match, discard, and actively reset the connection | reset |
pass | skip the packet, no event | (no event) |
Inline mode requires the -Q switch plus a DAQ running in inline mode. Part 1’s banner said:
1
pcap DAQ configured to passive.
With -i on two interfaces and -Q, it says:
1
afpacket DAQ configured to inline.
The JSON alert then reports the verdict Snort applied. That field is the subject of this lab.
Build the rig
Inline needs two interfaces whose only connection to each other is Snort. Network namespaces and veth pairs provide exactly that in a few commands, inside a sandbox that can be deleted without touching anything else [4][5]. Creating namespaces needs privileges a normal container refuses, so the rig runs in a --privileged container. A production sensor does not need this capability; it needs two NICs or a netfilter queue, covered under “Running an IPS in production”.
1
2
docker run -dit --privileged --user root --name soc-ips \
--entrypoint /bin/bash ciscotalos/snort3
The image is minimal, so we add the tools the lab needs and create the working tree:
1
2
3
4
docker exec -it soc-ips bash
apt-get update
apt-get install -y iproute2 iputils-ping tcpdump netcat-openbsd ethtool
mkdir -p /root/lab/{rules,logs}
Snort is the same build Part 1 used:
1
/home/snorty/snort3/bin/snort -V
1
2
3
--------------------------------------------------
o")~ Snort++ 3.10.0.0
--------------------------------------------------
Save the following as wire.sh. Netns a is the attacker (10.0.0.2), netns v is the victim (10.0.0.3), both on 10.0.0.0/24; the container-side legs are sa and sv:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# wire.sh: build the bump-in-the-wire rig
# tear down leftovers from previous runs
ip netns del a 2>/dev/null
ip netns del v 2>/dev/null
ip link del sa 2>/dev/null
ip link del sv 2>/dev/null
ip netns add a
ip netns add v
# attacker leg: veth pair sa <-> eth0 (in netns a)
ip link add sa type veth peer name na
ip link set na netns a
ip netns exec a ip link set na name eth0
ip netns exec a ip addr add 10.0.0.2/24 dev eth0
ip netns exec a ip link set eth0 up
ip link set sa up
# victim leg: veth pair sv <-> eth0 (in netns v)
ip link add sv type veth peer name nv
ip link set nv netns v
ip netns exec v ip link set nv name eth0
ip netns exec v ip addr add 10.0.0.3/24 dev eth0
ip netns exec v ip link set eth0 up
ip link set sv up
# Snort does not relay ARP (it forwards IP), so pin each end's neighbour entry
AMAC=$(ip netns exec a cat /sys/class/net/eth0/address)
VMAC=$(ip netns exec v cat /sys/class/net/eth0/address)
ip netns exec a ip neigh add 10.0.0.3 lladdr "$VMAC" dev eth0 nud permanent
ip netns exec v ip neigh add 10.0.0.2 lladdr "$AMAC" dev eth0 nud permanent
echo "WIRE_READY attacker=$AMAC victim=$VMAC"
Three details carry the topology:
- A
vethpair is a pipe: a frame into one end comes out the other, and nothing else connects the two sides. There is no bridge here; only Snort can move a frame fromsatosv. - The legs
sa/svcarry no IP address. They exist only for Snort to open with-i sa:sv. - Snort forwards IP but is not an Ethernet bridge, so it does not relay ARP. The static neighbour entries (
ip neigh ... nud permanent) point each end at the real MAC of the far side.
Run it and confirm addressing:
1
2
3
bash wire.sh
ip netns exec a ip addr show eth0
ip netns exec v ip addr show eth0
Until Snort starts, the rig is inert: both legs are up but nothing bridges them.
Checksum offload must be disabled
veth devices advertise checksum offload but never compute it, so TCP frames reach Snort with the checksum left empty and are dropped before detection. The end-of-run statistics show the cause:
1
2
3
4
5
6
7
8
9
codec
total: 2 (100.000%)
discards: 2 (100.000%)
eth: 2 (100.000%)
ipv4: 2 (100.000%)
tcp: 2 (100.000%)
...
tcp
bad_tcp4_checksum: 2
ICMP is unaffected, because the kernel computes ICMP checksums in software. That is why the ICMP tests below work while a first TCP attempt stayed silent. Disable offload on every interface that carries traffic [6]:
1
2
3
4
ip netns exec a ethtool -K eth0 tx off rx off
ip netns exec v ethtool -K eth0 tx off rx off
ethtool -K sa tx off rx off
ethtool -K sv tx off rx off
If a TCP rule never matches, check bad_tcp4_checksum in the stats before the rule syntax.
Configure and start Snort inline
The rules change per test by one keyword, so the Lua config stays minimal and each run supplies its rules with -R. Save this as /root/lab/snort.lua:
1
2
3
4
5
6
7
8
9
-- snort.lua: minimal config for the inline rig
-- rules are supplied per run with -R, one set per scenario
HOME_NET = 'any'
EXTERNAL_NET = 'any'
alert_json = {
file = true,
limit = 0,
}
Start Snort in one shell (it runs in the foreground) and generate traffic from a second shell. The detect-only run:
1
2
3
4
5
/home/snorty/snort3/bin/snort \
-c /root/lab/snort.lua \
-R /root/lab/rules/ips-alert.rules \
-i sa:sv -Q --daq afpacket \
-A alert_json -l /root/lab/logs
Two lines of the startup banner matter. The rule count confirms the file loaded, the DAQ line confirms the mode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
rule counts
total rules loaded: 1
text rules: 1
option chains: 1
chain headers: 1
--------------------------------------------------
port rule counts
tcp udp icmp ip
any 0 0 1 0
total 0 0 1 0
--------------------------------------------------
afpacket DAQ configured to inline.
Commencing packet processing
Retry queue interval is: 200 ms
++ [0] sa:sv
++ [0] sa:sv shows Snort bound both legs; the DAQ is now inline rather than passive.
Test A: alert
Rule file ips-alert.rules:
1
2
3
4
5
# ips-alert.rules: watch, do not block
alert icmp 10.0.0.0/24 any -> 10.0.0.0/24 any (
msg:"SOC-LAB IPS detect ping (inline, allow)";
sid:2000001; rev:1;
)
The header is scoped to 10.0.0.0/24 on purpose. A bare any header also matches IPv6, and the veth legs generate link-local ICMPv6 chatter that would log events which are not our ping.
From the attacker side, ping the victim:
1
ip netns exec a ping -c 3 -W 1 10.0.0.3
1
2
3
4
5
6
7
8
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_seq=1 ttl=64 time=0.251 ms
64 bytes from 10.0.0.3: icmp_seq=2 ttl=64 time=0.171 ms
64 bytes from 10.0.0.3: icmp_seq=3 ttl=64 time=0.553 ms
--- 10.0.0.3 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2033ms
rtt min/avg/max/mdev = 0.171/0.325/0.553/0.164 ms
0% loss. To prove the packets transited Snort and were re-injected rather than taking a private path, capture on the victim side (ip netns exec v tcpdump -ni eth0). The victim only sees packets Snort forwards across sv:
1
2
3
4
5
6
7
8
9
10
11
# on the victim's eth0
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
10:48:15.254579 IP 10.0.0.2 > 10.0.0.3: ICMP echo request, id 971, seq 1, length 64
10:48:15.254595 IP 10.0.0.3 > 10.0.0.2: ICMP echo reply, id 971, seq 1, length 64
10:48:16.262786 IP 10.0.0.2 > 10.0.0.3: ICMP echo request, id 971, seq 2, length 64
10:48:16.262802 IP 10.0.0.3 > 10.0.0.2: ICMP echo reply, id 971, seq 2, length 64
10:48:17.287874 IP 10.0.0.2 > 10.0.0.3: ICMP echo request, id 971, seq 3, length 64
10:48:17.287902 IP 10.0.0.3 > 10.0.0.2: ICMP echo reply, id 971, seq 3, length 64
6 packets captured
Snort logs each matched packet with the same JSON shape Part 1 produced:
1
2
3
4
{ "timestamp" : "09/06-10:48:15.254426", "pkt_num" : 1, "proto" : "ICMP",
"pkt_gen" : "raw", "pkt_len" : 84, "dir" : "UNK",
"src_ap" : "10.0.0.2:0", "dst_ap" : "10.0.0.3:0",
"rule" : "1:2000001:1", "action" : "allow" }
Six events (one per request and reply) match SID 2000001, all allow. Result: inline placement alone changes nothing. An inline Snort running alert rules is still functionally an IDS.
Test B: drop
Same rig, same ping, one keyword changed. Rule file ips-drop.rules:
1
2
3
4
5
# ips-drop.rules: silently block
drop icmp 10.0.0.0/24 any -> 10.0.0.0/24 any (
msg:"SOC-LAB IPS drop ping (blocked)";
sid:2000002; rev:1;
)
Stop the previous Snort (Ctrl-C) and start it with the drop rules file, then ping again:
1
2
3
4
5
/home/snorty/snort3/bin/snort \
-c /root/lab/snort.lua \
-R /root/lab/rules/ips-drop.rules \
-i sa:sv -Q --daq afpacket \
-A alert_json -l /root/lab/logs
1
ip netns exec a ping -c 3 -W 1 10.0.0.3
1
2
3
4
5
6
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
--- 10.0.0.3 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2045ms
exit=1
100% loss, and the victim capture confirms nothing arrived:
1
2
3
4
# on the victim's eth0, during the same run
0 packets captured
0 packets received by filter
0 packets dropped by kernel
Snort logged what it did to each packet:
1
2
3
4
{ "timestamp" : "09/06-10:48:22.506216", "pkt_num" : 1, "proto" : "ICMP",
"pkt_gen" : "raw", "pkt_len" : 84, "dir" : "UNK",
"src_ap" : "10.0.0.2:0", "dst_ap" : "10.0.0.3:0",
"rule" : "1:2000002:1", "action" : "drop" }
The packet still produced an alert, and the Part 1 pipeline would still index it. The difference is that the event now records something prevented rather than something watched. The block is silent to the attacker: pings simply stop being answered, with no error packet, so a scanner learns nothing beyond “no reply”.
Test C: reject
drop discards and says nothing; reject also forges a reset. For TCP the reset is a real, observable packet, so this test uses a TCP service on the victim (port 9999) instead of a ping.
Control: with an alert rule in place, the service is reachable and the handshake completes through Snort:
1
2
$ nc -vz 10.0.0.3 9999
Connection to 10.0.0.3 9999 port [tcp/*] succeeded!
1
2
3
4
# on the victim's eth0
10:49:07.108025 IP 10.0.0.2.37580 > 10.0.0.3.9999: Flags [S], seq 398453366 ...
10:49:07.108049 IP 10.0.0.3.9999 > 10.0.0.2.37580: Flags [S.], seq 1994068590 ...
10:49:07.108129 IP 10.0.0.2.37580 > 10.0.0.3.9999: Flags [.], ack 1, win 63 ...
SYN out, SYN-ACK back, ACK: connection up. Rule file ips-rejecttcp.rules:
1
2
3
4
5
# ips-rejecttcp.rules: block and actively reset
reject tcp 10.0.0.0/24 any -> 10.0.0.0/24 any (
msg:"SOC-LAB IPS reject TCP (reset)";
sid:2000004; rev:1;
)
Restart Snort with the reject rules file and retry the connect:
1
2
3
4
5
/home/snorty/snort3/bin/snort \
-c /root/lab/snort.lua \
-R /root/lab/rules/ips-rejecttcp.rules \
-i sa:sv -Q --daq afpacket \
-A alert_json -l /root/lab/logs
1
2
3
$ nc -vz 10.0.0.3 9999
nc: connect to 10.0.0.3 port 9999 (tcp) failed: Connection refused
exit=1
Connection refused, not a timeout. The victim capture shows why: the victim never saw the SYN; the only packet it received is a reset that looks like the client aborting the connection:
1
2
3
4
# on the victim's eth0
10:50:13.724579 IP 10.0.0.2.49882 > 10.0.0.3.9999: Flags [R.], seq 3091991509, ack 0, win 0, length 0
1 packet captured
The client received the mirror image, a reset made to look like it came from the server, hence “Connection refused” instead of a hang. Snort terminated the handshake from both ends at once. The JSON records the verdict:
1
2
3
4
{ "timestamp" : "09/06-10:50:13.724341", "pkt_num" : 1, "proto" : "TCP",
"pkt_gen" : "raw", "pkt_len" : 60, "dir" : "UNK",
"src_ap" : "10.0.0.2:49882", "dst_ap" : "10.0.0.3:9999",
"rule" : "1:2000004:1", "action" : "reset" }
Results
Side by side, the three runs are the whole IDS→IPS idea:
| rule | Snort’s verdict | JSON action | attacker sees | victim sees |
|---|---|---|---|---|
alert | let through, log | allow | ping replies, 0% loss | request + reply |
drop | discard, log | drop | 100% loss, silent | nothing |
reject | discard, reset both ends | reset | connection refused | forged RST, no SYN |
Two observations follow.
A blocked packet is still an alert. drop and reject both write JSON events; they are not quieter than alert, they are more consequential. Part 1 events all meant “traffic happened and we noticed”. Now events split into allow (observed, let through) and drop/reset (prevented). An analyst filters an IPS feed on that action field, because a stream of drop events tells a different story than a stream of allow events on the same rule SID.
Nothing downstream changed. The events are byte-for-byte the schema Part 1’s Filebeat parses and Logstash normalizes. Point the rig’s log directory at the Part 1 logstash and the same pipeline ingests inline verdicts with no config change. The only change is semantic: add a “prevented events” panel (action != allow) for the cases where the sensor changed the outcome.
Running an IPS in production
Moving Snort from tap to inline is not a flag you flip on a sensor you already trust. It changes the blast radius of every mistake. Three concerns Part 1 never had to think about become first-order.
Availability. If a passive sensor crashes, only the dashboard goes quiet. An inline sensor is the path: if the process or the host dies, the traffic between the two sides dies with it. Decide whether the device fails open (passes traffic when sick) or fails closed (drops it), and deploy IPS boxes in pairs at choke points, not as one copy per link.
False positives become outages. The drop icmp 10.0.0.0/24 rule blocked every ping on the segment, including legitimate monitoring traffic. The rule discipline that was a best practice in Part 1 (scoped headers, specific evidence, snort -T before every change) becomes a safety practice: a bad rule no longer adds dashboard noise, it removes service.
Placement decides posture. A common pattern keeps broad detection in an IDS that watches everything and runs a small, tuned rule-set inline only where policy can be enforced (the edge, a critical subnet). The rules written here, one keyword apart, are advisory in one position and enforced in the other.
Mechanism. The rig used afpacket inline because the image ships that DAQ and it works on any two interfaces on one host. Many real deployments use netfilter_queue instead: the kernel queues packets to Snort through iptables/nftables and Snort returns ACCEPT/DROP/REJECT. The concepts are identical; only the DAQ and the interface plumbing change [2].
Conclusion
Part 1 could only observe: every match became an allow alert. Moving the same engine into the path turns the rule action into enforcement. alert still passes the packet and logs it (allow), drop removes it before delivery, and reject removes it and resets both ends, which the client sees as “Connection refused”. Across the three runs, the JSON action field is the only thing that changes.
Cleanup is one command. The rig lives inside the container, so removing it leaves the Part 1 pipeline untouched:
1
docker rm -f soc-ips
The natural follow-up is to point this rig’s alert_json.txt at the Part 1 pipeline and watch a drop event land in Kibana as a “prevented” event.
References
- SOC Lab 1, Snort 3 as an IDS: the passive IDS baseline this post builds on.
- Snort 3 documentation: command-line options (
-Q), DAQ modules and running Snort as an IPS. - Snort 3 rule writing: rule actions: the
alert,drop,rejectandpassactions. - ip-netns(8) man page: network namespaces.
- veth(4) man page: virtual ethernet pair devices.
- ethtool(8) man page: checking and disabling interface offloads.
Tags
#Snort #Snort3 #IPS #IDS #Docker #SOC #BlueTeam
