Add header length check to GRE packet analyzer

This commit is contained in:
Tim Wojtulewicz 2020-10-19 10:26:23 -07:00
parent 4d27793f13
commit a19b018dc8

View file

@ -10,7 +10,7 @@
using namespace zeek::packet_analysis::GRE; using namespace zeek::packet_analysis::GRE;
static unsigned int gre_header_len(uint16_t flags) static unsigned int gre_header_len(uint16_t flags=0)
{ {
unsigned int len = 4; // Always has 2 byte flags and 2 byte protocol type. unsigned int len = 4; // Always has 2 byte flags and 2 byte protocol type.
@ -44,7 +44,7 @@ bool GREAnalyzer::AnalyzePacket(size_t len, const uint8_t* data, Packet* packet)
{ {
if ( ! packet->ip_hdr ) if ( ! packet->ip_hdr )
{ {
reporter->InternalError("GREAnalyzer: ip_hdr not found in packet keystore"); reporter->InternalError("GREAnalyzer: ip_hdr not provided from earlier analyzer");
return false; return false;
} }
@ -54,6 +54,12 @@ bool GREAnalyzer::AnalyzePacket(size_t len, const uint8_t* data, Packet* packet)
return false; return false;
} }
if ( len < gre_header_len() )
{
sessions->Weird("truncated_GRE", packet);
return false;
}
int proto = packet->proto; int proto = packet->proto;
int gre_link_type = DLT_RAW; int gre_link_type = DLT_RAW;