securitysnort

Snort rule for ESP packets


I'm wondering whether it's possible to write a snort rule matching ESP packet with spoofed SPI value.

Packets I want to alert:
00:00:00.000000 IP x.x.x.x > x.x.x.x: ESP(spi=0x00000000,seq=0x29)

Raw packet would look something like this:

4500 XXXX XXXX XXXX XXXX -> 20 bytes of IP header
0000 0000 XXXX XXXX XXXX -> ESP header starting with 4 bytes of zeroes
XXXX...

That's why my best guess is trying to match by:
1) IP Proto equals ESP
2) raw bytes at the start of ESP header equals 0x00000000

So far I came up with this:

alert ip any any -> any any \  
(ip_proto:esp; content: "|00 00 00 00|"; offset:0; depth: 4;)  

Unfortunately, that doesn't work. I believe it's because Snort starts looking at 'content:' in the payload. I tried using pkt_data option to reset detection cursor to the start of transport layer. Per manual: "pkt_data: This option sets the cursor used for detection to the raw transport payload"

I assumed it would fool snort to start 'content:' checking right after IP header. Unfortunately, no result.

Am I making a mistake here somewhere? Or is it just not possible for Snort to match by raw bytes in the ESP header? Any help/opinion would be greatly appreciated!


Solution

  • There is no good way to do this except to write your own preprocessor. Snort does not currently have anything that exposes the ESP spi value to the rules configuration language.

    While it is true that there is support to decode ESP data, this still only exposes the decrypted payload to your rules.

    To save you some trouble, byte_test might seem like a possibility, but it very specifically allows you to manipulate the payload only. For example, the following will not allow you to examine the UDP destination port in the header for 2049:

     ...byte_test:2,=,2049,-2,big;