Skip to content

Commit 6dc4533

Browse files
committed
Added support for RDP over TLS
1 parent e16b01c commit 6dc4533

File tree

4 files changed

+92
-7
lines changed

4 files changed

+92
-7
lines changed

src/lib/protocols/rdp.c

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* rdp.c
33
*
44
* Copyright (C) 2009-11 - ipoque GmbH
5-
* Copyright (C) 2011-22 - ntop.org
5+
* Copyright (C) 2011-24 - ntop.org
66
*
77
* This file is part of nDPI, an open source deep packet inspection
88
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -32,13 +32,39 @@
3232
#include "ndpi_api.h"
3333
#include "ndpi_private.h"
3434

35+
extern int ndpi_tls_obfuscated_heur_search_again(struct ndpi_detection_module_struct* ndpi_struct,
36+
struct ndpi_flow_struct* flow);
37+
38+
/* **************************************** */
39+
3540
static void ndpi_int_rdp_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
3641
struct ndpi_flow_struct *flow) {
3742
NDPI_LOG_INFO(ndpi_struct, "found RDP\n");
3843
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RDP, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
3944
ndpi_set_risk(flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found RDP"); /* Remote assistance */
4045
}
4146

47+
/* **************************************** */
48+
49+
/* tls.c */
50+
extern int ndpi_search_tls_tcp(struct ndpi_detection_module_struct *ndpi_struct,
51+
struct ndpi_flow_struct *flow);
52+
53+
int ndpi_search_tls_over_rdp(struct ndpi_detection_module_struct *ndpi_struct,
54+
struct ndpi_flow_struct *flow) {
55+
const struct ndpi_packet_struct * const packet = &ndpi_struct->packet;
56+
57+
if((packet->payload_packet_len > 1)
58+
&& (packet->payload[0] == 0x16 /* This might be a TLS block */)) {
59+
int rc = ndpi_search_tls_tcp(ndpi_struct, flow);
60+
61+
return(rc);
62+
} else
63+
return 1; /* Keep searching */
64+
}
65+
66+
/* **************************************** */
67+
4268
static void ndpi_search_rdp(struct ndpi_detection_module_struct *ndpi_struct,
4369
struct ndpi_flow_struct *flow) {
4470
const struct ndpi_packet_struct * const packet = &ndpi_struct->packet;
@@ -57,7 +83,21 @@ static void ndpi_search_rdp(struct ndpi_detection_module_struct *ndpi_struct,
5783
packet->payload[13] == 0x08 /* RDP Length */) ||
5884
(packet->payload_packet_len > 17 &&
5985
memcmp(&packet->payload[11], "Cookie:", 7) == 0))) /* RDP Cookie */ {
86+
87+
if(packet->payload_packet_len > 43) {
88+
u_int8_t rdp_requested_proto = packet->payload[43];
89+
90+
/* Check if TLS support has been requested in RDP */
91+
if((rdp_requested_proto & 0x1) == 0x1) {
92+
/* RDP Response + Client Hello + Server hello */
93+
flow->max_extra_packets_to_check = 5;
94+
95+
flow->extra_packets_func = ndpi_search_tls_over_rdp;
96+
}
97+
}
98+
6099
ndpi_int_rdp_add_connection(ndpi_struct, flow);
100+
61101
return;
62102
}
63103
} else {
@@ -66,7 +106,7 @@ static void ndpi_search_rdp(struct ndpi_detection_module_struct *ndpi_struct,
66106
packet->payload[11] == 0x02 && /* RDP Negotiation Response */
67107
packet->payload[13] == 0x08 /* RDP Length */) {
68108
ndpi_int_rdp_add_connection(ndpi_struct, flow);
69-
return;
109+
return;
70110
}
71111
}
72112
}
@@ -139,6 +179,7 @@ static void ndpi_search_rdp(struct ndpi_detection_module_struct *ndpi_struct,
139179
}
140180
}
141181

182+
/* **************************************** */
142183

143184
void init_rdp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id)
144185
{

src/lib/protocols/tls.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ static int check_set(struct ndpi_detection_module_struct* ndpi_struct,
242242
return 0;
243243
}
244244

245+
/* **************************************** */
246+
245247
static int tls_obfuscated_heur_search(struct ndpi_detection_module_struct* ndpi_struct,
246248
struct ndpi_flow_struct* flow) {
247249
struct ndpi_packet_struct* packet = &ndpi_struct->packet;
@@ -396,9 +398,10 @@ static int tls_obfuscated_heur_search(struct ndpi_detection_module_struct* ndpi_
396398
return 0; /* Continue */
397399
}
398400

401+
/* **************************************** */
402+
399403
static int tls_obfuscated_heur_search_again(struct ndpi_detection_module_struct* ndpi_struct,
400-
struct ndpi_flow_struct* flow)
401-
{
404+
struct ndpi_flow_struct* flow) {
402405
int rc;
403406

404407
NDPI_LOG_DBG2(ndpi_struct, "TLS-Obf-Heur: extra dissection\n");
@@ -436,6 +439,8 @@ static int tls_obfuscated_heur_search_again(struct ndpi_detection_module_struct*
436439
return 0; /* Stop */
437440
}
438441

442+
/* **************************************** */
443+
439444
void switch_extra_dissection_to_tls_obfuscated_heur(struct ndpi_detection_module_struct* ndpi_struct,
440445
struct ndpi_flow_struct* flow)
441446
{
@@ -1287,8 +1292,8 @@ static void ndpi_looks_like_tls(struct ndpi_detection_module_struct *ndpi_struct
12871292

12881293
/* **************************************** */
12891294

1290-
static int ndpi_search_tls_tcp(struct ndpi_detection_module_struct *ndpi_struct,
1291-
struct ndpi_flow_struct *flow) {
1295+
int ndpi_search_tls_tcp(struct ndpi_detection_module_struct *ndpi_struct,
1296+
struct ndpi_flow_struct *flow) {
12921297
struct ndpi_packet_struct *packet = &ndpi_struct->packet;
12931298
u_int8_t something_went_wrong = 0;
12941299
message_t *message;
@@ -1347,7 +1352,6 @@ static int ndpi_search_tls_tcp(struct ndpi_detection_module_struct *ndpi_struct,
13471352
break;
13481353
}
13491354

1350-
13511355
#ifdef DEBUG_TLS_MEMORY
13521356
printf("[TLS Mem] Processing %u bytes message\n", len);
13531357
#endif
@@ -1863,10 +1867,18 @@ static void ndpi_int_tls_add_connection(struct ndpi_detection_module_struct *ndp
18631867
printf("[TLS] %s()\n", __FUNCTION__);
18641868
#endif
18651869

1870+
if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_RDP) {
1871+
/* RDP over TLS */
1872+
ndpi_set_detected_protocol(ndpi_struct, flow,
1873+
NDPI_PROTOCOL_RDP, NDPI_PROTOCOL_TLS, NDPI_CONFIDENCE_DPI);
1874+
return;
1875+
}
1876+
18661877
if((flow->detected_protocol_stack[0] != NDPI_PROTOCOL_UNKNOWN) ||
18671878
(flow->detected_protocol_stack[1] != NDPI_PROTOCOL_UNKNOWN)) {
18681879
if(!flow->extra_packets_func)
18691880
tlsInitExtraPacketProcessing(ndpi_struct, flow);
1881+
18701882
return;
18711883
}
18721884

4.1 KB
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
DPI Packets (TCP): 7 (7.00 pkts/flow)
2+
Confidence DPI : 1 (flows)
3+
Num dissector calls: 1 (1.00 diss/flow)
4+
LRU cache ookla: 0/0/0 (insert/search/found)
5+
LRU cache bittorrent: 0/0/0 (insert/search/found)
6+
LRU cache stun: 0/0/0 (insert/search/found)
7+
LRU cache tls_cert: 0/0/0 (insert/search/found)
8+
LRU cache mining: 0/0/0 (insert/search/found)
9+
LRU cache msteams: 0/0/0 (insert/search/found)
10+
LRU cache fpc_dns: 0/1/0 (insert/search/found)
11+
Automa host: 0/0 (search/found)
12+
Automa domain: 0/0 (search/found)
13+
Automa tls cert: 0/0 (search/found)
14+
Automa risk mask: 0/0 (search/found)
15+
Automa common alpns: 0/0 (search/found)
16+
Patricia risk mask: 2/0 (search/found)
17+
Patricia risk mask IPv6: 0/0 (search/found)
18+
Patricia risk: 1/0 (search/found)
19+
Patricia risk IPv6: 0/0 (search/found)
20+
Patricia protocols: 2/0 (search/found)
21+
Patricia protocols IPv6: 0/0 (search/found)
22+
23+
RDP 19 3868 1
24+
25+
Acceptable 19 3868 1
26+
27+
JA3 Host Stats:
28+
IP Address # JA3C
29+
1 91.238.181.21 1
30+
31+
32+
1 TCP 91.238.181.21:35888 <-> 89.31.79.12:3389 [VLAN: 77][proto: 91.88/TLS.RDP][IP: 0/Unknown][Encrypted][Confidence: DPI][FPC: 0/Unknown, Confidence: Unknown][DPI packets: 7][cat: RemoteAccess/12][11 pkts/1862 bytes <-> 8 pkts/2006 bytes][Goodput ratio: 64/76][1.25 sec][bytes ratio: -0.037 (Mixed)][IAT c2s/s2c min/avg/max/stddev: 0/34 135/196 1035/961 319/342][Pkt Len c2s/s2c min/avg/max/stddev: 64/64 169/251 696/1255 175/385][Risk: ** Self-signed Cert **** TLS (probably) Not Carrying HTTPS **** Missing SNI TLS Extn **** Desktop/File Sharing **][Risk Score: 170][Risk Info: Found RDP / No ALPN / SNI should always be present / CN=topsalon][TCP Fingerprint: 32962_128_8192_6bb88f5575fd/Unknown][TLSv1.2][JA3C: 043c543b63b895881d9abfbc320cb863][JA4: t12d280600_bbd4f008d9b2_f28add8e7af0][JA3S: ae4edc6faf64d08308082ad26be60767][Issuer: CN=topsalon][Subject: CN=topsalon][Certificate SHA-1: A2:FF:78:9D:71:42:7A:00:97:9C:96:C2:E7:D1:C1:AD:A1:82:CC:2C][Firefox][Validity: 2024-07-26 06:03:40 - 2025-01-25 06:03:40][Cipher: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384][Plen Bins: 16,25,16,0,8,8,8,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0]

0 commit comments

Comments
 (0)