/src/ndpi/src/lib/protocols/nomachine.c
Line | Count | Source |
1 | | /* |
2 | | * nomachine.c |
3 | | * |
4 | | * Copyright (C) 2023 - ntop.org |
5 | | * Copyright (C) 2023 - V.G <v.gavrilov@securitycode.ru> |
6 | | * |
7 | | * This file is part of nDPI, an open source deep packet inspection |
8 | | * library based on the OpenDPI and PACE technology by ipoque GmbH |
9 | | * |
10 | | * nDPI is free software: you can redistribute it and/or modify |
11 | | * it under the terms of the GNU Lesser General Public License as published by |
12 | | * the Free Software Foundation, either version 3 of the License, or |
13 | | * (at your option) any later version. |
14 | | * |
15 | | * nDPI is distributed in the hope that it will be useful, |
16 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | | * GNU Lesser General Public License for more details. |
19 | | * |
20 | | * You should have received a copy of the GNU Lesser General Public License |
21 | | * along with nDPI. If not, see <http://www.gnu.org/licenses/>. |
22 | | * |
23 | | */ |
24 | | |
25 | | #include "ndpi_protocol_ids.h" |
26 | | |
27 | | #define NDPI_CURRENT_PROTO NDPI_PROTOCOL_NOMACHINE |
28 | | |
29 | | #include "ndpi_api.h" |
30 | | #include "ndpi_private.h" |
31 | | |
32 | | static void ndpi_int_nomachine_add_connection(struct ndpi_detection_module_struct *ndpi_struct, |
33 | | struct ndpi_flow_struct *flow) |
34 | 0 | { |
35 | 0 | NDPI_LOG_INFO(ndpi_struct, "found NoMachine\n"); |
36 | 0 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NOMACHINE, |
37 | 0 | NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
38 | 0 | ndpi_set_risk(ndpi_struct, flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found NoMachine"); |
39 | 0 | } |
40 | | |
41 | | static void ndpi_search_nomachine(struct ndpi_detection_module_struct *ndpi_struct, |
42 | | struct ndpi_flow_struct *flow) |
43 | 2.28k | { |
44 | 2.28k | struct ndpi_packet_struct const * const packet = &ndpi_struct->packet; |
45 | | |
46 | 2.28k | NDPI_LOG_DBG(ndpi_struct, "search NoMachine\n"); |
47 | | |
48 | 2.28k | if (packet->tcp != NULL) { |
49 | | /* A NoMachine connection starts with a handshake that contains |
50 | | * only the characters NXSH (request) & NXD (response) and a version |
51 | | * number. After that it is followed by a TLS handshake. */ |
52 | 1.61k | if ((packet->payload_packet_len > 10 && packet->payload_packet_len < 15) && |
53 | 56 | ((memcmp(packet->payload, "NXSH-", 5) == 0) || (memcmp(packet->payload, "NXD-", 4) == 0))) |
54 | 0 | { |
55 | 0 | ndpi_int_nomachine_add_connection(ndpi_struct, flow); |
56 | 0 | return; |
57 | 0 | } |
58 | 1.61k | } else if (packet->udp != NULL) { |
59 | | /* NoMachine uses UDP for multimedia data */ |
60 | 664 | if (packet->payload_packet_len > 9 && /* Shortest valid packet is 10 bytes long, probably it's keep-alive */ |
61 | 664 | le16toh(get_u_int16_t(packet->payload, 2)) == 1 && |
62 | 664 | le16toh(get_u_int16_t(packet->payload, 4)) == packet->payload_packet_len && |
63 | 0 | get_u_int16_t(packet->payload, 8) == 0) |
64 | 0 | { |
65 | 0 | ndpi_int_nomachine_add_connection(ndpi_struct, flow); |
66 | 0 | return; |
67 | 0 | } |
68 | 664 | } |
69 | | |
70 | 2.28k | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
71 | 2.28k | } |
72 | | void init_nomachine_dissector(struct ndpi_detection_module_struct *ndpi_struct) |
73 | 6.86k | { |
74 | 6.86k | register_dissector("NoMachine", ndpi_struct, |
75 | 6.86k | ndpi_search_nomachine, |
76 | 6.86k | NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION, |
77 | 6.86k | 1, NDPI_PROTOCOL_NOMACHINE); |
78 | 6.86k | } |