Fixed more buffer overflows with small packets
This commit is contained in:
@@ -36,13 +36,11 @@ void ndpi_search_dcerpc(struct ndpi_detection_module_struct *ndpi_struct, struct
|
|||||||
{
|
{
|
||||||
struct ndpi_packet_struct *packet = &flow->packet;
|
struct ndpi_packet_struct *packet = &flow->packet;
|
||||||
|
|
||||||
u_int16_t len_packet = (packet->payload[9]<<8) | packet->payload[8];
|
|
||||||
|
|
||||||
if((packet->tcp != NULL)
|
if((packet->tcp != NULL)
|
||||||
&& (packet->payload_packet_len >= 64)
|
&& (packet->payload_packet_len >= 64)
|
||||||
&& (packet->payload[0] == 0x05) /* version 5 */
|
&& (packet->payload[0] == 0x05) /* version 5 */
|
||||||
&& (packet->payload[2] < 16) /* Packet type */
|
&& (packet->payload[2] < 16) /* Packet type */
|
||||||
&& (len_packet == packet->payload_packet_len) /* Packet Length */
|
&& (((packet->payload[9]<<8) | packet->payload[8]) == packet->payload_packet_len) /* Packet Length */
|
||||||
) {
|
) {
|
||||||
NDPI_LOG(NDPI_PROTOCOL_DCERPC, ndpi_struct, NDPI_LOG_DEBUG, "DCERPC match\n");
|
NDPI_LOG(NDPI_PROTOCOL_DCERPC, ndpi_struct, NDPI_LOG_DEBUG, "DCERPC match\n");
|
||||||
ndpi_int_dcerpc_add_connection(ndpi_struct, flow);
|
ndpi_int_dcerpc_add_connection(ndpi_struct, flow);
|
||||||
|
|||||||
@@ -294,7 +294,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memcmp(packet->payload, "GND", 3) == 0) {
|
if (packet->payload_packet_len >= 3 && memcmp(packet->payload, "GND", 3) == 0) {
|
||||||
if ((packet->payload_packet_len == 8 && (memcmp(&packet->payload[6], "\x01\x00", 2) == 0))
|
if ((packet->payload_packet_len == 8 && (memcmp(&packet->payload[6], "\x01\x00", 2) == 0))
|
||||||
|| (packet->payload_packet_len == 11 && (memcmp(&packet->payload[6], "\x01\x01\x08\x50\x49", 5)
|
|| (packet->payload_packet_len == 11 && (memcmp(&packet->payload[6], "\x01\x01\x08\x50\x49", 5)
|
||||||
== 0)) || (packet->payload_packet_len == 17
|
== 0)) || (packet->payload_packet_len == 17
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ void ndpi_search_h323(struct ndpi_detection_module_struct *ndpi_struct, struct n
|
|||||||
NDPI_LOG(NDPI_PROTOCOL_H323, ndpi_struct, NDPI_LOG_DEBUG, "calculated dport over tcp.\n");
|
NDPI_LOG(NDPI_PROTOCOL_H323, ndpi_struct, NDPI_LOG_DEBUG, "calculated dport over tcp.\n");
|
||||||
|
|
||||||
/* H323 */
|
/* H323 */
|
||||||
if((packet->payload[0] == 0x03)
|
if(packet->payload_packet_len >= 3
|
||||||
|
&& (packet->payload[0] == 0x03)
|
||||||
&& (packet->payload[1] == 0x00)
|
&& (packet->payload[1] == 0x00)
|
||||||
&& (packet->payload[2] == 0x00)) {
|
&& (packet->payload[2] == 0x00)) {
|
||||||
struct tpkt *t = (struct tpkt*)packet->payload;
|
struct tpkt *t = (struct tpkt*)packet->payload;
|
||||||
@@ -63,7 +64,8 @@ void ndpi_search_h323(struct ndpi_detection_module_struct *ndpi_struct, struct n
|
|||||||
sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest);
|
sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest);
|
||||||
NDPI_LOG(NDPI_PROTOCOL_H323, ndpi_struct, NDPI_LOG_DEBUG, "calculated dport over udp.\n");
|
NDPI_LOG(NDPI_PROTOCOL_H323, ndpi_struct, NDPI_LOG_DEBUG, "calculated dport over udp.\n");
|
||||||
|
|
||||||
if(packet->payload[0] == 0x80 && packet->payload[1] == 0x08 && (packet->payload[2] == 0xe7 || packet->payload[2] == 0x26) &&
|
if(packet->payload_packet_len >= 5 && packet->payload[0] == 0x80 && packet->payload[1] == 0x08 &&
|
||||||
|
(packet->payload[2] == 0xe7 || packet->payload[2] == 0x26) &&
|
||||||
packet->payload[4] == 0x00 && packet->payload[5] == 0x00)
|
packet->payload[4] == 0x00 && packet->payload[5] == 0x00)
|
||||||
{
|
{
|
||||||
NDPI_LOG(NDPI_PROTOCOL_H323, ndpi_struct, NDPI_LOG_DEBUG, "found H323 broadcast.\n");
|
NDPI_LOG(NDPI_PROTOCOL_H323, ndpi_struct, NDPI_LOG_DEBUG, "found H323 broadcast.\n");
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ void ndpi_search_kakaotalk_voice(struct ndpi_detection_module_struct *ndpi_struc
|
|||||||
|
|
||||||
if(packet->iph
|
if(packet->iph
|
||||||
&& packet->udp
|
&& packet->udp
|
||||||
&& (packet->payload_packet_len > 0)
|
&& (packet->payload_packet_len >= 4)
|
||||||
) {
|
) {
|
||||||
if((packet->payload[0] == 0x81)
|
if((packet->payload[0] == 0x81)
|
||||||
|| (packet->payload[1] == 0xC8)
|
|| (packet->payload[1] == 0xC8)
|
||||||
|
|||||||
@@ -37,12 +37,11 @@ static void ndpi_check_radius(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
|
|
||||||
if(packet->udp != NULL) {
|
if(packet->udp != NULL) {
|
||||||
struct radius_header *h = (struct radius_header*)packet->payload;
|
struct radius_header *h = (struct radius_header*)packet->payload;
|
||||||
u_int len = ntohs(h->len);
|
|
||||||
|
|
||||||
if((payload_len > sizeof(struct radius_header))
|
if((payload_len > sizeof(struct radius_header))
|
||||||
&& (h->code > 0)
|
&& (h->code > 0)
|
||||||
&& (h->code <= 5)
|
&& (h->code <= 5)
|
||||||
&& (len == payload_len)) {
|
&& (ntohs(h->len) == payload_len)) {
|
||||||
NDPI_LOG(NDPI_PROTOCOL_RADIUS, ndpi_struct, NDPI_LOG_DEBUG, "Found radius.\n");
|
NDPI_LOG(NDPI_PROTOCOL_RADIUS, ndpi_struct, NDPI_LOG_DEBUG, "Found radius.\n");
|
||||||
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RADIUS, NDPI_PROTOCOL_UNKNOWN);
|
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RADIUS, NDPI_PROTOCOL_UNKNOWN);
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ void ndpi_search_rtcp(struct ndpi_detection_module_struct *ndpi_struct, struct n
|
|||||||
/* Let's check first the RTCP packet length */
|
/* Let's check first the RTCP packet length */
|
||||||
u_int16_t len, offset = 0, rtcp_section_len;
|
u_int16_t len, offset = 0, rtcp_section_len;
|
||||||
|
|
||||||
while(offset < packet->payload_packet_len) {
|
while(offset + 3 < packet->payload_packet_len) {
|
||||||
len = packet->payload[2+offset] * 256 + packet->payload[2+offset+1];
|
len = packet->payload[2+offset] * 256 + packet->payload[2+offset+1];
|
||||||
rtcp_section_len = (len + 1) * 4;
|
rtcp_section_len = (len + 1) * 4;
|
||||||
|
|
||||||
@@ -50,9 +50,10 @@ void ndpi_search_rtcp(struct ndpi_detection_module_struct *ndpi_struct, struct n
|
|||||||
|
|
||||||
sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest);
|
sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest);
|
||||||
NDPI_LOG(NDPI_PROTOCOL_RTCP, ndpi_struct, NDPI_LOG_DEBUG, "calculating dport over udp.\n");
|
NDPI_LOG(NDPI_PROTOCOL_RTCP, ndpi_struct, NDPI_LOG_DEBUG, "calculating dport over udp.\n");
|
||||||
if(((packet->payload_packet_len >= 28 || packet->payload_packet_len <= 1200) &&
|
/* TODO changed a pair of length condition to the && from ||. Is it correct? */
|
||||||
|
if(((packet->payload_packet_len >= 28 && packet->payload_packet_len <= 1200) &&
|
||||||
((packet->payload[0] == 0x80) && ((packet->payload[1] == 0xc8) || (packet->payload[1] == 0xc9)) && (packet->payload[2] == 0x00)))
|
((packet->payload[0] == 0x80) && ((packet->payload[1] == 0xc8) || (packet->payload[1] == 0xc9)) && (packet->payload[2] == 0x00)))
|
||||||
|| (((packet->payload[0] == 0x81) && ((packet->payload[1] == 0xc8) || (packet->payload[1] == 0xc9))
|
|| (packet->payload_packet_len >= 3 && ((packet->payload[0] == 0x81) && ((packet->payload[1] == 0xc8) || (packet->payload[1] == 0xc9))
|
||||||
&& (packet->payload[2] == 0x00)))) {
|
&& (packet->payload[2] == 0x00)))) {
|
||||||
NDPI_LOG(NDPI_PROTOCOL_RTCP, ndpi_struct, NDPI_LOG_DEBUG, "found rtcp.\n");
|
NDPI_LOG(NDPI_PROTOCOL_RTCP, ndpi_struct, NDPI_LOG_DEBUG, "found rtcp.\n");
|
||||||
ndpi_int_rtcp_add_connection(ndpi_struct, flow);
|
ndpi_int_rtcp_add_connection(ndpi_struct, flow);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ static void ndpi_check_spotify(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
}
|
}
|
||||||
} else if(packet->tcp != NULL) {
|
} else if(packet->tcp != NULL) {
|
||||||
|
|
||||||
if(packet->payload[0] == 0x00 && packet->payload[1] == 0x04 &&
|
if(payload_len >= 8 && packet->payload[0] == 0x00 && packet->payload[1] == 0x04 &&
|
||||||
packet->payload[2] == 0x00 && packet->payload[3] == 0x00&&
|
packet->payload[2] == 0x00 && packet->payload[3] == 0x00&&
|
||||||
packet->payload[6] == 0x52 && packet->payload[7] == 0x0e &&
|
packet->payload[6] == 0x52 && packet->payload[7] == 0x0e &&
|
||||||
packet->payload[8] == 0x50 ) {
|
packet->payload[8] == 0x50 ) {
|
||||||
|
|||||||
@@ -223,6 +223,8 @@ int getSSLcertificate(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
}
|
}
|
||||||
} else if(handshake_protocol == 0x01 /* Client Hello */) {
|
} else if(handshake_protocol == 0x01 /* Client Hello */) {
|
||||||
u_int offset, base_offset = 43;
|
u_int offset, base_offset = 43;
|
||||||
|
if (base_offset + 2 <= packet->payload_packet_len)
|
||||||
|
{
|
||||||
u_int16_t session_id_len = packet->payload[base_offset];
|
u_int16_t session_id_len = packet->payload[base_offset];
|
||||||
|
|
||||||
if((session_id_len+base_offset+2) <= total_len) {
|
if((session_id_len+base_offset+2) <= total_len) {
|
||||||
@@ -289,6 +291,7 @@ int getSSLcertificate(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return(0); /* Not found */
|
return(0); /* Not found */
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user