/src/ndpi/src/lib/protocols/xbox.c
Line | Count | Source |
1 | | /* |
2 | | * xbox.c |
3 | | * |
4 | | * Copyright (C) 2016-22 - ntop.org |
5 | | * |
6 | | * This file is part of nDPI, an open source deep packet inspection |
7 | | * library based on the OpenDPI and PACE technology by ipoque GmbH |
8 | | * |
9 | | * nDPI is free software: you can redistribute it and/or modify |
10 | | * it under the terms of the GNU Lesser General Public License as published by |
11 | | * the Free Software Foundation, either version 3 of the License, or |
12 | | * (at your option) any later version. |
13 | | * |
14 | | * nDPI is distributed in the hope that it will be useful, |
15 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | | * GNU Lesser General Public License for more details. |
18 | | * |
19 | | * You should have received a copy of the GNU Lesser General Public License |
20 | | * along with nDPI. If not, see <http://www.gnu.org/licenses/>. |
21 | | * |
22 | | */ |
23 | | |
24 | | #include "ndpi_protocol_ids.h" |
25 | | |
26 | | #define NDPI_CURRENT_PROTO NDPI_PROTOCOL_XBOX |
27 | | #include "ndpi_api.h" |
28 | | #include "ndpi_private.h" |
29 | | |
30 | | static void ndpi_int_xbox_add_connection(struct ndpi_detection_module_struct |
31 | | *ndpi_struct, struct ndpi_flow_struct *flow) |
32 | 114 | { |
33 | 114 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_XBOX, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
34 | 114 | } |
35 | | |
36 | | |
37 | | static void ndpi_search_xbox(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) |
38 | 1.10M | { |
39 | 1.10M | struct ndpi_packet_struct *packet = &ndpi_struct->packet; |
40 | | |
41 | | /* |
42 | | * XBOX UDP DETCTION ONLY |
43 | | * this detection also works for asymmetric xbox udp traffic |
44 | | */ |
45 | 1.10M | if(packet->udp != NULL) { |
46 | | |
47 | 1.10M | u_int16_t dport = ntohs(packet->udp->dest); |
48 | 1.10M | u_int16_t sport = ntohs(packet->udp->source); |
49 | | |
50 | 1.10M | NDPI_LOG_DBG(ndpi_struct, "search xbox\n"); |
51 | | |
52 | 1.10M | if (packet->payload_packet_len > 12 && |
53 | 962k | get_u_int32_t(packet->payload, 0) == 0 && packet->payload[5] == 0x58 && |
54 | 851 | memcmp(&packet->payload[7], "\x00\x00\x00", 3) == 0) { |
55 | | |
56 | 667 | if ((packet->payload[4] == 0x0c && packet->payload[6] == 0x76) || |
57 | 656 | (packet->payload[4] == 0x02 && packet->payload[6] == 0x18) || |
58 | 641 | (packet->payload[4] == 0x0b && packet->payload[6] == 0x80) || |
59 | 633 | (packet->payload[4] == 0x03 && packet->payload[6] == 0x40) || |
60 | 621 | (packet->payload[4] == 0x06 && packet->payload[6] == 0x4e)) { |
61 | | |
62 | 63 | ndpi_int_xbox_add_connection(ndpi_struct, flow); |
63 | 63 | NDPI_LOG_INFO(ndpi_struct, "found xbox udp connection detected\n"); |
64 | 63 | return; |
65 | 63 | } |
66 | 667 | } |
67 | 1.10M | if ((dport == 3074 || sport == 3074) |
68 | 6.68k | && ((packet->payload_packet_len == 24 && packet->payload[0] == 0x00) |
69 | 6.54k | || (packet->payload_packet_len == 42 && packet->payload[0] == 0x4f && packet->payload[2] == 0x0a) |
70 | 6.52k | || (packet->payload_packet_len == 80 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x50bc |
71 | 2 | && packet->payload[2] == 0x45) |
72 | 6.52k | || (packet->payload_packet_len == 40 && ntohl(get_u_int32_t(packet->payload, 0)) == 0xcf5f3202) |
73 | 6.52k | || (packet->payload_packet_len == 38 && ntohl(get_u_int32_t(packet->payload, 0)) == 0xc1457f03) |
74 | 6.52k | || (packet->payload_packet_len == 28 && ntohl(get_u_int32_t(packet->payload, 0)) == 0x015f2c00))) { |
75 | 201 | if (flow->l4.udp.xbox_stage == 1) { |
76 | 51 | ndpi_int_xbox_add_connection(ndpi_struct, flow); |
77 | 51 | NDPI_LOG_INFO(ndpi_struct, "found xbox udp connection detected\n"); |
78 | 51 | return; |
79 | 51 | } |
80 | 150 | NDPI_LOG_DBG(ndpi_struct, "maybe xbox\n"); |
81 | 150 | flow->l4.udp.xbox_stage++; |
82 | 150 | return; |
83 | 201 | } |
84 | | /* Disable this code. These checks are quite weak and these ports are not mentioned at |
85 | | https://support.xbox.com/en-US/help/hardware-network/connect-network/network-ports-used-xbox-live */ |
86 | | #if 0 |
87 | | else if ((dport == 3075 || dport == 3076 || dport == 3077 || dport == 3078) || |
88 | | (sport == 3075 || sport == 3076 || sport == 3077 || sport == 3078)) { |
89 | | ndpi_int_xbox_add_connection(ndpi_struct, flow); |
90 | | NDPI_LOG_INFO(ndpi_struct, "found xbox udp port connection detected\n"); |
91 | | return; |
92 | | } |
93 | | #endif |
94 | 1.10M | } |
95 | | |
96 | 1.10M | if(flow->packet_counter >= 5) |
97 | 54.8k | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
98 | 1.10M | } |
99 | | |
100 | | |
101 | | void init_xbox_dissector(struct ndpi_detection_module_struct *ndpi_struct) |
102 | 12.3k | { |
103 | 12.3k | register_dissector("Xbox", ndpi_struct, |
104 | 12.3k | ndpi_search_xbox, |
105 | 12.3k | NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD, |
106 | 12.3k | 1, NDPI_PROTOCOL_XBOX); |
107 | 12.3k | } |
108 | | |