/src/ndpi/src/lib/protocols/blizzard.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * blizzard.c |
3 | | * |
4 | | * Copyright (C) 2015 - Matteo Bracci <matteobracci1@gmail.com> |
5 | | * Copyright (C) 2015-22 - ntop.org |
6 | | * |
7 | | * nDPI is free software: you can redistribute it and/or modify |
8 | | * it under the terms of the GNU Lesser General Public License as published by |
9 | | * the Free Software Foundation, either version 3 of the License, or |
10 | | * (at your option) any later version. |
11 | | * |
12 | | * nDPI is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | * GNU Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General Public License |
18 | | * along with nDPI. If not, see <http://www.gnu.org/licenses/>. |
19 | | * |
20 | | */ |
21 | | |
22 | | #include "ndpi_protocol_ids.h" |
23 | | |
24 | | #define NDPI_CURRENT_PROTO NDPI_PROTOCOL_BLIZZARD |
25 | | |
26 | | #include "ndpi_api.h" |
27 | | #include "ndpi_private.h" |
28 | | |
29 | | |
30 | | static void search_blizzard_tcp(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) |
31 | 0 | { |
32 | 0 | struct ndpi_packet_struct* packet = &ndpi_struct->packet; |
33 | 0 | char wow_string[] = "WORLD OF WARCRAFT CONNECTION"; |
34 | 0 | char overwatch2_string_c[] = "HELLO PRO CLIENT\0"; |
35 | 0 | char overwatch2_string_s[] = "HELLO PRO SERVER\0"; |
36 | |
|
37 | 0 | NDPI_LOG_DBG(ndpi_struct, "search Blizzard\n"); |
38 | | |
39 | | /* Generic Battle.net traffic */ |
40 | 0 | if(flow->guessed_protocol_id_by_ip == NDPI_PROTOCOL_BLIZZARD && |
41 | 0 | flow->s_port == htons(1119)) { |
42 | | /* Looking for the first pkt sent by the server */ |
43 | 0 | if(current_pkt_from_server_to_client(ndpi_struct, flow) && |
44 | 0 | packet->payload_packet_len == 2 && |
45 | 0 | packet->payload[0] == 0x52 && packet->payload[1] == 0x08) { |
46 | 0 | NDPI_LOG_INFO(ndpi_struct, "Found Blizzard (battle.net)\n"); |
47 | 0 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BLIZZARD, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
48 | 0 | return; |
49 | 0 | } else if(flow->packet_direction_counter[packet->packet_direction] == 1) { |
50 | 0 | return; |
51 | 0 | } |
52 | 0 | } |
53 | | |
54 | | /* Pattern found on Hearthstone */ |
55 | 0 | if(packet->payload_packet_len >= 8 && |
56 | 0 | le32toh(*(uint32_t *)&packet->payload[4]) == (u_int32_t)(packet->payload_packet_len - 8)) { |
57 | 0 | NDPI_LOG_INFO(ndpi_struct, "Found Blizzard (Hearthstone)\n"); |
58 | 0 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BLIZZARD, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
59 | 0 | return; |
60 | 0 | } |
61 | | |
62 | | /* Pattern found on WoW */ |
63 | 0 | if(packet->payload_packet_len >= NDPI_STATICSTRING_LEN(wow_string) && |
64 | 0 | memcmp(packet->payload, wow_string, NDPI_STATICSTRING_LEN(wow_string)) == 0) { |
65 | 0 | NDPI_LOG_INFO(ndpi_struct, "Found Blizzard (wow)\n"); |
66 | | /* Which id? It should be NDPI_PROTOCOL_BLIZZARD, but we already have NDPI_PROTOCOL_WORLDOFWARCRAFT. |
67 | | Keep using the latter for the time being.... */ |
68 | 0 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_WORLDOFWARCRAFT, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
69 | 0 | return; |
70 | 0 | } |
71 | | |
72 | | /* Pattern found on Overwatch2 */ |
73 | 0 | if((packet->payload_packet_len == NDPI_STATICSTRING_LEN(overwatch2_string_c) && |
74 | 0 | memcmp(packet->payload, overwatch2_string_c, NDPI_STATICSTRING_LEN(overwatch2_string_c)) == 0) || |
75 | 0 | (packet->payload_packet_len == NDPI_STATICSTRING_LEN(overwatch2_string_s) && |
76 | 0 | memcmp(packet->payload, overwatch2_string_s, NDPI_STATICSTRING_LEN(overwatch2_string_s)) == 0)) { |
77 | 0 | NDPI_LOG_INFO(ndpi_struct, "Found Blizzard (overwatch2)\n"); |
78 | 0 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BLIZZARD, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
79 | 0 | return; |
80 | 0 | } |
81 | | |
82 | | /* TODO: other patterns */ |
83 | | |
84 | 0 | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
85 | 0 | } |
86 | | |
87 | | static void search_blizzard_udp(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) |
88 | 0 | { |
89 | 0 | struct ndpi_packet_struct* packet = &ndpi_struct->packet; |
90 | |
|
91 | 0 | NDPI_LOG_DBG(ndpi_struct, "search Blizzard\n"); |
92 | | |
93 | | /* Patterns found on Warcraft Rumble */ |
94 | | |
95 | | /* The last bytes are some kind of sequence number, always starting from 1 */ |
96 | 0 | if(/* First pkt send by the client */ |
97 | 0 | (packet->payload_packet_len == 18 && |
98 | 0 | le32toh(*(uint32_t *)&packet->payload[14]) == 1) || |
99 | | /* First pkt send by the server */ |
100 | 0 | (packet->payload_packet_len == 15 && |
101 | 0 | packet->payload[14] == 1)) { |
102 | 0 | NDPI_LOG_INFO(ndpi_struct, "Found Blizzard (Warcraft Ramble; pattern 1)\n"); |
103 | 0 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BLIZZARD, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
104 | 0 | return; |
105 | 0 | } |
106 | | /* First pkt send by the client */ |
107 | 0 | if(packet->payload_packet_len == 23 && |
108 | 0 | ndpi_match_strprefix(packet->payload, packet->payload_packet_len, "\xff\xff\xff\xff\xa3\x1f\xb6\x1e\x00\x00\x40\x01\x00\x00\x00\x00\x00\x00\x00\x04\x03\x02\x01")) { |
109 | 0 | NDPI_LOG_INFO(ndpi_struct, "Found Blizzard (Warcraft Ramble; pattern 2)\n"); |
110 | 0 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BLIZZARD, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
111 | 0 | return; |
112 | 0 | } |
113 | | |
114 | | /* Patterns found on Overwatch2 */ |
115 | | /* Some kind of ping */ |
116 | 0 | if(flow->guessed_protocol_id_by_ip == NDPI_PROTOCOL_BLIZZARD && |
117 | 0 | packet->payload_packet_len == 40 && |
118 | 0 | *(uint32_t *)&packet->payload[17] == 0 /* Seq number starting from 0 */) { |
119 | 0 | NDPI_LOG_INFO(ndpi_struct, "Found Blizzard (overwatch2; pattern 1)\n"); |
120 | 0 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BLIZZARD, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
121 | 0 | return; |
122 | 0 | } |
123 | 0 | if(flow->guessed_protocol_id_by_ip == NDPI_PROTOCOL_BLIZZARD && |
124 | 0 | packet->payload_packet_len == 50 && |
125 | 0 | ((*(uint64_t *)&packet->payload[32] == 0 && *(uint64_t *)&packet->payload[40] == 0) /* First pkt from client */ || |
126 | 0 | (*(uint64_t *)&packet->payload[0] == 0 && *(uint64_t *)&packet->payload[8] == 0)) /* First pkt from server */) { |
127 | 0 | NDPI_LOG_INFO(ndpi_struct, "Found Blizzard (overwatch2; pattern 2)\n"); |
128 | 0 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BLIZZARD, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
129 | 0 | return; |
130 | 0 | } |
131 | | |
132 | | /* TODO: other patterns */ |
133 | | |
134 | 0 | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
135 | 0 | } |
136 | | |
137 | | static void ndpi_search_blizzard(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) |
138 | 0 | { |
139 | 0 | if(flow->l4_proto == IPPROTO_TCP) |
140 | 0 | search_blizzard_tcp(ndpi_struct, flow); |
141 | 0 | else |
142 | 0 | search_blizzard_udp(ndpi_struct, flow); |
143 | 0 | } |
144 | | |
145 | | void init_blizzard_dissector(struct ndpi_detection_module_struct *ndpi_struct) |
146 | 1 | { |
147 | 1 | register_dissector("Blizzard", ndpi_struct, |
148 | 1 | ndpi_search_blizzard, |
149 | 1 | NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION, |
150 | 1 | 1, NDPI_PROTOCOL_BLIZZARD); |
151 | 1 | } |
152 | | |