入侵实验三snort的安装配置
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实验四基于WinPcap的
网络入侵检测系统的设计与开发
一、实验框架
实现总体分为三个部分,一个利用winpcap开发包进行数据采集和预处理,输出数据包基本内容(包头)到文本文档;一个将匹配算法整合成可用静态库;一个调用匹配算法的静态库检测文本文档信息,由手工输入特征库,输出屏幕结果作为响应模块。
使用win7旗舰版、Visual C++6.0,、winpcap4.13、winpack4.0
二、winpcap安装配置
(一)点击winpcap.exe安装winpcap驱动:
1.C:\WINDOWS\system32目录下自动生成: wpcap.dll,packet.dll
2.C:\WINDOWS\system32\drivers下自动生成:npf.sys
(二)winpcap-4.1.3在VC++6.0配置环境:
1. 需要在程序中使用了WinPcap中提供给Win32平台的特有的函数,在预处理中加入WPCAP的定义。
操作:工程->设置->c/c++->预处理器定义:加上“,WPCAP”
2. 程序使用了WinPcap的远程捕获功能,那么在预处理定义中加入HAVE_REMOTE。
操作:工程->设置->c/c++->预处理器定义:加上“HA VE_REMOTE”
3. 设置VC++的链接器,把wpcap.lib和ws2_32.lib库文件包含进来。
操作:工程->设置->连接->常规->对象/库模块: 加上“Packet.lib wpcap.lib ws2_32.lib”
5.添加一个新的库所在的路径
操作:工具->选项->目录->目录下拉列表选择“Library files”->路径点击添加开发包wpnpack里的lib文件夹的路径,我这里是“D:\WpdPack_4_0\WpdPack\Lib”
6.添加一个新的包含文件所在的路径
操作:工具->选项->目录->目录下拉列表选择“include”->路径点击添加开发包wpnpack 里的include文件夹的路径,我这里是“D:\WpdPack_4_0\WpdPack\Include”
三、模块具体实现
利用winpcap开发包进行数据采集和预处理
详细代码见< 数据采集.cpp >
1. 定义了以太网协议、ARP协议、IP协议、UDP协议、TCP协议、ICMP协议格式
2. 实现TCP协议、UDP协议、ICMP协议、ARP协议、IP协议、以太网协议分析的函数,其定义方式与回调函数相同
3. 实现主函数
pcap_t *pcap_handle;
/* Winpcap句柄*/
char error_content[PCAP_ERRBUF_SIZE];
/* 存储错误信息*/
char *net_interface;
/* 网络接口*/
struct bpf_program bpf_filter;
/* BPF过滤规则*/
char bpf_filter_string[] = "";
/* 过滤规则字符串*/
bpf_u_int32 net_mask;
/* 掩码*/
bpf_u_int32 net_ip;
/* 网路地址*/
net_interface = pcap_lookupdev(error_content);
/* 获得可用的网络接口*/
pcap_lookupnet(net_interface, &net_ip, &net_mask, error_content);
/* 获得网络地址和掩码地址*/
pcap_handle = pcap_open_live(net_interface, BUFSIZ, 1, 1, error_content);
/* 打开网路接口*/
pcap_compile(pcap_handle, &bpf_filter, bpf_filter_string, 0, net_ip);
/* 编译BPF过滤规则*/
pcap_setfilter(pcap_handle, &bpf_filter);
/* 设置过滤规则*/
if (pcap_datalink(pcap_handle) != DLT_EN10MB)
return ;
pcap_loop(pcap_handle, - 1, ethernet_protocol_packet_callback, NULL);
/* 注册回调函数,循环捕获网络数据包,利用回调函数来处理每个数据包*/
pcap_close(pcap_handle);
/* 关闭Winpcap操作*/
将匹配算法整合成可用静态库
详细代码见
主要是两个算法,BF匹配算法和KMP匹配算法,还有Rabin-Karp匹配算法和AC-BM多字符匹配算法
//BF算法
int BF_Find(string& s,string& t,int& index);
//KMP算法
void GetNext(string& s,int *next);
int KMP_Find(string& s,string& t,int &index);
//Rabin-Karp算法
int getV(char p, string set); // get the value of the character in the set
int RK(string& P, string& T,string& set); // d is the size of the character set
//AC-BM算法
int ACtree_build (pattern_tree *ptree,pattern_data *patterns,int npattern) ;
void _print_tree (pattern_tree_node *root) ;
void ACtree_print_tree (pattern_tree *ptree);
int match_resualt_printf_ex (unsigned char *text, pattern_data *patterns,int npattern,
matched_info_t matched_items[],int nmatched);
void _clean_tree(pattern_tree_node *root) ;
int ACtree_compute_BCshifts (pattern_tree *ptree) ;
pattern_tree *acbm_init (pattern_data *patterns, int npattern) ;
void acbm_clean (pattern_tree *ptree) ;
int acbm_search (pattern_tree *ptree, unsigned char *text,int text_len,
matched_info_t matched_items[], int nmax_index);
int ACtree_compute_shifts(pattern_tree *ptree) ;
int ACtree_compute_GSshifts(pattern_tree *ptree) ;
int ACtree_init_GSshifts(pattern_tree *ptree) ;
int _init_GSshifts(pattern_tree_node *root, int shift) ;
int set_GSshift (pattern_tree *ptree, unsigned char *pat, int depth,int shift) ;
int compute_GSshift(pattern_tree *ptree, unsigned char *pat1, int pat1_len,
unsigned char *pat2,int pat2_len) ;