Snort Walkthrough (TryHackMe)

In this room from TryHackMe, I solved each task to get more familiar with an open-source IDS/IPS solution called Snort. I will also put the bullet point notes that I chose from this room.

Project Image

Overview

During this TryHackMe room, I gained practical experience with Snort, a powerful open-source Intrusion Detection System (IDS) and Intrusion Prevention System (IPS). I explored Snort's various operational modes, including Sniffer, Packet Logger, IDS/IPS, and PCAP investigation. A significant portion of the exercises involved crafting and testing custom Snort rules to detect specific network patterns and anomalies. I learned to configure Snort, analyze its output, and interpret logs to identify malicious activities. This included tasks such as testing different configuration files, reading packet data from log files, and using Snort to investigate PCAP files. I also practiced creating rules based on IP IDs, TCP flags (SYN, PSH-ACK), and identifying UDP packets with identical source and destination IPs.

Key Skills Demonstrated

Understanding of IDS/IPS Concepts, Snort Installation and Configuration, Snort Operational Modes, Snort Rule Writing, Log Analysis

What is IDS?

IDS : IDS is a passive monitoring solution for detecting possible malicious activities/patterns, abnormal incidents, and policy violations. It is responsible for generating alerts for each suspicious event.

There are two main types of IDS systems;

  • Network Intrusion Detection System (NIDS)
  • Host-based Intrusion Detection System (HIDS)

What is IPS?

IPS : is an active protecting solution for preventing possible malicious activities/patterns, abnormal incidents, and policy violations. It is responsible for stopping/preventing/terminating the suspicious event as soon as the detection is performed.

There are four main types of IPS systems;

  • Network Intrusion Prevention System (NIPS)
  • Behaviour-based Intrusion Prevention System (Network Behaviour Analysis - NBA)
    • The difference between NIPS and Behaviour-based is that behaviour based systems require a training period (also known as "baselining") to learn the normal traffic and differentiate the malicious traffic and threats.
  • Wireless Intrusion Prevention System (WIPS)
  • Host-based Intrusion Prevention System (HIPS)

HIPS working mechanism is similar to HIDS. The difference between them is that while HIDS creates alerts for threats, HIPS stops the threats by terminating the connection.

Network Configuration Screenshot

Detection and Prevention Techniques

Network Configuration Screenshot

Basic Parameters for Snort

Network Configuration Screenshot

Run the Snort instance and check the build number?

Network Configuration Screenshot

Here "-T" is used for testing configuration, and "-c" is identifying the configuration file (snort.conf). Note that it is possible to use an additional configuration file by pointing it with "-c". After running the command we can see that the build number is 149

Network Configuration Screenshot

Test the current instance with "/etc/snort/snort.conf" file and check how many rules are loaded with the current build?

In the same output it can be seen.

Network Configuration Screenshot

Test the current instance with "/etc/snort/snortv2.conf" file and check how many rules are loaded with the current build?

Network Configuration Screenshot

All answers for this task

Network Configuration Screenshot

Operation Mode 1: Sniffer Mode

Network Configuration Screenshot

Operation Mode 2: Packet Logger Mode

Network Configuration Screenshot
Network Configuration Screenshot

Now, you should have the logs in the current directory. Navigate to folder "145.254.160.237". What is the source port used to connect port 53?

Network Configuration Screenshot

Use snort.log.1640048004 to read the snort.log file with Snort; what is the IP ID of the 10th packet? (snort -r snort.log.1640048004 -n 10)

Network Configuration Screenshot

Read the "snort.log.1640048004" file with Snort; what is the referer of the 4th packet? (sudo snort -r snort.log.1640048004 -n 4 -X)

Network Configuration Screenshot

Read the "snort.log.1640048004" file with Snort; what is the Ack number of the 8th packet? (sudo snort -r snort.log.1640048004 -n 8 -e)

Network Configuration Screenshot

Read the "snort.log.1640048004" file with Snort; what is the number of the "TCP port 80" packets? (sudo snort -r snort.log.1640048004 tcp)

Network Configuration Screenshot

All answers for this task

Network Configuration Screenshot

Operation Mode 3: IDS/IPS

Network Configuration Screenshot
Network Configuration Screenshot
Network Configuration Screenshot

IPS mode and dropping packets

Snort IPS mode activated with -Q --daq afpacket parameters.

Activate the Data Acquisition (DAQ) modules and use the afpacket module to use snort as an IPS:

  • -i eth0:eth1
  • task7 ->
  • start the sniffer :
  • sudo snort -c /etc/snort/snort.conf -A full -l .
  • start the attack/traffic generator task7
  • after the attack finished terminate the sniff (crtl+c)

What is the number of the detected HTTP GET methods?

Network Configuration Screenshot

Operation Mode 4: PCAP Investigation

Network Configuration Screenshot

Investigate the mx-1.pcap file with the default configuration file.

sudo snort -c /etc/snort/snort.conf -A full -l . -r mx-1.pcap

What is the number of the generated alerts? Keep reading the output. How many TCP Segments are Queued? (170 and 18)

Network Configuration Screenshot

Keep reading the output.How many "HTTP response headers" were extracted?

Network Configuration Screenshot

Investigate the mx-1.pcap file with the second configuration file.

sudo snort -c /etc/snort/snortv2.conf -A full -l . -r mx-1.pcap

What is the number of the generated alerts?

Network Configuration Screenshot

Investigate the mx-2.pcap file with the default configuration file.

sudo snort -c /etc/snort/snort.conf -A full -l . -r mx-2.pcap

What is the number of the generated alerts?

Network Configuration Screenshot

Keep reading the output. What is the number of the detected TCP packets?

Network Configuration Screenshot

Investigate the mx-2.pcap and mx-3.pcap files with the default configuration file.

sudo snort -c /etc/snort/snort.conf -A full -l . --pcap-list="mx-2.pcap mx-3.pcap"

What is the number of the generated alerts?

Network Configuration Screenshot

Snort Rule Structure

Network Configuration Screenshot
Network Configuration Screenshot

Remember, Snort is in passive mode by default. So most of the time, you will use Snort as an IDS. You will need to start "inline mode" to turn on IPS mode.

Rule Options

Network Configuration Screenshot

IP and Port Numbers

Network Configuration Screenshot

Direction

Network Configuration Screenshot

There are three main rule options in Snort;

  • General Rule Options - Fundamental rule options for Snort.
  • Payload Rule Options - Rule options that help to investigate the payload data. These options are helpful to detect specific payload patterns.
  • Non-Payload Rule Options - Rule options that focus on non-payload data. These options will help create specific patterns and identify network issues.

General

Network Configuration Screenshot

Payload

Network Configuration Screenshot

Non-Payload

Network Configuration Screenshot

Remember, once you create a rule, it is a local rule and should be in your "local.rules" file. This file is located under "/etc/snort/rules/local.rules".

sudo nano /etc/snort/rules/local.rules

Use "task9.pcap". Write a rule to filter IP ID "35369" and run it against the given pcap file. What is the request name of the detected packet? You may use this command: "snort -c local.rules -A full -l . -r task9.pcap"

The rule has to be = alert ip any any -> any any (msg:"Detected IP ID 35369"; id:35369; sid:1000001; rev:1;)

Network Configuration Screenshot

snort -c local.rules -A full -l . -r task9.pcap

alert.txt file created in the same path

Network Configuration Screenshot

It also could be seen with sudo snort -r snort.log.1748778710 -X

Network Configuration Screenshot

Clear the previous alert file and comment out the old rules. Create a rule to filter packets with Syn flag and run it against the given pcap file. What is the number of detected packets?

The rule has to be = alert tcp any any -> any any (msg:"SYN Flag Detected"; flags:S; sid:1000002; rev:1;)

Network Configuration Screenshot

Clear the previous alert file and comment out the old rules. Write a rule to filter packets with Push-Ack flags and run it against the given pcap file. What is the number of detected packets?

The rule has to be = alert tcp any any -> any any (msg:"PSH-ACK Flag Combination Detected"; flags:PA; sid:1000003; rev:1;)

It's easy to check from log file generated : sudo snort -r snort.log.1748779533 -X

Network Configuration Screenshot

Clear the previous alert file and comment out the old rules. Create a rule to filter UDP packets with the same source and destination IP and run it against the given pcap file. What is the number of packets that show the same source and destination address?

The rule has to be = alert udp any any <> any any (msg:"UDP Packet with Same Source/Dest IP"; sameip; sid:1000004; rev:1;)

sudo snort -r snort.log.1748780315 -X

Network Configuration Screenshot

All the answers for this task

Network Configuration Screenshot

Tools Used

Intrusion Detection Systems
Intrusion Prevention System
Snort Installation and Configuration
Snort Operational Modes
Log Analysis
Snort Rule Writing