STUN: improve extraction of Mapped-Address metadata (#2370)

Enable parsing of Mapped-Address attribute for all STUN flows: that
means that STUN classification might require more packets.

Add a configuration knob to enable/disable this feature.

Note that we can have (any) STUN metadata also for flows *not*
classified as STUN (because of DTLS).

Add support for ipv6.

Restore the correct extra dissection logic for Telegram flows.
This commit is contained in:
Ivan Nardi
2024-04-08 10:24:51 +02:00
committed by GitHub
parent f5905a62c7
commit 1b3ef7d7b2
35 changed files with 409 additions and 248 deletions
+11 -38
View File
@@ -1457,38 +1457,6 @@ static void parseOptions(int argc, char **argv) {
/* ********************************** */
/**
* @brief A faster replacement for inet_ntoa().
*/
char* intoaV4(u_int32_t addr, char* buf, u_int16_t bufLen) {
char *cp;
int n;
cp = &buf[bufLen];
*--cp = '\0';
n = 4;
do {
u_int byte = addr & 0xff;
*--cp = byte % 10 + '0';
byte /= 10;
if(byte > 0) {
*--cp = byte % 10 + '0';
byte /= 10;
if(byte > 0)
*--cp = byte + '0';
}
if(n > 1)
*--cp = '.';
addr >>= 8;
} while (--n > 0);
return(cp);
}
/* ********************************** */
static char* print_cipher(ndpi_cipher_weakness c) {
switch(c) {
case ndpi_cipher_insecure:
@@ -1903,14 +1871,19 @@ static void printFlow(u_int32_t id, struct ndpi_flow_info *flow, u_int16_t threa
}
}
if(flow->stun.mapped_address.ipv4 != 0) {
char buf[32];
if(flow->stun.mapped_address.port != 0) {
char buf[INET6_ADDRSTRLEN];
if(flow->stun.mapped_address.is_ipv6) {
inet_ntop(AF_INET6, &flow->stun.mapped_address.address, buf, sizeof(buf));
} else {
inet_ntop(AF_INET, &flow->stun.mapped_address.address, buf, sizeof(buf));
}
fprintf(out, "[Mapped IP/Port: %s:%u]",
intoaV4(flow->stun.mapped_address.ipv4, buf, sizeof(buf)),
flow->stun.mapped_address.port);
buf,
flow->stun.mapped_address.port);
}
if(flow->http.url[0] != '\0') {
ndpi_risk_enum risk = ndpi_validate_url(flow->http.url);
+6 -3
View File
@@ -1309,9 +1309,12 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl
ndpi_inc_bin(&flow->payload_len_bin, plen2slot(len), 1);
}
}
} else if(is_ndpi_proto(flow, NDPI_PROTOCOL_STUN)) {
flow->stun.mapped_address.ipv4 = flow->ndpi_flow->stun.mapped_address.ipv4,
flow->stun.mapped_address.port = flow->ndpi_flow->stun.mapped_address.port;
}
if(flow->ndpi_flow->stun.mapped_address.port) {
memcpy(&flow->stun.mapped_address.address, &flow->ndpi_flow->stun.mapped_address.address, 16);
flow->stun.mapped_address.port = flow->ndpi_flow->stun.mapped_address.port;
flow->stun.mapped_address.is_ipv6 = flow->ndpi_flow->stun.mapped_address.is_ipv6;
}
flow->multimedia_flow_type = flow->ndpi_flow->flow_multimedia_type;
+5 -1
View File
@@ -301,8 +301,12 @@ typedef struct ndpi_flow_info {
struct {
struct {
u_int32_t ipv4;
union {
u_int32_t v4;
u_int8_t v6[16];
} address;
u_int16_t port;
u_int16_t is_ipv6: 1, _pad: 15;
} mapped_address;
} stun;