Enhanced FTP_DATA recognition (issue #28)
This commit is contained in:
@@ -792,9 +792,6 @@ typedef struct ndpi_flow_struct {
|
|||||||
#ifdef NDPI_PROTOCOL_FTP_CONTROL
|
#ifdef NDPI_PROTOCOL_FTP_CONTROL
|
||||||
u_int32_t ftp_control_stage:2;
|
u_int32_t ftp_control_stage:2;
|
||||||
#endif
|
#endif
|
||||||
#ifdef NDPI_PROTOCOL_FTP_DATA
|
|
||||||
u_int32_t ftp_data_stage:2;
|
|
||||||
#endif
|
|
||||||
#ifdef NDPI_PROTOCOL_RTMP
|
#ifdef NDPI_PROTOCOL_RTMP
|
||||||
u_int32_t rtmp_stage:2;
|
u_int32_t rtmp_stage:2;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ static int ndpi_match_ftp_data_directory(struct ndpi_detection_module_struct *nd
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
|
static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
|
||||||
@@ -216,37 +215,17 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
|
|||||||
|
|
||||||
static void ndpi_check_ftp_data(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
|
static void ndpi_check_ftp_data(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
|
||||||
struct ndpi_packet_struct *packet = &flow->packet;
|
struct ndpi_packet_struct *packet = &flow->packet;
|
||||||
u_int32_t payload_len = packet->payload_packet_len;
|
|
||||||
|
|
||||||
/* Check if we so far detected the protocol in the request or not. */
|
if((packet->payload_packet_len > 0)
|
||||||
if(flow->ftp_data_stage == 0) {
|
&& (ndpi_match_file_header(ndpi_struct, flow)
|
||||||
NDPI_LOG(NDPI_PROTOCOL_FTP_DATA, ndpi_struct, NDPI_LOG_DEBUG, "FTP_DATA stage 0: \n");
|
|| ndpi_match_ftp_data_directory(ndpi_struct, flow)
|
||||||
|
|| ndpi_match_ftp_data_port(ndpi_struct, flow)
|
||||||
if((payload_len > 0) && (ndpi_match_file_header(ndpi_struct, flow) || ndpi_match_ftp_data_directory(ndpi_struct, flow) || ndpi_match_ftp_data_port(ndpi_struct, flow))) {
|
)
|
||||||
NDPI_LOG(NDPI_PROTOCOL_FTP_DATA, ndpi_struct, NDPI_LOG_DEBUG, "Possible FTP_DATA request detected, we will look further for the response...\n");
|
) {
|
||||||
|
NDPI_LOG(NDPI_PROTOCOL_FTP_DATA, ndpi_struct, NDPI_LOG_DEBUG, "Possible FTP_DATA request detected...\n");
|
||||||
/* Encode the direction of the packet in the stage, so we will know when we need to look for the response packet. */
|
ndpi_int_ftp_data_add_connection(ndpi_struct, flow);
|
||||||
flow->ftp_data_stage = packet->packet_direction + 1;
|
} else
|
||||||
}
|
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_FTP_DATA);
|
||||||
|
|
||||||
} else {
|
|
||||||
NDPI_LOG(NDPI_PROTOCOL_FTP_DATA, ndpi_struct, NDPI_LOG_DEBUG, "FTP_DATA stage %u: \n", flow->ftp_data_stage);
|
|
||||||
|
|
||||||
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
|
|
||||||
if((flow->ftp_data_stage - packet->packet_direction) == 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This is a packet in another direction. Check if we find the proper response. */
|
|
||||||
if(payload_len == 0) {
|
|
||||||
NDPI_LOG(NDPI_PROTOCOL_FTP_DATA, ndpi_struct, NDPI_LOG_DEBUG, "Found FTP_DATA.\n");
|
|
||||||
ndpi_int_ftp_data_add_connection(ndpi_struct, flow);
|
|
||||||
} else {
|
|
||||||
NDPI_LOG(NDPI_PROTOCOL_FTP_DATA, ndpi_struct, NDPI_LOG_DEBUG, "The reply did not seem to belong to FTP_DATA, resetting the stage to 0...\n");
|
|
||||||
flow->ftp_data_stage = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ndpi_search_ftp_data(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
|
void ndpi_search_ftp_data(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
|
||||||
@@ -259,15 +238,6 @@ void ndpi_search_ftp_data(struct ndpi_detection_module_struct *ndpi_struct, stru
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* skip marked or retransmitted packets */
|
|
||||||
if(packet->tcp_retransmission != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(packet->detected_protocol_stack[0] == NDPI_PROTOCOL_FTP_DATA) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NDPI_LOG(NDPI_PROTOCOL_FTP_DATA, ndpi_struct, NDPI_LOG_DEBUG, "FTP_DATA detection...\n");
|
NDPI_LOG(NDPI_PROTOCOL_FTP_DATA, ndpi_struct, NDPI_LOG_DEBUG, "FTP_DATA detection...\n");
|
||||||
ndpi_check_ftp_data(ndpi_struct, flow);
|
ndpi_check_ftp_data(ndpi_struct, flow);
|
||||||
}
|
}
|
||||||
@@ -278,7 +248,7 @@ void init_ftp_data_dissector(struct ndpi_detection_module_struct *ndpi_struct, u
|
|||||||
ndpi_set_bitmask_protocol_detection("FTP_DATA", ndpi_struct, detection_bitmask, *id,
|
ndpi_set_bitmask_protocol_detection("FTP_DATA", ndpi_struct, detection_bitmask, *id,
|
||||||
NDPI_PROTOCOL_FTP_DATA,
|
NDPI_PROTOCOL_FTP_DATA,
|
||||||
ndpi_search_ftp_data,
|
ndpi_search_ftp_data,
|
||||||
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITHOUT_RETRANSMISSION,
|
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
|
||||||
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
|
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
|
||||||
ADD_TO_DETECTION_BITMASK);
|
ADD_TO_DETECTION_BITMASK);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user