u_short len; // 16位UDP长度
u_short crc; // 16位UDP检验和
udp_header; /*TCP 头*/
typedef struct tcphdr
USHORT th_sport;// 16位源端口号 USHORT th_dport;// 16位目的端口号 ULONG th_seq;//32位序列号 ULONG th_ack;//32位确认号 UCHAR th_x2:4;
UCHAR th_off:4; //保留 UCHAR th_flags; #define TH_FIN 0x01 #define TH_SYN 0x02 #define TH_RST 0x04 #define TH_PUSH0x08 #define TH_ACK 0x10 #define TH_URG 0x20 #define TH_ECE 0x40 #define TH_CWR 0x80
#define
TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR
TH_FLAGS
USHORT th_win;//16位窗口大小 USHORT th_sum;//16位TCP检验和 USHORT th_urp;//16位紧急指针 tcphdr;
分析数据包模块实现
系统采用异常检测分析方法。对每一个进入的源IP地址作时间溢出判定,如果时间没有溢出,根据捕获信息,更新记录信息。否则,清空记录信息并重新记录。当记录信息中的规则变量超过规定值时,推测有异常行为。本系统实现了端口扫描和SYN洪水攻击的检测。
typedef struct tagrule // SYN洪水攻击的数据结构 struct ip_address keyword;// 记录源IP地址 time_t t1_tmpbuf_com;// IP地址进入时间 int count; // 记录某人连接我时SYN1的次数 synrule;
typedef struct tagrule2// 端口扫描的数据结构 struct ip_address keyword; // 记录源IP地址 time_t t2_tmpbuf_com; // IP地址进入时间 int count[NUM2]; // 记录某人当前扫描我的端口 int k; scnrule; int
scanportip_header
*ih,int
dport,int
timeout,time_t
t_tmpbuf_now,rule2 scanrule[]//检测端口扫描的规则函数
int h; int m; h0; iftimeout0
forh0;hi&&hNUM2;h++//查询进入的IP是否曾经出现
if ih-saddr.byte1scanrule[h].keyword.byte1&&
ih-saddr.byte2scanrule[h].keyword.byte2&&
ih-saddr.