Skip to content

Commit 983b8e8

Browse files
authored
STUN: parsing of DATA attribute (#2179)
1 parent 24df191 commit 983b8e8

File tree

13 files changed

+37
-10
lines changed

13 files changed

+37
-10
lines changed

fuzz/corpus/fuzz_is_stun_tcp/data_1

192 Bytes
Binary file not shown.

fuzz/corpus/fuzz_is_stun_tcp/data_2

168 Bytes
Binary file not shown.

fuzz/corpus/fuzz_is_stun_tcp/data_3

108 Bytes
Binary file not shown.

fuzz/corpus/fuzz_is_stun_udp/data_1

708 Bytes
Binary file not shown.

fuzz/corpus/fuzz_is_stun_udp/data_2

292 Bytes
Binary file not shown.

fuzz/corpus/fuzz_is_stun_udp/data_3

128 Bytes
Binary file not shown.

fuzz/corpus/fuzz_is_stun_udp/data_4

236 Bytes
Binary file not shown.

fuzz/corpus/fuzz_is_stun_udp/data_5

128 Bytes
Binary file not shown.

fuzz/corpus/fuzz_is_stun_udp/data_6

292 Bytes
Binary file not shown.

fuzz/fuzz_is_stun.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
static struct ndpi_detection_module_struct *ndpi_struct = NULL;
66
static struct ndpi_flow_struct ndpi_flow;
7+
struct ndpi_iphdr iph;
78
#ifdef STUN_TCP
89
struct ndpi_tcphdr tcph;
910
#else
@@ -31,6 +32,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
3132
#else
3233
packet->tcp = &tcph;
3334
#endif
35+
packet->iph = &iph; /* IPv4 only */
3436

3537
is_stun(ndpi_struct, &ndpi_flow, &app_proto);
3638
return 0;

src/lib/protocols/stun.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ static u_int32_t get_stun_lru_key_raw4(u_int32_t ip, u_int16_t port);
3838
static void ndpi_int_stun_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
3939
struct ndpi_flow_struct *flow,
4040
u_int app_proto);
41+
static int stun_search_again(struct ndpi_detection_module_struct *ndpi_struct,
42+
struct ndpi_flow_struct *flow);
4143

4244

4345
static u_int16_t search_into_cache(struct ndpi_detection_module_struct *ndpi_struct,
@@ -133,6 +135,8 @@ int is_stun(struct ndpi_detection_module_struct *ndpi_struct,
133135
int off;
134136
const u_int8_t *payload = packet->payload;
135137
u_int16_t payload_length = packet->payload_packet_len;
138+
const u_int8_t *orig_payload;
139+
u_int16_t orig_payload_length;
136140
u_int32_t magic_cookie;
137141

138142
if(payload_length < STUN_HDR_LEN) {
@@ -306,6 +310,22 @@ int is_stun(struct ndpi_detection_module_struct *ndpi_struct,
306310
*app_proto = NDPI_PROTOCOL_HANGOUT_DUO;
307311
return 1;
308312

313+
case 0x0013:
314+
NDPI_LOG_DBG(ndpi_struct, "DATA attribute\n");
315+
316+
orig_payload = packet->payload;
317+
orig_payload_length = packet->payload_packet_len;
318+
packet->payload = payload + off + 4;
319+
packet->payload_packet_len = payload_length - off - 4;
320+
321+
stun_search_again(ndpi_struct, flow);
322+
NDPI_LOG_DBG(ndpi_struct, "End recursion\n");
323+
324+
packet->payload = orig_payload;
325+
packet->payload_packet_len = orig_payload_length;
326+
327+
break;
328+
309329
default:
310330
NDPI_LOG_DBG2(ndpi_struct, "Unknown attribute %04X\n", attribute);
311331
break;
@@ -326,7 +346,7 @@ static int keep_extra_dissection(struct ndpi_detection_module_struct *ndpi_struc
326346
/* We have a sub-classification */
327347

328348
if((ndpi_struct->monitoring_stun_flags & NDPI_MONITORING_STUN_SUBCLASSIFIED) &&
329-
flow->detected_protocol_stack[1] != NDPI_PROTOCOL_RTP)
349+
flow->detected_protocol_stack[0] != NDPI_PROTOCOL_RTP)
330350
return 1;
331351

332352
/* Looking for XOR-PEER-ADDRESS metadata; TODO: other protocols? */

tests/cfgs/default/result/stun_dtls_rtp_unidir.pcapng.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Num dissector calls: 12 (6.00 diss/flow)
66
LRU cache ookla: 0/0/0 (insert/search/found)
77
LRU cache bittorrent: 0/0/0 (insert/search/found)
88
LRU cache zoom: 0/0/0 (insert/search/found)
9-
LRU cache stun: 6/20/0 (insert/search/found)
9+
LRU cache stun: 6/24/0 (insert/search/found)
1010
LRU cache tls_cert: 0/0/0 (insert/search/found)
1111
LRU cache mining: 0/0/0 (insert/search/found)
1212
LRU cache msteams: 0/0/0 (insert/search/found)
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
Guessed flow protos: 1
1+
Guessed flow protos: 0
22

3-
DPI Packets (UDP): 39 (19.50 pkts/flow)
3+
DPI Packets (UDP): 36 (18.00 pkts/flow)
44
Confidence DPI : 2 (flows)
55
Num dissector calls: 12 (6.00 diss/flow)
66
LRU cache ookla: 0/0/0 (insert/search/found)
77
LRU cache bittorrent: 0/0/0 (insert/search/found)
88
LRU cache zoom: 0/0/0 (insert/search/found)
9-
LRU cache stun: 35/78/0 (insert/search/found)
10-
LRU cache tls_cert: 0/0/0 (insert/search/found)
9+
LRU cache stun: 32/88/0 (insert/search/found)
10+
LRU cache tls_cert: 0/5/0 (insert/search/found)
1111
LRU cache mining: 0/0/0 (insert/search/found)
1212
LRU cache msteams: 0/0/0 (insert/search/found)
1313
LRU cache stun_zoom: 0/0/0 (insert/search/found)
1414
Automa host: 0/0 (search/found)
1515
Automa domain: 0/0 (search/found)
16-
Automa tls cert: 0/0 (search/found)
16+
Automa tls cert: 1/0 (search/found)
1717
Automa risk mask: 0/0 (search/found)
1818
Automa common alpns: 0/0 (search/found)
1919
Patricia risk mask: 4/0 (search/found)
@@ -23,7 +23,12 @@ Patricia risk IPv6: 0/0 (search/found)
2323
Patricia protocols: 4/0 (search/found)
2424
Patricia protocols IPv6: 0/0 (search/found)
2525

26-
STUN 43 10358 2
26+
RTP 43 10358 2
2727

28-
1 UDP 10.1.0.3:5853 -> 10.10.0.1:2808 [proto: 78/STUN][IP: 0/Unknown][ClearText][Confidence: DPI][DPI packets: 18][cat: Network/14][18 pkts/5384 bytes -> 0 pkts/0 bytes][Goodput ratio: 86/0][7.17 sec][bytes ratio: 1.000 (Upload)][IAT c2s/s2c min/avg/max/stddev: 0/0 386/0 4001/0 979/0][Pkt Len c2s/s2c min/avg/max/stddev: 102/0 299/0 750/0 221/0][Risk: ** Known Proto on Non Std Port **** Unidirectional Traffic **][Risk Score: 60][Risk Info: No server to client traffic][PLAIN TEXT (Coturn)][Plen Bins: 0,5,5,5,34,22,0,0,0,5,0,0,0,0,0,5,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
29-
2 UDP 10.10.0.1:65226 -> 10.1.0.3:57730 [proto: 78/STUN][IP: 0/Unknown][ClearText][Confidence: DPI][DPI packets: 21][cat: Network/14][25 pkts/4974 bytes -> 0 pkts/0 bytes][Goodput ratio: 79/0][7.16 sec][bytes ratio: 1.000 (Upload)][IAT c2s/s2c min/avg/max/stddev: 0/0 324/0 4001/0 904/0][Pkt Len c2s/s2c min/avg/max/stddev: 78/0 199/0 478/0 92/0][Risk: ** Known Proto on Non Std Port **** Unidirectional Traffic **][Risk Score: 60][Risk Info: No server to client traffic][PLAIN TEXT (username1)][Plen Bins: 0,8,16,16,32,0,4,8,0,12,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
28+
JA3 Host Stats:
29+
IP Address # JA3C
30+
1 10.10.0.1 1
31+
32+
33+
1 UDP 10.1.0.3:5853 -> 10.10.0.1:2808 [proto: 30.87/DTLS.RTP][IP: 0/Unknown][Encrypted][Confidence: DPI][DPI packets: 15][cat: Network/14][18 pkts/5384 bytes -> 0 pkts/0 bytes][Goodput ratio: 86/0][7.17 sec][bytes ratio: 1.000 (Upload)][IAT c2s/s2c min/avg/max/stddev: 0/0 386/0 4001/0 979/0][Pkt Len c2s/s2c min/avg/max/stddev: 102/0 299/0 750/0 221/0][Risk: ** Known Proto on Non Std Port **** Self-signed Cert **][Risk Score: 150][Risk Info: CN=8][DTLSv1.0][JA3S: 1cfcbe58451407e23669f1dd08565519][Issuer: CN=8][Subject: CN=8][Certificate SHA-1: 94:8C:6F:C3:00:6A:A1:63:F1:52:7E:7F:1F:A7:93:90:46:3B:B1:2D][Validity: 2015-12-10 05:41:43 - 2016-01-10 05:41:43][Cipher: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA][PLAIN TEXT (Coturn)][Plen Bins: 0,5,5,5,34,22,0,0,0,5,0,0,0,0,0,5,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
34+
2 UDP 10.10.0.1:65226 -> 10.1.0.3:57730 [proto: 30.87/DTLS.RTP][IP: 0/Unknown][Encrypted][Confidence: DPI][DPI packets: 21][cat: Network/14][25 pkts/4974 bytes -> 0 pkts/0 bytes][Goodput ratio: 79/0][7.16 sec][bytes ratio: 1.000 (Upload)][IAT c2s/s2c min/avg/max/stddev: 0/0 324/0 4001/0 904/0][Pkt Len c2s/s2c min/avg/max/stddev: 78/0 199/0 478/0 92/0][Risk: ** Known Proto on Non Std Port **** TLS (probably) Not Carrying HTTPS **** Missing SNI TLS Extn **][Risk Score: 110][Risk Info: No ALPN][DTLSv1.0][JA3C: fd8faf73d274d5614a51dae82304be0a][PLAIN TEXT (username1)][Plen Bins: 0,8,16,16,32,0,4,8,0,12,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

0 commit comments

Comments
 (0)