NDC & PKI

[Day 2] 3. SNORT Rules

D
DITISS Admin
••3 min read

Writing a SNORT Rule

  • To create a rule, start with an empty text file and write the rule in it.
  • Each rule is separated by a space.
  • This file must be saved with a
    .rules
    extension.

Basic Rule Syntax

Example:

plaintext
alert ip any any -> any any (msg: "Any alert message"; sid: 1000001;)

Explanation of Components:

  1. alert: Specifies the action to take (in this case, to generate an alert).
  2. ip: Protocol to monitor (here, IP protocol).
  3. any any -> any any:
    • source IP
      ,
      source port
      ->
      direction
      ->
      destination IP
      ,
      destination port
      .
    • any
      : Refers to any IP address or port.
  4. (msg: "Any alert message"): Custom message to display when the rule is triggered.
  5. sid: A unique identifier for the rule.
    • sid
      stands for "SNORT ID".
    • This helps SNORT differentiate between multiple rules.

What This Rule Does

This particular rule generates an alert for:

  • Traffic from any source IP and port,
  • To any destination IP and port,
  • Displaying the message: "Any alert message".

Saving the Rule

  • Save this file in the
    rules
    folder inside the
    Snort
    directory.
  • Use any name you prefer, but the file must have the
    .rules
    extension.
    Example:
plaintext
anything.rules

Linking the Rule in the Configuration

  1. Open the

    snort.conf
    file.

  2. Add the following line to include your custom rule file:

    plaintext
    include $RULE_PATH/anything.rules
    
  3. Save the configuration file.


Testing the Rule

Run the following command to validate your new rule file:

shell
snort -i 4 -c c:\Snort\etc\snort.conf -l c:\Snort\log -T

Explanation of the Command:

  • -i 4
    : Specifies the interface number.
  • -c c:\Snort\etc\snort.conf
    : Path to the SNORT configuration file.
  • -l c:\Snort\log
    : Path to the log folder.
  • -T
    : Testing mode to validate the configuration.

Successful Validation

If the output states "Successfully validated", your rule file is correctly configured and ready for use.


Read Next

8/26/2026

[Day 2] 4. Network Adapters in VMWare

VMware provides several types of virtual network adapters, each with distinct behaviors for connecting virtual machines (VMs) to each other, the host...

8/26/2026

[Day 2] 5. SYSLOG Server

#### **What is a SYSLOG Server?** A SYSLOG server is a centralized system that collects, stores, and manages log messages from various devices, ser...