版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
信息对抗技术入侵检测入侵检测系统定义入侵检测系统是通过诸如,数据审计,网络报文分析等手段,检测各种入侵行为,保证网络安全。英文是intrusiondetectionsystem(IDS)。IDS的历史在80年代就开展了早期基础理论研究工作。随着计算机系统软、硬件飞速发展,以及网络技术、分布式计算、系统工程、人工智能等计算机新兴技术与理论的不断完善,入侵检测理论也在发展变化中,至今仍未形成比较成熟的理论体系IDS的分类根据检测原理可分为异常入侵检测,误用入侵检测。根据数据来源和系统结构可分为基于主机的入侵检测和基于网络的入侵检测和分布式入侵检测。Snort是误用入侵检测的代表网站:该软件是开源软件。其基本原理是将网卡设定为混杂模式,然后监听网络上的报文,并将报文和用户自定义的规则进行比较,如果满足规则,则会根据用户要求将该次匹配命中的事件纪录到日志。一个简单的规则如下:alerttcpanyany->any7026(msg:“glacier”).这条规则的意思是:凡是从任何机器的任何端口到任何机器的7026端口的tcp访问,就纪录下来,而纪录的名字为glacier.因为后门冰河的缺省端口实7026所以满足该规则的就可能是冰河纪录下来的日志具有如下格式:[**][1:0:0]glacier[**][Priority:0]02/14-09:32:25.367646202.115.14.111123->202.115.14.1477026TCPTTL:255TOS:0x0ID:46482IpLen:20DgmLen:60很明显,snort的准确率依赖规则的准确性,更为重要的是,其判断依据往往会造成虚假告警或遗漏。Snort也对其加以改进。比如,它增加了一中规则叫动态规则,就是,当一个规则满足后,检测另外一条规则。这里有一定专家系统的影子。Snort在网络抓包方面,使用了一种libpcap库,这是unix上的一个抓包库,再linux和windows上都有相关的版本,windows上叫winpcap。可以在winpcap网站上下载到相关软件。异常入侵检测基于异常的入侵检测系统(Anomaly-basedIDS),其思路如下:正常系统有一“正常基准”,如CPU利用率、磁盘活动、用户注册、文件活动等等。一旦偏离这一“正常基准”,检测系统将触发。基于异常检测的主要优点是能识别新型攻击。但正常操作产生变化时会导致误报,而入侵行为表现为正常又将导致漏报,且系统很难确定攻击类型。基于系统调用序列的免疫系统该系统认为,对任何系统而言,存在一个基因库,该库中的基因是如下定义的:即一组系统调用序列,比如长度为4~5个系统调用。例如:socket—bind—listen—accept.就是一个基因。通过在正常无攻击环境下运行一个网络服务程序,可以得到其基因库。然后在检测时,比较这些库,如果基因出现偏差,就意味着异常或攻击发生。参见相关文章StephanieForrest,StevenHofmeyer,AsenseofselfforUNXIprocesses.InProceedingsofthe1996IEEESymposiumonSecurityandPrivacy.1996.StevenA.Hofmeyr,StephanieForrest,IntrusionDetectionusingSequencesofSystemCalls,JournalofComputerSecurity1998.按IDS结构分类基于主机的入侵检测系统
基于主机的入侵检测系统历史最久,多用户计算机系统出现不久已有雏形。最早用于审计用户的活动,比如用户的登陆、命令操作、应用程序使用资源情况等方面。此类系统一般使用操作系统的审计日志作为输入,某些也会主动与主机系统交互获得其它信息。收集的信息集中在系统调用和应用层审计上,试图从日志记录中判断出滥用和入侵事件的线索。典型的有NIDES和NetStat
混合分布式入侵检测系统
合分布式入侵检测系统能从不同的主机、网络组件、或通过网络监听方式收集数据,系统可利用网络数据也可收集分析来自主机系统的高层事件发现可疑行为。掌握libpcap掌握libpcap可以为我们自主开发基于网络的入侵检测提供方便。主要内容:一、Winpcap使用介绍二、面象对象对Winpcap的封装。3.方便的把捕获的数据包输出到文件和从文件输入见源码:DumpToFile
4.发送原始的数据包见源码SendPacket
5.统计网络流量
见源码:DisplayStatus二、Winpcap的安装使用方法1.到下载winpcap的安装包,程序员开发包。
2.执行安装包,运行winpcap程序
3.解压开发包,在VC的option的include和lib中加入winpcap的include和lib
有几种捕获数据的方法(捕获数据的数据都是最原始的数据包,即包含数据链路层的数据头)
a.是以回调的方式[pcap_loop,pcap_dispatch()].
这两种方法基本相同,底层收集数据包,当满足一定的条件(timeout或者缓冲区满),就会调用回调函数,把收集到的原始数据包s,交给用户。他们返回的数据缓冲区包含多个包
例子见:CapturePacketb.pcap_next_ex()的方式
每当一个包到到达以后,pcap_next_ex就会返回,返回的数据缓冲区里只包含一个包。(二)发送数据包Winpcap中有发送单个包和发送多个包的方法。这里只说说发送单个包
1.通过名字打开一个设备[pcap_open]
2.自己构造一个原始数据包(这个数据包会不经过任何处理就发送出去,所以必须把包中的各个字段设置好。另外这个数据包是包含数据链路层报头的)
3.使用pcap_sendpacket()发送数据包
见源码SendPacket工程
(三)统计网络流量
通过名字打开一个设备[pcap_open]
通过read_timeout来设置统计的时间间隔
设置filter[pcap_compile,pcap_setfilter](可选)
设置设备的为统计模式[pcap_setmode(MODE_STAT);]
4.开始统计,pcap_loop/pcap_dispatch()
5.在回调函数中的参数中就包含了统计信息//下面是一个应用winpcap写的一个网络流量统计的例子,也可参见源码DisplayStatus工程
//nettraffic.cpp:Definestheentrypointfortheconsole//application.
#include"stdafx.h"
#include<pcap.h>
#include<remote-ext.h>
#include<iostream>
#include<winsock2.h>
usingnamespacestd;
//------------------------------------------------------------------------
//------------------------------------------------------------------------
voiddispatcher_handler(u_char*user_data,conststructpcap_pkthdr*pkthdr,constu_char*pktdata);
//------------------------------------------------------------------------
intmain(intargc,char*argv[])
{
inti;
pcap_if_t*alldevs;
pcap_if_t*dev;
charerrorbuf[PCAP_ERRBUF_SIZE];
intchoice;
pcap_t*stathandle;
WSADATAwsadata;
structtimevaltimestamp;
if(WSAStartup(MAKEWORD(2,2),&wsadata)!=0)
{
cerr<<"WSAStartupfailed["<<WSAGetLastError()<<"]“<<endl;
return(-1);
}
//enumalldevice
if(pcap_findalldevs_ex(PCAP_SRC_IF_STRING,NULL,&alldevs,errorbuf)==-1)
{
WSACleanup();
cerr<<"pcap_findalldevs_exfailed!("<<errorbuf<<")"<<endl;
return(-1);
}
for(i=0,dev=alldevs;dev!=NULL;dev=dev->next)
{
cout<<++i<<'t'<<dev->name<<endl;
}
if(i==0)
{
WSACleanup();
cerr<<"nodevicefound!"<<endl;
return(-2);
}
//letuserchoice
while(1)
{
cout<<"pleasechoiceadevice:";
cin>>choice;
if(choice>=1&&choice<=i)
break;
cerr<<"inputerror,youshallchoiceadevicefromuponlist“<<endl;
}
//movetothechoosendevice
for(i=0,dev=alldevs;i<=choice-1;i++,dev=dev->next);
if((stathandle=pcap_open(dev->name,
100,
PCAP_OPENFLAG_PROMISCUOUS,
500,
NULL,errorbuf))==NULL)
{
cerr<<"opendevicefailed![device:"<<dev->name<<"]"
<<errorbuf<<endl;
pcap_freealldevs(alldevs);
WSACleanup();
return(-3);
}
cout<<"isStat"<<dev->name<<"..."<<endl;
pcap_freealldevs(alldevs);
pcap_setmode(stathandle,MODE_STAT);
timestamp.tv_sec=0;
timestamp.tv_usec=0;
pcap_loop(stathandle,0,dispatcher_handler,(unsignedchar*)×tamp);
pcap_close(stathandle);
return0;
}
//------------------------------------------------------------------------
voiddispatcher_handler(u_char*user_data,conststructpcap_pkthdr*pkthdr,constu_char*pktdata)
{
staticstructtimevaltstamp=*((structtimeval*)user_data);
LARGE_INTEGERBps,Pps;
unsignedlongdelay;
charstrtime[32];
delay=(pkthdr->ts.tv_sec-tstamp.tv_sec)*1000000–tstamp.tv_usec+pkthdr->ts.tv_usec;
Pps.QuadPart=((*(LONGLONG*)(pktdata))*1000000)/delay;
Bps.QuadPart=((*(LONGLONG*)(pktdata+8))*1000000)/delay;
structtm*ltime=localtime(&(pkthdr->ts.tv_sec));
strftime(strtime,sizeof(strtime),"%H:%M:%S",ltime);
printf("%s:",strtime);
printf("tPps=%I64utBps=%I64urn",Pps.QuadPart,Bps.QuadPart);
tstamp=pkthdr->ts;
}
二、面象对象对Winpcap的封装1、封装的原因:Winpcap提供的是C函数,是面向过程的对包进行协议解析。2、封装的目标:使对Winpcap的操作类似于对文件的操作。register,open,close,3、封装的申明classCCapture{private: pcap_t*adhandle; charbuff[1536]; CCapCallback*PCallbackObject; pcap_t*Open(int); intGetPackets(pcap_t*adhandle,char*pbuf,intlen,intpacketcount,int&RealLen); intClose(pcap_t*adhandle);public: CCapture(); ~CCapture(); intCapRegister(CCapCallback*PCbObject); intCapOpen(intNIC); intCapClose();};classCCapCallback{private:
public: CCapCallback(); ~CCapCallback(); virtualHandlePacket(char*buff,intlen) { };};////////////////////////////////////////////////这个文件包括两个类的实现CCaptureCCapCallback/////////////////////////////////////////////////////*说明:CCapCallback是一个纯虚类,不能直接使用,必须继/*承后才能使用,CCapCallback作为类CCapture的接口类,*/#include"stdafx.h"#include"WCapDll.h"pcap_t*adhandle;structtm*ltime;chartimestr[16];structpcap_pkthdr*header;constu_char*pkt_data;intres;export_packetrecvpacket;intdecode_iph(pexport_packetpacket);intdecode_eth(char*buff,constunsignedchar*packetbuf,intlen);/////////////////////////////////////////////////////以下是CCapture类的实现/////////////////////////////////////////////////////////////CCapture::CCapture(){}CCapture::~CCapture(){}intCCapture::CapRegister(CCapCallback*PCbObject){ if(PCbObject) { PCallbackObject=PCbObject; return0; } else return-1;}intCCapture::CapOpen(intNIC){ intresult; intRealBytes; adhandle=Open(NIC); if(adhandle==NULL){ return-1; } while(1){ result=GetPackets(adhandle,buff,1536,1,RealBytes); PCallbackObject->HandlePacket(buff,RealBytes); if(result!=1){ break; } } return-1;}intCCapture::CapClose(){ intres=0; res=Close(adhandle); returnres;}pcap_t*CCapture::Open(intnic){//staticpcap_t*adhandle;pcap_if_t*alldevs;pcap_if_t*d;inti=0; intNicTotal=0;charerrbuf[PCAP_ERRBUF_SIZE];
/*Retrievethedevicelistfromthelocalmachine*/if(pcap_findalldevs(&alldevs,errbuf)==-1){fprintf(stderr,"Errorinpcap_findalldevs_ex:%s\n",errbuf);returnNULL;}/*Printthelist*/for(d=alldevs;d!=NULL;d=d->next){ NicTotal++;} //checktheparamer if((nic<0)||(nic>NicTotal-1)||(NicTotal==0)) returnNULL; for(d=alldevs,i=0;i<=nic;d=d->next,i++);
/*Openthedevice*/if((adhandle=pcap_open_live(d->name,//nameof//thedevice 8000,//portionofthepackettocapture //65536guaranteesthatthewholepacketwillbe//capturedonallthelinklayers 1,//promiscuousmode 1000,//readtimeout errbuf//errorbuffer ))==NULL){fprintf(stderr,"\nUnabletoopentheadapter.%sisnotsupportedbyWinPcap\n",d->name);/*Freethedevicelist*/pcap_freealldevs(alldevs);returnNULL;}/*Wedon'tneedanymorethedevicelist.Freeit*/pcap_freealldevs(alldevs);
//MessageBox(NULL,"thisisatest","example",MB_OK);#ifdefDEBUG printf("%s\n","opensucceed");#endif returnadhandle;}intCCapture::GetPackets(pcap_t*adhandle,char*pbuf,intlen,intpacketcount,int&RealLen){intcount=0;RealLen=0;u_intretainlen=len; ZeroMemory((void*)pbuf,len);while((res=pcap_next_ex(adhandle,&header,&pkt_data))>=0){
if(res==0) continue; //36referencetothesizeoftheethernet_frame if(retainlen>=(header->len+36)) { //resolvethepacket decode_eth(pbuf,pkt_data,header->len);//decidewhethertoreceivethenextpacket pbuf+=(sizeof(export_packet)+header->len); count++;RealLen+=header->len+36; retainlen-=(sizeof(export_packet)+header->len); if(retainlen<=36) {#ifdefDEBUG printf("%s\n","memorysizelessthan36andexit");#endif returncount; } if(retainlen<(header->len+36)) {#ifdefDEBUG printf("%s\n","retainlen<header->len+36andexit");#endif returncount; } if(count>=packetcount) {#ifdefDEBUG printf("%s\n","thecountrequiredhaveenough");#endif returncount; } }elseif(retainlen<(header->len+36))//atfirst//thebuffisnotenoughtoloadapacket {#ifdefDEBUG printf("%s\n","retainlenlessthan(header->len+36)bytesandexit");#endif returncount; }if(res==-1){#ifdefDEBUGprintf("Errorreadingthepackets:%s\n",pcap_geterr(adhandle));#endif return-1; } }returncount;}intdecode_eth(char*buff,constunsignedchar*packetbuf,intlen){ export_packet*temp; memcpy((buff+36),packetbuf,len); temp=(export_packet*)buff; temp->buffer=buff+36; temp->totallen=len+36; temp->pethheader=(ethernet_frame*)(buff+36); ethernet_frame*tef=(ethernet_frame*)packetbuf; if(tef->h_type==0x08&&tef->l_type==0x00) {#ifdefDEBUG printf("thisisaIPpacket\n");#endif temp->pipheader=(ip_header*)(temp->buffer+14);#ifdefDEBUG printf("\n%d.%d.%d.%d---->%d.%d.%d.%d\n",temp->pipheader->saddr.byte1, temp->pipheader->saddr.byte2,temp->pipheader->saddr.byte3, temp->pipheader->saddr.byte4, temp->pipheader->daddr.byte1,temp->pipheader->daddr.byte2, temp->pipheader->daddr.byte3, temp->pipheader->daddr.byte4);#endifdecode_iph(temp);
} if(tef->h_type==0x08&&tef->l_type==0x06) {#ifdefDEBUG printf("%s\n","thisisaarppacket"); //printf("TargetHardaddress%X=%d\tSourceaddress=%X\n",(ethernet_frame*)packetbuf->h_dest,(ethernet_frame*)packetbuf->h_source);#endif temp->parpheader=(arp_header*)(temp->buffer+14); }if(tef->h_type==0x80&&tef->l_type==0x35) {#ifdefDEBUG printf("%s\n","thisisararppacket");#endif temp->parpheader=(arp_header*)(temp->buffer+14); } return1;}intdecode_iph(pexport_packetpacket){ pip_headertempip; tempip=packet->pipheader; intip_len=(tempip->ver_ihl&0xf)*4;//uh=(udp_header*)((u_char*)ih+ip_len); switch(tempip->proto){ caseIPPROTO_TCP://tcpprotocal
//printf("tcpSport:%d\tDport:%d\n",packet->ptcphead
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 文学写作实战:随笔写作指南(轻松上手自由表达)
- 2026年高职(工程造价)工程造价综合实训综合测试题及答案
- 高考作文突破明确类型抓住核心精准新材料作文审题立意
- 2026年职高教师招聘考试试题及答案
- 2026年建筑设计原理考试及答案
- 欧美私募基金监管改革:历程、措施与中国镜鉴
- 主题17 规则与标志Rules and Signs- 2026年初中英语中考主题作文满分训练
- 次贷危机对中国经济的多维度冲击与应对策略之思
- 欠发达地区中学思想政治教育困境与出路探寻
- 2026年火灾急救知识考试卷及答案(共十八套)
- 防雷安全方面考核制度
- 技术团队培养
- 2026年长江商学院金融-EMBA-面试题及答案
- 四川四川省地球物理调查研究所2025年考核招聘8人笔试历年参考题库附带答案详解
- 2026年教师资格证(历史学科知识与教学能力-高级中学)考试题及答案
- 2026年浙江单招酒店管理专业面试经典题含答案含应急处理题
- SJG 171-2024建筑工程消耗量标准
- 浙江省金丽衢十二校2026届高三上学期一模试题 英语 含解析
- 创新创业创效比赛项目介绍
- 新疆维吾尔自治区小学五年级下学期数学第二单元测试卷-因数和倍数单元检测
- 专升本康复治疗2025年物理治疗学测试试卷(含答案)
评论
0/150
提交评论