diff options
author | Luca Deri <deri@ntop.org> | 2020-05-15 19:19:17 +0200 |
---|---|---|
committer | Luca Deri <deri@ntop.org> | 2020-05-15 19:19:17 +0200 |
commit | e90c5c7c3223d033467aa359d8b1e264f961fde1 (patch) | |
tree | 2adf23c16d38695188805f8a913e1023d0d0b5a9 /src/lib/protocols/http.c | |
parent | 7dfbfff743aaae57691ade003066aeca632e5d49 (diff) |
Added NDPI_HTTP_SUSPICIOUS_USER_AGENT ndpi_risk
Diffstat (limited to 'src/lib/protocols/http.c')
-rw-r--r-- | src/lib/protocols/http.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/lib/protocols/http.c b/src/lib/protocols/http.c index e050a69a8..1c81f8cfb 100644 --- a/src/lib/protocols/http.c +++ b/src/lib/protocols/http.c @@ -214,7 +214,6 @@ static void setHttpUserAgent(struct ndpi_detection_module_struct *ndpi_struct, /* Good reference for future implementations: * https://github.com/ua-parser/uap-core/blob/master/regexes.yaml */ - //printf("==> %s\n", ua); snprintf((char*)flow->protos.http.detected_os, sizeof(flow->protos.http.detected_os), "%s", ua); } @@ -236,6 +235,23 @@ static void ndpi_http_parse_subprotocol(struct ndpi_detection_module_struct *ndp /* ************************************************************* */ +static void ndpi_check_user_agent(struct ndpi_detection_module_struct *ndpi_struct, + struct ndpi_flow_struct *flow, + char *ua) { + if((!ua) || (ua[0] == '\0')) return; + + // printf("[%s:%d] ==> '%s'\n", __FILE__, __LINE__, ua); + + if((strlen(ua) < 4) + || (!strcmp(ua, "test")) + || (!strcmp(ua, "<?")) + || ndpi_match_bigram(ndpi_struct, &ndpi_struct->bigrams_automa, ua)) { + NDPI_SET_BIT_16(flow->risk, NDPI_HTTP_SUSPICIOUS_USER_AGENT); + } +} + +/* ************************************************************* */ + /** NOTE ndpi_parse_packet_line_info is in ndpi_main.c @@ -300,7 +316,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_ strncpy(ua, (const char *)packet->user_agent_line.ptr, mlen); ua[mlen] = '\0'; - + if(strncmp(ua, "Mozilla", 7) == 0) { char *parent = strchr(ua, '('); @@ -360,6 +376,8 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_ strncpy(flow->http.user_agent, (char*)packet->user_agent_line.ptr, packet->user_agent_line.len); flow->http.user_agent[packet->user_agent_line.len] = '\0'; + + ndpi_check_user_agent(ndpi_struct, flow, flow->http.user_agent); } } |