diff options
author | Toni <matzeton@googlemail.com> | 2022-06-03 18:21:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-03 18:21:29 +0200 |
commit | 09fbe0a64a11b08a35435f516e9a19f7e0c20d7c (patch) | |
tree | 3a1f16a822cd21e52da4b9e56486906cb104bb62 /src/lib/protocols/syslog.c | |
parent | 6149c0f880163b0bebd513fa957ece325c77cb88 (diff) |
Fixed syslog false positives. (#1577)
* syslog: removed unnecessary/unreliable printable string check
* added `ndpi_isalnum()`
* splitted `ndpi_is_printable_string()` into `ndpi_is_printable_buffer()` and `ndpi_normalize_printable_string()`
Signed-off-by: lns <matzeton@googlemail.com>
Diffstat (limited to 'src/lib/protocols/syslog.c')
-rw-r--r-- | src/lib/protocols/syslog.c | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/lib/protocols/syslog.c b/src/lib/protocols/syslog.c index 9722c92a0..406bf5e8f 100644 --- a/src/lib/protocols/syslog.c +++ b/src/lib/protocols/syslog.c @@ -38,13 +38,11 @@ void ndpi_search_syslog(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { struct ndpi_packet_struct *packet = &ndpi_struct->packet; - u_int8_t i; + u_int16_t i; NDPI_LOG_DBG(ndpi_struct, "search syslog\n"); if (packet->payload_packet_len > 20 && packet->payload[0] == '<') { - int j; - NDPI_LOG_DBG2(ndpi_struct, "checked len>20 and <1024 and first symbol=<\n"); for (i = 1; i <= 3; i++) { @@ -70,18 +68,31 @@ void ndpi_search_syslog(struct ndpi_detection_module_struct NDPI_LOG_DBG2(ndpi_struct, "no blank following the >: do nothing\n"); } - /* Even if there are 2 RFCs (3164, 5424), syslog format after "<NUMBER>" is - not standard. The only common pattern seems to be that the entire - payload is made by printable characters */ - /* TODO: check only the first N bytes to avoid touching the entire payload? */ - for (j = 0; j < packet->payload_packet_len - i; j++) { - if (!(ndpi_isprint(packet->payload[i + j]) || - ndpi_isspace(packet->payload[i + j]))) { - NDPI_LOG_DBG2(ndpi_struct, "no printable char 0x%x [i/j %d/%d]\n", - packet->payload[i + j], i, j); - NDPI_EXCLUDE_PROTO(ndpi_struct, flow); - return; - } + while (i < packet->payload_packet_len) + { + if (ndpi_isalnum(packet->payload[i]) == 0) + { + if (packet->payload[i] == ' ' || packet->payload[i] == ':' || + packet->payload[i] == '=') + { + break; + } + NDPI_EXCLUDE_PROTO(ndpi_struct, flow); + return; + } + + i++; + } + + if (packet->payload[i] == ':') + { + i++; + if (i >= packet->payload_packet_len || + packet->payload[i] != ' ') + { + NDPI_EXCLUDE_PROTO(ndpi_struct, flow); + return; + } } NDPI_LOG_INFO(ndpi_struct, "found syslog\n"); |