Snort Rule
Snort Rule
Snort Rule
Aim: The aim of these labs are to further investigate the Snort, network IDS, and methods
for detection rule development, on both a Windows and a Linux platform
Time to complete:
4 hours (Two supervised hours in lab, and two additional hours, unsupervised).
Activities:
Complete Lab 7: Snort
.pdf from WebCT or http://www.dcs.napier.ac.uk/~cs342/CSN11102/Lab7.pdf
(Use Unit 2 – IDS for reference)
Optional PartB:
.pdf from WebCT or http://www.dcs.napier.ac.uk/~cs342/CSN11102/Lab7B.pdf
(Use Unit 2 – IDS for reference)
The End Of Unit Tutorial Questions for the Authentication chapter (from the unit pdf).
Take some End Of Unit Online Tests for the Authentication chapter at:
http://www.asecuritysite.com/security/tests/tests?sortBy=sfc04
Learning activities:
At the end of these activities, you should understand:
How to perform deep packet inspection of data packets, using Snort.
How develop Snort rules, by analyzing protocol traffic.
How the NMap network scanner is used to scan networks and systems, and how to
detect scans using Snort.
How to use the Windows Superscan network scanner.
References:
Course Handbook - Unit 2 IDS
Online: Snort User Manual, NMap User Manual.
7.1 Details
Aim: To develop the use of the Snort IDS software, to create NIDS Sensors capable of
detecting unwanted network traffic, as well as report on possible intrusions.
7.2 Overview
Employing Network IDS (NIDS) sensors
around an organisations network, means
traffic can be monitored for intrusions and
security policy breaches. IDS sensors can be
used to report on insider attacks, misuse of
network resources, and intrusions from
outside the organisations network
perimeter.
This lab gives further IDS development using the Snort IDS, including application level
analysis, rule development, and network reconnaissance detection. Use the previous lab or
online materials as reference for Snort configuration.
Snort documentation, including the Snort Users Manual can be found at:
http://www.snort.org/docs
The hosted virtualised lab architecture, using VM Workstation to run the Windows2003
Server VM, is shown below.
DESKTOP
Host OS - Windows7
VM Workstation
Virtual NIC
192.168.
VMNet Gateway Web Server
Physical NIC 192.168. .2 FTP Server
VM Workstation
146.176. Telnet Server
WINDOWS2003
Virtual NIC Server
192.168.
UBUNTU
Linux VM
From VMWare Workstation open the guest Windows Server 2003 VM WINDOWS2003. Log
into the Windows server as User name: Administrator, Password: napier. (In VMWare
CTRL+ALT+INS can be used to send a CTRL+ALT+DEL)
Within the virtual image WINDOWS2003, run a Command Prompt Window and determine
the servers IP Address using ipconfig.
7.4 Activities
7.2.1 Snort as Packet Sniffer
On WINDOWS2003 change to the directory Snort is installed in, typically c:\snort
Check the interfaces available to Snort with:
C:\Snort> snort -W
Run the Snort IDS sensor as a packet sniffer to test it can inspect traffic, using:
C:\Snort> snort -dev -i 3
Logs
Snort can be used as a signature-based IDS, with signatures defined in the rules. Signature-
based IDS can compare signatures against each packets application protocol data (the packet
payload). This is sometimes called deep packet inspection.
Firewalls tend to filter at lower levels as inspecting deep inside each packet can reduce
throughput. As IDS sensors are inspecting copies of the packets off-line, there is no effect on
throughput. This means IDS sensors can inspect packets much more thoroughly than most
firewalls.
To detect Facebook use by employees, an IDS detection rule can be created which will detect
the text “facebook.com” in the payload of HTTP packets being downloaded from a web
server.
Now monitor the output folder c:\snort\log folder with Windows Explorer. Right click
the file panel and select View>Details, as shown below. The timestamp and size of the file
can now be viewed, and used to check if a rule has caused an alert to be raised, and packet
details to be logged.
Resize/rearrange your windows, so you can see the output alert.ids file in explorer, the
console window running snort, and the web browser window.
Check if an alert has been generated, by checking the log folder, as shown below. Stop Snort
running with <CTRL+C>, and open the alert file in an editor.
Q: What is the IP Address of the facebook server, which the packet came from?
From the Windows command line, use nslookup (name server lookup tool) to check for
DNS information on the server such as with the following:
C:\> nslookup serverIPAddress
Q: Does the Snort IDS Sensor detect the job search, and produce an alert?
YES/NO
Q: Can you locate and view the associated packet logged by Snort, and can you identify the
search string in the payload of the packet.
YES/NO
To develop your own Snort rules, it is recommended that the vulnerability be researched or
the intrusion traffic generated in a controlled environment while Snort or another packet
sniffer capture the network traffic. The traffic should then be analysed, along with
researching any protocols involved, and a Snort rule(s) created based in any triggering
conditions (Roesch, 1999).
Stop the wireshark capture, and scroll up to the Ping packets, as shown.
Q: Which Wireshark display filter can be used to filter out these packets?
Q: Is this the same for all the Ping packets? (research online)
YES/NO
Q: How might this signature differ for Ping traffic from a Linux OS?
Change the Snort ICMP detection rule to only alert on Pings which are outgoing from your
host system. The alert should be “Windows Ping Detected - Outgoing”
Test the changed rule.
Add a new Snort ICMP detection rule to only alert on Pings which are generated within the
local network network, but are destined for an external IP Address. (Hint: the CIDR /24 and
the negation operator ! might help)
The alert should be “Windows Ping Detected – Inside to Outside Net”
Test the rule DOES NOT fire for Pings on the local network first. Ping a single packet to a
device on the local network, such as shown below.
Now test the rule for Pings from the local network to an external network. Ping a single
packet to a server on the internet, such as google.com.
Open a command window, and using the netstat command, determine your systems
connected ports.
Then using netstat –a –p TCP, determine the all your machines TCP listening ports
(servers running on the local machine).
A typical scan would be a Port Scan which is used to determine the network services which
are running on a specific target machine.
Eve
This is performed by sending packets to ports, on the target machine, and checking which
services respond. A good example, and the default Nmap scan, is a TCP SYN scan, or Half-
open scan, were TCP SYN packets are crafted by Nmap, and sent to the target, and the SYN
ACK response packets show that TCP services are running on the target.
A basic nmap port scan (TCP SYN scan) against a single system should look something like
the below:
Note: From the Windows version of nmap, a scan must be performed from another machine,
as it cannot scan the local system.
Scan your machine, by running the nmap scanner from the host machine, or from another
VM (such as The Napier UBUNTU Linux VM):
nmap WindowsPC_IPAddress
On the Windows machine, determine the TCP services running, and their port numbers:
netstat –a –p TCP -n
The output should look similar to the below (based on Windows2003 server VM as target
machine):
The default Nmap scan is a TCP SYN Scan. Scan your machine again with Nmap, this time
with a UDP scan: (the scan may need sudo from a Linux OS)
sudo nmap –sU WindowsPC_IPAddress
On the Windows machine, determine the TCP services running, and their port numbers:
netstat –a –p TCP -n
Add the Snort port scan pre-processor and the correct parameters, which allows a port scan
to be detected. (pre-processors have to be the first rules in the rules file)
Other tools can be used to perform port scans such as the extremely useful network packet
crafting tool netcat. Netcat is often called the swiss army knife of network tools as it can be
used for many purposes.
The Snort network scanning detection output should look similar to the below:
This can be done by varying the parameters of nmap (-T parameter), while tuning the Snort
IDS scan detection pre-processor (Sense level).
Try only scanning small ranges of ports using netcat, such as 21-25
Try scanning the same small ranges of ports using netcat with Snort still running.
Host PC
DESKTOP
Host OS - Windows7
VM Workstation
WINDOWS2003
Virtual NIC
Server
192.168.
UBUNTU
Linux VM
Snort should run, and you should see the Not Using PCAP_FRAMES msg as shown below
Stop Snort, and scroll back up to the Snort output in the console window, showing the
Packets Detected Totals, and complete the following:
Q: Received Packets Total?
Create a snort, and rules and a log directory under the home directory using:
napier@ubuntu:~$ cd ~
napier@ubuntu:~$ mkdir snort
napier@ubuntu:~$ cd snort
napier@ubuntu:~$ mkdir rules
napier@ubuntu:~$ mkdir log
Create a detection rules file in the rules dir with a text editor, such as with:
napier@ubuntu:~$ vi rules/snort.rules
or
napier@ubuntu:~$ gedit rules/snort.rules &
From UBUNTU, in the snort dir, run the snort sensor (against the appropriate interface):
sudo snort -i eth0 -dev -p -c rules/snort.rules -l log -K ascii -k none
To monitor the alerts being generated by the Snort IDS Sensor open a second terminal
window on the Linux VM. The output file can be checked for any lines being appended to it
using the tail command, as shown below.
sudo tail -f log/alert
To test the detection rules, ping the Linux VM UBUNTU from WINDOWS2003.
From UBUNTU, open another terminal window, and ping the WINDOWS2003.
The output from the tail command should look something like the following.
Unpack the zip file to the C:\ directory and run the executable superscan.exe. It should look
like the following:
Then run Snort, while monitoring the output log directory as before.
Generate scan traffic to test the rule using Nmap, while monitoring the log file for alerts
And open another terminal window and monitor the scanning log file with:
sudo tail -f portscan.log
From WINDOWS2003, run a default host discovery/port scan against UBUNTU, using the
superscan network scanner.