中南大学网络安全课外实验报告嗅探与欺骗.docx

上传人:b****5 文档编号:6201694 上传时间:2023-01-04 格式:DOCX 页数:29 大小:675.72KB
下载 相关 举报
中南大学网络安全课外实验报告嗅探与欺骗.docx_第1页
第1页 / 共29页
中南大学网络安全课外实验报告嗅探与欺骗.docx_第2页
第2页 / 共29页
中南大学网络安全课外实验报告嗅探与欺骗.docx_第3页
第3页 / 共29页
中南大学网络安全课外实验报告嗅探与欺骗.docx_第4页
第4页 / 共29页
中南大学网络安全课外实验报告嗅探与欺骗.docx_第5页
第5页 / 共29页
点击查看更多>>
下载资源
资源描述

中南大学网络安全课外实验报告嗅探与欺骗.docx

《中南大学网络安全课外实验报告嗅探与欺骗.docx》由会员分享,可在线阅读,更多相关《中南大学网络安全课外实验报告嗅探与欺骗.docx(29页珍藏版)》请在冰豆网上搜索。

中南大学网络安全课外实验报告嗅探与欺骗.docx

中南大学网络安全课外实验报告嗅探与欺骗

 

中南大学

CENTRALSOUTHUNIVERSITY

 

《SEEDPROJECT》

实验报告

 

学生姓名孙毅

学号**********

指导教师王伟平

学院信息科学与工程

专业班级信息安全1401

成时间2016.12

 

 

Sniffing_Spoofing

 

一、实验原理

Sniffing就是一种能将本地网卡状态设成‘混杂’状态的模式,当网卡处于这种“混杂”方式时,该网卡具备“广播地址”,它对遇到的每一个帧都产生一个硬件中断以便提醒操作系统处理流经该物理媒体上的每一个报文包。

(绝大多数的网卡具备置成混杂模式的能力)

一般来说,sniffing和poofing会联合起来使用。

当攻击者嗅探到关键信息时,通常会使用poofing技术来构造数据包来劫持会话或者去获取更多信息,通常会造成很大的危害。

Poofing技术就是攻击者自己构造数据包的ip/tcp数据包帧头部数据来达到自己的目的。

本次实验就是基于以上原理,在linux下模拟整个过程。

二、实验器材

1.Ubuntu12.04。

2.Wireshark等常用捕包工具。

三、实验步骤及运行结果

Task1.编写嗅探程序

嗅探程序可以很容易地使用pcap库。

利用PCAP,嗅探器的任务变得在pcap库调用一系列简单的程序。

在序列结束时,数据包将被放置在缓冲区中,以进一步处理,只要它们被捕获。

所有的数据包捕获的细节由pcap库处理。

TimCarstens写了一个教程如何使用pcap库写的嗅探程序。

1:

深入理解并可以编写嗅探程序。

2:

编写过滤器。

请为您的嗅探程序捕捉每个写过滤表达式如下。

在你的实验报告,你需要包括screendumps显示应用这些过滤器的结果。

•捕获ICMP数据包。

•捕获TCP数据包有一个目的端口范围从端口10-100。

 

运行结果如下:

在程序中预设捕获10个数据包,当捕获数据包之后会将数据包进行处理,会下显示数据包的类型,还有数据包的源ip和目的ip,源端口和目的端口,当有数据时还会显示数据。

对于任务一的2,主要是修改filter中的过滤条件,要实现只捕获ICMP类型的数据包,只需要将charfilter_exp[]="ip"中的ip改为ICMP,然后要捕获端口在10-100之间的tcp数据包,同理,将这条语句中的条件改为‘tcpanddstportrange10-100’即可。

 

Task2.包欺骗

在正常的情况下,当一个用户发送一个数据包时,操作系统通常不允许用户设置所有的在协议头字段(如TCP,UDP,和IP报头)。

操作系统将大部分的领域,而

只允许用户设置几个字段,如目标IP地址、目标端口号等。

但是当用户有有root权限,他们可以在数据包标头设置为任意字段。

这就是所谓的包欺骗,它可以通过原始套接字完成。

原始套接字给程序员的数据包结构的绝对控制,允许程序员构建任何任意的数据包,包括设置头字段和有效载荷。

使用原始套接字是相当简单的,它包括四个步骤:

(1)创建一个原始套接字,

(2)设置套接字选项,(3)构建数据包,和(4)通过原始套接字发送数据包。

有许多在线教程,可以教你如何使用原始套接字在C编程。

我们已经把一些教程与实验室的网页联系起来了。

请阅读它们,并学习如何写一个spoonfing程序包。

我们展示了一个简单的的程序。

 

运行结果如下:

可以看到成功向193.123.123.11的80端口发送了伪造的的源IP为127.1.1.1且端口的234的数据包,这就实现包欺骗的过程。

 

Task3:

综合使用

在这个任务中,你将嗅探和欺骗技术实现连接,并实现程序。

你需要在同一局域网两虚拟机。

从VMAping另一个VM的IP,这将产生一个ICMP回送请求报文。

如果X是活着的,ping程序将收到一个回音答复,并打印出响应。

你嗅探到数据包然后伪造程序运行在虚拟机B、监控网络数据包嗅探。

每当它看到ICMP回送请求,不管目标IP地址是什么,你的程序应该立即发出回声应答数据包欺骗技术的使用。

因此,考虑到机器X是否是活的,这个程序将总是收到一个回复,这表明X是活的。

你要写这样一个程序,包括在你显示你的程序的工作报告screendumps。

请在你的报告中附上代码。

四、附件

Task1

 

#defineAPP_NAME"sniffex"

#defineAPP_DESC"Snifferexampleusinglibpcap"

#defineAPP_COPYRIGHT"Copyright(c)2005TheTcpdumpGroup"

#defineAPP_DISCLAIMER"THEREISABSOLUTELYNOWARRANTYFORTHISPROGRAM."

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

/*defaultsnaplength(maximumbytesperpackettocapture)*/

#defineSNAP_LEN1518

/*ethernetheadersarealwaysexactly14bytes[1]*/

#defineSIZE_ETHERNET14

/*Ethernetaddressesare6bytes*/

#defineETHER_ADDR_LEN6

/*Ethernetheader*/

structsniff_ethernet{

u_charether_dhost[ETHER_ADDR_LEN];/*destinationhostaddress*/

u_charether_shost[ETHER_ADDR_LEN];/*sourcehostaddress*/

u_shortether_type;/*IP?

ARP?

RARP?

etc*/

};

/*IPheader*/

structsniff_ip{

u_charip_vhl;/*version<<4|headerlength>>2*/

u_charip_tos;/*typeofservice*/

u_shortip_len;/*totallength*/

u_shortip_id;/*identification*/

u_shortip_off;/*fragmentoffsetfield*/

#defineIP_RF0x8000/*reservedfragmentflag*/

#defineIP_DF0x4000/*dontfragmentflag*/

#defineIP_MF0x2000/*morefragmentsflag*/

#defineIP_OFFMASK0x1fff/*maskforfragmentingbits*/

u_charip_ttl;/*timetolive*/

u_charip_p;/*protocol*/

u_shortip_sum;/*checksum*/

structin_addrip_src,ip_dst;/*sourceanddestaddress*/

};

#defineIP_HL(ip)(((ip)->ip_vhl)&0x0f)/*与15与运算*/

#defineIP_V(ip)(((ip)->ip_vhl)>>4)/*ip_vhl的各二进位全部右移4位*/

/*TCPheader*/

typedefu_inttcp_seq;

structsniff_tcp{

u_shortth_sport;/*sourceport*/

u_shortth_dport;/*destinationport*/

tcp_seqth_seq;/*sequencenumber*/

tcp_seqth_ack;/*acknowledgementnumber*/

u_charth_offx2;/*dataoffset,rsvd*/

#defineTH_OFF(th)(((th)->th_offx2&0xf0)>>4)

u_charth_flags;

#defineTH_FIN0x01

#defineTH_SYN0x02

#defineTH_RST0x04

#defineTH_PUSH0x08

#defineTH_ACK0x10

#defineTH_URG0x20

#defineTH_ECE0x40

#defineTH_CWR0x80

#defineTH_FLAGS(TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR)

u_shortth_win;/*window*/

u_shortth_sum;/*checksum*/

u_shortth_urp;/*urgentpointer*/

};

void

got_packet(u_char*args,conststructpcap_pkthdr*header,constu_char*packet);

void

print_payload(constu_char*payload,intlen);

void

print_hex_ascii_line(constu_char*payload,intlen,intoffset);

void

print_app_banner(void);

void

print_app_usage(void);

void/*输出相关信息*/

print_app_banner(void)

{

printf("%s-%s\n",APP_NAME,APP_DESC);

printf("%s\n",APP_COPYRIGHT);

printf("%s\n",APP_DISCLAIMER);

printf("\n");

return;

}

void

print_app_usage(void)

{

printf("Usage:

%s[interface]\n",APP_NAME);

printf("\n");

printf("Options:

\n");

printf("interfaceListenonforpackets.\n");

printf("\n");

return;

}

void

print_hex_ascii_line(constu_char*payload,intlen,intoffset)

{

inti;

intgap;

constu_char*ch;

printf("%05d",offset);

ch=payload;

for(i=0;i

printf("%02x",*ch);

ch++;

/*printextraspaceafter8thbyteforvisualaid*/

if(i==7)

printf("");

}

/*printspacetohandlelinelessthan8bytes*/

if(len<8)

printf("");

if(len<16){

gap=16-len;

for(i=0;i

printf("");

}

}

printf("");

ch=payload;

for(i=0;i

if(isprint(*ch))

printf("%c",*ch);

else

printf(".");

ch++;

}

printf("\n");

return;

}

void

print_payload(constu_char*payload,intlen)

{

intlen_rem=len;

intline_width=16;/*numberofbytesperline*/

intline_len;

intoffset=0;/*zero-basedoffsetcounter*/

constu_char*ch=payload;

if(len<=0)

return;

if(len<=line_width){

print_hex_ascii_line(ch,len,offset);

return;

}

for(;;){

/*computecurrentlinelength*/

line_len=line_width%len_rem;

/*printline*/

print_hex_ascii_line(ch,line_len,offset);

/*computetotalremaining*/

len_rem=len_rem-line_len;

/*shiftpointertoremainingbytestoprint*/

ch=ch+line_len;

/*addoffset*/

offset=offset+line_width;

/*checkifwehavelinewidthcharsorless*/

if(len_rem<=line_width){

/*printlastlineandgetout*/

print_hex_ascii_line(ch,len_rem,offset);

break;

}

}

return;

}

void

got_packet(u_char*args,conststructpcap_pkthdr*header,constu_char*packet)

{

staticintcount=1;/*packetcounter*/

/*declarepointerstopacketheaders*/

conststructsniff_ethernet*ethernet;/*Theethernetheader[1]*/

conststructsniff_ip*ip;/*TheIPheader*/

conststructsniff_tcp*tcp;/*TheTCPheader*/

constchar*payload;/*Packetpayload*/

intsize_ip;

intsize_tcp;

intsize_payload;

printf("\nPacketnumber%d:

\n",count);

count++;

/*defineethernetheader*/

ethernet=(structsniff_ethernet*)(packet);

/*define/computeipheaderoffset*/

ip=(structsniff_ip*)(packet+SIZE_ETHERNET);

size_ip=IP_HL(ip)*4;

if(size_ip<20){

printf("*InvalidIPheaderlength:

%ubytes\n",size_ip);

return;

}

/*printsourceanddestinationIPaddresses*/

printf("From:

%s\n",inet_ntoa(ip->ip_src));

printf("To:

%s\n",inet_ntoa(ip->ip_dst));

/*determineprotocol*/

switch(ip->ip_p){

caseIPPROTO_TCP:

printf("Protocol:

TCP\n");

break;

caseIPPROTO_UDP:

printf("Protocol:

UDP\n");

return;

caseIPPROTO_ICMP:

printf("Protocol:

ICMP\n");

return;

caseIPPROTO_IP:

printf("Protocol:

IP\n");

return;

default:

printf("Protocol:

unknown\n");

return;

}

tcp=(structsniff_tcp*)(packet+SIZE_ETHERNET+size_ip);

size_tcp=TH_OFF(tcp)*4;

if(size_tcp<20){

printf("*InvalidTCPheaderlength:

%ubytes\n",size_tcp);

return;

}

printf("Srcport:

%d\n",ntohs(tcp->th_sport));

printf("Dstport:

%d\n",ntohs(tcp->th_dport));

/*define/computetcppayload(segment)offset*/

payload=(u_char*)(packet+SIZE_ETHERNET+size_ip+size_tcp);

/*computetcppayload(segment)size*/

size_payload=ntohs(ip->ip_len)-(size_ip+size_tcp);

/*

*Printpayloaddata;itmightbebinary,sodon'tjust

*treatitasastring.

*/

if(size_payload>0){

printf("Payload(%dbytes):

\n",size_payload);

print_payload(payload,size_payload);

}

return;

}

intmain(intargc,char**argv)

{

char*dev=NULL;/*capturedevicename*/

charerrbuf[PCAP_ERRBUF_SIZE];/*errorbuffer*/

pcap_t*handle;/*packetcapturehandle*/

charfilter_exp[]="ip";/*filterexpression[3]*/

structbpf_programfp;/*compiledfilterprogram(expression)*/

bpf_u_int32mask;/*子网掩码*/

bpf_u_int32net;/*IP地址*/

intnum_packets=10;/*numberofpacketstocapture*/

print_app_banner();

/*checkforcapturedevicenameoncommand-line*/

if(argc==2){

dev=argv[1];

}

elseif(argc>2){

fprintf(stderr,"error:

unrecognizedcommand-lineoptions\n\n");

print_app_usage();

exit(EXIT_FAILURE);

}

else{

/*findacapturedeviceifnotspecifiedoncommand-line*/

dev=pcap_lookupdev(errbuf);

if(dev==NULL){

fprintf(stderr,"Couldn'tfinddefaultdevice:

%s\n",

errbuf);

exit(EXIT_FAILURE);

}

}

/*getnetworknumberandmaskassociatedwithcapturedevice*/

if(pcap_lookupnet(dev,&net,&mask,errbuf)==-1){

fprintf(stderr,"Couldn'tgetnetmaskfordevice%s:

%s\n",

dev,errbuf);

net=0;

mask=0;

}

/*printcaptureinfo*/

printf("Device:

%s\n",dev);

printf("Numberofpackets:

%d\n",num_packets);

printf("Filterexpression:

%s\n",filter_exp);

/*opencapturedevice*/

handle=pcap_open_live(dev,SNAP_LEN,1,1000,errbuf);

if(handle==NULL){

fprintf(stderr,"Couldn'topendevice%s:

%s\n",dev,e

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1