added git protocol dissector and pcap for test

This commit is contained in:
Campus
2016-06-24 13:19:14 +02:00
parent d0665bb301
commit 0f089bd49a
7 changed files with 139 additions and 7 deletions
+2 -1
View File
@@ -273,8 +273,9 @@
#define NDPI_PROTOCOL_RX 223
#define NDPI_SERVICE_WEIBO 224
#define NDPI_SERVICE_OPENDNS 225
#define NDPI_PROTOCOL_GIT 226
/* UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE */
#define NDPI_LAST_IMPLEMENTED_PROTOCOL NDPI_SERVICE_OPENDNS
#define NDPI_LAST_IMPLEMENTED_PROTOCOL NDPI_PROTOCOL_GIT
#define NDPI_MAX_SUPPORTED_PROTOCOLS (NDPI_LAST_IMPLEMENTED_PROTOCOL + 1)
#define NDPI_MAX_NUM_CUSTOM_PROTOCOLS (NDPI_NUM_BITS-NDPI_LAST_IMPLEMENTED_PROTOCOL)
+2
View File
@@ -194,6 +194,7 @@ void ndpi_search_ubntac2(struct ndpi_detection_module_struct *ndpi_struct, struc
void ndpi_search_coap(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_rx(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_git(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
/* --- INIT FUNCTIONS --- */
void init_afp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_aimini_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
@@ -334,4 +335,5 @@ void init_ubntac2_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_
void init_coap_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_mqtt_dissector (struct ndpi_detection_module_struct *ndpi_struct,u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_rx_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_git_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
#endif /* __NDPI_PROTOCOLS_H__ */
+1
View File
@@ -155,6 +155,7 @@ libndpi_la_SOURCES = ndpi_content_match.c.inc \
protocols/coap.c \
protocols/mqtt.c \
protocols/rx.c \
protocols/git.c \
third_party/include/actypes.h \
third_party/include/ahocorasick.h \
third_party/include/node.h \
+13 -6
View File
@@ -1531,22 +1531,26 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp
no_master, "COAP",
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0), /* TCP */
ndpi_build_default_ports(ports_b, 5683, 5684, 0, 0, 0)); /* UDP */
ndpi_set_proto_defaults(ndpi_mod,NDPI_PROTOCOL_ACCEPTABLE,NDPI_PROTOCOL_MQTT,
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_MQTT,
no_master,
no_master, "MQTT",
ndpi_build_default_ports(ports_a, 1883, 8883, 0, 0, 0), /* TCP */
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0)); /* UDP */
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0);
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0)); /* UDP */
/* Port guess is disabled as this is UDP and we can figure our immediately looking
at the RX header, is this is RX or not
See https://www-01.ibm.com/support/docview.wss?uid=swg21044407
*/
ndpi_set_proto_defaults(ndpi_mod,NDPI_PROTOCOL_ACCEPTABLE,NDPI_PROTOCOL_RX,
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_RX,
no_master,
no_master, "RX",
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0), /* TCP */
ports_b); /* UDP */
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0)); /* UDP */
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_GIT,
no_master,
no_master, "Git",
ndpi_build_default_ports(ports_a, 9418, 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);
@@ -2325,7 +2329,7 @@ void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *n
/* SSDP */
init_ssdp_dissector(ndpi_struct, &a, detection_bitmask);
/* WORLD_OF_WARCRAFT */
/* WORLD_OF_WARCRAFT */
init_world_of_warcraft_dissector(ndpi_struct, &a, detection_bitmask);
/* POSTGRES */
@@ -2559,6 +2563,9 @@ void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *n
/* RX */
init_rx_dissector(ndpi_struct, &a, detection_bitmask);
/* GIT */
init_git_dissector(ndpi_struct, &a, detection_bitmask);
/* Put false-positive sensitive protocols at the end */
/* SKYPE */
+118
View File
@@ -0,0 +1,118 @@
/*
* git.c
*
* Copyright (C) 2012-16 - ntop.org
*
* This module 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.
*
* This module 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.
* If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdlib.h>
#include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_GIT
#define GIT_PORT 9418
/* read all the length even if there is a null byte inside */
u_int16_t read_all_len(char * s, u_int16_t git_len)
{
char * p = s;
int c = 0;
while(*p && c < git_len-4) {
c++;
p++;
if(!*p) {
if(c < git_len-4) {
p++;
c++;
}
}
}
return c;
}
void ndpi_search_git(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct * packet = &flow->packet;
const u_int8_t * pp = packet->payload;
u_int16_t payload_len = packet->payload_packet_len;
u_int8_t * git_pkt_len_buff = NULL;
u_int8_t * git_pkt_data = NULL;
u_int16_t git_len = 0, count = 0 , is_git = 0;
if(packet->tcp != NULL) {
if((ntohs(packet->tcp->source) == GIT_PORT ||
ntohs(packet->tcp->dest) == GIT_PORT)) {
git_pkt_len_buff = malloc(4 * sizeof(u_int8_t));
do {
memcpy(git_pkt_len_buff, pp, 4);
git_len = (int)strtol(git_pkt_len_buff, NULL, 16);
if(git_pkt_len_buff[0] == 48 &&
git_pkt_len_buff[1] == 48 &&
git_pkt_len_buff[2] == 48 &&
git_pkt_len_buff[3] == 48)
/* Terminator packet */
count += 4;
else {
git_pkt_data = malloc((git_len-4) * sizeof(u_int8_t));
memcpy(git_pkt_data, pp+4, git_len-4);
u_int16_t data_len = read_all_len(git_pkt_data, git_len);
free(git_pkt_data);
if(git_len != data_len+4)
goto no_git;
else {
count += git_len;
pp += git_len;
}
}
} while(count < payload_len);
}
else goto no_git;
}
else goto no_git;
NDPI_LOG(NDPI_PROTOCOL_GIT, ndpi_struct, NDPI_LOG_DEBUG, "found Git.\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_GIT, NDPI_PROTOCOL_UNKNOWN);
return;
no_git:
NDPI_LOG(NDPI_PROTOCOL_GIT, ndpi_struct, NDPI_LOG_DEBUG, "exclude Git.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_GIT);
}
/* ***************************************************************** */
void init_git_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id,
NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("Git", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_GIT,
ndpi_search_git,
NDPI_SELECTION_BITMASK_PROTOCOL_TCP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
#endif /* NDPI_PROTOCOL_GIT */
Binary file not shown.
+3
View File
@@ -0,0 +1,3 @@
Git 90 74005 1
1 TCP 5.153.231.21:9418 <-> 192.168.0.77:47991 [proto: 226/Git][90 pkts/74005 bytes]