Showing posts with label tcp/ip. Show all posts
Showing posts with label tcp/ip. Show all posts

Aug 2, 2010

IDS Evasion by TCP Checksum

Good posting at Packetstan about potential evasion where IPS fails to validate TCP checksums.

Summary:

  • If IDS turns off the validation on TCP checksum, packet evasion is possible.
  • First, establish the 3 way-handshake.
  • Then, fool the IDS by sending a RST packet with bad TCP checksum.
  • Then continue sending the EVIL packets.

Jul 22, 2010

IDS Evasion on Linux Off-by-one TCP Timestamps

A very good article explaining potential IDS/IPS evasion with Linux 2.4/2.6 Kernel using off-by-one TCP timestamps.
In a nutshell, TCP timestamps can be included as a TCP option to specify the sending host's timestamp and echo the most recently received timestamp from the other side of the connection. The notion of time or timestamp is not the typical one since it denotes, for most operating systems except OpenBSD, a representation of the uptime of the host since the last reboot.

Jul 1, 2010

IDS Evasion with Syncookies

Is it possible that after a destination host (server) sends you a RST packet, you still can continue to send the server some data and continue the connections?

Yes, it is possible, on a Linux server with SynCookies enabled.

sysctl -a | grep net.ipv4.tcp_syncookies
net.ipv4.tcp_syncookies = 1

Steps (howto):

  • During the 3-way handshake, the client sends a ACK packet (3rd packet) to the server with a value one more than the expected value.
  • The Linux server will response with a RST at the 4th packet. - > fool the IDS that the TCP connection is terminated.
  • Then, the client can continue to send EVIL stuff to the server.
Summary:
  • TCP SynCookies is used to combat Syn flood (DoS) attack.
  • By right, should see a re-transmit of SYN+ACK instead of RST, by the server.
  • The faked ACK packet (4th) is just a stray packet (in SynCookies).
  • The subsequent GET /EVIL packet (5th), is considered as valid final ACK of three-way handshake since the syn-cookie will match.
  • With Snort IDS, the default stream5 policy of "windows" will not be fooled by this because of what it considers an invalid reset sequence number.

Source articles:


Source codes:

Jun 30, 2010

How TCP SynCookies Work?

So far, TCP Syn-Cookies is only available in Linux (some are turned on by default). Below is an interesting quirk of TCP Syncookies of how it works.

>>> From IDS/IPS Evasion with SynCookies
I will start off by covering the relevant parts of syncookies. There are many types of Denial of service attack, but the most powerful are low rate DoS attacks; attacks that need very little of the attackers resources, but cause major disruption to the attacked host or network. 
One such attack was the SYN flood attack. The attacker would spoof thousands of packets from fake hosts. Since the destination would half-open a connection for each of these, its resources would soon be overwhelmed with these faked connections, and it would then stop acting as it should (either by rejecting new connections, or dropping old ones, or even crashing outright). 
Some clever folks devised TCP Syncookies to combat this problem. Whenever a SYN was received, the connection was not opened by the destination. Instead, it SYN-ACK’d using a ‘magic’ sequence number that it calculated. The calculation involved the IP Source, Destination, TCP Source port and Destination port, along with an unknown random bit of data that only the server would know. No entry was added to the servers table, so its resources would stay free. When the client would ACK, it would increase the sequence number by one. The server would see this ack, and would do the same math it did before to create its magic sequence number, and subtract one from the received number. 
Since the number is only based on the IP, Port, and random number, the numbers should be identical, even though it would not remember the original connection. If the two matched, it would open the connection. Since the magic number was effectively unguessable to the client, this would make it impossible for an attacker to flood the server with a low rate SYN flood attack.

Jun 28, 2010

Spot Crafted Packet in PCAP

An excellent article about detecting crafted packets: Fitting in:
If you ever see a packet flying by on your network that has a SYN flag set and does not have a TCP options Maximum Segment Size (MSS) – you can be fairly certain that it was crafted. And, if it was crafted – it probably is for some nefarious purposes. There are other TCP options too that can be included, but most current well-known TCP/IP stacks list the MSS as the first of the TCP options in the TCP header. However, Solaris stacks do not follow this convention and may present some false positives if you include this check.
Another unusual condition that may be a reflection of a crafted packet or a poorly written TCP/IP stack is where a client SYN packet has a non-zero acknowledgement value. After all, the client has received nothing to acknowledge.
To filter (SYN and !MSS) with tcpdump:
tcp[13] & 2 != 0 and ((tcp[12]/16 == 5) or (tcp[12]/16 > 5 and tcp[20] != 02))
  • 'tcp[13] & 2 !=0' looks for the SYN flag set
  • 'tcp[12]/16 ==5' looks for a TCP header length of 5. This is fairly convoluted because the value for the TCP header length is found in the high-order nibble so we must first divide by 16 to make it more logical (at least for me). Now, a TCP header length of 5 (32-bit words) means a conventional 20-byte TCP header with no options.
  • There can still be TCP options, yet no MSS. The rest of the "and" clause examines that by finding TCP options where the TCP header length is greater than 5, and assumes that the MSS value appears first in the 20th byte offset of the TCP header with a value of 02.
To filter (SYN and !MSS) with Wireshark (display filter) :
!(tcp.options.mss) && (tcp.flags.syn == 1)

To find bogus packet with Wireshark (display filter):
tcp.flags.syn == 0 && (tcp.options.mss || tcp.options.wscale || tcp.options.sack)

To filter (SYN and non-zero ACK ) with tcpdump:
tcp[13] = 2 and tcp[8:4] > 0
To filter (SYN and non-zero ACK ) with tcpdump:
tcp.flags.syn == 1 && tcp.flags.ack == 0 && tcp[8:4] > 0

Feb 19, 2009

TCP/IP Headers

Very nice TCP/IP header drawing diagrams in both PDF and PNG formats. It has IPv4, IPv6, TCP, UDP, and ICMP.

Links: