Implemented STUN peer_address, relayed_address, response_origin, other_address parsing
Added code to ignore invalid STUN realm Extended JSON output with STUN information
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
AR=@AR@
|
||||
CC=@CC@
|
||||
CXX=@CXX@
|
||||
ifneq ($(OS),Windows_NT)
|
||||
OS := $(shell uname)
|
||||
endif
|
||||
ifeq ($(OS),Darwin)
|
||||
CC=clang -fno-color-diagnostics
|
||||
endif
|
||||
|
||||
+22
-13
@@ -1521,6 +1521,22 @@ void print_bin(FILE *fout, const char *label, struct ndpi_bin *b) {
|
||||
|
||||
/* ********************************** */
|
||||
|
||||
static void print_ndpi_address_port(FILE *out, const char *label, ndpi_address_port *ap) {
|
||||
if(ap->port != 0) {
|
||||
char buf[INET6_ADDRSTRLEN];
|
||||
|
||||
if(ap->is_ipv6) {
|
||||
inet_ntop(AF_INET6, &ap->address, buf, sizeof(buf));
|
||||
} else {
|
||||
inet_ntop(AF_INET, &ap->address, buf, sizeof(buf));
|
||||
}
|
||||
|
||||
fprintf(out, "[%s: %s:%u]", label, buf, ap->port);
|
||||
}
|
||||
}
|
||||
|
||||
/* ********************************** */
|
||||
|
||||
/**
|
||||
* @brief Print the flow
|
||||
*/
|
||||
@@ -1871,19 +1887,12 @@ static void printFlow(u_int32_t id, struct ndpi_flow_info *flow, u_int16_t threa
|
||||
}
|
||||
}
|
||||
|
||||
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]",
|
||||
buf,
|
||||
flow->stun.mapped_address.port);
|
||||
}
|
||||
|
||||
print_ndpi_address_port(out, "Mapped IP/Port", &flow->stun.mapped_address);
|
||||
print_ndpi_address_port(out, "Peer IP/Port", &flow->stun.peer_address);
|
||||
print_ndpi_address_port(out, "Relayed IP/Port", &flow->stun.relayed_address);
|
||||
print_ndpi_address_port(out, "Rsp Origin IP/Port", &flow->stun.response_origin);
|
||||
print_ndpi_address_port(out, "Other IP/Port", &flow->stun.other_address);
|
||||
|
||||
if(flow->http.url[0] != '\0') {
|
||||
ndpi_risk_enum risk = ndpi_validate_url(flow->http.url);
|
||||
|
||||
|
||||
+11
-8
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* reader_util.c
|
||||
*
|
||||
* Copyright (C) 2011-23 - ntop.org
|
||||
* Copyright (C) 2011-24 - ntop.org
|
||||
*
|
||||
* This file is part of nDPI, an open source deep packet inspection
|
||||
* library based on the OpenDPI and PACE technology by ipoque GmbH
|
||||
@@ -42,6 +42,7 @@
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#endif
|
||||
#include <assert.h>
|
||||
|
||||
#include "reader_util.h"
|
||||
|
||||
@@ -1077,11 +1078,13 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl
|
||||
u_int j;
|
||||
|
||||
if(flow->ndpi_flow->protos.bittorrent.hash[0] != '\0') {
|
||||
flow->bittorent_hash = ndpi_malloc(sizeof(flow->ndpi_flow->protos.bittorrent.hash) * 2 + 1);
|
||||
u_int avail = sizeof(flow->ndpi_flow->protos.bittorrent.hash) * 2 + 1;
|
||||
flow->bittorent_hash = ndpi_malloc(avail);
|
||||
|
||||
if(flow->bittorent_hash) {
|
||||
|
||||
for(i=0, j = 0; i < sizeof(flow->ndpi_flow->protos.bittorrent.hash); i++) {
|
||||
sprintf(&flow->bittorent_hash[j], "%02x",
|
||||
snprintf(&flow->bittorent_hash[j], avail-j, "%02x",
|
||||
flow->ndpi_flow->protos.bittorrent.hash[i]);
|
||||
|
||||
j += 2;
|
||||
@@ -1311,11 +1314,11 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
memcpy(&flow->stun.mapped_address, &flow->ndpi_flow->stun.mapped_address, sizeof(ndpi_address_port));
|
||||
memcpy(&flow->stun.peer_address, &flow->ndpi_flow->stun.peer_address, sizeof(ndpi_address_port));
|
||||
memcpy(&flow->stun.relayed_address, &flow->ndpi_flow->stun.relayed_address, sizeof(ndpi_address_port));
|
||||
memcpy(&flow->stun.response_origin, &flow->ndpi_flow->stun.response_origin, sizeof(ndpi_address_port));
|
||||
memcpy(&flow->stun.other_address, &flow->ndpi_flow->stun.other_address, sizeof(ndpi_address_port));
|
||||
|
||||
flow->multimedia_flow_type = flow->ndpi_flow->flow_multimedia_type;
|
||||
|
||||
|
||||
@@ -295,19 +295,14 @@ typedef struct ndpi_flow_info {
|
||||
} ssh_tls;
|
||||
|
||||
struct {
|
||||
char url[256], request_content_type[64], content_type[64], user_agent[256], server[128], nat_ip[32], filename[256];
|
||||
char url[256], request_content_type[64], content_type[64],
|
||||
user_agent[256], server[128], nat_ip[32], filename[256];
|
||||
u_int response_status_code;
|
||||
} http;
|
||||
|
||||
struct {
|
||||
struct {
|
||||
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;
|
||||
ndpi_address_port mapped_address, peer_address,
|
||||
relayed_address, response_origin, other_address;
|
||||
} stun;
|
||||
|
||||
struct {
|
||||
|
||||
Reference in New Issue
Block a user