📄 ipcontroldoc.h
字号:
// IPControlDoc.h : interface of the CIPControlDoc class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_IPCONTROLDOC_H__64682051_09F1_4238_86B4_C1BD15453EA3__INCLUDED_)
#define AFX_IPCONTROLDOC_H__64682051_09F1_4238_86B4_C1BD15453EA3__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "pcap.h"
#include "remote-ext.h"
#include "MainFrm.h"
#define TCP_PROTO 6 //tcp
#define UDP_PROTO 17 //UDP
#define ICMP_PROTO 1
/***********一些说明**********************************
//1字节=8位
sizeof(u_char)==1
sizeof(u_short)==2
sizeof(u_int)==4
sizeof(u_long)==4
sizeof(u_int8_t)==1
sizeof(u_int16_t)==2
sizeof(u_int32_t)==4
sizeof(u_int64_t)==8
***********************************************/
//Mac帧头 占14个字节
typedef struct tag_mac_header
{
u_char dadd[6];//6个字节 目标地址
u_char sadd[6];//6个字节 源地址
u_short mac_type;//2个字节 类型
}mac_header;
//IP地址 4字节
typedef struct tag_ip_address
{
u_char byte1; //sizeof(u_char)==1 u_char占一个字节(8位)
u_char byte2;
u_char byte3;
u_char byte4;
}ip_address;
//定义IP头 IP数据包=IP头+TCP数据段(或UDP数据段)
typedef struct tag_ip_header
{
u_char ver_ihl; // u_char 8位 版本(4位) + 头长(4位)
u_char tos;//TOS 服务类型
u_short tlen;//包总长 u_short占两个字节
u_short identification;//标识
u_short flags_fo;//标志位Flags(3位)+分段偏移(13位)
u_char ttl;//TTL
u_char proto;//Protocol
u_short crc;//校验和
ip_address saddr;//源地址
ip_address daddr;//目的地址
u_int op_pad;//选项+填充字段 u_int占4个字节 32位
//接下来是数据段,不属于IP头部
}ip_header;
//定义UDP头
typedef struct tag_udp_header
{
u_short sport;//源端口 16位
u_short dport;//目的端口 16位
u_short len;//数据报长度 16位
u_short crc;//校验和 16位
}udp_header;
//定义TCP头
typedef struct tag_tcp_header
{
u_short sport;//源端口地址 16位
u_short dport;//目的端口地址 16位
u_int32_t sn;//序列号 32位
u_int32_t an;//确认号 32位
u_int16_t other;//16位 其中 头长度4位+保留6位+UPG1+ACK1+PSH1+RST1+SYN1+FIN1
u_int16_t window_size;//窗口大小 16位
u_int16_t check_sum;//校验和 16位
u_int16_t urgent_pointer;//紧急指针 16位
u_int32_t option;//选项0或32位
}tcp_header;
//定义ICMP
typedef struct tag_icmp_header
{
u_char type;//8位 类型
u_char identifer; //8位 代码
u_char sequence;//序列号 8位
u_char chksum;//8位校验和
}icmp_header;
//////////////////////////////////////////////////////////////////////////
//要保存的数据结构
typedef struct tag_DataPacket
{
char strPacketType[8];//包类型
char strTime[16];//时间
int len;//长度
mac_header mach;//MAC头
ip_header iph;//IP头
void* pTCP_UDP;//可能位tcp也可能位udp 无法预料,所以用指针保存
}DataPacket;
struct ip_variable
{int ip_hlength;
int ip_length;
char ip_sip[1024];
char ip_dip[1024];
char ip_type[1024];
int ip_version;
int ip_service;
int ip_ident;
int ip_flags;
int ip_distance;
int ip_ttl;
};
struct tcp_variable
{int tcp_sport;
int tcp_dport;
unsigned long int tcp_sequence;
unsigned long int tcp_ack;
int tcp_hlength;
char tcp_flags[1024];
int tcp_window;
int tcp_checksum;
int tcp_urge;
char tcp_content[65535];
};
struct udp_variable
{int udp_sport;
int udp_dport;
int udp_length;
int udp_checksum;
char udp_content[65535];
};
struct icmp_variable
{int icmp_type;
int icmp_code;
int icmp_checksum;
char icmp_content[65535];
};
class CIPControlDoc : public CDocument
{
protected: // create from serialization only
CIPControlDoc();
DECLARE_DYNCREATE(CIPControlDoc)
// Attributes
public:
_ConnectionPtr m_pConnection;
_CommandPtr m_pCommand;
_RecordsetPtr m_pRecordset;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CIPControlDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
//}}AFX_VIRTUAL
// Implementation
public:
int StartCapture(int index);
int InitPacp();
void CleanData();
int AnalyzeData(DataPacket* pdata);
int SavePacket(struct pcap_pkthdr *header,const u_char *pkt_data);
void UpdateEdit(int index);
void UpdateTree(int index);
int StopCapture();
virtual ~CIPControlDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
public:
HANDLE m_ThreadHandle;
// Generated message map functions
public:
void make_log(int number);
void whole_parse_rules();
int get_protocol_variable(char variable[1024]);
void get_icmp_variable();
void get_udp_variable();
void get_tcp_variable();
void get_ip_variable();
int get_yu_result(char*str1,char *str2);
void read_event_defination(char *event);
int compare_variable(char variable[1024],char fuhao,char *result);
int read_a_statement(char *statement);
int parse_rules(char *rules);
char * ReadData(char *line,char flag);
void clear_all_rules();
void read_statement_from_rules();
char* ReadFile(FILE *fp,char flag);
void read_rules_from_file(char *filename);
char filename[100];
pcap_dumper_t *dumpfile; //保存数据的文件
int total_rules_number;
int m_nPackerNum; //捕获到的数据包个数
// struct pcap_pkthdr *header;
// const u_char *pkt_data;
u_int netmask;//掩码
int m_nDeviceCount; //设备个数
pcap_t *adhandle;//打开的网络设备的句并
CPtrList m_data;
pcap_if_t *alldevs; //所有设备列表
pcap_if_t *d; //某个设备
char errbuf[PCAP_ERRBUF_SIZE]; //保存错误信息
//////////////////////////////////////////////////////////////////////////
struct ip_variable nids_ip_variable;
struct icmp_variable nids_icmp_variable;
struct udp_variable nids_udp_variable;
struct tcp_variable nids_tcp_variable;
char m_strPacketIndex[10]; //序号
char m_strTime[16];//包的时间
char m_strLen[10]; //长度
char m_strSourMAC[18];//源MAC地址
char m_strDestMAC[18];//目的MAC地址
char m_strPacketType[8];//包类型,TCP UDP ICMP ARP ...
char m_strSourIP[16];//源IP
char m_strDestIP[16];//目的IP
char m_strSport[10];//源端口
char m_strDport[10];//目的端口
char m_mactype[10];
char m_ver_ihl[10];
char m_tos[10];
char m_tlen[10];
char m_identification[10];
char m_flags_fo[10];
char m_ttl[10];
char m_proto[10];
char m_crc[10];
char m_op_pad[10];
char m_udplen[10];
char m_udpcrc[10];
char m_tcpsn[16];
char m_tcpan[16];
char m_tcpother[16];
char m_tcpwindow_size[10];
char m_tcpcheck_sum[10];
char m_tcpurgent_pointer[10];
char m_tcpoption[10];
char m_icmptype[10];
char m_icmpidentifer[10];
char m_icmpsequence[10];
char m_icmpchksum[10];
char total_rules[1024][1024];
char event_name[1024][1024];
char event_protocol[1024][1024];
char event_code[1024][1024];
char event_defination[1024][1024];
char event_information[1024][1024];
char alert_type[1024][1024];
char event_statement[1024][1024];
int state_number;
char relation[1024];
//////////////////////////////////////////////////////////////////////////
//{{AFX_MSG(CIPControlDoc)
afx_msg void OnFileOpen();
afx_msg void OnFileSave();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_IPCONTROLDOC_H__64682051_09F1_4238_86B4_C1BD15453EA3__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -