Improve normalization of flow->host_server_name (#2310)
Follow-up of 4543385d10
Remove trailing spaces for any HTTP header (we already remove leading
spaces)
We want:
* a "normalized" string in `flow->host_server_name`, but
* to parse the original string for flow risk checking
`ndpi_hostname_sni_set()` is a private function, so there is no need to
export its flags.
This commit is contained in:
@@ -397,6 +397,10 @@ struct ndpi_detection_module_struct {
|
|||||||
#define NDPI_PROTOCOL_NO_MORE_SUBPROTOCOLS (-1)
|
#define NDPI_PROTOCOL_NO_MORE_SUBPROTOCOLS (-1)
|
||||||
#define NDPI_PROTOCOL_MATCHED_BY_CONTENT (-2)
|
#define NDPI_PROTOCOL_MATCHED_BY_CONTENT (-2)
|
||||||
|
|
||||||
|
#define NDPI_HOSTNAME_NORM_LC 1
|
||||||
|
#define NDPI_HOSTNAME_NORM_REPLACE_IC 2
|
||||||
|
#define NDPI_HOSTNAME_NORM_STRIP_EOLSP 4
|
||||||
|
#define NDPI_HOSTNAME_NORM_ALL (NDPI_HOSTNAME_NORM_LC | NDPI_HOSTNAME_NORM_REPLACE_IC | NDPI_HOSTNAME_NORM_STRIP_EOLSP)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -263,11 +263,6 @@ typedef u_int32_t ndpi_ndpi_mask;
|
|||||||
#define NDPI_NUM_FDS_BITS 16
|
#define NDPI_NUM_FDS_BITS 16
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NDPI_HOSTNAME_NORM_LC 1
|
|
||||||
#define NDPI_HOSTNAME_NORM_REPLACE_IC 2
|
|
||||||
#define NDPI_HOSTNAME_NORM_STRIP_EOLSP 4
|
|
||||||
#define NDPI_HOSTNAME_NORM_ALL (NDPI_HOSTNAME_NORM_LC | NDPI_HOSTNAME_NORM_REPLACE_IC | NDPI_HOSTNAME_NORM_STRIP_EOLSP)
|
|
||||||
|
|
||||||
typedef struct ndpi_protocol_bitmask_struct {
|
typedef struct ndpi_protocol_bitmask_struct {
|
||||||
ndpi_ndpi_mask fds_bits[NDPI_NUM_FDS_BITS];
|
ndpi_ndpi_mask fds_bits[NDPI_NUM_FDS_BITS];
|
||||||
} ndpi_protocol_bitmask_struct_t;
|
} ndpi_protocol_bitmask_struct_t;
|
||||||
|
|||||||
@@ -8698,6 +8698,13 @@ static void parse_single_packet_line(struct ndpi_detection_module_struct *ndpi_s
|
|||||||
if(h->line->len == 0)
|
if(h->line->len == 0)
|
||||||
h->line->ptr = NULL;
|
h->line->ptr = NULL;
|
||||||
|
|
||||||
|
/* Stripping trailing spaces */
|
||||||
|
while(h->line->len > 0 && h->line->ptr[h->line->len - 1] == ' ') {
|
||||||
|
h->line->len--;
|
||||||
|
}
|
||||||
|
if(h->line->len == 0)
|
||||||
|
h->line->ptr = NULL;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,8 +213,8 @@ static void ndpi_search_fastcgi(struct ndpi_detection_module_struct *ndpi_struct
|
|||||||
&ret_match, NDPI_PROTOCOL_FASTCGI);
|
&ret_match, NDPI_PROTOCOL_FASTCGI);
|
||||||
ndpi_check_dga_name(ndpi_struct, flow,
|
ndpi_check_dga_name(ndpi_struct, flow,
|
||||||
flow->host_server_name, 1, 0);
|
flow->host_server_name, 1, 0);
|
||||||
if(ndpi_is_valid_hostname(flow->host_server_name,
|
if(ndpi_is_valid_hostname((char *)packet->host_line.ptr,
|
||||||
strlen(flow->host_server_name)) == 0) {
|
packet->host_line.len) == 0) {
|
||||||
char str[128];
|
char str[128];
|
||||||
|
|
||||||
snprintf(str, sizeof(str), "Invalid host %s", flow->host_server_name);
|
snprintf(str, sizeof(str), "Invalid host %s", flow->host_server_name);
|
||||||
|
|||||||
@@ -958,8 +958,8 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
|
|||||||
|
|
||||||
hostname_just_set = 1;
|
hostname_just_set = 1;
|
||||||
|
|
||||||
if(ndpi_is_valid_hostname(flow->host_server_name,
|
if(ndpi_is_valid_hostname((char *)packet->host_line.ptr,
|
||||||
strlen(flow->host_server_name)) == 0) {
|
packet->host_line.len) == 0) {
|
||||||
char str[128];
|
char str[128];
|
||||||
|
|
||||||
snprintf(str, sizeof(str), "Invalid host %s", flow->host_server_name);
|
snprintf(str, sizeof(str), "Invalid host %s", flow->host_server_name);
|
||||||
|
|||||||
@@ -1465,8 +1465,8 @@ void process_chlo(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
ndpi_check_dga_name(ndpi_struct, flow,
|
ndpi_check_dga_name(ndpi_struct, flow,
|
||||||
flow->host_server_name, 1, 0);
|
flow->host_server_name, 1, 0);
|
||||||
|
|
||||||
if(ndpi_is_valid_hostname(flow->host_server_name,
|
if(ndpi_is_valid_hostname((char *)&crypto_data[tag_offset_start + prev_offset],
|
||||||
strlen(flow->host_server_name)) == 0) {
|
len) == 0) {
|
||||||
char str[128];
|
char str[128];
|
||||||
|
|
||||||
snprintf(str, sizeof(str), "Invalid host %s", flow->host_server_name);
|
snprintf(str, sizeof(str), "Invalid host %s", flow->host_server_name);
|
||||||
|
|||||||
@@ -2258,7 +2258,7 @@ int processClientServerHello(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
#ifdef DEBUG_TLS
|
#ifdef DEBUG_TLS
|
||||||
printf("[TLS] SNI: [%s]\n", sni);
|
printf("[TLS] SNI: [%s]\n", sni);
|
||||||
#endif
|
#endif
|
||||||
if(ndpi_is_valid_hostname(sni, sni_len) == 0) {
|
if(ndpi_is_valid_hostname((char *)&packet->payload[offset+extension_offset+5], len) == 0) {
|
||||||
ndpi_set_risk(ndpi_struct, flow, NDPI_INVALID_CHARACTERS, sni);
|
ndpi_set_risk(ndpi_struct, flow, NDPI_INVALID_CHARACTERS, sni);
|
||||||
|
|
||||||
/* This looks like an attack */
|
/* This looks like an attack */
|
||||||
|
|||||||
Reference in New Issue
Block a user