From 5f460c95ccdf2a95ff49aae04710aedceffbeac1 Mon Sep 17 00:00:00 2001 From: Matteo Bracci Date: Fri, 17 Jul 2015 13:38:41 +0200 Subject: Create starcraft2.c --- src/lib/protocols/starcraft2.c | 280 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 280 insertions(+) create mode 100644 src/lib/protocols/starcraft2.c diff --git a/src/lib/protocols/starcraft2.c b/src/lib/protocols/starcraft2.c new file mode 100644 index 000000000..1f91df573 --- /dev/null +++ b/src/lib/protocols/starcraft2.c @@ -0,0 +1,280 @@ +/* +* starcraft2.c +* +* Copyright (C) 2009-2011 by ipoque GmbH +* Copyright (C) 2011-15 - ntop.org +* +* This file is part of nDPI, an open source deep packet inspection +* library based on the OpenDPI and PACE technology by ipoque GmbH +* +* nDPI is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* nDPI is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with nDPI. If not, see . +* +*/ + + +#include "ndpi_protocols.h" +#ifdef NDPI_PROTOCOL_STARCRAFT2 + +<<<<<<< HEAD +/* +HTTP traffic seems to almost exclusively be requests for xml docs, jpgs or .s2* files. +The first two are easy to detect, for the latter a partial string search is needed. +*/ +u_int8_t ndpi_check_starcraft2_http(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) +{ + struct ndpi_packet_struct* packet = &flow->packet; + //printf("HTTP Test\n"); + if (packet->user_agent_line.ptr == NULL) + ndpi_parse_packet_line_info(ndpi_struct, flow); + + /* First look for the Battle.net client user agent */ + if (packet->user_agent_line.ptr != NULL + && packet->user_agent_line.len == NDPI_STATICSTRING_LEN("Battle.net Web Client") + && match_first_bytes(packet->user_agent_line.ptr, "Battle.net Web Client")) + { + /* Now make sure it's actually Starcraft 2 and not some other Blizzard software */ + + /* The destination port has to be either 1119 or 80 */ + if (packet->tcp->dest != htons(1119) && packet->tcp->dest != htons(80)) + return 0; + + if (packet->payload_packet_len >= NDPI_STATICSTRING_LEN("GET /") + && match_first_bytes(packet->payload, "GET /")) + { + + /* Requests may start with a semi common pattern... */ + if (packet->payload_packet_len >= NDPI_STATICSTRING_LEN("S2") + && match_first_bytes(packet->payload + NDPI_STATICSTRING_LEN("GET /"), "S2")) + return 1; + + + if (packet->payload_packet_len >= NDPI_STATICSTRING_LEN("s2") + && match_first_bytes(packet->payload + NDPI_STATICSTRING_LEN("GET /"), "s2")) + return 1; + + if (packet->payload_packet_len >= NDPI_STATICSTRING_LEN("sc2") + && match_first_bytes(packet->payload + NDPI_STATICSTRING_LEN("GET /"), "sc2")) + return 1; + + /* ..or end with a specific file format. */ + int i = 0; + while (i < packet->payload_packet_len && packet->payload[i] != '.') /* look for the extension of the requested file */ + i++; + + if (i + 5 < packet->payload_packet_len && packet->payload[i] == '.' + && match_first_bytes(packet->payload + i + 1, "s2") /* the format can be one between s2mh, s2ml, s2mv, s2ma, s2qh */ + && match_first_bytes(packet->payload + i + 5, " ")) /* make sure the file name is over and it's not just a lucky coincidence */ + return 1; + } + } + + return 2; +} + +======= +>>>>>>> FETCH_HEAD +u_int8_t sc2_using_bnetgame_tcp_port(struct ndpi_packet_struct* packet) +{ + return ((packet->tcp->source == htons(1119)) || (packet->tcp->dest == htons(1119))); +} + +u_int8_t sc2_using_bnetgame_udp_port(struct ndpi_packet_struct* packet) +{ + return ((packet->udp->source == htons(1119)) || (packet->udp->dest == htons(1119))); +} + +u_int8_t sc2_match_logon_ip(struct ndpi_packet_struct* packet) +{ + u_int32_t source_ip = ntohl(packet->iph->saddr); + u_int32_t dest_ip = ntohl(packet->iph->daddr); + return (ndpi_ips_match(source_ip, dest_ip, 0xD5F87F82, 32) // EU 213.248.127.130 + || ndpi_ips_match(source_ip, dest_ip, 0x0C81CE82, 32) // US 12.129.206.130 + || ndpi_ips_match(source_ip, dest_ip, 0x79FEC882, 32) // KR 121.254.200.130 + || ndpi_ips_match(source_ip, dest_ip, 0xCA09424C, 32) // SG 202.9.66.76 + || ndpi_ips_match(source_ip, dest_ip, 0x0C81ECFE, 32)); // BETA 12.129.236.254 +} + +/* +The main TCP flow starts with the user login and stays alive until the logout. +<<<<<<< HEAD +Although hard to read, judging from what happens elsewhere this flow probably contains all the data +transfer generated by the user interaction with the client, e.g. chatting or looking at someone's +======= +Although hard to read, judging from what happens elsewhere this flow probably contains all the data +transfer generated by the user interaction with the client, e.g. chatting or looking at someone's +>>>>>>> FETCH_HEAD +match history. The current way to detect this is plain dumb packet matching. +*/ +u_int8_t ndpi_check_starcraft2_tcp(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) +{ + if (!sc2_match_logon_ip(&flow->packet)) + return 2; + + if (flow->packet.payload_packet_len >= 10 + && match_first_bytes(flow->packet.payload, "\x4a\x00\x00\x0a\x66\x02\x0a\xed\x2d\x66")) + return 1; + + return 0; +} + +/* +UPD traffic is the actual game data and it uses a port owned by Blizzard itself, 1119. Therefore the +<<<<<<< HEAD +real key point here is to make sure that it's actually Starcraft 2 that is using the port and not +======= +real key point here is to make sure that it's actually Starcraft 2 that is using the port and not +>>>>>>> FETCH_HEAD +some other Blizzard software. +The flow is taken if a pattern in the size of some subsequent packets is found. +*/ +u_int8_t ndpi_check_starcraft2_udp(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) +{ + struct ndpi_packet_struct* packet = &flow->packet; + + /* First filter out traffic not using port 1119 */ + if (!sc2_using_bnetgame_udp_port(packet)) + return 2; + +<<<<<<< HEAD + /* Then use a simple automa to detect the size pattern */ + switch (flow->starcraft2_udp_stage) + { + case 0: + start: + if (packet->payload_packet_len == 548) + flow->starcraft2_udp_stage = 1; + else + flow->starcraft2_udp_stage = 0; + break; + case 1: + if (packet->payload_packet_len == 548) + flow->starcraft2_udp_stage = 2; + else + goto start; + break; + case 2: + if (packet->payload_packet_len == 548) +======= + /* Then use a simple automaton to detect the size pattern */ + switch (flow->starcraft2_udp_stage) + { + case 0: + start : + if (packet->payload_packet_len == 548) + flow->starcraft2_udp_stage = 1; + else + flow->starcraft2_udp_stage = 0; + break; + case 1: + if (packet->payload_packet_len == 548) + flow->starcraft2_udp_stage = 2; + else + goto start; + break; + case 2: + if (packet->payload_packet_len == 548) +>>>>>>> FETCH_HEAD + flow->starcraft2_udp_stage = 3; + else + goto start; + break; + case 3: +<<<<<<< HEAD + if (packet->payload_packet_len == 484) + return 1; + else +======= + if (packet->payload_packet_len == 484) + return 1; + else +>>>>>>> FETCH_HEAD + goto start; + break; + } + + return 0; +} + +void ndpi_check_starcraft2(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) +{ + struct ndpi_packet_struct* packet = &flow->packet; + u_int8_t result = 0; +<<<<<<< HEAD + u_int8_t kill = 0; +======= +>>>>>>> FETCH_HEAD + + if (packet->udp != NULL) + { + result = ndpi_check_starcraft2_udp(ndpi_struct, flow); +<<<<<<< HEAD + kill = result == 2; + if(result == 1) +======= + if (result == 1) +>>>>>>> FETCH_HEAD + { + printf("Found Starcraft 2 [Game, UDP]\n"); + NDPI_LOG(NDPI_PROTOCOL_STARCRAFT2, ndpi_struct, NDPI_LOG_DEBUG, "Found Starcraft 2 [Game, UDP]\n"); + } + } + else if (packet->tcp != NULL) + { +<<<<<<< HEAD + result = ndpi_check_starcraft2_http(ndpi_struct, flow); + kill = result == 2; + if (result == 1) + { + printf("Found Starcraft 2 [Client, HTTP]\n"); + NDPI_LOG(NDPI_PROTOCOL_STARCRAFT2, ndpi_struct, NDPI_LOG_DEBUG, "Found Starcraft 2 [Client, HTTP]\n"); + } + else + { + result = ndpi_check_starcraft2_tcp(ndpi_struct, flow); + kill = kill || result == 2; + if (result == 1) + { + printf("Found Starcraft 2 [Client, TCP]\n"); + NDPI_LOG(NDPI_PROTOCOL_STARCRAFT2, ndpi_struct, NDPI_LOG_DEBUG, "Found Starcraft 2 [Client, TCP]\n"); + } +======= + result = ndpi_check_starcraft2_tcp(ndpi_struct, flow); + if (result == 1) + { + printf("Found Starcraft 2 [Client, TCP]\n"); + NDPI_LOG(NDPI_PROTOCOL_STARCRAFT2, ndpi_struct, NDPI_LOG_DEBUG, "Found Starcraft 2 [Client, TCP]\n"); +>>>>>>> FETCH_HEAD + } + } + + if (result == 1) + ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_STARCRAFT2, NDPI_REAL_PROTOCOL); +<<<<<<< HEAD + else if (kill) +======= + else if (result == 2) +>>>>>>> FETCH_HEAD + NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_STARCRAFT2); +} + +void ndpi_search_starcraft2(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) +{ + NDPI_LOG(NDPI_PROTOCOL_STARCRAFT2, ndpi_struct, NDPI_LOG_DEBUG, "Starcraft2 protocol detection...\n"); + if (flow->packet.detected_protocol_stack[0] != NDPI_PROTOCOL_STARCRAFT2) + { + ndpi_check_starcraft2(ndpi_struct, flow); + } +} + +#endif -- cgit v1.2.3 From aa4bdebf407e035e8c61cb86bd20d890ef3d1239 Mon Sep 17 00:00:00 2001 From: Matteo Bracci Date: Fri, 17 Jul 2015 13:40:35 +0200 Subject: Update starcraft2.c --- src/lib/protocols/starcraft2.c | 241 ++++++++++------------------------------- 1 file changed, 56 insertions(+), 185 deletions(-) diff --git a/src/lib/protocols/starcraft2.c b/src/lib/protocols/starcraft2.c index 1f91df573..69bba700c 100644 --- a/src/lib/protocols/starcraft2.c +++ b/src/lib/protocols/starcraft2.c @@ -26,76 +26,13 @@ #include "ndpi_protocols.h" #ifdef NDPI_PROTOCOL_STARCRAFT2 -<<<<<<< HEAD -/* -HTTP traffic seems to almost exclusively be requests for xml docs, jpgs or .s2* files. -The first two are easy to detect, for the latter a partial string search is needed. -*/ -u_int8_t ndpi_check_starcraft2_http(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) -{ - struct ndpi_packet_struct* packet = &flow->packet; - //printf("HTTP Test\n"); - if (packet->user_agent_line.ptr == NULL) - ndpi_parse_packet_line_info(ndpi_struct, flow); - - /* First look for the Battle.net client user agent */ - if (packet->user_agent_line.ptr != NULL - && packet->user_agent_line.len == NDPI_STATICSTRING_LEN("Battle.net Web Client") - && match_first_bytes(packet->user_agent_line.ptr, "Battle.net Web Client")) - { - /* Now make sure it's actually Starcraft 2 and not some other Blizzard software */ - - /* The destination port has to be either 1119 or 80 */ - if (packet->tcp->dest != htons(1119) && packet->tcp->dest != htons(80)) - return 0; - - if (packet->payload_packet_len >= NDPI_STATICSTRING_LEN("GET /") - && match_first_bytes(packet->payload, "GET /")) - { - - /* Requests may start with a semi common pattern... */ - if (packet->payload_packet_len >= NDPI_STATICSTRING_LEN("S2") - && match_first_bytes(packet->payload + NDPI_STATICSTRING_LEN("GET /"), "S2")) - return 1; - - - if (packet->payload_packet_len >= NDPI_STATICSTRING_LEN("s2") - && match_first_bytes(packet->payload + NDPI_STATICSTRING_LEN("GET /"), "s2")) - return 1; - - if (packet->payload_packet_len >= NDPI_STATICSTRING_LEN("sc2") - && match_first_bytes(packet->payload + NDPI_STATICSTRING_LEN("GET /"), "sc2")) - return 1; - - /* ..or end with a specific file format. */ - int i = 0; - while (i < packet->payload_packet_len && packet->payload[i] != '.') /* look for the extension of the requested file */ - i++; - - if (i + 5 < packet->payload_packet_len && packet->payload[i] == '.' - && match_first_bytes(packet->payload + i + 1, "s2") /* the format can be one between s2mh, s2ml, s2mv, s2ma, s2qh */ - && match_first_bytes(packet->payload + i + 5, " ")) /* make sure the file name is over and it's not just a lucky coincidence */ - return 1; - } - } - - return 2; -} - -======= ->>>>>>> FETCH_HEAD -u_int8_t sc2_using_bnetgame_tcp_port(struct ndpi_packet_struct* packet) -{ - return ((packet->tcp->source == htons(1119)) || (packet->tcp->dest == htons(1119))); -} - -u_int8_t sc2_using_bnetgame_udp_port(struct ndpi_packet_struct* packet) -{ - return ((packet->udp->source == htons(1119)) || (packet->udp->dest == htons(1119))); -} - +int k = 0; +/* Sender or receiver are one of the known login portals? */ u_int8_t sc2_match_logon_ip(struct ndpi_packet_struct* packet) { + if (packet->iph == NULL) + return 0; + u_int32_t source_ip = ntohl(packet->iph->saddr); u_int32_t dest_ip = ntohl(packet->iph->daddr); return (ndpi_ips_match(source_ip, dest_ip, 0xD5F87F82, 32) // EU 213.248.127.130 @@ -107,34 +44,25 @@ u_int8_t sc2_match_logon_ip(struct ndpi_packet_struct* packet) /* The main TCP flow starts with the user login and stays alive until the logout. -<<<<<<< HEAD -Although hard to read, judging from what happens elsewhere this flow probably contains all the data -transfer generated by the user interaction with the client, e.g. chatting or looking at someone's -======= Although hard to read, judging from what happens elsewhere this flow probably contains all the data transfer generated by the user interaction with the client, e.g. chatting or looking at someone's ->>>>>>> FETCH_HEAD match history. The current way to detect this is plain dumb packet matching. */ u_int8_t ndpi_check_starcraft2_tcp(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) { - if (!sc2_match_logon_ip(&flow->packet)) - return 2; - - if (flow->packet.payload_packet_len >= 10 - && match_first_bytes(flow->packet.payload, "\x4a\x00\x00\x0a\x66\x02\x0a\xed\x2d\x66")) + if (sc2_match_logon_ip(&flow->packet) + && flow->packet.tcp->dest == htons(1119) //bnetgame port + && flow->packet.payload_packet_len >= 10 + && (match_first_bytes(flow->packet.payload, "\x4a\x00\x00\x0a\x66\x02\x0a\xed\x2d\x66") + || match_first_bytes(flow->packet.payload, "\x49\x00\x00\x0a\x66\x02\x0a\xed\x2d\x66"))) return 1; - - return 0; + else + return -1; } /* UPD traffic is the actual game data and it uses a port owned by Blizzard itself, 1119. Therefore the -<<<<<<< HEAD -real key point here is to make sure that it's actually Starcraft 2 that is using the port and not -======= real key point here is to make sure that it's actually Starcraft 2 that is using the port and not ->>>>>>> FETCH_HEAD some other Blizzard software. The flow is taken if a pattern in the size of some subsequent packets is found. */ @@ -142,138 +70,81 @@ u_int8_t ndpi_check_starcraft2_udp(struct ndpi_detection_module_struct* ndpi_str { struct ndpi_packet_struct* packet = &flow->packet; - /* First filter out traffic not using port 1119 */ - if (!sc2_using_bnetgame_udp_port(packet)) - return 2; + /* First off, filter out any traffic not using port 1119, removing the chance of any false positive if we assume that non allowed protocols don't use the port */ + if (packet->udp->source != htons(1119) && packet->udp->dest != htons(1119)) + return -1; -<<<<<<< HEAD - /* Then use a simple automa to detect the size pattern */ + /* Then try to detect the size pattern */ switch (flow->starcraft2_udp_stage) { case 0: - start: - if (packet->payload_packet_len == 548) + if (packet->payload_packet_len == 20) flow->starcraft2_udp_stage = 1; else flow->starcraft2_udp_stage = 0; break; case 1: - if (packet->payload_packet_len == 548) + if (packet->payload_packet_len == 20) flow->starcraft2_udp_stage = 2; - else - goto start; break; case 2: - if (packet->payload_packet_len == 548) -======= - /* Then use a simple automaton to detect the size pattern */ - switch (flow->starcraft2_udp_stage) - { - case 0: - start : + if (packet->payload_packet_len == 75 || packet->payload_packet_len == 85) + flow->starcraft2_udp_stage = 3; + break; + case 3: + if (packet->payload_packet_len == 20) + flow->starcraft2_udp_stage = 4; + break; + case 4: if (packet->payload_packet_len == 548) - flow->starcraft2_udp_stage = 1; - else - flow->starcraft2_udp_stage = 0; - break; - case 1: + flow->starcraft2_udp_stage = 5; + break; + case 5: if (packet->payload_packet_len == 548) - flow->starcraft2_udp_stage = 2; - else - goto start; + flow->starcraft2_udp_stage = 6; break; - case 2: + case 6: if (packet->payload_packet_len == 548) ->>>>>>> FETCH_HEAD - flow->starcraft2_udp_stage = 3; - else - goto start; + flow->starcraft2_udp_stage = 7; break; - case 3: -<<<<<<< HEAD - if (packet->payload_packet_len == 484) - return 1; - else -======= + case 7: if (packet->payload_packet_len == 484) return 1; - else ->>>>>>> FETCH_HEAD - goto start; break; } - return 0; + return -1; } -void ndpi_check_starcraft2(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) +void ndpi_search_starcraft2(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) { - struct ndpi_packet_struct* packet = &flow->packet; - u_int8_t result = 0; -<<<<<<< HEAD - u_int8_t kill = 0; -======= ->>>>>>> FETCH_HEAD - - if (packet->udp != NULL) - { - result = ndpi_check_starcraft2_udp(ndpi_struct, flow); -<<<<<<< HEAD - kill = result == 2; - if(result == 1) -======= - if (result == 1) ->>>>>>> FETCH_HEAD - { - printf("Found Starcraft 2 [Game, UDP]\n"); - NDPI_LOG(NDPI_PROTOCOL_STARCRAFT2, ndpi_struct, NDPI_LOG_DEBUG, "Found Starcraft 2 [Game, UDP]\n"); - } - } - else if (packet->tcp != NULL) - { -<<<<<<< HEAD - result = ndpi_check_starcraft2_http(ndpi_struct, flow); - kill = result == 2; - if (result == 1) - { - printf("Found Starcraft 2 [Client, HTTP]\n"); - NDPI_LOG(NDPI_PROTOCOL_STARCRAFT2, ndpi_struct, NDPI_LOG_DEBUG, "Found Starcraft 2 [Client, HTTP]\n"); + NDPI_LOG(NDPI_PROTOCOL_STARCRAFT2, ndpi_struct, NDPI_LOG_DEBUG, "Starcraft2 protocol detection...\n"); + if (flow->packet.detected_protocol_stack[0] != NDPI_PROTOCOL_STARCRAFT2) { + struct ndpi_packet_struct* packet = &flow->packet; + int8_t result = 0; + + if (packet->udp != NULL) { + result = ndpi_check_starcraft2_udp(ndpi_struct, flow); + if (result == 1) { + printf("%d Found Starcraft 2 [Game, UDP]\n", k++); + NDPI_LOG(NDPI_PROTOCOL_STARCRAFT2, ndpi_struct, NDPI_LOG_DEBUG, "Found Starcraft 2 [Game, UDP]\n"); + } } - else - { + else if (packet->tcp != NULL) { result = ndpi_check_starcraft2_tcp(ndpi_struct, flow); - kill = kill || result == 2; - if (result == 1) - { - printf("Found Starcraft 2 [Client, TCP]\n"); + if (result == 1) { + printf("%d Found Starcraft 2 [Client, TCP]\n", k++); NDPI_LOG(NDPI_PROTOCOL_STARCRAFT2, ndpi_struct, NDPI_LOG_DEBUG, "Found Starcraft 2 [Client, TCP]\n"); } -======= - result = ndpi_check_starcraft2_tcp(ndpi_struct, flow); - if (result == 1) - { - printf("Found Starcraft 2 [Client, TCP]\n"); - NDPI_LOG(NDPI_PROTOCOL_STARCRAFT2, ndpi_struct, NDPI_LOG_DEBUG, "Found Starcraft 2 [Client, TCP]\n"); ->>>>>>> FETCH_HEAD } - } - if (result == 1) - ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_STARCRAFT2, NDPI_REAL_PROTOCOL); -<<<<<<< HEAD - else if (kill) -======= - else if (result == 2) ->>>>>>> FETCH_HEAD - NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_STARCRAFT2); -} - -void ndpi_search_starcraft2(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) -{ - NDPI_LOG(NDPI_PROTOCOL_STARCRAFT2, ndpi_struct, NDPI_LOG_DEBUG, "Starcraft2 protocol detection...\n"); - if (flow->packet.detected_protocol_stack[0] != NDPI_PROTOCOL_STARCRAFT2) - { - ndpi_check_starcraft2(ndpi_struct, flow); + if (result == 1) { + ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_STARCRAFT2, NDPI_PROTOCOL_UNKNOWN); + } + else if (result == -1) { + NDPI_LOG(NDPI_PROTOCOL_STARCRAFT2, ndpi_struct, NDPI_LOG_DEBUG, "Starcraft2 excluded\n"); + NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_STARCRAFT2); + } } } -- cgit v1.2.3 From e29bd2270f22cd0e0d92c8ca6518a9afe7aad95f Mon Sep 17 00:00:00 2001 From: Matteo Bracci Date: Fri, 17 Jul 2015 13:44:50 +0200 Subject: Update ndpi_content_match.c.inc starcraft2 --- src/lib/ndpi_content_match.c.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/ndpi_content_match.c.inc b/src/lib/ndpi_content_match.c.inc index a7442b8c9..03f133549 100644 --- a/src/lib/ndpi_content_match.c.inc +++ b/src/lib/ndpi_content_match.c.inc @@ -7401,7 +7401,8 @@ ndpi_protocol_match host_match[] = { { ".microsoft.com", "Microsoft", NDPI_SERVICE_MICROSOFT, NDPI_PROTOCOL_ACCEPTABLE }, { "update.microsoft.com", "WindowsUpdate", NDPI_SERVICE_WINDOWS_UPDATE, NDPI_PROTOCOL_ACCEPTABLE }, { ".windowsupdate.com", "WindowsUpdate", NDPI_SERVICE_WINDOWS_UPDATE, NDPI_PROTOCOL_ACCEPTABLE }, - + { ".battle.net", "Battle.net", NDPI_SERVICE_BATTLENET, NDPI_PROTOCOL_FUN }, + { "bnetcmsus-a.akamaihd.net", "Battle.net", NDPI_SERVICE_BATTLENET, NDPI_PROTOCOL_FUN }, { NULL, 0 } }; -- cgit v1.2.3 From c62e8dadb6cf77a093c4623e337256ce31f193d7 Mon Sep 17 00:00:00 2001 From: Matteo Bracci Date: Fri, 17 Jul 2015 13:53:31 +0200 Subject: Update ndpi_main.c starcraft2 --- src/lib/ndpi_main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index 0623433bb..feb613733 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -1607,6 +1607,11 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp no_master, "VHUA", ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */, ndpi_build_default_ports(ports_b, 58267, 0, 0, 0, 0) /* UDP */); + ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_FUN, NDPI_PROTOCOL_STARCRAFT2, + no_master, + no_master, "Starcraft 2", + ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0), /* TCP */ + ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0)); /* UDP */ /* calling function for host and content matched protocols */ init_string_based_protocols(ndpi_mod); -- cgit v1.2.3 From 0739b577d4506bbc7bb78a99626f358d4743d9bd Mon Sep 17 00:00:00 2001 From: Matteo Bracci Date: Fri, 17 Jul 2015 15:30:34 +0200 Subject: Update starcraft2.c starcraft2 --- src/lib/protocols/starcraft2.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lib/protocols/starcraft2.c b/src/lib/protocols/starcraft2.c index 69bba700c..d342e91a4 100644 --- a/src/lib/protocols/starcraft2.c +++ b/src/lib/protocols/starcraft2.c @@ -148,4 +148,15 @@ void ndpi_search_starcraft2(struct ndpi_detection_module_struct* ndpi_struct, st } } +void init_starcraft2_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) +{ + ndpi_set_bitmask_protocol_detection("STARCRAFT2", ndpi_struct, detection_bitmask, *id, + NDPI_PROTOCOL_STARCRAFT2, ndpi_search_starcraft2, + NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION, + SAVE_DETECTION_BITMASK_AS_UNKNOWN, + ADD_TO_DETECTION_BITMASK); + + *id += 1; +} + #endif -- cgit v1.2.3 From d215d6d8617ab1454fcb74776b6b245a1f4dc670 Mon Sep 17 00:00:00 2001 From: Matteo Bracci Date: Fri, 17 Jul 2015 18:42:42 +0200 Subject: Update ndpi_protocols.h --- src/include/ndpi_protocols.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/include/ndpi_protocols.h b/src/include/ndpi_protocols.h index 4b898d6ec..904ae956e 100644 --- a/src/include/ndpi_protocols.h +++ b/src/include/ndpi_protocols.h @@ -194,6 +194,7 @@ void ndpi_search_quic(struct ndpi_detection_module_struct *ndpi_struct, struct n void ndpi_search_eaq(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); void ndpi_search_kakaotalk_voice(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); void ndpi_search_mpegts(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); +void ndpi_search_starcraft2(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); /* --- INIT FUNCTIONS --- */ @@ -296,6 +297,7 @@ void init_soulseek_dissector(struct ndpi_detection_module_struct *ndpi_struct, u void init_spotify_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask); void init_ssh_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask); void init_ssl_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask); +void init_starcraft2_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask); void init_stealthnet_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask); void init_steam_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask); void init_stun_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask); -- cgit v1.2.3 From 5165102f817d73246e392c9fddcc77a9b7ac74d7 Mon Sep 17 00:00:00 2001 From: Matteo Bracci Date: Fri, 17 Jul 2015 18:43:32 +0200 Subject: Update world_of_warcraft.c Commented the first part of the dissector, as it steals traffic from other Battle.net based protocols. --- src/lib/protocols/world_of_warcraft.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/protocols/world_of_warcraft.c b/src/lib/protocols/world_of_warcraft.c index b9f4dee31..59d5c0a4d 100644 --- a/src/lib/protocols/world_of_warcraft.c +++ b/src/lib/protocols/world_of_warcraft.c @@ -61,6 +61,7 @@ void ndpi_search_worldofwarcraft(struct ndpi_detection_module_struct NDPI_LOG(NDPI_PROTOCOL_WORLDOFWARCRAFT, ndpi_struct, NDPI_LOG_DEBUG, "Search World of Warcraft.\n"); if (packet->tcp != NULL) { + /* if ((packet->payload_packet_len > NDPI_STATICSTRING_LEN("POST /") && memcmp(packet->payload, "POST /", NDPI_STATICSTRING_LEN("POST /")) == 0) || (packet->payload_packet_len > NDPI_STATICSTRING_LEN("GET /") && @@ -76,6 +77,7 @@ void ndpi_search_worldofwarcraft(struct ndpi_detection_module_struct return; } } + */ if (packet->payload_packet_len > NDPI_STATICSTRING_LEN("GET /") && memcmp(packet->payload, "GET /", NDPI_STATICSTRING_LEN("GET /")) == 0) { ndpi_parse_packet_line_info(ndpi_struct, flow); -- cgit v1.2.3 From eb49f15453837483e6966768a437ae7c9ea4100d Mon Sep 17 00:00:00 2001 From: Matteo Bracci Date: Fri, 17 Jul 2015 18:47:00 +0200 Subject: Update ndpi_protocol_ids.h --- src/include/ndpi_protocol_ids.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/include/ndpi_protocol_ids.h b/src/include/ndpi_protocol_ids.h index 6bac39160..97974d05c 100644 --- a/src/include/ndpi_protocol_ids.h +++ b/src/include/ndpi_protocol_ids.h @@ -199,6 +199,7 @@ #define NDPI_PROTOCOL_TELEGRAM 185 /* Gianluca Costa */ #define NDPI_PROTOCOL_QUIC 188 /* Andrea Buscarinu - Michele Campus */ #define NDPI_PROTOCOL_WHATSAPP_VOICE 189 +#define NDPI_PROTOCOL_STARCRAFT2 213 /* matteobracci1@gmail.com */ #define NDPI_CONTENT_AVI 39 @@ -261,7 +262,7 @@ #define NDPI_SERVICE_MICROSOFT 212 /* UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE */ -#define NDPI_LAST_IMPLEMENTED_PROTOCOL NDPI_SERVICE_MICROSOFT +#define NDPI_LAST_IMPLEMENTED_PROTOCOL NDPI_PROTOCOL_STARCRAFT2 #define NDPI_MAX_SUPPORTED_PROTOCOLS (NDPI_LAST_IMPLEMENTED_PROTOCOL + 1) #define NDPI_MAX_NUM_CUSTOM_PROTOCOLS (NDPI_NUM_BITS-NDPI_LAST_IMPLEMENTED_PROTOCOL) -- cgit v1.2.3 From e5f3d21f81437203dd9555a12aac5a683cbc462e Mon Sep 17 00:00:00 2001 From: Matteo Bracci Date: Fri, 17 Jul 2015 18:47:31 +0200 Subject: Update ndpi_protocol_ids.h --- src/include/ndpi_protocol_ids.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/ndpi_protocol_ids.h b/src/include/ndpi_protocol_ids.h index 97974d05c..cfc1e70b8 100644 --- a/src/include/ndpi_protocol_ids.h +++ b/src/include/ndpi_protocol_ids.h @@ -199,7 +199,7 @@ #define NDPI_PROTOCOL_TELEGRAM 185 /* Gianluca Costa */ #define NDPI_PROTOCOL_QUIC 188 /* Andrea Buscarinu - Michele Campus */ #define NDPI_PROTOCOL_WHATSAPP_VOICE 189 -#define NDPI_PROTOCOL_STARCRAFT2 213 /* matteobracci1@gmail.com */ +#define NDPI_PROTOCOL_STARCRAFT2 213 /* matteobracci1@gmail.com */ #define NDPI_CONTENT_AVI 39 -- cgit v1.2.3 From deb96d83d321c670dfcf041510b90400a742e2c4 Mon Sep 17 00:00:00 2001 From: Matteo Bracci Date: Fri, 17 Jul 2015 18:47:50 +0200 Subject: Update ndpi_protocol_ids.h --- src/include/ndpi_protocol_ids.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/ndpi_protocol_ids.h b/src/include/ndpi_protocol_ids.h index cfc1e70b8..9c10dc964 100644 --- a/src/include/ndpi_protocol_ids.h +++ b/src/include/ndpi_protocol_ids.h @@ -199,7 +199,7 @@ #define NDPI_PROTOCOL_TELEGRAM 185 /* Gianluca Costa */ #define NDPI_PROTOCOL_QUIC 188 /* Andrea Buscarinu - Michele Campus */ #define NDPI_PROTOCOL_WHATSAPP_VOICE 189 -#define NDPI_PROTOCOL_STARCRAFT2 213 /* matteobracci1@gmail.com */ +#define NDPI_PROTOCOL_STARCRAFT2 213 /* matteobracci1@gmail.com */ #define NDPI_CONTENT_AVI 39 -- cgit v1.2.3 From d9745a2e2c2e4e1092c342288f4e89e716c986a4 Mon Sep 17 00:00:00 2001 From: Matteo Bracci Date: Fri, 17 Jul 2015 18:48:05 +0200 Subject: Update ndpi_protocol_ids.h --- src/include/ndpi_protocol_ids.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/ndpi_protocol_ids.h b/src/include/ndpi_protocol_ids.h index 9c10dc964..22c9320ee 100644 --- a/src/include/ndpi_protocol_ids.h +++ b/src/include/ndpi_protocol_ids.h @@ -199,7 +199,7 @@ #define NDPI_PROTOCOL_TELEGRAM 185 /* Gianluca Costa */ #define NDPI_PROTOCOL_QUIC 188 /* Andrea Buscarinu - Michele Campus */ #define NDPI_PROTOCOL_WHATSAPP_VOICE 189 -#define NDPI_PROTOCOL_STARCRAFT2 213 /* matteobracci1@gmail.com */ +#define NDPI_PROTOCOL_STARCRAFT2 213 /* matteobracci1@gmail.com */ #define NDPI_CONTENT_AVI 39 -- cgit v1.2.3 From 912c160ad3859026586bae3007660a46859dfb94 Mon Sep 17 00:00:00 2001 From: Matteo Bracci Date: Fri, 17 Jul 2015 18:50:21 +0200 Subject: Update ndpi_typedefs.h --- src/include/ndpi_typedefs.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h index 262dc71a4..57f3d3d3f 100644 --- a/src/include/ndpi_typedefs.h +++ b/src/include/ndpi_typedefs.h @@ -809,6 +809,9 @@ typedef struct ndpi_flow_struct { u_int32_t pplive_stage2:2; // 0-2 u_int32_t pplive_stage3:2; // 0-2 #endif +#ifdef NDPI_PROTOCOL_STARCRAFT2 + u_int32_t starcraft2_udp_stage : 3; // 0-7 +#endif /* internal structures to save functions calls */ struct ndpi_packet_struct packet; -- cgit v1.2.3 From 3ea5f2f0a649f406f3e9eb8cabe77e9ba2ffe921 Mon Sep 17 00:00:00 2001 From: Matteo Bracci Date: Fri, 17 Jul 2015 19:00:36 +0200 Subject: Update ndpi_protocol_ids.h --- src/include/ndpi_protocol_ids.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/include/ndpi_protocol_ids.h b/src/include/ndpi_protocol_ids.h index 22c9320ee..e724f452d 100644 --- a/src/include/ndpi_protocol_ids.h +++ b/src/include/ndpi_protocol_ids.h @@ -199,7 +199,7 @@ #define NDPI_PROTOCOL_TELEGRAM 185 /* Gianluca Costa */ #define NDPI_PROTOCOL_QUIC 188 /* Andrea Buscarinu - Michele Campus */ #define NDPI_PROTOCOL_WHATSAPP_VOICE 189 -#define NDPI_PROTOCOL_STARCRAFT2 213 /* matteobracci1@gmail.com */ +#define NDPI_PROTOCOL_STARCRAFT2 214 /* matteobracci1@gmail.com */ #define NDPI_CONTENT_AVI 39 @@ -260,6 +260,7 @@ #define NDPI_SERVICE_DEEZER 210 #define NDPI_SERVICE_INSTAGRAM 211 /* Andrea Buscarinu */ #define NDPI_SERVICE_MICROSOFT 212 +#define NDPI_SERVICE_BATTLENET 213 /* matteobracci1@gmail.com */ /* UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE */ #define NDPI_LAST_IMPLEMENTED_PROTOCOL NDPI_PROTOCOL_STARCRAFT2 -- cgit v1.2.3 From 0ce34f341e8184abb798fb7abc8b5aa1a3b235cb Mon Sep 17 00:00:00 2001 From: Matteo Bracci Date: Mon, 20 Jul 2015 12:55:14 +0200 Subject: Update starcraft2.c Removed debug leftovers --- src/lib/protocols/starcraft2.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/lib/protocols/starcraft2.c b/src/lib/protocols/starcraft2.c index d342e91a4..6372c78ca 100644 --- a/src/lib/protocols/starcraft2.c +++ b/src/lib/protocols/starcraft2.c @@ -26,7 +26,6 @@ #include "ndpi_protocols.h" #ifdef NDPI_PROTOCOL_STARCRAFT2 -int k = 0; /* Sender or receiver are one of the known login portals? */ u_int8_t sc2_match_logon_ip(struct ndpi_packet_struct* packet) { @@ -80,8 +79,6 @@ u_int8_t ndpi_check_starcraft2_udp(struct ndpi_detection_module_struct* ndpi_str case 0: if (packet->payload_packet_len == 20) flow->starcraft2_udp_stage = 1; - else - flow->starcraft2_udp_stage = 0; break; case 1: if (packet->payload_packet_len == 20) @@ -112,8 +109,6 @@ u_int8_t ndpi_check_starcraft2_udp(struct ndpi_detection_module_struct* ndpi_str return 1; break; } - - return -1; } void ndpi_search_starcraft2(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) @@ -126,14 +121,14 @@ void ndpi_search_starcraft2(struct ndpi_detection_module_struct* ndpi_struct, st if (packet->udp != NULL) { result = ndpi_check_starcraft2_udp(ndpi_struct, flow); if (result == 1) { - printf("%d Found Starcraft 2 [Game, UDP]\n", k++); + //printf("Found Starcraft 2 [Game, UDP]\n"); NDPI_LOG(NDPI_PROTOCOL_STARCRAFT2, ndpi_struct, NDPI_LOG_DEBUG, "Found Starcraft 2 [Game, UDP]\n"); } } else if (packet->tcp != NULL) { result = ndpi_check_starcraft2_tcp(ndpi_struct, flow); if (result == 1) { - printf("%d Found Starcraft 2 [Client, TCP]\n", k++); + //printf("Found Starcraft 2 [Client, TCP]\n"); NDPI_LOG(NDPI_PROTOCOL_STARCRAFT2, ndpi_struct, NDPI_LOG_DEBUG, "Found Starcraft 2 [Client, TCP]\n"); } } -- cgit v1.2.3