Merge branch 'develop-ssh-identify' into develop-20.09

# Conflicts:
#	inc/tsg_rule.h
#	src/tsg_entry.cpp
#	src/tsg_rule.cpp
This commit is contained in:
liuxueli
2020-08-24 16:36:54 +08:00
5 changed files with 43 additions and 2 deletions

View File

@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8)
add_definitions(-fPIC) add_definitions(-fPIC)
set(SRC tsg_entry.cpp tsg_rule.cpp tsg_ssl_utils.cpp tsg_send_log.cpp tsg_statistic.cpp) set(SRC tsg_entry.cpp tsg_rule.cpp tsg_ssl_utils.cpp tsg_send_log.cpp tsg_statistic.cpp tsg_ssh_utils.cpp)
include_directories(${CMAKE_SOURCE_DIR}/inc) include_directories(${CMAKE_SOURCE_DIR}/inc)
include_directories(/opt/MESA/include/MESA/) include_directories(/opt/MESA/include/MESA/)

View File

@@ -19,6 +19,7 @@
#include "tsg_statistic.h" #include "tsg_statistic.h"
#include "tsg_send_log_internal.h" #include "tsg_send_log_internal.h"
#include "tsg_ssl_utils.h" #include "tsg_ssl_utils.h"
#include "tsg_ssh_utils.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@@ -229,6 +230,9 @@ static char *schema_index2string(tsg_protocol_t proto)
case PROTO_QUIC: case PROTO_QUIC:
schema_field_value=(char *)"QUIC"; schema_field_value=(char *)"QUIC";
break; break;
case PROTO_SSH:
schema_field_value=(char *)"SSH";
break;
default: default:
break; break;
} }
@@ -421,7 +425,7 @@ static struct Maat_rule_t *tsg_policy_decision_criteria(struct streaminfo *a_str
static int identify_application_protocol(struct streaminfo *a_stream, struct _identify_info *identify_info, void *a_packet) static int identify_application_protocol(struct streaminfo *a_stream, struct _identify_info *identify_info, void *a_packet)
{ {
int ret=0; int ret=0;
identify_info->proto = PROTO_UNKONWN; identify_info->proto = PROTO_UNKONWN;
//http //http
char *host=NULL; char *host=NULL;
@@ -507,6 +511,13 @@ static int identify_application_protocol(struct streaminfo *a_stream, struct _id
return 1; return 1;
} }
ret = ssh_protocol_identify((unsigned char *)a_stream->ptcpdetail->pdata, (unsigned int)a_stream->ptcpdetail->datalen,g_tsg_para.logger);
if(ret > 0)
{
identify_info->proto=PROTO_SSH;
return 1;
}
//ssh
//quic //quic
ret=quic_protocol_identify(a_stream, a_packet, identify_info->domain, sizeof(identify_info->domain)); ret=quic_protocol_identify(a_stream, a_packet, identify_info->domain, sizeof(identify_info->domain));
if(ret>0) if(ret>0)

View File

@@ -52,6 +52,7 @@ const struct _str2index g_tsg_proto_string[PROTO_MAX+1]={{PROTO_UNKONWN, 0, (cha
{PROTO_BGP, 4, (char *)"BGP."}, {PROTO_BGP, 4, (char *)"BGP."},
{PROTO_STREAMING_MEDIA, 16, (char *)"STREAMING_MEDIA."}, {PROTO_STREAMING_MEDIA, 16, (char *)"STREAMING_MEDIA."},
{PROTO_QUIC, 5, (char *)"QUIC."}, {PROTO_QUIC, 5, (char *)"QUIC."},
{PROTO_SSH, 4, (char *)"SSH."},
{PROTO_MAX, 0, (char *)""} {PROTO_MAX, 0, (char *)""}
}; };

22
src/tsg_ssh_utils.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
#include "tsg_ssh_utils.h"
#define SSH_PROTOCOL_FIELD "SSH"
#define SSH_PROTOCOL_FIELD_LEN 3
int ssh_protocol_identify(const unsigned char* buff, size_t buff_len, void* argp)
{
void *logger=argp;
if(buff == NULL || buff_len < SSH_PROTOCOL_FIELD_LEN)
{
return -1;
}
if(memcmp((void *)buff,SSH_PROTOCOL_FIELD, SSH_PROTOCOL_FIELD_LEN) == 0)
return 1;
else
return 0;
}

7
src/tsg_ssh_utils.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef __TSG_SSH_UTILS_H__
#define __TSG_SSH_UTILS_H__
#include <string.h>
#include <MESA/MESA_handle_logger.h>
int ssh_protocol_identify(const unsigned char* buff, size_t buff_len, void* argp);
#endif