深度剖析WinPcap之(二)
深度剖析WinPcap之(二)——网络分析与嗅探的基础知识(4)

1.3.3 CSMA/CD以太网使用载波监听多点接入/冲突检测(CSMA/CD)协议,为了设备在网络上家交换数据。
多点接入这个术语指许多网络设备连接到同一个网段有发送的机会。
每个设备赋予等同的发送机会;没有任何设备优先于其它设备。
载波监听描述了一个网络设备的以太网接口在传送之前如何监听网线。
网络接口确保没有其它信号在网线上,在它传送之前,并且在传送的时候监听确保在同一时刻没有其它网络设备传送数据。
当两个网络设备在同一时刻传送时,一个冲突发生。
因为以太网接口在它们正在传送时监听媒体,通过冲突检测它们能够标识其它传送的出现。
如果一个冲突发生了,正在传送的设备在重新传送之前等待一个小的,随机的时间量。
该功能就是随机补偿(random backoff)。
传统地,以太网操作是半双工的,其意味着一个接口只能传送或接收数据,但是并不是同时。
如果一个网段中多于一个的网络接口试图在同一时刻传送,一个冲突发生每个载波监听多点接入/冲突检测。
当一个交叉的网线用来连接两个设备,或者一个单个设备连接一个交换机端口,在该网段中仅仅两个接口需要传送或接收,没有冲突发生。
这是因为设备A的传送连接到设备B的接收,设备B的接收连接到设备A的传送。
冲突检测的方法不再是必需的,因此,接口能够工作于全双工模式,其允许网络设备在同一时刻传送与接收,从而提高性能。
1.3.4 主要的协议:IP、TCP、UDP与ICMP协议下列IP、TCP、UDP与ICMP四个协议是现今互联网工作的核心。
IP(网际互连协议)IP是一个非连接协议,管理寻址数据从一个点到另一个点,把大数据包分割成小的、能传输的数据包。
IP数据报的主要组成如下:<!--[if !supportLists]--> ∙∙∙∙∙∙∙∙ <!--[endif]-->IP标识(IPID) 试图唯一标识IP数据报<!--[if !supportLists]--> ∙∙∙∙∙∙∙∙ <!--[endif]-->协议描述使用IP层服务的高层协议<!--[if !supportLists]--> ∙∙∙∙∙∙∙∙ <!--[endif]-->生存时间(TTL) 数据报在通过互联网是必须具有的受限的寿命。
WinPcap编程

Packet.dll应用步骤
2) 打开指定的网卡 lpAdapter = PacketOpenAdapter(AdapterList [0 ]) ; if ( ! lpAdapter | | (lpAdapter - > hFile = = INVALID_HANDLE_VALUE) ) { dwErrorCode = GetLastError() ; sprintf ( szErr ,″Unable to open the adapter ,error code : %lx″, dwErrorCode) ; AfxMessageBox(szErr) ; return FALSE; }
1> LPPACKET PacketAllocatePacket(void) 如果运行成功,返回一个_PACKET结构的指针, 否则返回NULL。成功返回的结果将会传送到 PacketReceivePacket()函数,接收来自驱动的网络 数据报。 2> VOID PacketFreePacket(LPPACKET lpPacket) 释放参数提供的_PACKET结构。 3> VOID PacketCloseAdapter(LPADAPTER lpAdapter) 关闭参数中提供的网络适配器,释放相关的 ADAPTER结构。
WinPcap
WinPcap包括三个部分 第一个模块:内核级的包过滤驱动程序
NPF(Netgroup Packet Filter),是一个虚拟设备驱动程序文件, 是架构的核心(在Win95/98 中是一个VXD文件,在NT/2000 中是 一个SYS 文件) ,它的主要功能是过滤数据包,在包上附加时间戳、 数据包长度等信息。
第二个模块:低级动态链接库packet.dll,在Win32 平台 上提供了与NPF 的一个通用接口。 packet.dll数据包驱 动程序库是与libpcap 相兼容的一组用户级的函数库。 第三个模块:用户级的Wpcap.dll。通过调用packet.dll 提供的函数生成,它包括了过滤器生成等一系列可以被 用户级调用的高级函数,另外还有诸如数据包统计及发 送功能。
Windows下截获网络数据——winpcap源代码分析

Windows下截获网络数据——winpcap源代码分析王守彦1简介在本刊的前期中,介绍用于截获网络数据的通用库libpcap的高层实现,及在linux/unix 下底层实现。
Winpcap是libpcap的windows版本,它们虽然提供了同样的高层接口,但底层实现却截然不同。
对于linux/unix,网络数据的截获作为系统的一项基本功能,大多直接实现于内核中,用户只要调用简单的接口函数,就能截获通过网络适配器的数据,windows 系统本身不提供截获网络数据的接口,但提供一套和网络适配器交互的网络驱动器接口规范(NDIS),可以通过NDIS实现网络数据的截获。
本文作为前文的补充,详细分析winpcap 的结构和如何通过NDIS实现网络数据的截获和过滤。
本文分为三个部分:winpcap结构、NDIS概述和winpcap包截获驱动器源代码分析。
2Winpcap结构图1 winpcap结构图1描述了winpcap的结构,其中windump.exe是一个使用winpcap的外部程序,winpcap 包括libpcap通用接口、packet.dll动态链接库和NDIS包截获驱动器三个部分。
NDIS包截获驱动器用于从网络适配器(Network Adapter)截获数据,并提供一套标准的接口函数,如read,write,ioctl等;packet.dll提供对NDIS包截获驱动器接口函数的封装,对上层(libpcap)提供更为方便的接口;libpcap调用packet.dll中的函数,提供和linux/unix平台上libpcap相同的接口,实现代码的通用性。
实际上在windows编程中使用packet.dll提供的接口函数和使用libpcap函数一样方便,它们都是对其它函数的封装,本文不做分析,而是着重分析NDIS包截获驱动器的实现。
3NDIS概述包截获驱动器通过NDIS(网络驱动器接口规范)与网络适配器交互,NDIS是win32网络代码的一部分。
WinPcap 原理技术

WinPcap 原理技术winpcap是windows平台下一个免费,公共的网络访问系统。
开发winpcap这个项目的目的在于为win32应用程序提供访问网络底层的能力。
1、网络及协议分析2、网络监控3、通信日志记录4、traffic generators5、用户级别的桥路和路由6、网络入侵检测系统(NIDS)7、网络扫描8、安全工具WinPcap导入WinPcap是一个开源的专业网络数据捕获开发包,其实,WinPcap的强大功能并不仅限于数据包的获取,主要功能:捕获原始数据包,包括在共享网络上各主机发送/接收的以及相互之间交换的数据包;在数据包发往应用程序之前,按照自定义的规则将某些特殊的数据包过滤掉;在网络上发送原始的数据包;收集网络通信过程中的统计信息。
Sniffer 嗅探原理Winpcap是针对Win32平台上的抓包和网络分析的一个架构。
它包括一个核心态的包过滤器,一个底层的动态链接库(packet.dll)和一个高层的不依赖于系统的库(wpcap.dll)Packet.dll提供更方便更易用的编程接口,wpcap.dll中的接口函数Sniffer嗅探器,是一种基于被动侦听原理的网络分析方式。
使用这种技术方式,可以监视网络的状态、数据流动情况以及网络上传输的信息。
当信息以明文的形式在网络上传输时,便可以使用网络监听的方式来进行攻击。
将网络接口设置在监听模式,便可以将网上传输的源源不断的信息截获。
Sniffer技术常常用于网络故障诊断、协议分析、应用性能分析和网络安全保障等各个领域。
实现Sniffer 功能函数序列第一步:获取网络设备指针pcap_findalldevs_ex()第二步:打开网卡pcap_open()第三步:检查链路层pcap_datalink()第四步:编译BPF过滤规则pcap_compile第五步:设置过滤规则pcap_setfilter第六步:注册回调函数,循环捕获数据包pcap_loop()第七步:释放网络设备列表pcap_freealldevs()第八步:关闭WinPcap会话句柄pcap_close()获取网络设备指针(查找机器的所有网络设备接口,并使用链表结构返回)打开网络设备(打开一个用来捕获或发送流量的通用源(网卡))检查链路3层类型(检查链路层类型)编译BFP过滤规则(编译数据包过滤器,将程序中高级的过滤表达式(即过滤规则字符串)转换为能被内核级的过滤引擎所处理的内容)执行过滤规则(把一个过滤器绑定到WinPcap会话句柄)注册回调函数,循环捕获数据包(循环捕获数据包并分析)释放网络设备列表(释放链表空间)关闭WinPcap会话句柄(关闭一个和p关联的文件,并释放资源)数据包分析1.数据包的分析内容数据包(Packet)是TCP/IP协议通信传输中的数据单位,TCP/IP协议是工作在OSI模型第三层(网络层)、第四层(传输层)上的,而帧是工作在第二层(数据链路层)。
基于WinPcap的获取局域网用户名和密码的研究+AES算法原理分析及实现

网络安全导论课程考核论文题目一:基于WinPcap的用户名和密码监听器实现题目二:AES算法的加密和解密实现院(系):物联网工程学院专业: 计算机科学与技术班级:学号:姓名:摘要:本文基于WinPcap,解决了局域网网络流量监测和用户名登陆信息的截取等问题,同时基于对截获的报文的解析,可以显示截获的报文的源和目的,报文的长度,报文的内容等。
第二部分通过对AES算法的研究,实现了对信息的加密和解密过程。
关键词:WinPcap;网络编程;AES一.引言在21世纪互联网的今天,各种网络构成了我们的信息交流网,因此对网络流量的监测成为一个关键的问题,通过对网络流量的监测,可以发现异常流量,从而及时的发现问题,WinPcap提供了很好的用于网络分析的工具,同时通过对开放APT的进一步研究,进行报文解析,可以直接获取基于局域网登陆的用户名和密码等信息。
另一方面,随着网络的发展,对于信息安全性的提高也成为了一个研究关键,在国际上有通用的安全的密码加密体系DES,AES等,本文对AES的数学原理进行了探索,同时用C/C++实现了AES的加密和解密过程。
二.基于WinPcap的用户名和密码监听器实现(一)WinPcap简介WinPcap is an open source library for packet capture and network analysis for the Win32 platforms.Most networking applications access the network through widely used operating system primitives such as sockets. It is easy to access data on the network with this approach since the operating system copes with the low level details (protocol handling, packet reassembly, etc.) and provides a familiar interface that is similar to the one used to read and write files.The purpose of WinPcap is to give this kind of access to Win32 applications; it provides facilities to:1.capture raw packets, both the ones destined to the machine where it's running and the ones exchanged by other hosts (on shared media)2.filter the packets according to user-specified rules before dispatching them to the application3.transmit raw packets to the network4.gather statistical information on the network trafficWinPcap receives and sends the packets independently from the host protocols,like TCP-IP. This means that it isn't able to block, filter or manipulate the traffic generated by other programs on the same machine: it simply "sniffs" thepackets that transit on the wire. Therefore, it does not provide the appropriate support for applications like traffic shapers, QoS schedulers and personal firewalls.(二)WinPcap架构WinPcap is an architecture for packet capture and network analysis for the Win32 platforms. It includes a kernel-level packet filter, a low-level dynamic link library (packet.dll), and a high-level and system-independent library (wpcap.dll).The following figure shows the various components of WinPcap:Netgroup Packet Filter (NPF), the kernel portion of WinPcap.It is the WinPcap component that does the hard work, processing the packets that transit on the network and exporting capture, injection and analysis capabilities to user-level.NIC drivers directly manage network interface cards, referred to as NICs. The NIC drivers interface directly to the hardware at their lower edge and at their upper edge present an interface to allow upper layers to send packets on the network, to handle interrupts, to reset the NIC, to halt the NIC and to query and set the operational characteristics of the driver. NIC drivers can be either miniports or legacy full NIC drivers.NDIS (Network Driver Interface Specification) is a standard that defines the communication between a network adapter (or, better, the driver that manages it) and the protocol drivers (that implement for example TCP/IP). Main NDIS purpose is to act as a wrapper that allows protocol drivers to send and receive packets onto a network (LAN or WAN) without caring either the particular adapter or the particular Win32 operating system.Next figure shows the position of NPF inside the NDIS stack:Next figure shows the structure of WinPcap, with particular reference to the NPF driver:(三)WireShark简介Wireshark is a free and open-source packet analyzer. It is used for networktroubleshooting, analysis, software and communications protocol development, and education.Wireshark is cross-platform, using the GTK+ widget toolkit in current releases, andQt in the development version, to implement its user interface, and using pcap to capture packets.Wireshark allows the user to put network interface controllers that support promiscuous mode into that mode, in order to see all traffic visible on that interface, not just traffic addressed to one of the interface's configured addresses and broadcast/multicast traffic.Wireshark is software that "understands" the structure (encapsulation) of different networking protocols. It can parse and display the fields, along with their meanings as specified by different networking protocols. Wireshark uses pcap to capture packets, so it can only capture packets on the types of networks that pcap supports.Next figure shows the menu of Wireshark:(四)基于WinPcap流量监测1.关键结构体和函数分析struct pcap_if {struct pcap_if *next;char *name; /* name to hand to "pcap_open_live()" */char *description; /* textual description of interface, or NULL */ struct pcap_addr *addresses;bpf_u_int32 flags; /* PCAP_IF_ interface flags */};struct pcap{int fd; /* 文件描述字,实际就是 socket */int selectable_fd;/* 在 socket,可以使用 select() 和 poll() 等 I/O 复用类型函数 */ int snapshot; /* 用户期望的捕获数据包最大长度 */int linktype; /* 设备类型 */int tzoff; /* 时区位置,实际上没有被使用 */int offset; /* 边界对齐偏移量 */int break_loop; /* 强制从读数据包循环中跳出的标志 */struct pcap_sf sf; /* 数据包保存到文件的相关配置数据结构 */struct pcap_md md; /* 具体描述如下 */int bufsize; /* 读缓冲区的长度 */u_char buffer; /* 读缓冲区指针 */u_char *bp;int cc;u_char *pkt;/* 相关抽象操作的函数指针,最终指向特定操作系统(os)的处理函数 */int (*read_op)(pcap_t *, int cnt, pcap_handler, u_char *);int (*setfilter_op)(pcap_t *, struct bpf_program *);int (*set_datalink_op)(pcap_t *, int);int (*getnonblock_op)(pcap_t *, char *);int (*setnonblock_op)(pcap_t *, int, char *);int (*stats_op)(pcap_t *, struct pcap_stat *);void (*close_op)(pcap_t *);/*如果 BPF 过滤代码不能在内核中执行,则将其保存并在用户空间执行 */struct bpf_program fcode;/* 函数调用出错信息缓冲区 */char errbuf[PCAP_ERRBUF_SIZE + 1];/* 当前设备支持的、可更改的数据链路类型的个数 */int dlt_count;/* 可更改的数据链路类型号链表,在 linux 下没有使用 */int *dlt_list;/* 数据包自定义头部,对数据包捕获时间、捕获长度、真实长度描述 [pcap.h] */ struct pcap_pkthdr pcap_header;};struct pcap_pkthdr {struct timeval ts; /* time stamp */bpf_u_int32 caplen; /* length of portion present */bpf_u_int32 len; /* length this packet (off wire) */};int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf);/* pcap_findalldevs_ex() 获取适配器列表,返回0表示正常,-1表示出错*/void pcap_freealldevs(pcap_if_t *);/*pcap_freealldevs() 释放适配器链表空间*/pcap_t *pcap_open(const char *source, int snaplen, int flags, int read_timeout, struct pcap_rmtauth *auth, char *errbuf);/*pcap_open() 打开适配器*/int pcap_next_ex ( pcap_t * p, struct pcap_pkthdr ** pkt_header, const u_char ** pkt_data)/*pcap_next_ex() 直接获得一个数据包,非回调方法; pcap_pkthdr结构体表示dump 文件中数据包首部*/2.算法流程3.代码清单#include <pcap.h>#define LINE_LEN 16int main(int argc,char* argv[]){/* Get all the devices */pcap_if_t *alldevs, *d;/* File descriptor */pcap_t *fp;u_int inum, i=0/* Work as a counter to count the number of the interface */;/* As the buffer of the error */char errbuf[PCAP_ERRBUF_SIZE];/* The flag of getting the package */int res;/* Pkt header */struct pcap_pkthdr *header;/* u_char means unsigned char */const u_char *pkt_data;printf("printing the device list:\n");/* Get the local device list */if(pcap_findalldevs(&alldevs, errbuf) == -1){fprintf(stderr,"Error:pcap_findalldevs_ex: %s\n", errbuf);exit(1);}/* Print the list */for(d=alldevs; d; d=d->next){printf("%d. %s\n", ++i, d->name);/* The description:textual description of interface, or NULL */if (d->description)printf(" (%s)\n", d->description);elseprintf("No description available\n");}if (i==0){printf("\nNo interfaces found! Make sure WinPcap is installed.\n");return -1;}printf("Enter the interface number (1-%d)[enter Ctrl+C to stop the program]:",i);scanf("%d", &inum);if (inum < 1 || inum > i){printf("\nInterface number out of range.\n");/* Free the device list */pcap_freealldevs(alldevs);/* It's important to free the devs */return -1;}/* Jump to the selected adapter */for (d=alldevs, i=0; i< inum-1 ;d=d->next, i++);/* I think if I can index the number of the devs,maybe I can find it easily *//* Open the adapter */if ((fp = pcap_open_live(d->name, // name of the device65536, // portion of the packet to capture.// 65536 grants that the whole packet will be captured on all the MACs.1, // promiscuous mode (nonzero means promiscuous)1000, // read timeouterrbuf // error buffer)) == NULL){fprintf(stderr,"\nError opening adapter\n");return -1;}/* Read the packets */while((res = pcap_next_ex( fp, &header, &pkt_data)) >= 0){if(res == 0)/* Timeout elapsed */continue;/* Print pkt timestamp and pkt len */printf("%ld:%ld (%ld)\n", header->_sec, header->_usec, header->len);/* Print the packet */for (i=1; (i < header->caplen + 1 ) ; i++){/* Control the format of the packet */printf("%.2x ", pkt_data[i-1]);if ( (i % LINE_LEN) == 0)printf("\n");/* Dealy the time to show the dat */Sleep(10);}printf("\n\n");}if(res == -1){printf("Error reading the packets: %s\n", pcap_geterr(fp));return -1;}/* It's easy to forget closing the file description */pcap_close(fp);return 0;}4.测试结果(五)基于WinPcap的用户名和密码监听器1.关键结构体和函数分析pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);/*pcap_dump_open() 打开一个文件来写入数据包;而pcap_dumper结构体表示libpcap存储文件的描述符*/int pcap_loop ( pcap_t * p, int cnt, pcap_handler callback, u_char*user) /*pcap_loop() 捕获数据包,其中pcap_handler为回调函数指针*/void packet_handler(u_char *dumpfile, const struct pcap_pkthdr *header, const u_char *pkt_data)/* 包处理函数*/void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);/* 将数据包保存到磁盘*/pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);typedef struct pcap_dumper pcap_dumper_t;/*打开一个文件写入数据包,pcap_dumper 表示的写入的文件描述*/2.算法流程WriteDat:ReadDat:False3.代码清单WriteDat:#include <pcap.h>/* To deal with the packet */void packet_handler(u_char *dumpfile, const struct pcap_pkthdr *header, const u_char *pkt_data){/* Store the dump infos into file */pcap_dump(dumpfile, header, pkt_data);}int main(){pcap_if_t *alldevs;pcap_if_t *d;int inum;int i=0;/* Including the file description and the buffer and so on */pcap_t *adhandle;char errbuf[PCAP_ERRBUF_SIZE];/* Store the infos about the dump files */pcap_dumper_t *dumpfile;/* Store the dump infos into the file named filename */const char* filename = "dat.txt";/* Get the local devs as lists */if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1) {fprintf(stderr,"Error:in pcap_findalldevs: %s\n", errbuf);exit(1);}/* Print the list */for(d=alldevs; d; d=d->next){printf("%d. %s", ++i, d->name);if (d->description)printf(" (%s)\n", d->description);elseprintf("No description available\n");}if(i==0){printf("\nNo interfaces found! Make sure WinPcap is installed.\n");return -1;}printf("Enter the interface number (1-%d):",i);scanf("%d", &inum);if(inum < 1 || inum > i){printf("\nInterface number out of range.\n");/* Free the list */pcap_freealldevs(alldevs);return -1;}/* Jump to the adapter chosed */for(d=alldevs, i=0; i< inum-1 ; d=d->next, i++);/* Open the adapter */if ( (adhandle= pcap_open(d->name, // the name of the dev65536, //Snaplen/* Get all the infos */PCAP_OPENFLAG_PROMISCUOUS, // Set the pattern 1000, // Set the timeNULL, // Be checked?errbuf // Errbuf) ) == NULL){fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);/* Free the list */pcap_freealldevs(alldevs);return -1;}/* Open the dump files */dumpfile = pcap_dump_open(adhandle,filename);if(dumpfile==NULL){fprintf(stderr,"\nError opening output file\n");return -1;}printf("\nlistening on %s... Press Ctrl+C to stop...\n", d->description);/* Free the list */pcap_freealldevs(alldevs);/* Begin to capture */pcap_loop(adhandle, 0, packet_handler, (unsigned char *)dumpfile);return 0;}ReadDat:#include <stdio.h>#include <pcap.h>#define LINE_LEN 16void dispatcher_handler(u_char *temp1,const struct pcap_pkthdr *header,const u_char *pkt_data){u_int i=0;/* Print pkt timestamp and pkt len */printf("%ld:%ld (%ld)\n", header->_sec, header->_usec, header->len);/* Print the packet */for (i=1; (i < header->caplen + 1 ) ; i++){printf("%.2c ", pkt_data[i-1]);/* It's better to insert a Hex2Char() */if ( (i % LINE_LEN) == 0) printf("\n");}printf("\n\n");}int main(){pcap_t *fp;char errbuf[PCAP_ERRBUF_SIZE];const char* filename = "dat.txt";/* Open the capture file */if ((fp = pcap_open_offline(filename, // Name of the deviceerrbuf // Error buffer)) == NULL){fprintf(stderr,"\nUnable to open the file %s.\n",filename);return -1;}/* Read and dispatch packets until EOF is reached */pcap_loop(fp, 0, dispatcher_handler, NULL);pcap_close(fp);return 0;}4.测试结果WriteDat:存储在文件中的内容:ReadDat:和WireShark对比的结果:三. AES算法的加密和解密实现 (一)数学原理Four-term polynomials can be defined - with coefficients that are finite field elements - as:a(x) = a3 x3 + a2x2 + a1x + a(4.5)which will be denoted as a word in the form [a0, a1, a2, a3 ]. Note that the polynomials in this section behave somewhat differently than the polynomials used in the definition of finite field elements, even though both types of polynomials use the same indeterminate, x. The coefficients in this section are themselves finite field elements, i.e., bytes, instead of bits; also, the multiplication of four-term polynomials uses a different reduction polynomial, defined below. The distinction should always be clear from the context.To illustrate the addition and multiplication operations, letb(x) = bx3 + bx2 + bx + bdefine a second four-term polynomial. Addition is performed by adding the finite field coefficients of like powers of x. This addition corresponds to an XOR operation between the corresponding bytes in each of the words – in other words, the XOR of the complete word values.Thus, using the equations of (4.5) and (4.6),Multiplication is achieved in two steps. In the first step, the polynomial product c(x) = a(x) •b(x) is algebraically expanded, and like powers are collected to givewhereThe result, c(x), does not represent a four-byte word. Therefore, the second step of the multiplication is to reduce c(x) modulo a polynomial of degree 4; the result can be reduced to a polynomial of degree less than 4. For the AES algorithm, thisis accomplished with the polynomial x 4+ 1, so thatThe modular product of a(x) and b(x), denoted by a(x) ˜b(x), is given by the four-term polynomial d(x), defined as follows:d(x) = d3 x3 + d2x2 + d1x + d(4.11)withWhen a(x) is a fixed polynomial, the operation defined in equation (4.11) can be written in matrix form as:Because x 4+1 is not an irreducible polynomial over GF(28), multiplication by a fixed four-term polynomial is not necessarily invertible. However, the AES algorithm specifies a fixed four-term polynomial that does have an inverse (see Sec. 5.1.3 and Sec. 5.3.3):a (x ) = {03}x 3 + {01}x 2+ {01}x + {02} (4.14) a -1(x ) = {0b}x 3+ {0d}x 2+ {09}x + {0e}. (4.15)Another polynomial used in the AES algorithm (see the RotWord()function in Sec. 5.2) has a 0 = a 1 = a 2 = {00} and a 3 = {01}, which is the polynomial x 3. Inspection of equation (4.13) above will show that its effect is to form the output word by rotating bytes in the input word. This means that [b 0, b 1, b 2, b 3] is transformed into [b 1, b 2, b 3, b 0].(二)算法流程加密过程伪代码;解密过程伪代码:KeyExpansion是将输入的密钥扩展为11组128位的密钥组,其中第0组为输入密钥本身,其后第n组第i列为第(n - 1)组第i列和第n组第(i - 1)列之和,其中(1 <= i <= 3)SubBytes 操作比较简单,在加密和解密过程中,分别对照加密和解密置换表即可完成KeyExpansion分为两种情况:i = 0时的密钥编排方案不同于上述过程:如下其中的加法和乘法都是建立在(GF)域上的。
课程设计(论文)_基于WinPcap的网络数据包捕获与分析

基于WinPcap的网络数据包捕获与分析一、WinPcap介绍1.WinPcap简介WinPcap是一个在Windows操作系统下的免费、公开的用于直接访问网络的开发工具包(编程API)。
大多数Windows网络应用程序都是通过Winsock API(Windows套接口)这类高级编程接口访问网络的。
这种方法允许在网络上进行简单的数据传送,因为操作系统的TCP/IP协议栈实现软件会处理底层细节(协议操作、流程重组等等),并提供一个类似于读写文件的函数接口。
然而,有时候“简便方法”并不能满足实际需要。
有些程序希望绕过TCP/IP协议栈,直接处理底层网络中的通信数据,它们需要对网络进行底层进行直接访问,即在没有类似协议栈(TCP/IP协议栈)的实体介入条件下对网络进行原始访问。
基于Winsock API编程,应用程序是通过调用操作系统提供的编程接口访问TCP/IP协议栈实现网络通信的。
基于WinPcap编程,网络程序实际上是绕开操作系统的TCP/IP协议栈直接通过底层网络发送数据,因此,网络程序可以实现一些更低级、更灵活的功能。
2.WinPcap的组成与结构如图1.1,WinPcap由一个数据包监听设备驱动程序(NPF)、一个底层的动态连接库()和一个高层的不依赖于操作系统的静态库()共三个部分构成。
这里,NPF在操作系统的内核级,、在用户级。
1)数据包监听设备驱动程序Array技术实现上,为了实现抓包,系统必须绕过操作系统的协议栈来访问在网络上传输的原始数据包(rawpacket)。
这就要求WinPcap的一部分运行在操作系统核心内部,直接与网络接口驱动交互。
由于这个部分是系统依赖(system dependent)的,在Winpcap的解决方案中它被视为是一个设备驱动,称作NPF(Netgroup Packet Filter)。
图1.1 WinPcap的组成和结构2)底层的动态连接库()和高层静态库()为了方便编程,WinPcap必须提供一个编程接口(API),这就是WinPcap的底层的动态连接库()和高层静态库()。
Winpcap使用介绍

Winpcap使用介绍Winpcap使用介绍Winpcap简介Winpcap(windowspacketcapture)是在Win32平台上的强大的、有较好扩展性的底层网络分析体系结构,是Unix下的lipbcap移植到windows下的产物,是Win32环境下数据包捕获的开放代码函数库。
Winpcap是第一个Win32开放式的捕获包的体系结构,能够支持大多数应用程序的需要。
如图A-1所示,Winpcap包含了一个内核级的数据包过滤器——NPF(NetgroupPacketFilter)、一个底层动态链接库(Packet.dll)和一个高层的独立于系统的库(Wpcap.dll)。
这三个模块中,NPF属于内核级,其他两模块属于用户级。
图A-1Winpcap的结构图NPF模块过滤数据包,将数据包不做任何改动的传递给用户,它还包含了一些操作系统专用代码(如:时间戳管理)。
Packet.dll模块提供了Win32平台下的捕获包的驱动接口。
实际上,不同版本的Windows都提供了不同的内核模块和应用程序之间的接口函数,Packet.dll有一套独立于系统的API来处理这些差异。
基于Packet.dll编写的程序可以不经过重新编译就在各种Win32平台下实现捕获数据包。
Packet.dll还包含了其他一些函数。
它可以进行一些底层的操作,Packet.dll和NPF都依赖于操作系统,并且由于Windows95/98和WindowsNT/2000之间操作系统结构的不同而在不同版本的操作系统上有所不同。
Wpcap.dll库不依赖于操作系统,并且它包含了一些其它高层的函数,比如:过滤器生成器、用户定义的缓冲区和高层特性(数据统计和构造数据包)。
Winpcap提供的功能包括四个方面:捕获原始数据包,包括在共享网络上各主机发送/接收的以及相互之间交换的数据包;在数据包发往应用程序之前,按照自定义的规则将某些特殊的数据包过滤掉;在网络上发送原始的数据包;收集网络通信过程中的流量信息。
winpcap分析

4.3.2 4.3.3 4.4 4.4.1 4.4.2
结构图............................................................................................................... 25 源码分析............................................................................................................29 系统特色............................................................................................................46 分布式网络监听 .................................................................................................46 简单网络管理.................................................................................................... 46
第 5 章 系统测试与使用说明书 ......................................................................................47 5.1 5.1.1 5.1.2 5.1.2 5.1.3 5.2 5.3 结论 致谢: 系统测试............................................................................................................47 监听功能............................................................................................................47 显示功能............................................................................................................48 管理功能............................................................................................................51 连接功能............................................................................................................52 工具软件的配置 .................................................................................................54 监听工具的使用 .................................................................................................55 .....................................................................................................................56 .....................................................................................................................61
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
深度剖析WinPcap之(二)——网络分析与嗅探的基础知识
工欲善其事,必先利其器。
为了有利于深入了解WinPcap的内部机制,我们需要对网络分析与嗅探、网络模型与硬件基础作必要了解。
1.1 什么是网络分析与嗅探
网络分析(Network analysis) (也称为网络流量分析、协议分析、嗅探、数据包分析、窃听,等等)就是通过捕获网络流量并深入检查,来决定网络中发生了什么情况的过程。
一个网络分析器对通用协议的数据包进行解码,并以可读的格式显示网络流量的内容。
嗅探器(sniffer)是一种监视网络上所传输数据的程序。
未经授权的嗅探器对网络安全构成威胁,因为它们很难被发现并且可在任何地方被插入,这使得它们成为黑客最喜欢使用的一种工具。
网络分析器之间的差别,在于诸如支持能解码的协议数量、用户接口、图形化与统计能力等主要特性的不同。
其它的差别还包括了推理能力(比如,专家分析特性)与数据包解码的质量。
尽管几个不同的网络分析器针对同一个协议进行解码,但在实际环境中可能其中的一些会比另外一些工作得更好。
图2-1为Wireshark网络分析器的显示窗口。
一个典型的网络分析器用三个窗格显示所捕获的网络流量:
图2-1 Wireshark网络分析器的显示窗口
概要该窗格对所捕获的内容显示一行概要。
包含日期、时间、源地址、目标地址、与最高层协议的名字与信息字段。
详情该窗格提供所捕获数据包所包含的每层细节信息(采用树形结构)。
数据该窗格用十六进制与文本格式显示原始的被捕获数据。
一个网络分析器是由硬件与软件共同组成。
可以是一个带有特定软件的单独硬件设备,或者是安装在台式电脑或膝上电脑之上的一个软件。
尽管每种产品之间具有差别,但都是由下列五个基本部分组成。
硬件多数网络分析器是基于软件的,并工作于标准的操作系统与网卡之上。
然而,一些硬件网络分析器提供额外的功能,诸如分析硬件故障(比如循环冗余纠错(CRC)错误、电压问题、网线问题、抖动、逾限(jabber)、协商错误等等)。
一些网络分析器仅支持以太网或无线网适配器,而其它的可支持多重适配器,并允许用户定制它们的配置。
依据实际情况,可能也需要一个集线器或一个网线探针(cable tap)连接已有的网线。
捕获驱动器这是网络分析器中负责从网线上捕获原始网络流量的部分。
它滤出了所需保持的流量,并把所捕的获数据保存在一个缓冲区中。
这是网络分析器的核心——没有它就无法捕获数据。
缓冲区该组件存储所捕获的数据。
数据能够被存入一个缓冲区中只到该缓冲区被填满为止,或者采用循环缓冲的方式,那么最新的数据将会替换最旧的数据。
采用磁盘或内存均可实现缓冲区。
实时分析当数据一离开网线,该特性就可对数据执行分析。
一些网络分析器利用该特性发现网络性能问题、同时网络入侵检测系统利用它寻找入侵活动。
解码(器) 该组件显示网络流量的内容(带有描述),所以是可读的。
解码是特定于每个协议的,因此网络分析器当前支持可解码的协议数目是变化的,网络分析器可能经常加入新的解码。