© 2019 Caendra Inc. - Hera For IHRP - Effectively Using Snort
© 2019 Caendra Inc. - Hera For IHRP - Effectively Using Snort
A test instance of Snort has already been set up and waiting for you!
The learning objective of this lab is to not only get familiar with the detection capabilities of
Snort but to also learn effective writing of Snort rules.
Specifically, you will learn how to use Snort’s capabilities in order to:
• Have better visibility over a network
• Respond to incidents timely and effectively
• Proactively hunt for threats
Snort is an open source IDS and IPS, that can also be used as a packet sniffer or packet
logger. Just like Suricata, Snort inspects all traffic on a link for malicious activity and can
extensively log all flows seen on the wire, producing high-level situational awareness and
detailed application layer transaction records. It needs specific rules (holding instructions)
to tell it not only how to inspect the traffic it looks at but also what to look for. It was
designed to perform on commodity and purpose-built hardware.
• Passive IDS
• NIDS
• HIDS (Snort is not a host-based IDS per se. Prefer more specialized solutions.)
0
1
3
2 a
3
a
For Snort to evolve from a packet sniffer into a full-fledged IDS, some components had to
be added. These components were the Preprocessor, the Detection Engine, the Logging and
Alerting System, and the various Output modules.
• The packet sniffer (including the Packet Decoder), as its name suggests, “sniffs”
network traffic and identifies each packet’s structure (layer information). The raw
packets that have been “collected” are then sent to the Preprocessors.
• The Preprocessors determine the type or the behavior of the forwarded packets.
Inside Snort, there are numerous Preprocessor plugins. An example of such a plugin
is the HTTP plugin which is responsible for identifying HTTP-related packets.
Another example is the sfPortscan Preprocessor that, armed with defined protocols,
types of scans and certain thresholds, can identify a group of packets as a port scan
attempt. Once the Preprocessors cease their operations, information is sent to the
Detection Engine.
• The Logging and Alerting System as well as the various Output modules are
responsible for logging or triggering alerts based on each rule action. Logs are
stored in different formats (most of the times syslog or unified2) or directly into a
DB. Output modules are configured through Snort’s configuration file snort.conf.
Example:
output alert_syslog: host=192.168.2.10:514, <facility> <priority>
<options>
output alert_syslog: host=192.168.2.10:514, log_auth log_alert
log_ndelay
All Snort-related directories are usually under /opt/snort and are structured similarly to
the following.
.
|-- admin
|-- bin
|-- etc
|-- lib
|-- preproc_rules
|-- rules
|-- share
|-- so_rules
`-- src
In the context of this lab, we will use Snort from inside a Security Onion distribution.
Security Onion has its own Snort directory structure.
Snort rules:
Snort rules are very much like Suricata rules. They consist of two major parts, the rule
header, and the rule options. Examples:
The red part is the header whereas the green part is options.
Even though Snort rules are similar to Suricata rules. Dedicate some time to study Snort
rule writing from the following resource: http://manual-snort-org.s3-website-us-east-
1.amazonaws.com/node27.html
The latest Snort rules can be downloaded from snort.org or the Emerging Threats website.
Remember that the location of the rules can be specified in the snort.conf file. Example:
include $RULE_PATH/backdoor.rules
As a callout, when you download Snort rules, the filenames contain the Snort version, so
download files that are relevant to your Snort installation. Also, note that there is also a
local.rules file where you can put your own rules in it.
Snort logs:
Snort’s default log directory is /var/log/snort, but as previously mentioned we can instruct
Snort (via a command line switch of from inside snort.conf) to log in any directory.
Testing Snort:
To quickly test if a Snort installation is working or not, try executing the commands below.
Take some time to read the comments inside the snort.conf file, they are quite enlightening.
Another interesting Snort configuration file is the classification.config file. This file is used
to set the priority of alerts, and it is included inside snort.conf.
Format: config classification:shortname,short description,priority
Example: config classification: unknown,Unknown Traffic,3
• Bro: 172.16.71.100
All provided PCAPs are inside the /home/elsuser/PCAPs directory. They can be transferred
to the machine, from inside which you connected to this lab as follows.
cd PCAPs
sudo python -m SimpleHTTPServer 80
Now, you can simply launch a browser of your choice inside the machine from which you
connected to this lab and browse to http://172.16.71.100 to download the provided PCAP
files.
Introduce a Snort rule into its local.rules file that detects an ICMP Echo request (ping) or
Echo reply message towards your organization’s subnet (192.168.10/24).
Now it’s time to write your own Snort rules. Analyze the eternalblue.pcap PCAP file (stored
in the /home/elsuser/PCAPs directory) using tcpdump. This PCAP file includes network
traffic of an exploitation attempt, against a Windows 7 host, that leveraged the notorious
Eternal Blue exploit and resulted in the attacker obtaining Windows shell access.
In plain terms, the authors of the Eternal Blue exploit identified that the Windows SMBv1
implementation is vulnerable to buffer overflow. The Eternal Blue exploit received
immense attention, and consequently, numerous rules (including Snort ones) have been
written to detect it on the wire. For this reason, write a Snort rule that detects:
Hint: Refer to the included cert_trafficwireshark.pdf resource, “6. FOLLOW TCP STREAM”
section, to see how buffer overflow attacks look like on the wire. Specifically, notice all
those “A” characters that facilitate the buffer overflow.
Note that exploitation of this vulnerability leaves no traces since it takes place inside the
SSL handshake negotiation. The SSL handshake negation occurs before the listening
service receives the request. Subsequently, you won’t be able to see any revealing log in the
backend. Traffic analysis is your only choice.
Armed with the knowledge you obtained so far regarding Snort rules, analyze the Snort
rule below and describe what it looks for.
Snort’s default snort.conf already contains the 192.168.1.0/24 subnet inside the HOME_NET
variable. No changes need to be made.
Once you are connected to the deployed Snort instance over SSH, you can introduce a new
Snort rule as follows.
Inside vim enter the following rule that is able to detect an ICMP Echo request (ping) or
Echo reply message.
alert icmp any any -> $HOME_NET any (msg: "ICMP test"; sid:1000001;
rev:1; classtype:icmp-event;)
Rule Header
alert – Rule action. When the specified condition is observed on the wire, Snort will throw
an alert.
$HOME_NET – Destination IP. We are leveraging the HOME_NET variable specified in the
snort.conf file.
any – Destination port. Snort will consider all ports of our network.
sid:1000001 – Snort rule ID. Remember all IDs smaller than 1,000,000 are reserved.
Then, instruct Snort to update its rule set. Inside Security Onion you can do that as follows.
sudo rule-update
Finally, replay the icmp.pcap file towards the eth0 interface (the one Snort monitors), to see
if any alerts will be triggered. You can do so as follows.
To see if any alerts were triggered you can use a web UI called Squert. Launch any browser,
navigate to https://172.16.71.100/squert/login.php and submit the credentials you used
to SSH into the Bro instance (username: elsuser, password: GwoZbb3B).
If you don’t see any alerts (and you are sure you entered the rule correctly) make sure you
are viewing the alerts of the correct date.
Before you continue, clear the current events in the Sguil database as follows.
If you don’t like watching alerts on a web UI, you can execute the below, which will output
any alerts on the standard output.
cd PCAPs
sudo tcpdump -nnttttAr eternalblue.pcap
-tttt is used so that we are provided with the maximal human-readable timestamp output
-A is used so that tcpdump prints each packet (minus its link level header) in ASCII
Starting from the bottom up, you should see something similar to the below image.
The above looks quite similar to what you saw inside the included cert_trafficwireshark.pdf
resource in the 6. FOLLOW TCP STREAM section. In this case, the buffer overflow attempt
happens over SMB (notice the 445 port). Let’s use this buffer overflow-related portion of
the traffic to create our rule.
It is more efficient to specify the rule content in hex. Let’s turn the above into hex as follows
(A is 41 in hex).
alert tcp $EXTERNAL_NET any -> $HOME_NET 445 (msg:"Buffer overflow activity
over SMB"; content:"|paste all 41s here|"; sid:1000002; rev:1;)
cd ~
sudo rule-update
sudo snort -q -A console --daq pcap -c /etc/nsm/securityonion-
eth0/snort.conf -k none -r PCAPs/eternalblue.pcap
So far, we wrote a rule that detects buffer overflow attempts on the wire (in this case
over SMB).
Let’s continue our analysis by executing tcpdump as follows, in order to search for a traffic
portion that is related to the attacker obtaining Windows shell access.
cd PCAPs
sudo tcpdump -nnttttAr eternalblue.pcap
Starting from the bottom up, you should see something similar to the below image.
The above is a unique enough traffic portion we can use to write a Snort rule that can
detect Windows (7) shell access on the wire; this is actually what we see if the execute
cmd.exe inside a Windows 7 machine.
Let’s create a Snort rule that will detect Window (7) shell access on the wire, as follows.
alert tcp $EXTERNAL_NET any -> $HOME_NET any (msg:"Microsoft shell access
detected."; flow:established; content:"Copyright |28|c|29| 2009 Microsoft
Corporation"; sid:1000003; rev:1;)
cd ~
sudo rule-update
sudo snort -q -A console --daq pcap -c /etc/nsm/securityonion-
eth0/snort.conf -k none -r PCAPs/eternalblue.pcap
Let’s open heart.pcap in Wireshark and filter the traffic in order to see only encrypted
Heartbeat messages. We can do that as follows.
ssl.record.content_type == 24
This is the case because the Heartbeat response is 16384 bytes long.
We can create an unreliable Snort rule based on the Heartbeat request above, as follows.
cd ~
sudo rule-update
sudo snort -q -A console --daq pcap -c /etc/nsm/securityonion-
eth0/snort.conf -k none -r PCAPs/heart.pcap
The rule above is unreliable because it is constructed to match the exact Heartbeat request
in the PCAP. The attacker could specify a payload length different than 16384 bytes and
also use another TLS version.
For this reason, we can create a more reliable Snort rule that detects suspiciously large
Heartbeat responses, as follows.
• 0: Start from the first position within the packet (first byte)
The first byte_test is related to the TLS version used, whereas the second byte_test checks if
the length is suspiciously large. Refer to the below image to comprehend which bytes are
being checked. The first byte_test checks what is inside the red rectangle, whereas the
second byte_test checks what is inside the blue rectangle.
• alert tcp $EXTERNAL_NET any -> $HOME_NET 445 describes the action that
will take place in case of a signature match. Traffic should be TCP-based for the alert
to be triggered. The rest should be easy for you to comprehend.
• content:"|05|"; distance:59; Snort will start searching for |05| 59 bytes after
the previous content’s (|FF|SMB) position.
• sid:2514; rev:7; sid is this rule’s Snort identification number, while rev is the
number of the revision this rule has undergone.
2. https://snort-org-
site.s3.amazonaws.com/production/document_files/files/000/000/046/original/S
nortUsersWebcast-Rules_pt2.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-
Credential=AKIAIXACIED2SPMSC7GA%2F20190222%2Fus-east-
1%2Fs3%2Faws4_request&X-Amz-Date=20190222T230448Z&X-Amz-
Expires=172800&X-Amz-SignedHeaders=host&X-Amz-
Signature=2390ecd554e08833cd90e39220a74e6332f094d711ee1392d287d9197b
a58d0a