aboutsummaryrefslogtreecommitdiff
path: root/src/lib/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/protocols')
-rw-r--r--src/lib/protocols/bittorrent.c21
-rw-r--r--src/lib/protocols/csgo.c124
2 files changed, 135 insertions, 10 deletions
diff --git a/src/lib/protocols/bittorrent.c b/src/lib/protocols/bittorrent.c
index a88b1cce5..e7a5e890a 100644
--- a/src/lib/protocols/bittorrent.c
+++ b/src/lib/protocols/bittorrent.c
@@ -59,14 +59,14 @@ static void ndpi_add_connection_as_bittorrent(struct ndpi_detection_module_struc
const char *bt_hash = NULL; /* 20 bytes long */
if(bt_offset == -1) {
- const char *bt_magic = ndpi_strnstr((const char *)flow->packet.payload,
+ const char *bt_magic = ndpi_strnstr((const char *)flow->packet.payload,
"BitTorrent protocol", flow->packet.payload_packet_len);
if(bt_magic)
bt_hash = &bt_magic[19];
} else
bt_hash = (const char*)&flow->packet.payload[28];
-
+
if(bt_hash) memcpy(flow->bittorent_hash, bt_hash, 20);
}
@@ -387,15 +387,15 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
char *bt_proto = NULL;
/* This is broadcast */
- if(packet->iph
+ if(packet->iph
&& (((packet->iph->saddr == 0xFFFFFFFF) || (packet->iph->daddr == 0xFFFFFFFF))
- || (packet->udp
+ || (packet->udp
&& ((ntohs(packet->udp->source) == 3544) /* teredo.c */
|| (ntohs(packet->udp->dest) == 3544))))) {
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_BITTORRENT);
return;
}
-
+
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_BITTORRENT) {
/* check for tcp retransmission here */
@@ -441,7 +441,8 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
/* Heuristic */
bt_proto = ndpi_strnstr((const char *)&packet->payload[20], "BitTorrent protocol", packet->payload_packet_len-20);
goto bittorrent_found;
- } else if(((v1_version & 0x0f) == 1)
+ /* CSGO/DOTA conflict */
+ } else if(flow->packet_counter > 8 && ((v1_version & 0x0f) == 1)
&& ((v1_version >> 4) < 5 /* ST_NUM_STATES */)
&& (v1_extension < 3 /* EXT_NUM_EXT */)
&& (v1_window_size < 32768 /* 32k */)
@@ -466,8 +467,8 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
if(flow->bittorrent_stage < 10) {
/* We have detected bittorrent but we need to wait until we get a hash */
-
- if(packet->payload_packet_len > 19 /* min size */) {
+
+ if(packet->payload_packet_len > 19 /* min size */) {
if(ndpi_strnstr((const char *)packet->payload, ":target20:", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, ":find_node1:", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, "d1:ad2:id20:", packet->payload_packet_len)
@@ -475,7 +476,7 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
|| ndpi_strnstr((const char *)packet->payload, ":filter64", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, "d1:rd2:id20:", packet->payload_packet_len)
|| (bt_proto = ndpi_strnstr((const char *)packet->payload, "BitTorrent protocol", packet->payload_packet_len))
- ) {
+ ) {
bittorrent_found:
if(bt_proto && (packet->payload_packet_len > 47))
memcpy(flow->bittorent_hash, &bt_proto[27], 20);
@@ -486,7 +487,7 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
return;
}
- }
+ }
return;
}
diff --git a/src/lib/protocols/csgo.c b/src/lib/protocols/csgo.c
new file mode 100644
index 000000000..14073aef7
--- /dev/null
+++ b/src/lib/protocols/csgo.c
@@ -0,0 +1,124 @@
+/*
+ * csgo.c
+ *
+ * Copyright (C) 2016-2017 Vitaly Lavrov <vel21ripn@gmail.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#include "ndpi_api.h"
+
+#ifdef NDPI_PROTOCOL_CSGO
+
+void ndpi_search_csgo(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) {
+ struct ndpi_packet_struct* packet = &flow->packet;
+
+ if (packet->udp != NULL) {
+ uint32_t w = htonl(get_u_int32_t(packet->payload, 0));
+ NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "CSGO: word %08x\n", w);
+
+ if (!flow->csgo_state && packet->payload_packet_len == 23 && w == 0xfffffffful) {
+ if (!memcmp(packet->payload + 5, "connect0x", 9)) {
+ NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo connect0x.\n");
+ flow->csgo_state++;
+ memcpy(flow->csgo_strid, packet->payload + 5, 18);
+ return;
+ }
+ }
+ if (flow->csgo_state == 1 && packet->payload_packet_len >= 42 && w == 0xfffffffful) {
+ if (!memcmp(packet->payload + 24, flow->csgo_strid, 18)) {
+ NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo connect0x reply.\n");
+ flow->csgo_state++;
+ ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
+ return;
+ }
+ }
+ if (packet->payload_packet_len == 8 && ( w == 0x3a180000 || w == 0x39180000) ) {
+ NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo udp 8b.\n");
+ ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
+ return;
+ }
+ if (packet->payload_packet_len >= 36 && w == 0x56533031ul) {
+ NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo udp.\n");
+ ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
+ return;
+ }
+ if (packet->payload_packet_len >= 36 && w == 0x01007364) {
+ uint32_t w2 = htonl(get_u_int32_t(packet->payload, 4));
+ if (w2 == 0x70696e67) {
+ NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo udp ping.\n");
+ ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
+ return;
+ }
+ }
+ if (flow->csgo_s2 < 3 && (w & 0xffff0000ul) == 0x0d1d0000) {
+ uint32_t w2 = get_u_int32_t(packet->payload, 2);
+ if (packet->payload_packet_len == 13) {
+ if (!flow->csgo_s2) {
+ flow->csgo_id2 = w2;
+ flow->csgo_s2 = 1;
+ NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo udp 0d1d step1.\n");
+ return;
+ }
+ if (flow->csgo_s2 == 1 && flow->csgo_id2 == w2) {
+ NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo udp 0d1d step1 DUP.\n");
+ return;
+ }
+ flow->csgo_s2 = 3;
+ return;
+ }
+ if (packet->payload_packet_len == 15) {
+ if (flow->csgo_s2 == 1 && flow->csgo_id2 == w2) {
+ NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo udp 0d1d.\n");
+ ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
+ return;
+ }
+ }
+ flow->csgo_s2 = 3;
+ }
+ if (packet->payload_packet_len >= 140 && (w == 0x02124c6c || w == 0x02125c6c) &&
+ !memcmp(&packet->payload[3], "lta\000mob\000tpc\000bhj\000bxd\000tae\000urg\000gkh\000", 32)) {
+ NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo dictionary udp.\n");
+ ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
+ return;
+ }
+ if (packet->payload_packet_len >= 33 && packet->iph && packet->iph->daddr == 0xffffffff &&
+ !memcmp(&packet->payload[17], "LanSearch", 9)) {
+ NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo LanSearch udp.\n");
+ ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
+ return;
+ }
+ }
+ if (flow->packet_counter > 20)
+ NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_CSGO);
+}
+
+void init_csgo_dissector(struct ndpi_detection_module_struct *ndpi_struct,
+ u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) {
+ ndpi_set_bitmask_protocol_detection("CSGO", ndpi_struct, detection_bitmask, *id,
+ NDPI_PROTOCOL_CSGO,
+ ndpi_search_csgo,
+ NDPI_SELECTION_BITMASK_PROTOCOL_UDP_WITH_PAYLOAD,
+ SAVE_DETECTION_BITMASK_AS_UNKNOWN,
+ ADD_TO_DETECTION_BITMASK);
+
+ *id += 1;
+}
+
+#endif