02 Intrusion Detection by Analyzing Traffic Part2
02 Intrusion Detection by Analyzing Traffic Part2
(Part 2)
S e c t i o n 0 2 | M o d u l e 0 2
© Caendra Inc. 2018
All Rights Reserved
Table of Contents
Module 02 – Intrusion Detection By Analyzing Traffic (Part 2)
Notes:
1. The TCP header’s size is 20 bytes,
when no options are specified
2. Offset = TCP header length
3. When the SYN flag is set on a TCP
segment, you’ll most probably come
across the TCP maximum segment
size option
4. When the SYN flag is set, there are
no data following the header
Source: https://skminhaj.wordpress.com/2016/02/15/tcp-segment-vs-udp-datagram-header-format/
0 1
The header fields involved 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
in the handshake are: | Source Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
• Sequence number | Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
• Acknowledgement | Acknowledgment Number |
numbers +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data | |U|A|P|R|S|F|
• SYN and ACK flags | Offset| Reserved |R|C|S|S|Y|I|
| | |G|K|H|T|N|N|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
The steps in the handshake are used to synchronize the sequence and
acknowledgement numbers between the server and the client.
SYN
SYN+ ACK
ACK
Time Time
IHRPv1 - Caendra Inc. © 2018 | p.12
2.1.1 TCP
During the first step, the client sends a TCP packet to the server with the
SYN flag enabled and a random sequence number.
SYN
Seq: 329 Ack: 0
Time Time
IHRPv1 - Caendra Inc. © 2018 | p.13
2.1.1 TCP
In the second step, the server replies by sending a packet with both the
SYN and ACK flag set and another random sequence number.
SYN
Seq: 329 Ack: 0
SYN/ACK
Seq: 498 Ack: 330
Time Time
IHRPv1 - Caendra Inc. © 2018 | p.14
2.1.1 TCP
The ACK number is always a simple increment of the SYN number sent
by the client.
SYN
Seq: 329 Ack: 0
SYN/ACK
Seq: 498 Ack: 330
Time Time
IHRPv1 - Caendra Inc. © 2018 | p.15
2.1.1 TCP
SYN
Seq: 329 Ack: 0
SYN/ACK
Seq: 498 Ack: 330
ACK
Seq: 330 Ack: 499
Time Time
IHRPv1 - Caendra Inc. © 2018 | p.16
2.1.1 TCP
One of the ways using which the venerable Nmap tool tries
to perform OS fingerprinting, is by examining the Initial
Sequence Numbers (ISNs) generated by the target host
(after connections are being attempted to a listening port).
Each TCP/IP stack (and subsequently each OS) features its
own way of generating Initial Sequence Numbers.
Detection
The first thing you should notice, is the big amount of SYN packets being sent
to the 192.168.1.2 host (in a short amount of time and without the
corresponding SYN/ACK packets).
If you also carefully analyze the series of SYN packets that Nmap sent, you will
notice something weird. Nmap repeatedly used the ISN from the scanning host,
while scanning the different ports of the remote host. Unique ISNs should be
used, while attempting to connect to different ports of a remote host.
Detection
Once you identify a scanning host, you can determine if you are dealing
with Nmap, by noting the scanning host’s ISN and executing the below.
>> tcpdump -S -r nmap_sequence_number_prediction.pcap tcp[4:4] = 3917476875
The scanning
host’s ISN reuse,
indicates that the
scanning/fingerp
rinting attempt
most probably
originates from a
Nmap instance
Detection
Detection
If you carefully look at packets #1, #3-#9 and #12-#13, you will notice that the host 192.168.1.6 uses the same source port (36901)
for multiple connection attempts to different ports of the remote host. This is abnormal. The normal behavior would be
incrementing the source port numbers inside the ephemeral port range.
Detection
Detection
Obviously, we are dealing with a scanning attempt, but what is that destination port 0 (TCP) all about?
A host is not supposed to be listening on port 0. A scanning tool sending packets to port 0 (TCP) of the remote host, is trying
identify if the remote host is alive. If the remote host is alive, then, a RST response should be sent to all those packets.
It has been known for years that an existing TCP connection can
be cut apart through a crafted TCP RST (and other) packet sent
either to the client or the server. For a successful RST attack to
be executed, an attacker should have prior knowledge of the
below.
• Source Port
• Destination Port
• Source IP
• Destination IP
• “correct” Sequence Number
IHRPv1 - Caendra Inc. © 2018 | p.34
2.1.1.5 TCP RST Attack
It has been known for years that an existing TCP connection can
be cut apart through a crafted TCP RST (and other) packet sent
either to the client or the server. For a successful RST attack to
be executed, an attacker should have prior knowledge of the
below.
Those can be easily identified by an attacker in
• Source Port the same network, who is sniffing the network
traffic.
• Destination Port
• Source IP TCP RST attacks can also be executed remotely
though, as described in the following paper
• Destination IP https://packetstormsecurity.com/files/downloa
d/33170/SlippingInTheWindow_v1.0.doc
• “correct” Sequence Number
IHRPv1 - Caendra Inc. © 2018 | p.35
2.1.1.5 TCP RST Attack
Detection
Detection
• If you carefully look at packet #12, you will notice that the 192.168.1.5 host sent a TCP RST packet and subsequently terminated the
connection. So far, everything seems normal. Now, if you carefully look at packet #11, you will notice normal data transmission
originating from the 192.168.1.5 host, but its MAC address is different than the one included in packet #12.
• It looks like an attacker executed a TCP RST attack to terminate the connection, spoofing the 192.168.1.5 host.
• The next sequence number was first identified through sniffing traffic and then used inside the spoofed RST packet.
Detection
Detection
• This is obviously a capture file of a Telnet session. Telnet offers no encryption and thus, we can see every command the client issued and every result returned by the
server in clear text.
• Let’s analyze packet #15.
o TCP Retransmission is displayed because the sequence number and the acknowledgement number of this packet are the same as the ones in packet #11.
o The MAC address of the client (192.168.1.4) in this packet is different than the MAC address that is included in all previous packets related to this host.
• It looks like an attacker has taken over (hijacked) the whole Telnet session. This is also apparent in packet #17, that includes the MAC address of the attacker and the
command the attacker issued (uname –a)
• The server has no defense mechanism to detect that the Telnet session is hijacked and sends the output of the uname –a command back to the 192.168.1.4 client.
At the end of the TCP header, one may find TCP options
being specified.
http://www.caida.org/publications/papers/2005/fingerprinting/KohnoBroidoClaffy05-
devicefingerprinting.pdf
IHRPv1 - Caendra Inc. © 2018 | p.45
2.1.1.7.1 TCP Timestamps Option
UDP Overview
ICMP Overview
We all know that we can map live hosts via ICMP echo
requests to a single, broadcast or subnet address. This
mapping technique though has been abused in the past to
such a degree that most sites nowadays disallow inbound
and/or outbound ICMP echo requests.
Detection
Detection
Detection
Detection
Source: http://www.uwindsor.ca/
Detection
Source: http://www.uwindsor.ca/
Detection
The victim
no longer
replies to
Echo
Requests
Source: http://www.uwindsor.ca/
Detection
The IPv6 variant of the Smurf attack on the wire looks as follows.
Detection
The IPv6 variant of the Smurf attack on the wire looks as follows.
The spoofed
packet was
injected and
broadcasted
successfully
Detection
Detection
• The capture file seems imbalanced as far as the amount of Echo requests and Echo replies is concerned. You can see two
or more replies for each request
• An Echo request and the associated Echo reply should have the same length (have identical payloads). This isn’t the case in
this capture file.
• The payload size in some ICMP packets is a lot bigger than normal. For example, see packet #16.
Detection
Detection
Detection
Detection
Detection
Detection
• A large number of ICMP Redirect packets exist. In those packets the router instructs the client 10.100.13.126 to make a change in its routing table to use
the gateway 10.100.13.20 for all subsequent packets. At this moment, you should check if the gateway 10.100.13.20 is a legitimate gateway.
• If you filter the whole capture file, based on the MAC address of the router (10.100.13.1) [eth.src==72:9b:2f:a0:90:91], you will notice that this MAC
address is associated with the 10.100.13.20 machine.
• Even though it is not clearly visible in the capture file, every HTTP request can now be sniffed by the 10.100.13.20 host, as a result of the ICMP Redirect
attack.
• So, it looks like the penetration tester crafted malicious ICMP Redirect packets, spoofing the router, and mounted an ICMP Redirect attack.
IHRPv1 - Caendra Inc. © 2018 | p.80
2.1 Analyzing & Detecting Transport Layer Attacks
We will analyze them on the wire and also see attacks that
either leverage them or misuse them.
Detection
SMB works in a client-server model,
where the client makes specific
requests to the server, and based on
the requests, the server responds
accordingly. Most of the requests are
related to accessing filesystems, while
other forms of requests involve Inter-
Process Communication (IPC).
Code 0 means STATUS_OK, which
implies that everything works fine and
there is no problem. Any other code
should be examined. STATUS_ACCESS_DENIED SMB error example
Detection
SMB works in a client-server model,
where the client makes specific
requests to the server, and based on
the requests, the server responds
accordingly. Most of the requests are
related to accessing filesystems, while
other forms of requests involve Inter-
Process Communication (IPC). SMB errors you should examine
Detection
In the image above we see the packet information as it pertains the different layers of the
OSI model.
• Ethernet II = MAC Addresses (SRC, DST)
• Internet Protocol Version 4 = IP Address (SRC, DST)
• Transmission Control Protocol = TCP (SRC PORT, DST PORT)
• Hypertext Transfer Protocol = HTTP
So far we can tell that the traffic is using an expected port, port 80. Remember
that this port doesn’t necessarily have to be port 80. An organization can
decide to use a different port altogether but we know the standard port is 80
and if it’s port 80 then we’re expecting web traffic.
Here, we’re looking at the HTTP section of the packet details. The HTTP method is GET and the host is not in
FQDN format. The http://IP format should alarm you, but in this case its pointing to an internal server and that
is normal behavior in corporate environments. The source host has an IP of 10.54.15.100.
If we double click the link, [Response in frame: 9], in the HTTP section of the packet details of packet 7 we’ll
jump to packet 9 which contains the packet details of the HTTP response to the HTTP request.
Within this packet we can do the same, jump back to packet 7 using the link
[Request in frame: 7].
IHRPv1 - Caendra Inc. © 2018 | p.114
2.2.2.1 HTTP
Above we notice a section called Line-based text data: text/html within the packet
details. We can clearly see that the packet is returning a login page for the server.
Before looking at cleartext credentials let’s test our packet analysis skills.
How many TCP streams are there in the packet capture below?
1. From the packet capture we can see different source ports, so, each different source
port will have its own TCP Handshake followed by its corresponding traffic.
2. Another way this can be done is by using a display filter and increment the number of
the TCP Stream. You will identify a non-valid TCP Stream by the non-visible packets.
3. Under the TCP tab in Conversations we can see there are 3 TCP Streams. From here we
can select a stream and choose Follow Stream from bottom right corner.
Detection
Before we dive deeper, let’s take a moment to give the traffic capture
below a look and see if we can spot anything that might look odd.
Detection
There is one thing that stands out right away which is highlighted below.
• In the screenshot we can quickly see normal requests to web pages such as news.php and newsdetails.php?id=26 then we see another request to
newsdetails.php?id=26%27
• If we URL decode %27 it corresponds to a single quote (‘). This behavior is typical when looking for a SQL injection. Now was someone looking for a SQLi or did someone
make a typo in their web page request? Let’s go further down the capture file to find out.
https://www.acunetix.com/websitesecurity/sql-injection/
IHRPv1 - Caendra Inc. © 2018 | p.125
2.2.2.1.1 Malicious HTTP Traffic Example
Detection
Glancing further at the capture file, a few packets down, we can see more indications of SQL injection
attempts. Looking at packets #32 and #44 we can see that the person didn’t make a typo request at
packet #20. This is indeed an attempt to find SQL injection on the server.
Detection
Detection
We begin at the first packet in question, packet #20. By further inspection, we see that
the User-Agent is Firefox and the OS is Linux. User-Agent’s can be spoofed, but not
always, as we will see shortly.
Detection
Detection
By looking back to the initial packet of interest, packet #20, we can look at the Line-
based text data: text/html portion of the packet details and notice that error
messages are being displayed to the individual conducting the SQL injection
queries.
Detection
Strangely, packet #56, and the packet after that, packet #73, don’t seem to contain
any SQL injection queries. Maybe the individual decided not to continue the attack?
Detection
Let’s take a closer look at packet #56. Indeed no SQL injection attempt is visible within
this packet, but something else should have already alarmed us, the User-Agent. The
User-Agent for this HTTP GET Request is Sqlmap. So the attacker didn’t quit, he/she
escalated.
Detection
• When analyzing HTTPS traffic, we should see encrypted packets. All traffic on port 443 should look this way.
The traffic is unreadable, but if this is internal traffic within our corporate
environment, then, it is feasible to decrypt this traffic using the private key
from the internal server.
Detection
MAIL FROM Identifies the sender of the message; used in the form
MAIL FROM:.
The server replies with the options that an SMTP client can
pick from.
Detection
The lack of proper security
configuration may also allow the
attacker to connect to the SMTP
server and manually enumerate the
users on that server using the VRFY,
EXPN or RCPT TO commands.
You can learn more, or freshen up, on DNS here and here.
https://www.ietf.org/rfc/rfc1034.txt
https://www.ietf.org/rfc/rfc1035.txt
IHRPv1 - Caendra Inc. © 2018 | p.162
2.2.4 DNS
Should only go to DNS Servers. DNS traffic not going to DNS Servers.
Should see DNS Responses to DNS A lot of DNS Queries with no DNS
Queries. responses or vice versa.
Also notice that there are 2 different transaction IDs for the packets: 0xde40 & 0xa620.
Below we can verify that this is a UDP packet and it’s using
an expected port, 53.
Detection
Let’s take a closer look at the packet details for this zone
transfer.
IHRPv1 - Caendra Inc. © 2018 | p.171
2.2.4.1 Malicious DNS Traffic Example
Detection
Here we see details of packet #60, which is
a zone transfer. We also see that instead of
using UDP/53 this DNS Query used
TCP/53. Also in case you didn’t know that
AXFR referred to a zone transfer the clue is
within the packet details.
Detection
Effectively Using
Open Source IDS
During those labs, you will not only get familiar with their
detection capabilities, but you will also learn effective rule
writing and how to detect whole classes of attacks.
Suricata Fundamentals
In this lab, you will learn about Suricata's
capabilities, features and configuration. In
addition, you will get familiar with
configuring Suricata, according to your
detection needs and, at the same time, you
will learn all about Suricata Inputs and
Outputs. Finally, you will be shown, how to
effectively parse Suricata output and how to
extract critical information out of it.
*To access, go to the course in your members area and click the lab drop-down in the appropriate module line to access a lab, or go to the
virtual labs tab on the left navigation.
IHRPv1 - Caendra Inc. © 2018 | p.178
LAB: Effectively Using
Suricata
*To access, go to the course in your members area and click the lab drop-down in the appropriate module line to access a lab, or go to the
virtual labs tab on the left navigation.
IHRPv1 - Caendra Inc. © 2018 | p.179
LAB: Effectively Using Bro
*To access, go to the course in your members area and click the lab drop-down in the appropriate module line to access a lab, or go to the
virtual labs tab on the left navigation.
IHRPv1 - Caendra Inc. © 2018 | p.180
LAB: Effectively Using
Snort
*To access, go to the course in your members area and click the lab drop-down in the appropriate module line to access a lab, or go to the
virtual labs tab on the left navigation.
IHRPv1 - Caendra Inc. © 2018 | p.181
References
OS fingerprinting
https://nmap.org/book/osdetect-methods.html#osdetect-gcd
Ptunnel
http://freshmeat.sourceforge.net/projects/ptunnel/
ONC RPC
https://www.ietf.org/rfc/rfc1831.txt
DCE RPC
http://pubs.opengroup.org/onlinepubs/9629399/
SQL injection
https://www.acunetix.com/websitesecurity/sql-injection/
Sqlmap
https://github.com/sqlmapproject/sqlmap
RFC 6101
https://tools.ietf.org/html/rfc6101
RFC 8446
https://datatracker.ietf.org/doc/rfc8446/
Transaction IDs
https://technet.microsoft.com/en-us/library/dd197470(v=ws.10).aspx
*To access, go to the course in your members area and click the lab drop-down in the appropriate module line to access a lab, or go to the
virtual labs tab on the left navigation.
*To access, go to the course in your members area and click the lab drop-down in the appropriate module line to access a lab, or go to the
virtual labs tab on the left navigation.