2022年网络嗅探器推荐 .pdf

上传人:H****o 文档编号:33398669 上传时间:2022-08-10 格式:PDF 页数:23 大小:1.09MB
返回 下载 相关 举报
2022年网络嗅探器推荐 .pdf_第1页
第1页 / 共23页
2022年网络嗅探器推荐 .pdf_第2页
第2页 / 共23页
点击查看更多>>
资源描述

《2022年网络嗅探器推荐 .pdf》由会员分享,可在线阅读,更多相关《2022年网络嗅探器推荐 .pdf(23页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、四 川 大 学 计 算 机 学 院、软件 学 院实验报告课程名称信息安全产品开发实践实验课时5 实验项目网络嗅探器实验时间2011 年 11 月 11 号实验目的1)继续了解 Linux 下 C语言程序开发的过程2)了解嗅探器3)了解 Libpcap 简介、安装与程序编译4)掌握 Libpcap 进行网络嗅探的工作流程5)了解 Libpcap 的主要函数6)完成一个简单的网络嗅探器的编写实验环境VMware5.0,RedHat Linux 9.0 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - -

2、- - 第 1 页,共 23 页 - - - - - - - - - 实验内容(算法、程序、步骤和方法)试验题目使用 Libpcap 库捕获局域网中的IP 包,要求:1. 打印数据包的源与目的物理地址;2. 打印源与目的地址;3. 打印出上层协议类型;4. 如果上层协议为 TCP或 UDP 协议,打印目的与源端口信息;5. 如果上层协议为 TCP或 UDP 协议, 将数据以 16进制与 ASCII 的两种方式同时打印出来,不可打印字符以. 代替; 00000 47 45 54 20 2f 20 48 54 54 50 2f 31 2e 31 0d 0a GET / HTTP/1.1.实验:一:

3、嗅探器概述定义与作用定义: 网络嗅探也叫网络侦听,指的是使用特定的网络协议来分解捕获到的数据包,并根据对应的网络协议识别对应数据片断。作用:1. 管理员可以用来监听网络的流量情况2. 开发网络应用的程序员可以监视程序的网络情况3. 黑客可以用来刺探网络情报数据包的处理流程名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 23 页 - - - - - - - - - 实现机制二:使用 Libpcap 编写程序流程名师资料总结 - - -精品资料欢迎下载 - - - - - -

4、 - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 23 页 - - - - - - - - - 三:打印数据流程图名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 23 页 - - - - - - - - - 四:具体实现1. 打开虚拟机,利用gedit编辑器编写服务器端mysniffer.c程序名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心

5、整理 - - - - - - - 第 5 页,共 23 页 - - - - - - - - - 2. 保存 mysniffer.c,使用命令 gcc o mysniffer mysniffer.c l pcap命令编译程序。3. 执行 ./mysniffer命令,程序运行,输出结果名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 23 页 - - - - - - - - - 从输出的结果来看,程序打印出了设备的名字,网络的网关地址,子网掩码等信息,在捕获一个数据报后,计算出

6、了它的长度并且打印出了捕获它的时间,然后打印出了它的源物理地,目的物理地址,源IP 地址,目的 IP 地址;经过程序分析之后,这个数据报的上层协议是UDP 协议,然后打印出它的源端口号和目的端口号,并且将它的数据按照16 进制以及 ASCII 码两种形式打印出来。其他捕获的数据报的输出格式类似。附试验源代码(附部分注释):#include #include #include #include #include #include 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,

7、共 23 页 - - - - - - - - - #include #include #include #include #include #include /处理劫获的数据包的函数void my_callback(u_char *useless, const struct pcap_pkthdr* pkthdr,const u_char* packet); /主函数int main(int argc, char *argv) char *dev; / 设备名char errbufPCAP_ERRBUF_SIZE;/错误缓冲区bpf_u_int32 mask; / BPF (伯克利包过滤器)格

8、式的网络掩码bpf_u_int32 net; /BPF 格式的网络地址struct in_addr addr; / 用来表示一个32 位的 IPv4 地址char *net_c; / 字符串形式网络地址,用于打印输出char *mask_c; / 字符串形式的网络掩码地址名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 23 页 - - - - - - - - - struct pcap_pkthdr header; /libpcap 包头结构,包含捕获时间,捕获长度与数据

9、包实际长度const u_char *packet;/捕获到的实际数据包内容pcap_t *handle;/libpcap 设备描述符号struct tm *now_tm; / 时间结构体time_t now; struct bpf_program fp;/ 过滤器char filter_exp = ip;/设置过滤规则为ip /*获取活动的网络设备名,通常为eth0*/ dev = pcap_lookupdev(errbuf); if (dev = NULL) fprintf(stderr, Couldnt find default device: %sn, errbuf); return(

10、2); printf(Device: %sn, dev); /*获取设备的网络地址与网络掩码地址,并将其打印出来*/ if (pcap_lookupnet(dev, &net, &mask, errbuf) = -1) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 23 页 - - - - - - - - - fprintf(stderr, Cant get netmask for device %sn, dev); net_c = 0; mask_c = 0; ret

11、urn(2); addr.s_addr = net; net_c = inet_ntoa(addr); printf(Net: %sn, net_c); addr.s_addr = mask; mask_c = inet_ntoa(addr); printf(Mask: %sn,mask_c); printf(=n); /*获取 Libpcap bpf 过滤设备 */ /*设备最大捕获包的字节数为1518(针对以太网)*/ /*将 NIC 设为混在模式,可以侦听局域网的所有内容*/ handle = pcap_open_live(dev, BUFSIZ, 1, 0, errbuf); 名师资料

12、总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 23 页 - - - - - - - - - if (handle = NULL) fprintf(stderr, Couldnt open device %s: %sn, dev, errbuf); return(2); /*将过滤规则添加到过滤器上*/ if (pcap_compile(handle, &fp, filter_exp, 0, net) = -1) fprintf(stderr, Couldnt parse fi

13、lter %s: %sn, filter_exp, pcap_geterr(handle); return(2); /*在 BPF 过滤器上启动数据过滤*/ if (pcap_setfilter(handle, &fp) = -1) fprintf(stderr, Couldnt install filter %s: %sn, filter_exp, pcap_geterr(handle); return(2); /*捕获一个数据包*/ 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第

14、 11 页,共 23 页 - - - - - - - - - packet = pcap_next(handle, &header); printf(Jacked one packet at %sn, filter_exp); /* * Each packet in the dump file is prepended with this generic header. * This gets around the problem of different headers for different * packet interfaces. * struct pcap_pkthdr * str

15、uct timeval ts; * time stamp * * bpf_u_int32 caplen; * length of portion present * * bpf_u_int32 len; * length this packet (off wire) * * ; */ /*打印数据包的长度*/ printf(Length of this packet is %d bytesn, header.len); now = header.ts.tv_sec; now_tm = localtime(&now); printf(Time Stamp of this packet is %d

16、/%2d/%2d %2d:%2d:%2dn, now_tm-tm_year+1900, now_tm-tm_mon+1, now_tm-tm_mday, now_tm-tm_hour, now_tm-tm_min, now_tm-tm_sec); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 12 页,共 23 页 - - - - - - - - - /*打印数据包的捕获时间*/ printf(Recieved at . %sn,ctime(const time_t*)&heade

17、r.ts.tv_sec); /调用 my_callback 函数if (pcap_loop(handle ,-1 , my_callback,NULL) = -1) fprintf(stderr, errorn); return(2); /*关闭 bpf 过滤器 */ pcap_close(handle); return(0); void my_callback(u_char *useless, const struct pcap_pkthdr* pkthdr,const u_char* packet) int count = 0; /计数int otherPart_len; /数据报的其他信

18、息的长度int IPlength; /IP 数据报的长度名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 13 页,共 23 页 - - - - - - - - - int n; /临时变量struct ether_header *frame; /以太网地址结构struct iphdr *IPpacket; /ip 头部struct tcphdr *TCPpacket; /tcp 头部struct udphdr *UDPpacket; /udp 头部struct in_addr src

19、IP, destIP; /用来表示一个32位的 IPv4 地址/转换成帧数据报frame = (struct ether_header *)packet; /转换为 IP 数据报IPpacket = (struct iphdr *)(packet + sizeof(struct ether_header); /转换为 TCP 数据报TCPpacket = (struct tcphdr *)(packet + sizeof(struct ether_header) + sizeof(struct iphdr); /转换为 UDP 数据报UDPpacket = (struct udphdr *)(

20、packet + sizeof(struct ether_header) + sizeof(struct iphdr); /打印源物理地址和目的物理地址,每个物理地址占6 个字节名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 14 页,共 23 页 - - - - - - - - - printf(the DestMac is : %02X:%02X:%02X:%02X:%02X:%02X the SrcMac is : %02X:%02X:%02X:%02X:%02X:%02Xn,

21、 frame-ether_dhost0,frame-ether_dhost1,frame-ether_dhost2,frame-ether_dhost3, frame-ether_dhost4,frame-ether_dhost5,frame-ether_shost0,frame-ether_shost1, frame-ether_shost2,frame-ether_shost3,frame-ether_shost4,frame-ether_shost5); /打印源 IP 地址和目的IP 地址memcpy(&srcIP, &IPpacket-saddr, sizeof(IPpacket-s

22、addr); memcpy(&destIP, &IPpacket-daddr, sizeof(IPpacket-daddr); IPlength = ntohs(IPpacket-tot_len); printf(the srcIP is : %s the destIP is : %sn,inet_ntoa(srcIP),inet_ntoa(destIP); /打印协议类型 (TCP) if(IPpacket-protocol = IPPROTO_TCP) printf(the protocol of the packet is TCP:n); printf(srcport: %d destp

23、ort: %dn, ntohs(TCPpacket-source), ntohs(TCPpacket-dest); otherPart_len = IPlength - sizeof(struct iphdr) - sizeof(struct tcphdr); const u_char *data = packet + sizeof(struct ether_header) + sizeof(struct iphdr) + sizeof(struct tcphdr); /打印数据信息 (以 16 进制和 ASCII 码两种形式 ) while(otherPart_len 0) 名师资料总结 -

24、 - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 15 页,共 23 页 - - - - - - - - - if(otherPart_len 16) printf(%5d ,count); for(n=0; n otherPart_len; n+) printf(%02X , datacount+n); if(n+1) % 8 = 0) printf( ); printf( ); for(n=0; n otherPart_len; n+) if(isprint(datacount+n) printf

25、(%c, datacount+n); else printf(.,datacount+n); printf(n); otherPart_len = 0; else 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 16 页,共 23 页 - - - - - - - - - printf(%5d ,count); for(n = 0; n 16; n+) printf(%02X ,datacount+n); if(n+1) % 8 = 0) printf( ); printf( ); f

26、or(n = 0; n protocol = IPPROTO_UDP) printf(the protocol of the packet is UDP:n); printf(srcport: %d destport: %dn,ntohs(UDPpacket-source), ntohs(UDPpacket-dest); otherPart_len = IPlength - sizeof(struct iphdr) - sizeof(struct udphdr); const u_char *data = packet + sizeof(struct ether_header) + sizeo

27、f(struct iphdr) + sizeof(struct udphdr); /打印数据信息 (以 16 进制和 ASCII 码两种形式 ) while(otherPart_len 0) if(otherPart_len 16) printf(%5d ,count); for(n = 0; n otherPart_len; n+) printf(%02X ,datacount+n); if(n+1) % 8 = 0) printf( ); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - -

28、- 第 18 页,共 23 页 - - - - - - - - - printf( ); for(n = 0; n otherPart_len; n+) if(isprint(datacount+n) printf(%c,datacount+n); else printf(., datacount+n); printf(n); otherPart_len = 0; else printf(%5d ,count); for(n = 0; n 16; n+) printf(%02X ,datacount+n); if(n+1) % 8 = 0) printf( ); printf( ); for(

29、n = 0; n 16; n+) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 19 页,共 23 页 - - - - - - - - - if(isprint(datacount+n) printf(%c,datacount+n); else printf(.,datacount+n); printf(n); otherPart_len = otherPart_len - 16; count = count + 16; else printf(the protocol of th

30、e packet is others :n); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 20 页,共 23 页 - - - - - - - - - (接上)实验内容(算法、程序、步骤和方法)数据记录和计算详细见上面结论(结果)利用 Libpcap 函数库能很好的实现一个网络嗅探器,从而能对网络中的数据报进行捕获,然后进行分析,方便我们掌握网络中的流量等一些信息,更好的控制网络行为。小结通过本实验,我掌握了:1)进一步熟悉了Linux 下 C语言程序开发的过程;2)继续了解 L

31、inux 下 C语言程序开发的过程3)了解了什么是嗅探器4)掌握了 Libpcap 安装与程序编译5)了解了 Libpcap 进行网络嗅探的工作流程6)了解 Libpcap 的一些主要函数名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 21 页,共 23 页 - - - - - - - - - 目前我存在的问题有:对一些 Libpcap 函数掌握的不是很熟练。指导老师评议成绩评定:指导教师签名:实验报告说明专业实验中心实验名称要用最简练的语言反映实验的内容。如验证某程序、定律、算法,

32、可写成“验证”;分析。实验目的目的要明确,要抓住重点,可以从理论和实践两个方面考虑。在理论上,验证定理、公式、算法,并使实验者获得深刻和系统的理解,在实践上,掌握使用实验设备的技能技巧和程序的调试方法。一般需说明是验证型实验还是设计型实验,是创新型实验还是综合型实验。实验环境实验用的软硬件环境(配置)。实验内容(算法、程序、步骤和方法)这是实验报告极其重要的内容。这部分要写明依据何种原理、定律算法、或操作方法进行实验,要写明经过哪几个步骤。还应该画出流程名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - -

33、 - - - 第 22 页,共 23 页 - - - - - - - - - 图(实验装置的结构示意图),再配以相应的文字说明,这样既可以节省许多文字说明,又能使实验报告简明扼要,清楚明白。数据记录和计算指从实验中测出的数据以及计算结果。结论(结果)即根据实验过程中所见到的现象和测得的数据,作出结论。小结对本次实验的体会、思考和建议。备注或说明可写上实验成功或失败的原因,实验后的心得体会、建议等。注意:实验报告将记入实验成绩;每次实验开始时,交上一次的实验报告,否则将扣除此次实验成绩。名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 23 页,共 23 页 - - - - - - - - -

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 技术资料 > 技术总结

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com