01 Intrusion Detection by Analyzing Traffic Part1
01 Intrusion Detection by Analyzing Traffic Part1
Traffic (Part 1)
S e c t i o n 0 2 | M o d u l e 0 1
© Caendra Inc. 2018
All Rights Reserved
Table of Contents
Module 01 | Intrusion Detection By Analyzing Traffic (Part 1)
✓ How the attacks at the IEEE 802.x Link and IP layers work
Networking Concepts
& Analysis
But, you will also have to perform the same during the
Containment, Eradication & Recovery phase; specifically,
during Long-term Containment and Recovery.
TCP, UDP
IP
IEEE
802.x
Encapsulation
Application Payload
At the Application layer, the
respective payload or data is
supplied. The payload or data
will appear after all the
encapsulating headers.
Encapsulation
TCP Header
The Application layer passes the
payload down to the Transport
layer (in this case TCP). The
Transport layer adds a TCP
header to the application
payload.
Encapsulation
IP Packet Header
The TCP header and the application
payload are now being pushed to the
Internet layer. As you can imagine, the
Internet layer adds yet another header
known as the IP header. This header
includes information that makes sure
the packet is delivered to the correct
destination IP.
Encapsulation
Frame header
The IP and TCP headers, as well
as the application payload (aka
the IP packet), are now passed
to the Network Access layer.
Encapsulation
De-encapsulation
Each layer deals only with the data that are meant to be
handled by it. Most of the time, a protocol identifier exists
which can be found in the previous layer.
IHRPv1 - Caendra Inc. © 2018 | p.19
1.1.2 TCP/IP
De-encapsulation
De-encapsulation
De-encapsulation
This means that the card understands the format and all
the fields in the frame header.
De-encapsulation
4. Unfortunately, the Transport layer knows nothing about the protocol that follows
Application or the application’s data/protocol format. It only knows the destination port. We
may be dealing with HTTP, but we are not sure.
3. The IPv4 header, in turn, includes an indicator about the transport protocol that
Transport follows; this is the protocol field. Let’s suppose the protocol is TCP. The data
following the TCP header is passed to the Transport protocol.
Internet 2. The Ethernet layer will pass all data following the Ethernet header to the IPv4-
handling part of the IP layer.
Network 1. For data to be passed properly to the IP layer, an indicator should exist that reveals
what protocol follows the Ethernet header (could be IPv4 or IPv6); this is where the
Access
type field of the Ethernet header jumps in. Let’s suppose the protocol is IPv4.
IHRPv1 - Caendra Inc. © 2018 | p.23
1.1.2 TCP/IP
4. The amount of data to be passed to the Application layer can be derived as follows. Total IP
Application datagram length - IP header length - TCP header length = Length of data to be passed
3. The Transport layer header could be of fixed length (UDP or ICMP) or of variable length (TCP).
For example, we can find a header length value about the TCP header, so that the position of the
Transport data that follow the TCP header can be identified and passed to the Application layer.
2. The standard IPv4 header has a length of 20 bytes; however, there are cases when IP option data
Internet exist. Those data can result in the IPv4 header expanding up to 60 bytes (variable length). The IP
header contains a length-related field, so that data following the IP header are passed to the
Transport layer. The IP header also has a field indicating the whole IP datagram length.
Network
Access 1. The Ethernet (802.3) header has a fixed length of 14 bytes; this means that the data that will be
passed to the IP layer begin 14 bytes after the Ethernet header.
IHRPv1 - Caendra Inc. © 2018 | p.24
1.1.2 TCP/IP
Encapsulation
Encapsulation
Network Access layer Internet layer Transport layer Application layer
Encapsulation
Network Access layer: In this line, Wireshark displays the source and destination MAC addresses.
Encapsulation
Internet layer: In this line, Wireshark displays the IP layer that comes right after the Frame header.
Encapsulation
Transport layer: In this case, UDP. It follows the IP header (recall the TCP/IP stack). Source
and destination ports are included in this summary line.
Application layer: This summary line, displays a description of the application payload, a DNS response.
Encapsulation
We can have a detailed look at each encapsulated layer
by expanding the respective fields.
Encapsulation
• 802.3: Ethernet
• 802.11: Wireless
• 802.15.1: Bluetooth
Over the years ARP has been greatly abused by attackers, due to its
inherent security shortcomings.
• There is no way to validate MAC address ownership whenever an
ARP request or response is issued.
• ARP is stateless. Whenever an ARP response is received, hosts will
create or update a cache entry with the observed IP/MAC pair
(regardless of them issuing an ARP request or not).
• An initial ARP request can result in the requester’s IP/MAC pair being
cached by listening (for broadcasts) hosts; this is done to reduce
ARP broadcast requests.
Not only that, but the attacker can also receive, inspect or
alter the traffic from the original destination and ultimately
forward it back to the original sender.
To see the MAC Address for both the source and destination, we can make a quick
change within Wireshark: View > Name Resolution > Resolve Physical Addresses.
This is how ARP works if one of the hosts in the network asks for it;
however, this is not the only way though.
Even without knowing off hand what legit device can potentially
have that MAC address on your network, but just based on the
flow and speed of the ARP Requests, we can tell something is
odd.
ARP Poisoning
ARP Poisoning
Once the gratuitous ARP packet is sent, B’s ARP cache gets poisoned
with the entry: IP_A->MAC_M. Next time B wants to send a packet to A,
it will be forwarded to M.
ARP Cache Victim (B)
IP_A: MAC_M
IP_G: MAC_G
ARP Poisoning
The same thing happens against A. The attacker sends the gratuitous
ARP packet, and A’s ARP cache gets poisoned with the entry IP_B-
>MAC_M. Next time A wants to send a packet to B, it will be forwarded to
M.
ARP Cache Victim (B)
IP_B: MAC_M
IP_G: MAC_G
ARP Poisoning
ARP Poisoning
When a host in a LAN wants to send packets to hosts outside the
LAN, it uses the default gateway.
ARP Poisoning
This diagram explains the MitM scenario. Host A sends all the traffic aimed for the internet through the
Attacker.
LAN
IP_G MAC_M
IP_M MAC_M
IP_G MAC_M
ARP Poisoning
The following describes the steps that take place in the previous
scenario:
1. Host A wants to send packets to the Internet. It already has the
IP of the gateway (IP_G), and it needs the associated MAC
address.
2. M can use a gratuitous ARP reply to advertise itself as the
default gateway: binds IP_G with his own (MAC_M).
3. All the traffic meant to leave the LAN will pass through M, which
will then redirect it to the real gateway.
IHRPv1 - Caendra Inc. © 2018 | p.79
1.2.2.1 ARP Attacks & Detection
ARP Reply
A malicious device on
the network is telling
that the router’s MAC
address is Gratuitous
00:0c:29:20:bc:14, by ARP Replies
issuing gratuitous
ARP replies at
frequent intervals .
There must be
something going on.
For the complete picture, also browse the MAC Conversation tab. You
will be presented with the following:
Finally, to be 100% sure of the assumption, browse the Packet tab. You
will be presented with the following:
Compared to wired packets, wireless ones feature a 802.11 (layer 2) header. This
header contains additional information regarding the packet and medium upon
which it travels. The types of 802.11 packets are:
Below you can see a representation of the IP header. Note that in order
to facilitate de-encapsulation, the IP header features three distinct
length values.
Length (IP header length): A field
containing the length of the IP
header.
Oftentimes, attackers check the reactions of firewalls and IDS by crafting and
sending datagrams with an invalid IP version.
In yellow, we can
see that the IP
version field has
a value of 0x7.
We can safely
conclude we are
dealing with
malicious traffic.
Another important set of IPv4 header fields are the Source IP Address
and the Destination IP Address fields. There are three golden detection
rules that are related to this set of IPv4 header fields.
• Incoming traffic to your network should obviously have a Source IP
Address that doesn’t belong to your network address space. If it
does, it is most probably crafted.
• Outgoing traffic from your network should obviously have a Source
IP Address that belongs to your network address space. If it doesn’t,
there is most probably a misconfiguration or the address is spoofed.
• Private network addresses or the loopback mode address also
require your attention
Fragment ID
Fragment
offset
Fragments
follow
Fragment ID
Fragment
offset
Fragments
follow
HINT: A stealthy mapping technique exists that leverages fragmentation. Specifically, the attacker sends an incomplete set of fragments (the zero offset fragment must be
included) to the scanned hosts. Of course, the scanned hosts should be listening on the specified port or protocol.
If this is the case, once the first fragment is received, a timer is set. Once this timer expires, the receiving host transmits an ICMP “Fragment reassembly time exceeded” error
back to the attacker.
2. Ultimately, we notice an
ICMP “reassembly time
exceeded” error being sent
back to the source that
transmitted the
incomplete fragment.
Right after that, the value of the reassembled packet will exceed the 65535 bytes limit.
Let’s also see a brief comparison between the IPv4 and IPv6 headers.
IPv4 Header IPv6 Header
Let’s also see a brief comparison between the IPv4 and IPv6 headers.
IPv6 Header
The version field is 4 bits long and contains the IP version to be expected in
Version the following contents; since we are talking about IPv6, this value is always
going to be 6 (0110).
The traffic class field is 8 bits long and operates the same as the IPv4 Type
Traffic Class of Service field; this includes support for the marking of traffic based on a
differentiated services code point (DSCP).
The flow label field is 20 bits long and is new to IPv6. It enables the ability to
Flow Label
track specific traffic flows at the network layer.
The payload length field is 16 bits long and operates the same as the IPv4
Payload Length length field; this field includes the length of the data portion of the IPv6
packet.
The next header field is 8 bits long and operates similarly to the IPv4
Next Header protocol field. The next header field indicates what to expect after the basic
IPv6 header; this includes options like a TCP or UDP header and packet.
The hop limit field is 8 bits long and operates similarly to the IPv4 Time to
Hop Limit Live field. This field is used to specify the maximum number of routers that
the packet is allowed to travel through before being discarded.
The source address field is 128 bits long and operates the same as the IPv4
Source Address
source address field, with the exception of the length differences.
The destination address field is 128 bits long and operates the same as the
Destination Address
IPv4 destination address field, with the exception of the length differences.
Let’s also see a brief comparison between the IPv4 and IPv6 headers.
• Any IP options can now be specified in extension headers between the IPV6 header and the transport-related portion of the packet.
• Fragmentation, Flags, Checksum, etc. can be specified in another extension header.
• Validation now lies in the shoulders of the protocol checksums and their pseudo-headers. This means no re-computing of the IPv6
header is required by the routers.
IPv6 Header
The version field is 4 bits long and contains the IP version to be expected in
Version the following contents; since we are talking about IPv6, this value is always
going to be 6 (0110).
The traffic class field is 8 bits long and operates the same as the IPv4 Type
Traffic Class of Service field; this includes support for the marking of traffic based on a
differentiated services code point (DSCP).
The flow label field is 20 bits long and is new to IPv6. It enables the ability to
Flow Label
track specific traffic flows at the network layer.
The payload length field is 16 bits long and operates the same as the IPv4
Payload Length length field; this field includes the length of the data portion of the IPv6
packet.
The next header field is 8 bits long and operates similarly to the IPv4
Next Header protocol field. The next header field indicates what to expect after the basic
IPv6 header; this includes options like a TCP or UDP header and packet.
The hop limit field is 8 bits long and operates similarly to the IPv4 Time to
Hop Limit Live field. This field is used to specify the maximum number of routers that
the packet is allowed to travel through before being discarded.
The source address field is 128 bits long and operates the same as the IPv4
Source Address
source address field, with the exception of the length differences.
The destination address field is 128 bits long and operates the same as the
Destination Address
IPv4 destination address field, with the exception of the length differences.
An important set of IPv6 header fields are the Source Address and the Destination
Address fields. There are three golden detection rules that are related with this set
of IPv6 header fields.
• Incoming traffic to your network should obviously have a Source Address that
doesn’t belong to your network address space. If it does, it is most probably
crafted. Incoming traffic with Destination Address being a multicast/anycast
address needs investigation.
• Outgoing traffic from your network should obviously have a Source IP Address
that belongs to your network address space. If it doesn’t, there is most probably
a misconfiguration or the address is spoofed. Outgoing traffic with Destination
Address being a multicast/anycast address needs investigation.
• Private network addresses also require your attention.
The Next Header field is used so that the type of the protocol header that follows can be identified. More specifically, the Next
Header field identifies the type of header that resides right after the IPv6 header, or the IPv6 Extension header that carries it.
Source: FIRST/SWITCH
Concerns: Threats:
• The number of EHs is not limited 1. High number of EHs could be used for FW/IDS/IPS/RA-
Guard evasion
• The number of options within an (Hop-by-Hop or
Destination) Options Header is not limited 2. High number of EHs could be used to cause DoS to the
destination
• There is no defined order of EHs (only a 3. Manipulation/fuzzing of the EHs could be used to cause
recommendation) (Exception: Hop-by-Hop Options DoS to the destination
Header must be first and non-recurring) 4. An attacker could use EHs for stealthy payload
• EH have different formats exchanges or covert communication
Source: FIRST/SWITCH
IPv6 Fragmentation
• The Unfragmentable Part will consist of the IPv6 main header plus any IPv6
Extension headers that must be processed by intermediate nodes en route to
the destination (suppose that those are the Hop-by-Hop and the Routing IPv6
Extension headers in a later example).
• The Fragmentable Part will consist of the rest of the packet, that is, any IPv6
Extension headers that need be processed only by the final destination
node(s), plus the upper-layer header and data (suppose that those are the
Destination Options IPv6 Extension header, TCP header and its payload in a
later example).
Threats:
1. DoS by sending a high number of incomplete
fragment sets (M-flag 1)
2. IDS/IPS evasion by sending overlapping or
nested fragments
For example:
• IPv4 Protocol type 41 (ISATAP, 6to4 traffic)
• IPv4 to UDP 3544 (Teredo traffic)
• Traffic to 192.88.99.1 (6to4 anycast server)
• DNS server log: resolution of "ISATAP"
https://www.cisco.com/c/en/us/products/collateral/ios-nx-os-software/enterprise-ipv6-solution/white_paper_c11-629391.pdf IHRPv1 - Caendra Inc. © 2018 | p.148
1.3.4 IPv6 Tunneling
• Frames 1 to 5 show the connection attempts to 64.233.169.104 (google.com) being closed [Notice the
FIN, ACK on frame 4]
• Frame 6 and 7 are actually IPv6 packets being transmitted by IPv4 UDP. They actually depict a Router
Solicitation and a Router Advertisement. We will analyze both in just a bit. For now, they can be seen as
the IPv6 mechanism to ask for an IPv6 address and offer an IPv6 prefix.
ICMPv6 Usages
SLAAC
Neighbor Advertisement
• An attacker can also craft an NS request containing the fake IPv6 host
address/link layer pairing. Listening neighbors will introduce this ill-
intended pairing in their neighbor cache; this is the equivalent of abused
Gratuitous ARP in IPv4.
IHRPv1 - Caendra Inc. © 2018 | p.166
1.3.6 IPv6 Security Shortcomings
Those, are only a subset of the attacks that can be executed against an
IPv6 implementation. For more, please refer to the following resources:
1. https://www.ripe.net/support/training/material/ipv6-
security/ipv6security-slides.pdf
2. https://www.blackhat.com/docs/sp-14/materials/arsenal/sp-14-
Schaefer-Workshop-Slides.pdf
3. https://www.tno.nl/media/3274/testing_the_security_of_ipv6_imple
mentations.pdf
*To access, go to the course in your members area and click the resources drop-down in the appropriate module
line to access the files for this offline lab.
IHRPv1 - Caendra Inc. © 2018 | p.170
References
RFC 826
https://www.ietf.org/rfc/rfc826.txt
RFC 791
https://www.ietf.org/rfc/rfc791.txt
CVE-2018-5391
https://portal.msrc.microsoft.com/en-US/security-guidance/advisory/ADV180022
RFC 2460
https://tools.ietf.org/html/rfc2460#page-4
RA-Guard
https://www.juniper.net/documentation/en_US/junos/topics/concept/port-security-ra-guard.html
RFC 3971
https://tools.ietf.org/html/rfc3971
*To access, go to the course in your members area and click the resources drop-down in
the appropriate module line to access the files for this offline lab.
IHRPv1 - Caendra Inc. © 2018 | p.177