Main starter refactoring, import-rescan bug fixed.

This commit is contained in:
cora32 2015-04-14 14:58:33 +03:00
parent b9ed3ef870
commit 2f26648d48
15 changed files with 1521 additions and 2139 deletions

1320
MainStarter.cpp Normal file

File diff suppressed because it is too large Load Diff

130
MainStarter.h Normal file
View File

@ -0,0 +1,130 @@
#ifndef MAINSTARTER_H
#define MAINSTARTER_H
#include <string>
#include "externData.h"
#include "mainResources.h"
#include "Threader.h"
#include "FileUpdater.h"
class MainStarter {
private: char dnsTarget[256];
int ipsstart[4], ipsend[4];
unsigned int **ipsstartfl = NULL, **ipsendfl = NULL;
unsigned long ip1, ip2;
int gflIndex = 0;
private:
void startIPScan();
void startDNSScan();
void startImportScan();
int loadPorts(const char *data, char delim);
int loadTargets(const char *data);
public:
static std::vector<int> portVector;
static int flCounter;
public:
MainStarter(short mode,
const char* targets,
const char* ports,
const char* tld = nullptr
)
{
horLineFlag = false;
PieAnomC1 = 0, PieWF = 0, PieBA = 0, PieSusp = 0, PieLowl = 0, PieSSH = 0;
AnomC1 = 0, baCount = 0, Filt = 0, Overl = 0, Lowl = 0, Alive = 0, Activity = 0, saved = 0, Susp = 0,
WF = 0, offlines = 0;
BrutingThrds = 0;
found = 0;
gTargets = 0;
cons = 0;
found = 0;
indexIP = 0;
flCounter = 0;
gflIndex = 0;
ZeroMemory(ipsstart, sizeof(ipsstart));
ZeroMemory(ipsend, sizeof(ipsend));
if (loadTargets(targets) == -1 ||
loadPorts(ports, ',') == -1) return;
curl_global_init(CURL_GLOBAL_ALL);
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
CreateDirectoryA(RESULT_DIR_NAME, NULL);
#else
struct stat str = { 0 };
if (stat(RESULT_DIR_NAME, &str) == -1) {
mkdir(RESULT_DIR_NAME, 0700);
}
#endif
}
~MainStarter(){
FileUpdater::FUClear();
Threader::cleanUp();
curl_global_cleanup();
while (__savingBackUpFile) Sleep(100);
if (loginLst != NULL)
{
for (int i = 0; i < MaxLogin; ++i) delete[]loginLst[i];
delete[]loginLst;
loginLst = NULL;
};
if (passLst != NULL)
{
for (int i = 0; i < MaxPass; ++i) delete[]passLst[i];
delete[]passLst;
passLst = NULL;
};
if (GlobalNegatives != NULL)
{
for (int i = 0; i < GlobalNegativeSize; ++i) delete[]GlobalNegatives[i];
delete[]GlobalNegatives;
GlobalNegatives = NULL;
};
if (wfPassLst != NULL)
{
for (int i = 0; i < MaxWFPass; ++i) delete[]wfPassLst[i];
delete[]wfPassLst;
wfPassLst = NULL;
};
if (wfLoginLst != NULL)
{
for (int i = 0; i < MaxWFLogin; ++i) delete[]wfLoginLst[i];
delete[]wfLoginLst;
wfLoginLst = NULL;
};
if (sshlpLst != NULL)
{
for (int i = 0; i < MaxSSHPass; ++i) delete[]sshlpLst[i];
delete[]sshlpLst;
sshlpLst = NULL;
};
if (ipsstartfl != NULL)
{
for (int i = 0; i < flCounter; ++i) delete[]ipsstartfl[i];
delete[]ipsstartfl;
ipsstartfl = NULL;
};
if (ipsendfl != NULL)
{
for (int i = 0; i < flCounter; ++i) delete[]ipsendfl[i];
delete[]ipsendfl;
ipsendfl = NULL;
};
}
void runAuxiliaryThreads();
void saver();
void saveBackupToFile();
void fileLoader(const char *fileName);
void start();
};
#endif // MAINSTARTER_H

View File

@ -1,5 +0,0 @@
#include "NescaLogicStarter.h"
int NLC::startScan(const char* args){
return 1;
}

View File

@ -1,75 +0,0 @@
#ifndef NESCALOGICSTARTER_H
#define NESCALOGICSTARTER_H
class NLC {
public:
NLC(){
}
~NLC(){
/*FileUpdater::FUClear();
Threader::cleanUp();
curl_global_cleanup();
while (__savingBackUpFile) Sleep(100);
if (loginLst != NULL)
{
for (int i = 0; i < MaxLogin; ++i) delete[]loginLst[i];
delete[]loginLst;
loginLst = NULL;
};
if (passLst != NULL)
{
for (int i = 0; i < MaxPass; ++i) delete[]passLst[i];
delete[]passLst;
passLst = NULL;
};
if (GlobalNegatives != NULL)
{
for (int i = 0; i < GlobalNegativeSize; ++i) delete[]GlobalNegatives[i];
delete[]GlobalNegatives;
GlobalNegatives = NULL;
};
if (wfPassLst != NULL)
{
for (int i = 0; i < MaxWFPass; ++i) delete[]wfPassLst[i];
delete[]wfPassLst;
wfPassLst = NULL;
};
if (wfLoginLst != NULL)
{
for (int i = 0; i < MaxWFLogin; ++i) delete[]wfLoginLst[i];
delete[]wfLoginLst;
wfLoginLst = NULL;
};
if (sshlpLst != NULL)
{
for (int i = 0; i < MaxSSHPass; ++i) delete[]sshlpLst[i];
delete[]sshlpLst;
sshlpLst = NULL;
};
if (ipsstartfl != NULL)
{
for (int i = 0; i < flCounter; ++i) delete[]ipsstartfl[i];
delete[]ipsstartfl;
ipsstartfl = NULL;
};
if (ipsendfl != NULL)
{
for (int i = 0; i < flCounter; ++i) delete[]ipsendfl[i];
delete[]ipsendfl;
ipsendfl = NULL;
};
if (starterIP != NULL)
{
for (int i = 0; i < flCounter; ++i) delete[]starterIP[i];
delete[]starterIP;
starterIP = NULL;
};*/
}
int startScan(const char* args);
};
#endif // NESCALOGICSTARTER_H

16
STh.cpp
View File

@ -1,4 +1,5 @@
#include "STh.h"
#include "externData.h"
void STh::doEmitionShowRedVersion()
{
@ -73,7 +74,20 @@ void STh::doEmitionUpdateArc(unsigned long gTargets)
emit stt->signalUpdateArc(gTargets);
}
void STh::setMode(short mode) {
gMode = mode;
}
void STh::setTarget(QString target) {
this->target = target;
}
void STh::setPorts(QString ports) {
this->ports = ports;
}
void STh::run()
{
startScan(inputStr);
MainStarter ms(gMode,
this->target.toLocal8Bit().data(),
this->ports.toLocal8Bit().data()
);
ms.start();
}

9
STh.h
View File

@ -4,15 +4,22 @@
#pragma once
#include "nesca_3.h"
#include "externFunctions.h"
#include "MainStarter.h"
extern int tMax;
class STh : public QThread
{
Q_OBJECT
public:
private:
QString target = "";
QString ports = "";
public:
void setMode(short mode);
void setTarget(QString target);
void setPorts(QString ports);
static void doEmitionDataSaved(bool status);
static void doEmitionStartScanIP();
static void doEmitionStartScanDNS();

View File

@ -24,8 +24,6 @@ void Threader::fireThread(std::string ip, void *func(void)) {
void Threader::cleanUp() {
ready = true;
cv.notify_all();
//Wait for threads to exit correctly
Sleep(gTimeOut*1000 + 2000);
std::unique_lock<std::mutex> lk(m);
lk.unlock();
lk.release();

View File

@ -20,7 +20,7 @@
extern QJsonArray *jsonArr;
extern unsigned long long gTargetsOverall;
extern unsigned long long gTargetsNumber;
extern long long unsigned int gTargets;
extern volatile int cons, BrutingThrds, gThreads;
extern char **loginLst, **passLst, **wfLoginLst, **wfPassLst, **sshlpLst, **GlobalNegatives;
@ -40,7 +40,7 @@ extern int found, indexIP, gMode,
extern unsigned int Activity;
extern char trcSrv[256], trcScr[256], trcProxy[128], trcPersKey[64],
trcPort[32], trcSrvPortLine[32], saveEndIP[128],
gRange[128], gTLD[128], gPorts[65536],
gTLD[128], gPorts[65536],
gProxyIP[64], gProxyPort[8],
currentIP[MAX_ADDR_LEN],
finalIP[32];

View File

@ -4,12 +4,9 @@
extern std::string toLowerStr(const char *str);
extern int startScan(char* argv);
extern QString GetNSErrorDefinition(const char *str, const char *defin);
extern void _SaveBackupToFile();
extern char* strstri(const char *_Str, const char *_SubStr);
extern void nCleanup();
extern void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest);
extern void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest);
extern void _SaveBackupToFile();
extern char *_findFirst(const char *str, char *delim);

View File

@ -2,8 +2,8 @@
#include "base64.h"
#include <libssh/libssh.h>
#include <vector>
#include <curl/curl.h>
#include <vector>
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#include "iostream"
#include <time.h>

View File

@ -45,7 +45,6 @@ bool smBit_7 = false;
bool smBit_8 = false;
bool privateMsgFlag = false;
char inputStr[256] = {0};
bool proxyEnabledFlag = false;
bool disableBlink = false;
char gVER[32] = {0};
@ -175,10 +174,13 @@ void _LoadPersInfoToLocalVars(int savedTabIndex) {
{
if (ui->ipLine->text().indexOf("/") < 0)
{
strcpy(currentIP, ui->ipLine->text().toLocal8Bit().data());
strcat(currentIP, "-");
strcat(currentIP, ui->ipLine->text().toLocal8Bit().data());
};
sprintf(currentIP, "%s-%s",
ui->ipLine->text().toLocal8Bit().data(), ui->ipLine->text().toLocal8Bit().data());
}
else {
sprintf(currentIP, "%s",
ui->ipLine->text().toLocal8Bit().data());
}
};
strncpy(gPorts, ("-p" + ui->portLine->text()).toLocal8Bit().data(), 65536);
@ -270,7 +272,7 @@ void nesca_3::drawVerboseArcs(unsigned long gTargets) {
fSz = 6;
QPainterPath pathTargets;
pathTargets.arcMoveTo(leftX, sharedY, rightX, sharedheight1, 0);
pathTargets.arcTo(leftX, nSharedY, rightX, sharedheight2, 0, indexIP*((float)(180/(float)gTargetsOverall)));
pathTargets.arcTo(leftX, nSharedY, rightX, sharedheight2, 0, indexIP*((float)(180/(float)gTargetsNumber)));
QGraphicsPathItem* itmTargets = new QGraphicsPathItem(pathTargets);
itmTargets->setPen(penTargets);
testScene->addItem(itmTargets);
@ -278,7 +280,7 @@ void nesca_3::drawVerboseArcs(unsigned long gTargets) {
fSz = 3;
QPainterPath pathSaved;
pathSaved.arcMoveTo(leftX, sharedY, rightX, sharedheight1, 0);
pathSaved.arcTo(leftX, nSharedY, rightX, sharedheight2, 0, saved*((float)(180/(float)gTargetsOverall)));
pathSaved.arcTo(leftX, nSharedY, rightX, sharedheight2, 0, saved*((float)(180/(float)gTargetsNumber)));
QGraphicsPathItem* itmSaved = new QGraphicsPathItem(pathSaved);
itmSaved->setPen(penSaved);
testScene->addItem(itmSaved);
@ -2052,27 +2054,15 @@ void nesca_3::IPScanSeq()
ui->tabMainWidget->setTabEnabled(1, false);
ui->tabMainWidget->setTabEnabled(2, false);
QString rangeData = ui->ipLine->text();
if(rangeData.indexOf("-") > 0)
{
rangeData = ui->ipLine->text();
}
else
{
if(rangeData.indexOf("/") < 0)
{
rangeData = ui->ipLine->text() + "-" + ui->ipLine->text();
}
else
{
rangeData = ui->ipLine->text();
};
};
saveOptions();
strcpy(inputStr, ("DUMMY|0|" + rangeData + "|" + ui->threadLine->text() + "|-p" + ui->portLine->text().replace(" ", "")).toLocal8Bit().data());
stt->setMode(0);
stt->setTarget((ui->ipLine->text().indexOf("-") > 0 ? ui->ipLine->text() :
(ui->ipLine->text().indexOf("/") < 0 ? ui->ipLine->text() + "-" + ui->ipLine->text() : ui->ipLine->text())
));
stt->setPorts(ui->portLine->text().replace(" ", ""));
stt->start();
startFlag = true;
ui->startScanButton_3->setText("Stop");
ui->startScanButton_3->setStyleSheet(
@ -2132,6 +2122,10 @@ void nesca_3::DNSScanSeq()
{
if(ui->lineEditStartIPDNS->text().indexOf(".") > 0)
{
stopFirst = false;
ui->tabMainWidget->setTabEnabled(0, false);
ui->tabMainWidget->setTabEnabled(2, false);
QStringList lst = ui->lineEditStartIPDNS->text().split(".");
ui->lineEditStartIPDNS->setText(lst[0]);
QString topLevelDomainStr;
@ -2144,14 +2138,12 @@ void nesca_3::DNSScanSeq()
};
saveOptions();
stopFirst = false;
ui->tabMainWidget->setTabEnabled(0, false);
ui->tabMainWidget->setTabEnabled(2, false);
strcpy(inputStr, ("DUMMY|1|" + ui->lineEditStartIPDNS->text() + "|" + ui->lineILVL->text() + "|" + ui->lineEditThread->text() + "|-p" + ui->lineEditPort->text().replace(" ", "")).toLocal8Bit().data());
stt->setMode(1);
stt->setTarget(ui->lineEditStartIPDNS->text());
stt->setPorts(ui->lineEditPort->text().replace(" ", ""));
stt->start();
startFlag = true;
ui->startScanButton_4->setText("Stop");
ui->startScanButton_4->setStyleSheet(
@ -2186,15 +2178,18 @@ void nesca_3::ImportScanSeq()
if(fileName != "")
{
stopFirst = false;
ui->tabMainWidget->setTabEnabled(0, false);
ui->tabMainWidget->setTabEnabled(1, false);
_LoadPersInfoToLocalVars(savedTabIndex);
strcpy(inputStr, ("DUMMY|-f|" + fileName + "|" + ui->importThreads->text() + "|-p" + ui->importPorts->text().replace(" ", "")).toLocal8Bit().data());
stt->setMode(-1);
stt->setTarget(fileName);
stt->setPorts(ui->importPorts->text().replace(" ", ""));
stt->start();
startFlag = true;
stopFirst = false;
pbTh->start();
ui->importButton->setText("Stop");
ui->importButton->setStyleSheet(
@ -2351,6 +2346,8 @@ void nesca_3::ConnectEvrthng()
connect ( ui->trackerOnOff, SIGNAL(toggled(bool)), this, SLOT(ChangeTrackerOK(bool)));
connect ( ui->importThreads, SIGNAL( textChanged(QString) ), this, SLOT( ChangeLabelThreads_ValueChanged(QString) ) );
connect(ui->threadLine, SIGNAL(textChanged(QString)), this, SLOT(ChangeLabelThreads_ValueChanged(QString)));
connect(ui->lineILVL, SIGNAL(textChanged(QString)), this, SLOT(saveTLD(QString)));
connect ( ui->PingTO, SIGNAL( textChanged(QString) ), this, SLOT( PingTO_ChangeValue(QString) ) );
connect ( ui->threadDelayBox, SIGNAL( textChanged(QString) ), this, SLOT( ThreadDelay_ChangeValue(QString) ) );
connect ( ui->maxBrutingThrBox, SIGNAL( textChanged(QString) ), this, SLOT( MaxBrutingThr_ChangeValue(QString) ) );
@ -2416,7 +2413,6 @@ void nesca_3::ConnectEvrthng()
void nesca_3::saveOptions()
{
_LoadPersInfoToLocalVars(savedTabIndex);
_SaveBackupToFile();
}
QString loadNescaSetup(const char *resStr, const char *option) {
@ -2470,28 +2466,22 @@ void RestoreSession()
{
if(strstr(lex, "-") != NULL)
{
strncpy(gRange, lex, (int)(strstr(lex, "-") - lex));
strcat(gRange, "-");
strcat(gRange, strstr(lex, "-") + 1);
ui->ipLine->setText(QString(lex));
lex = strtok(NULL, " ");
gThreads = atoi(lex);
ui->threadLine->setText(QString(lex));
ui->ipLine->setText(QString(gRange));
ui->tabMainWidget->setCurrentIndex(0);
}
else if(strstr(lex, "/") != NULL)
{
strncpy(gRange, lex, (int)(strstr(lex, "/") - lex));
strcat(gRange, "/");
strcat(gRange, strstr(lex, "/") + 1);
ui->ipLine->setText(QString(lex));
lex = strtok(NULL, " ");
gThreads = atoi(lex);
ui->threadLine->setText(QString(lex));
ui->ipLine->setText(QString(gRange));
ui->tabMainWidget->setCurrentIndex(0);
};
}
@ -2812,6 +2802,7 @@ void nesca_3::exitButtonClicked()
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
WSACleanup();
#endif
Threader::cleanUp();
qApp->quit();
}
@ -2992,6 +2983,10 @@ void nesca_3::ChangeLabelThreads_ValueChanged(QString str)
gThreads = str.toInt();
}
void nesca_3::saveTLD(QString str){
strncpy(gTLD, str.toLocal8Bit().data(), 128);
}
void nesca_3::PingTO_ChangeValue(QString str)
{
gPingTimeout = str.toInt();

View File

@ -29,7 +29,6 @@ extern bool widgetIsHidden, blinkFlag, disableBlink, QOSWait,
smBit_8, smBit_7, smBit_6, smBit_5, smBit_4, smBit_3, smBit_2, smBit_1, printDelimiter;
extern float QoSStep;
extern int MaxDataVal;
extern char inputStr[256];
extern SOCKET lSock;
extern QVector<int> vAlivLst, vAnomLst, vWFLst, vSuspLst, vLowlLst, vBALst, vSSHLst, vOvrlLst, actLst;
@ -61,6 +60,7 @@ protected:
QString GetSSLContent(QString str);
void SSLConnect(QString str);
protected slots:
void saveTLD(QString str);
void onLinkClicked(QUrl);
void MaxBrutingThr_ChangeValue(QString str);
void ThreadDelay_ChangeValue(QString val);

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@ void ProgressbarDrawer::run()
while(globalScanFlag)
{
msleep(1000);
nesca_3::perc = (unsigned long)100*indexIP/(gTargetsOverall == 0 ? 1 : gTargetsOverall);
nesca_3::perc = (unsigned long)100*indexIP/(gTargetsNumber == 0 ? 1 : gTargetsNumber);
update();
};
};

View File

@ -1 +1 @@
24B85-51F
24B8E-5B2