Mmh i tought that i've read that somewhere....but if it doesn't crash a server, then here is my code (need to be cleaned...etc) :
Code:
#include <iostream>
#include <string.h>
#include <string>
#include <sstream>
#include <unistd.h>
#if defined (WIN32)
#include <winsock2.h>
typedef int socklen_t;
#pragma comment(lib,"ws2_32.lib")
#elif defined (linux)
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#define closesocket(s) close(s)
typedef int SOCKET;
typedef struct sockaddr_in SOCKADDR_IN;
typedef struct sockaddr SOCKADDR;
#endif
using namespace std;
static int initSocket(void);
static void endSocket(void);
int rbuffersize(0);
string buffer, buffer2, buffer3, rbufferstr, final;
char rbuffer[65000];
SOCKET sockmaster, sockserver;
string getFakeName();
int getRandomNumber(int a, int b);
int waitTimeOut(SOCKET &sock, unsigned int time);
int main()
{
// Initialization Of Needed Variable
int sentmaster(0), sentserver(0), tempsize(0), x(0);
srand(time(NULL)); // Useful Random Function
initSocket(); // Socket Initialization
// Creating Both Sockets Needed
sockmaster = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
sockserver = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
// If Any Error During Creation Of Socket...
if(sockmaster == INVALID_SOCKET || sockserver == INVALID_SOCKET)
{
cout << "Error : Creating Socket." << endl;
endSocket();
return 1;
}
// Buffer To Send To The Master Server And To The Server
buffer = "????????getKeyAuthorize 0 XXXXXXXXXXXXXXXX"; // Replace XXXXXXXXXXXXXXXX by first 16 chars of your cd key
buffer2 = "????????getchallenge";
// Creation Of Both SOCKADDR_IN Structures Needed For Server And MasterServer
sockaddr_in sin, sinserver;
sin.sin_addr.s_addr = inet_addr("63.146.124.40");
sin.sin_port = htons(20700);
sin.sin_family = AF_INET;
sinserver.sin_addr.s_addr = inet_addr(""); // put ip of the server
sinserver.sin_port = htons(28960); // Change port if needed
sinserver.sin_family = AF_INET;
// Sending a Message To The Master Server In Order To Register The CD KEY
if( (sentmaster = sendto(sockmaster, buffer.c_str(), buffer.size(),0, (SOCKADDR *)&sin, sizeof(sin) )) != buffer.size() )
{
cout << "Error : Connexion Impossible on " << inet_ntoa(sin.sin_addr) << ":"<< htons(sin.sin_port) << endl;
endSocket();
return 3;
}
//##################################################################################
//##################################################################################
//##################################################################################
//##################################################################################
tempsize = sizeof(sin);;
for(x=0;x<10;x++)
{
// Cleaning Some Stuff
sentserver = 0;
rbufferstr.empty();
rbuffersize = 0;
memset(rbuffer, 0, sizeof(rbuffer));
cout << "\n-----------------------Sending First Packet-----------------------" << endl;
// Sending The First Packet To The Normal Server
if( (sentserver = sendto(sockserver, buffer2.c_str(), buffer2.size(),0, (SOCKADDR *)&sinserver, sizeof(sinserver) )) != buffer2.size() )
{
cout << "Error : Connexion Impossible on " << inet_ntoa(sinserver.sin_addr) << ":"<< htons(sinserver.sin_port) << endl;
endSocket();
return 3;
}
// Time Out Function
if(!waitTimeOut(sockserver, 3))
{
cout << "Error : Time out." << endl;
endSocket();
return 10;
}
// We Wait For The Response From Normal Server
if( (rbuffersize = recvfrom(sockserver,rbuffer,65000, 0, NULL, NULL)) != SOCKET_ERROR)
{
cout <<"\nReceived Datas :" << rbuffer << endl;
rbufferstr = rbuffer;
}
// Check IF Cd Key Is In Use
if(rbufferstr.substr(10, 20)=="EXE_ERR_CDKEY_IN_USE")
{
cout << "\n/!\\ CD Key Is In Use, Try Another Key Or Try Later" << endl;
endSocket();
return 11;
}
cout << "\n-----------------------Sending Second Packet-----------------------" << endl;
// Converting The Random Port To an INT
std::ostringstream out;
out << getRandomNumber(10000, 65000);
// Creating Last Packet To Connect
buffer3 = "????????connect \"\\cg_predictItems\\1\\cl_anonymous\\0\\cl_voice\\1\\rate\\25000\\snaps\\30\\name\\"+ getFakeName() +"\\protocol\\115\\challenge\\" + rbufferstr.substr(22, 10) + "\\qport\\"+ out.str() +"\"";
//cout << endl << buffer3 << endl;
// We Send That Connect Packet To The Normal Server
if( (sentserver = sendto(sockserver, buffer3.c_str(), buffer3.size(),0, (SOCKADDR *)&sinserver, sizeof(sinserver) )) != buffer3.size() )
{
cout << "Error : Connexion Impossible on " << inet_ntoa(sinserver.sin_addr) << ":"<< htons(sinserver.sin_port) << endl;
endSocket();
return 3;
}
// Same As Above
if(!waitTimeOut(sockserver, 3))
{
cout << "Error : Time out." << endl;
endSocket();
return 10;
}
// We Wait For The Response From Normal Server For Teh Second Packet
if( ( rbuffersize = recvfrom(sockserver,rbuffer,65000, 0, NULL, NULL) ) != SOCKET_ERROR)
{
rbuffer[rbuffersize]=0;
cout <<"\nReceived Datas :" << rbuffer << endl;
}
}
if(WSAGetLastError() != 0)
{
cout <<WSAGetLastError() << endl;
}
endSocket();
return 0;
}
static int initSocket(void)
{
#if defined (WIN32)
WSADATA WSAData;
int err = WSAStartup(MAKEWORD(2,2), &WSAData);
#else
int err= 0;
#endif
if(err < 0)
{
cout << "Error : Initialization Socket." << endl;
return 1;
}
return 0;
}
static void endSocket(void)
{
closesocket(sockmaster);
closesocket(sockserver);
#if defined (WIN32)
WSACleanup();
#endif
}
int waitTimeOut(SOCKET &sock, unsigned int time)
{
fd_set readSet;
FD_ZERO(&readSet);
FD_SET(sock, &readSet);
struct timeval timeVal;
timeVal.tv_sec = time;
timeVal.tv_usec = 0;
if(select(sock+1, &readSet, NULL, NULL, &timeVal) > 0)
{
return true;
}
return false;
}
string getFakeName()
{
string noms[] = {"fly",
"??pium",
"[11]glyhigh'",
"55th|supah",
"pandemic prank`",
"esuba' Lucker",
"skill>l33t",
":P'Owner:",
"BB|goliot",
"aG.L4stknight",
"revol<3",
"[vg]Frst",
"[11]glyhigh'",
"cr33p inct'v",
"=TFF=MinuteMan",
"shox",
"Bodyguard#",
"phnyyyyyyyyyyyy",
"Local",
"(LZ) Tr3n",
"eZ0o_",
"Interc3pt0r",
"[K9] EnV0ltA",
"LoL.mp",
"eMuda.Mandar1ni",
"Jo!Ntzz",
"Death Magnet1c",
"St1flersMum",
"Virtue.Drush",
"Kqp",
"<-Low",
"h4ns",
"Pown-D.D&B",
"Kr0ketje1.",
"scrappycoco",
"-=SnF=-STIN",
"Accce",
"element0",
"|IF|Kebe",
"|IF|SadiC",
"#MHB::Sho0ter",
"#MHB::Urwan",
"(-GPS-)Own3d",
"[C.SF.]boreas",
"SOLO",
"Berta incazz0so",
"cabutssss",
"daro",
"[SdF] GhOsT!",
"MA3EH_HEPE",
"Moron",
"McLovin",
"=OSM=Amantis",
"BrotherS|KAM!L3",
"*R!P* ^6ZDRAWEX",
"^6???",
"WdC^4|^7.Vig",
"^5z^30^9h4n",
"mordshase",
"m0u",
"Wac Emigration",
"^6BrotherS^7|^3NuK3",
"^9Doggy^7Fashion",
"[^3SWL^7]MadToni",
"[KUR!] ^1W^7alkuere ^1!",
"Lisa ^5:)",
"^4]^7PBC^4[^7 Pvt.Paula",
"[k^90^7|^9L^7eckSieKon]",
"^^00[DFF]D4rk",
"WdC|^8.Myros",
"Alam^5...",
"<cH0p^3-Ch0P>",
"FG' SoNNy",
"Lucker.Pro <3",
"Where",
"=TCFF=MinuteMan",
"GL^1-^7M^14^7FIA",
"ubojica",
"thoMPson",
"NAPUSENA KAMILA",
"|AFK|bidzy",
"d2T.TurboHIGH",
"{silk}AxE",
"Ruzno pace",
"exor",
"[1oolac] haTa*",
"b4rr4",
"=^9TCFF^7=^"};
string nomFinal = noms[getRandomNumber(0,86)];
return(nomFinal);
}
int getRandomNumber(int a, int b)
{
int nombre = a + (int)((double)rand() / ((double)RAND_MAX + 1) * b);
return nombre;
}