Traffic_parseトラフィック特性分析プロジェクト

プロジェクト紹介

トラフィックを分類するには、ネットワークトラフィックの元の特性を抽出する必要があります。ここでの元の機能には、パケット長、パケット到着時間間隔、特別なヘッダーフィールド、およびペイロードが含まれます。等々。
pysharkやscapyなどのPythonパッケージ解析ライブラリは使いにくいです。この問題は主に、ラベル付きトランスポート層プロトコルUDP / TCPの場合、その属性フィールドが変更されるという事実に反映されています。たとえば、UDP上のNetBIOS、pyshark、およびscapyは、非常にスマートなudp.payloadにアクセスして取得することはできません。したがって、必要な機能を抽出するための独自のコードを記述してください。
さらにいくつかの苦情pyshark、scapyはゴミです!

プロジェクトアドレス:

https://github.com/jmhIcoding/Traffic_parse

プロジェクトコード:

プロジェクトコードは次の場所にあります:https://github.com/jmhIcoding/Traffic_parse/tree/master/src
VSプロジェクトディレクトリは次の場所にあります:https://github.com/jmhIcoding/Traffic_parse/tree/master/vsrc vs2013を直接使用してインポートし、再構築します。

抽出する必要のある機能はhttps://github.com/jmhIcoding/Traffic_parse/blob/master/src/util.cppに
あり、DbgPrint関数があります。

void DbgPrint(int level, void *header)
{
    
    
	ethII_header* eth_headerp = (ethII_header*)header;
	ip_header* ip_headerp = (ip_header*)header;
	udp_header* udp_headerp = (udp_header*)header;
	tcp_header* tcp_headerp = (tcp_header*)header;
	in_addr srcip, dstip;
	char srcip_dot[32] = {
    
     0 }, dstip_dot[32] = {
    
     0 };
	if(!(level & DEBUG_INFO))
	{
    
    
		return;
	}
	switch (level & DEBUG_INFO)
	{
    
    
	case eth_info:
		
		printf("EthII");
		for (int i = 0; i < sizeof(eth_headerp->destination); i++)
		{
    
    
			if (i == 0) printf("\tdst:");
			printf("%0.2X", eth_headerp->destination[i]);
			if (i < (sizeof(eth_headerp->destination) - 1)) printf(":");
		}
		for (int i = 0; i < sizeof(eth_headerp->source); i++)
		{
    
    
			if (i == 0) printf("\tsrc:");
			printf("%0.2X", eth_headerp->source[i]);
			if (i < (sizeof(eth_headerp->source) - 1)) printf(":");
		}
		printf("\ttype:%0.4X\n", eth_headerp->type);
		break;
	case tcp_info:
		printf("%d,%d,tcp,", tcp_headerp->sport, tcp_headerp->dport);
		break;
	case udp_info:
		printf("%d,%d,udp,", udp_headerp->sport, udp_headerp->dport);
		break;
	case ip_info:
		//printf("IP");
		srcip.S_un.S_addr = ip_headerp->saddr;
		dstip.S_un.S_addr = ip_headerp->daddr;
		//sprintf(srcip_dot, "%s", inet_ntoa(srcip));
		//sprintf(dstip_dot, "%s", inet_ntoa(dstip));
		//dont parse ip addr to xx.yy.zz.aa
		printf("%x,%x,", srcip.S_un.S_addr, dstip.S_un.S_addr);
		break;
	default:
		break;
	}
}

ここで直接変更し、各レイヤーにどのような情報を出力する必要があるかを確認します。
どのレイヤーを解決する必要があるかDEBUG_INFOは、util.hファイルでこのマクロを制御することによって行われます

#define eth_info	0x01
#define ip_info		0x02
#define tcp_info	0x04
#define udp_info	0x08
#define dns_info	0x10
#define http_info	0x20
#define https_info	0x40
#define raw_packet_info 0x80
//#define DEBUG_INFO (eth_info | ip_info | tcp_info | udp_info | dns_info | http_info | https_info)

#define DEBUG_INFO (ip_info|tcp_info|udp_info)

自分で拡張するために必要な機能。

その他

このツールは、他の解析ライブラリであるflowcontainerほど使いやすいものではありません。

[flowcontainer:python3に基づくネットワークフロー情報抽出ライブラリ]、アドレス:https://blog.csdn.net/jmh1996/article/details/107148871の移動を検討できます。

おすすめ

転載: blog.csdn.net/jmh1996/article/details/106965440