HTTP dissector improvements

This commit is contained in:
Luca Deri
2020-05-30 18:40:15 +02:00
parent cbb0b864a2
commit 374a24a1fb
+47 -34
View File
@@ -28,20 +28,16 @@
#include "ndpi_api.h" #include "ndpi_api.h"
#include <stdlib.h> #include <stdlib.h>
static const char* binary_file_mimes[] = { static const char* binary_file_mimes_e[] = { "exe", NULL };
"exe", static const char* binary_file_mimes_v[] = { "vnd.ms-cab-compressed", "vnd.microsoft.portable-executable", NULL };
"vnd.ms-cab-compressed", static const char* binary_file_mimes_x[] = { "x-msdownload", "x-dosexec", NULL };
"vnd.microsoft.portable-executable"
"x-msdownload",
"x-dosexec",
NULL
};
#define ATTACHMENT_LEN 3
static const char* binary_file_ext[] = { static const char* binary_file_ext[] = {
".exe", "exe",
".msi", "msi",
".cab", "cab",
NULL NULL
}; };
static void ndpi_search_http_tcp(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_search_http_tcp(struct ndpi_detection_module_struct *ndpi_struct,
@@ -112,34 +108,51 @@ static ndpi_protocol_category_t ndpi_http_check_content(struct ndpi_detection_mo
if(ndpi_strncasestr(app, "mpeg", app_len_avail) != NULL) { if(ndpi_strncasestr(app, "mpeg", app_len_avail) != NULL) {
flow->guessed_category = flow->category = NDPI_PROTOCOL_CATEGORY_STREAMING; flow->guessed_category = flow->category = NDPI_PROTOCOL_CATEGORY_STREAMING;
return(flow->category); return(flow->category);
} else { } else if (app_len_avail > 1) {
for (int i = 0; binary_file_mimes[i] != NULL; i++) { const char** cmp_mimes = NULL;
if (ndpi_strncasestr(app, binary_file_mimes[i], app_len_avail) != NULL) {
flow->guessed_category = flow->category = NDPI_PROTOCOL_CATEGORY_DOWNLOAD_FT; switch(app[0]) {
NDPI_SET_BIT(flow->risk, NDPI_BINARY_APPLICATION_TRANSFER); case 'e': cmp_mimes = binary_file_mimes_e; break;
NDPI_LOG_INFO(ndpi_struct, "found executable HTTP transfer"); case 'v': cmp_mimes = binary_file_mimes_v; break;
return(flow->category); case 'x': cmp_mimes = binary_file_mimes_x; break;
} }
}
if(cmp_mimes) {
for(int i = 0; cmp_mimes[i] != NULL; i++) {
if(ndpi_strncasestr(app, cmp_mimes[i], app_len_avail) != NULL) {
flow->guessed_category = flow->category = NDPI_PROTOCOL_CATEGORY_DOWNLOAD_FT;
NDPI_SET_BIT(flow->risk, NDPI_BINARY_APPLICATION_TRANSFER);
NDPI_LOG_INFO(ndpi_struct, "found executable HTTP transfer");
return(flow->category);
}
}
}
} }
} }
/* check for attachment */ /* check for attachment */
if (packet->content_disposition_line.len > 0) { if (packet->content_disposition_line.len > 0) {
uint8_t attachment_len = sizeof("attachment; filename"); u_int8_t attachment_len = sizeof("attachment; filename");
if (packet->content_disposition_line.len > attachment_len) {
uint8_t filename_len = packet->content_disposition_line.len - attachment_len; if(packet->content_disposition_line.len > attachment_len) {
for (int i = 0; binary_file_ext[i] != NULL; i++) { u_int8_t filename_len = packet->content_disposition_line.len - attachment_len;
if (ndpi_strncasestr((const char*)&packet->content_disposition_line.ptr[attachment_len],
binary_file_ext[i], filename_len)) { if(filename_len > ATTACHMENT_LEN) {
flow->guessed_category = flow->category = NDPI_PROTOCOL_CATEGORY_DOWNLOAD_FT; attachment_len += filename_len-ATTACHMENT_LEN-1;
NDPI_SET_BIT(flow->risk, NDPI_BINARY_APPLICATION_TRANSFER);
NDPI_LOG_INFO(ndpi_struct, "found executable HTTP transfer"); for(int i = 0; binary_file_ext[i] != NULL; i++) {
return(flow->category); if(strncmp((const char*)&packet->content_disposition_line.ptr[attachment_len],
} binary_file_ext[i], ATTACHMENT_LEN) == 0) {
flow->guessed_category = flow->category = NDPI_PROTOCOL_CATEGORY_DOWNLOAD_FT;
NDPI_SET_BIT(flow->risk, NDPI_BINARY_APPLICATION_TRANSFER);
NDPI_LOG_INFO(ndpi_struct, "found executable HTTP transfer");
return(flow->category);
}
}
}
} }
} }
}
switch(packet->content_line.ptr[0]) { switch(packet->content_line.ptr[0]) {
case 'a': case 'a':
if(strncasecmp((const char *)packet->content_line.ptr, "audio", if(strncasecmp((const char *)packet->content_line.ptr, "audio",