tools

Overview

Snort is one of the most widely used open-source Intrusion Detection System (IDS) solutions, developed in 1998. It uses both signature-based and anomaly-based detection defined in rule files. Snort ships with built-in rule files covering a variety of known attack patterns and supports custom rules for traffic not covered by defaults.


Target / Context

Network traffic monitoring and intrusion detection on Linux systems. Can monitor traffic for a single host or an entire network (requires promiscuous mode). Operates as a packet sniffer, packet logger, or full NIDS.


Installation

ℹ︎Installation Commands:
sudo apt install snort

During installation you must provide the network interface and IP range. To monitor an entire network, enable promiscuous mode on the host’s network interface.


Basic Usage

ℹ︎Basic Usage:
sudo snort -q -l /var/log/snort -i lo -A console -c /etc/snort/snort.conf

Flags & Options

ℹ︎Flags & Options:
FlagDescriptionExample
-qQuiet mode; suppresses banner and init infosudo snort -q
-lSets the output logging directory-l /var/log/snort
-iNetwork interface to monitor-i eth0
-AAlert mode-A console
-cConfig file to use-c /etc/snort/snort.conf
-rRead and analyze a PCAP file instead of live traffic-r Task.pcap

Common Use Cases

Packet Sniffer Mode

Reads and displays network packets without performing analysis. Useful for network monitoring and troubleshooting.

ℹ︎Commands:
sudo snort -v -i eth0

Packet Logging Mode

Performs detection on live network traffic in real-time, displays alerts on console, and logs traffic as PCAP.

ℹ︎Commands:
sudo snort -q -l /var/log/snort -i eth0 -A console -c /etc/snort/snort.conf

NIDS Mode

Primary mode — monitors network traffic in real-time and applies rule files to identify known attack patterns.

ℹ︎Commands:
sudo snort -q -l /var/log/snort -i eth0 -A console -c /etc/snort/snort.conf

PCAP File Detection

Analyze a previously captured PCAP file against Snort rules instead of live traffic.

ℹ︎Commands:
sudo snort -q -l /var/log/snort -r Task.pcap -A console -c /etc/snort/snort.conf

Writing a Custom Rule

Open local.rules and add custom detection logic.

ℹ︎Commands:
sudo nano /etc/snort/rules/local.rules
alert icmp any any -> 127.0.0.1 any (msg:"Loopback Ping Detected"; sid:10003; rev:1;)

Rule Format

ICMP Rule Example

ComponentDescription
ActionWhat to do when rule triggers (alert, log, drop)
ProtocolProtocol to match (tcp, udp, icmp, ip)
Source IPWhere traffic originates; use any for all
Source PortPort traffic originates from
Destination IPWhere traffic is going; use $HOME_NET for local network
Destination PortPort traffic is destined for
msgMessage displayed when rule triggers
sidUnique rule identifier
revRevision number; increment on each rule change

Example rule: alert icmp any any -> 127.0.0.1 any (msg:"Loopback Ping Detected"; sid:10003; rev:1;)

File Locations

PathPurpose
/etc/snort/Snort root directory
/etc/snort/snort.confMain configuration file
/etc/snort/rules/Rule files directory
/etc/snort/rules/local.rulesCustom user-defined rules


References / Images

  • ICMP Rule Example