aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/ndpi_protocol_ids.h4
-rw-r--r--src/include/ndpi_protocols.h1
-rw-r--r--src/lib/ndpi_main.c9
-rw-r--r--src/lib/protocols/mining.c94
-rw-r--r--tests/pcap/bitcoin.pcapbin0 -> 591290 bytes
-rw-r--r--tests/pcap/ethereum.pcapbin0 -> 147293 bytes
-rw-r--r--tests/pcap/monero.pcapbin0 -> 171804 bytes
-rw-r--r--tests/pcap/zcash.pcapbin0 -> 22988 bytes
-rw-r--r--tests/result/bitcoin.pcap.out8
-rw-r--r--tests/result/ethereum.pcap.out4
-rw-r--r--tests/result/monero.pcap.out4
-rw-r--r--tests/result/zcash.pcap.out3
12 files changed, 122 insertions, 5 deletions
diff --git a/src/include/ndpi_protocol_ids.h b/src/include/ndpi_protocol_ids.h
index 7b4961a0e..607e8deef 100644
--- a/src/include/ndpi_protocol_ids.h
+++ b/src/include/ndpi_protocol_ids.h
@@ -75,9 +75,9 @@ typedef enum {
NDPI_PROTOCOL_SKYPE_CALL_OUT = 38,
NDPI_PROTOCOL_MUSICALLY = 39,
NDPI_PROTOCOL_MEMCACHED = 40, /* Memcached - Darryl Sokoloski <darryl@egloo.ca> */
- NDPI_PROTOCOL_SMBV23 = 41, /* SMB version 2/3 */
+ NDPI_PROTOCOL_SMBV23 = 41, /* SMB version 2/3 */
+ NDPI_PROTOCOL_MINING = 42, /* Bitcoin, Ethereum, ZCash, Monero */
- NDPI_PROTOCOL_FREE_42 = 42, /* Free */
NDPI_PROTOCOL_FREE_43 = 43, /* Free */
NDPI_PROTOCOL_FREE_44 = 44, /* Free */
NDPI_PROTOCOL_FREE_45 = 45, /* Free */
diff --git a/src/include/ndpi_protocols.h b/src/include/ndpi_protocols.h
index 5c08f85f5..e1f3af4fb 100644
--- a/src/include/ndpi_protocols.h
+++ b/src/include/ndpi_protocols.h
@@ -260,6 +260,7 @@ void init_maplestory_dissector(struct ndpi_detection_module_struct *ndpi_struct,
void init_mdns_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_megaco_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_mgpc_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
+void init_mining_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_mms_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_msn_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_mpegts_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 8fed1ebf1..9b6501d9b 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -1222,10 +1222,10 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp
no_master, "SMBv23", NDPI_PROTOCOL_CATEGORY_SYSTEM_OS,
ndpi_build_default_ports(ports_a, 445, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
- ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_FUN, NDPI_PROTOCOL_FREE_42,
+ ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_FUN, NDPI_PROTOCOL_MINING,
no_master,
- no_master, "Free", NDPI_PROTOCOL_CATEGORY_CUSTOM_1 /* dummy */,
- ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
+ no_master, "Mining", CUSTOM_CATEGORY_MINING /* dummy */,
+ ndpi_build_default_ports(ports_a, 8333, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_FUN, NDPI_PROTOCOL_FREE_43,
no_master,
@@ -2929,6 +2929,9 @@ void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *n
/* SMB */
init_smb_dissector(ndpi_struct, &a, detection_bitmask);
+ /* MINING */
+ init_mining_dissector(ndpi_struct, &a, detection_bitmask);
+
/* TELNET */
init_telnet_dissector(ndpi_struct, &a, detection_bitmask);
diff --git a/src/lib/protocols/mining.c b/src/lib/protocols/mining.c
new file mode 100644
index 000000000..ec094e7d3
--- /dev/null
+++ b/src/lib/protocols/mining.c
@@ -0,0 +1,94 @@
+/*
+ * mining.c [Bitcoin, Ethereum, ZCash, Monero]
+ *
+ * Copyright (C) 2018 - 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+#include "ndpi_protocol_ids.h"
+
+#include "ndpi_api.h"
+
+void ndpi_search_mining_tcp(struct ndpi_detection_module_struct *ndpi_struct,
+ struct ndpi_flow_struct *flow) {
+ struct ndpi_packet_struct *packet = &flow->packet;
+
+ NDPI_LOG_DBG(ndpi_struct, "search MINING\n");
+
+ /* Check connection over TCP */
+ if(packet->tcp && (packet->payload_packet_len > 10)) {
+
+ if(packet->tcp->source == htons(8333)) {
+ /*
+ Bitcoin
+
+ bitcoin.magic == 0xf9beb4d9 || bitcoin.magic == 0xfabfb5da
+ */
+ u_int32_t magic = htonl(0xf9beb4d9), magic1 = htonl(0xfabfb5da), *to_match = (u_int32_t*)packet->payload;
+
+ if((*to_match == magic) || (*to_match == magic1)) {
+ ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MINING, NDPI_PROTOCOL_UNKNOWN);
+ }
+ } if(ndpi_strnstr((const char *)packet->payload, "\"eth1.0\"", packet->payload_packet_len)
+ || ndpi_strnstr((const char *)packet->payload, "\"worker\"", packet->payload_packet_len)
+ || ndpi_strnstr((const char *)packet->payload, "\"id\"", packet->payload_packet_len)) {
+ /*
+ Ethereum
+
+ {"worker": "eth1.0", "jsonrpc": "2.0", "params": ["0x0fccfff9e61a230ff380530c6827caf4759337c6.rig2", "x"], "id": 2, "method": "eth_submitLogin"}
+ { "id": 2, "jsonrpc":"2.0","result":true}
+ {"worker": "", "jsonrpc": "2.0", "params": [], "id": 3, "method": "eth_getWork"}
+ */
+ ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MINING, NDPI_PROTOCOL_UNKNOWN);
+ } else if(ndpi_strnstr((const char *)packet->payload, "\"method\"", packet->payload_packet_len)
+ || ndpi_strnstr((const char *)packet->payload, "\"blob\"", packet->payload_packet_len)
+ || ndpi_strnstr((const char *)packet->payload, "\"id\"", packet->payload_packet_len)) {
+ /*
+ ZCash
+
+ {"method":"login","params":{"login":"4BCeEPhodgPMbPWFN1dPwhWXdRX8q4mhhdZdA1dtSMLTLCEYvAj9QXjXAfF7CugEbmfBhgkqHbdgK9b2wKA6nqRZQCgvCDm.cb2b73415c4faf214035a73b9d947c202342f3bf3bdf632132bd6d7af98cb257.ryzen","pass":"x","agent":"xmr-stak-cpu/1.3.0-1.5.0"},"id":1}
+ {"id":1,"jsonrpc":"2.0","error":null,"result":{"id":"479059546883218","job":{"blob":"0606e89883d205a65d8ee78991838a1cf3ec2ebbc5fb1fa43dec5fa1cd2bee4069212a549cd731000000005a88235653097aa3e97ef2ceef4aee610751a828f9be1a0758a78365fb0a4c8c05","job_id":"722134174127131","target":"dc460300"},"status":"OK"}}
+ {"method":"submit","params":{"id":"479059546883218","job_id":"722134174127131","nonce":"98024001","result":"c9be9381a68d533c059d614d961e0534d7d8785dd5c339c2f9596eb95f320100"},"id":1}
+
+ Monero
+
+ {"method":"login","params":{"login":"4BCeEPhodgPMbPWFN1dPwhWXdRX8q4mhhdZdA1dtSMLTLCEYvAj9QXjXAfF7CugEbmfBhgkqHbdgK9b2wKA6nqRZQCgvCDm.cb2b73415c4faf214035a73b9d947c202342f3bf3bdf632132bd6d7af98cb257.ryzen","pass":"x","agent":"xmr-stak-cpu/1.3.0-1.5.0"},"id":1}
+ {"id":1,"jsonrpc":"2.0","error":null,"result":{"id":"479059546883218","job":{"blob":"0606e89883d205a65d8ee78991838a1cf3ec2ebbc5fb1fa43dec5fa1cd2bee4069212a549cd731000000005a88235653097aa3e97ef2ceef4aee610751a828f9be1a0758a78365fb0a4c8c05","job_id":"722134174127131","target":"dc460300"},"status":"OK"}}
+ {"method":"submit","params":{"id":"479059546883218","job_id":"722134174127131","nonce":"98024001","result":"c9be9381a68d533c059d614d961e0534d7d8785dd5c339c2f9596eb95f320100"},"id":1}
+ */
+ ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MINING, NDPI_PROTOCOL_UNKNOWN);
+ }
+ }
+
+ ndpi_exclude_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MINING, __FILE__, __FUNCTION__, __LINE__);
+}
+
+
+void init_mining_dissector(struct ndpi_detection_module_struct *ndpi_struct,
+ u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
+{
+ ndpi_set_bitmask_protocol_detection("Mining", ndpi_struct, detection_bitmask, *id,
+ NDPI_PROTOCOL_MINING,
+ ndpi_search_mining_tcp,
+ NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
+ SAVE_DETECTION_BITMASK_AS_UNKNOWN,
+ ADD_TO_DETECTION_BITMASK);
+
+ *id += 1;
+}
+
diff --git a/tests/pcap/bitcoin.pcap b/tests/pcap/bitcoin.pcap
new file mode 100644
index 000000000..ce62ed779
--- /dev/null
+++ b/tests/pcap/bitcoin.pcap
Binary files differ
diff --git a/tests/pcap/ethereum.pcap b/tests/pcap/ethereum.pcap
new file mode 100644
index 000000000..f77637d62
--- /dev/null
+++ b/tests/pcap/ethereum.pcap
Binary files differ
diff --git a/tests/pcap/monero.pcap b/tests/pcap/monero.pcap
new file mode 100644
index 000000000..67d796882
--- /dev/null
+++ b/tests/pcap/monero.pcap
Binary files differ
diff --git a/tests/pcap/zcash.pcap b/tests/pcap/zcash.pcap
new file mode 100644
index 000000000..213585dbd
--- /dev/null
+++ b/tests/pcap/zcash.pcap
Binary files differ
diff --git a/tests/result/bitcoin.pcap.out b/tests/result/bitcoin.pcap.out
new file mode 100644
index 000000000..d10fa583d
--- /dev/null
+++ b/tests/result/bitcoin.pcap.out
@@ -0,0 +1,8 @@
+Mining 637 581074 6
+
+ 1 TCP 192.168.1.142:55328 <-> 69.118.54.122:8333 [proto: 42/Mining][cat: Unspecified/99][2 pkts/281 bytes <-> 137 pkts/191029 bytes]
+ 2 TCP 192.168.1.142:55348 <-> 74.89.181.229:8333 [proto: 42/Mining][cat: Unspecified/99][55 pkts/28663 bytes <-> 117 pkts/134830 bytes]
+ 3 TCP 192.168.1.142:55383 <-> 66.68.83.22:8333 [proto: 42/Mining][cat: Unspecified/99][65 pkts/45271 bytes <-> 96 pkts/70339 bytes]
+ 4 TCP 192.168.1.142:55400 <-> 195.218.16.178:8333 [proto: 42/Mining][cat: Unspecified/99][47 pkts/26824 bytes <-> 72 pkts/55927 bytes]
+ 5 TCP 192.168.1.142:55317 <-> 188.165.213.169:8333 [proto: 42/Mining][cat: Unspecified/99][16 pkts/21673 bytes <-> 3 pkts/1771 bytes]
+ 6 TCP 192.168.1.142:55487 <-> 184.58.165.119:8333 [proto: 42/Mining][cat: Unspecified/99][24 pkts/3082 bytes <-> 3 pkts/1384 bytes]
diff --git a/tests/result/ethereum.pcap.out b/tests/result/ethereum.pcap.out
new file mode 100644
index 000000000..a4c607d2d
--- /dev/null
+++ b/tests/result/ethereum.pcap.out
@@ -0,0 +1,4 @@
+Mining 819 134165 2
+
+ 1 TCP 192.168.2.92:57726 <-> 94.23.36.128:4444 [proto: 42/Mining][cat: Unspecified/99][478 pkts/52883 bytes <-> 308 pkts/76667 bytes]
+ 2 TCP 192.168.2.92:41680 <-> 91.121.222.33:4444 [proto: 42/Mining][cat: Unspecified/99][20 pkts/2159 bytes <-> 13 pkts/2456 bytes]
diff --git a/tests/result/monero.pcap.out b/tests/result/monero.pcap.out
new file mode 100644
index 000000000..732ada2ed
--- /dev/null
+++ b/tests/result/monero.pcap.out
@@ -0,0 +1,4 @@
+Mining 319 166676 2
+
+ 1 TCP 192.168.2.148:46838 <-> 94.23.199.191:3333 [proto: 42/Mining][cat: Unspecified/99][159 pkts/143155 bytes <-> 113 pkts/13204 bytes]
+ 2 TCP 192.168.2.148:53846 <-> 116.211.167.195:3333 [proto: 42/Mining][cat: Unspecified/99][24 pkts/4455 bytes <-> 23 pkts/5862 bytes]
diff --git a/tests/result/zcash.pcap.out b/tests/result/zcash.pcap.out
new file mode 100644
index 000000000..eb3e155ee
--- /dev/null
+++ b/tests/result/zcash.pcap.out
@@ -0,0 +1,3 @@
+Mining 145 20644 1
+
+ 1 TCP 192.168.2.92:55190 <-> 178.32.196.217:9050 [proto: 42/Mining][cat: Unspecified/99][83 pkts/11785 bytes <-> 62 pkts/8859 bytes]