diff --git a/MainStarter.cpp b/MainStarter.cpp index 31800dd..53f651c 100644 --- a/MainStarter.cpp +++ b/MainStarter.cpp @@ -72,7 +72,7 @@ std::vector splitToIntVector(const std::string &s, char delim) { return elems; } -void MainStarter::fileLoader(const char *fileName) { +int MainStarter::fileLoader(const char *fileName) { char curIP[256] = { 0 }, curIPCopy[256] = { 0 }; unsigned int importFileSize = 0; @@ -84,20 +84,28 @@ void MainStarter::fileLoader(const char *fileName) { { if (curIP[0] != '#' && curIP[0] != ' ' && curIP[0] != '\n' && curIP[0] != '\r' && strcmp(curIP, "") != 0 && ((curIP[0] == '/' && curIP[1] == '/') == false) && ((curIP[0] == '\t' && curIP[1] == '\t' && curIP[2] == '\t' && (curIP[3] == 13 || curIP[3] == 10 || curIP[3] == '#')) == false) - && (curIP[0] == '\t' && curIP[1] == '\t' && curIP[2] == '\t' && (curIP[3] == '/' && curIP[4] == '/')) == false) - { - ++importFileSize; - }; + && (curIP[0] == '\t' && curIP[1] == '\t' && curIP[2] == '\t' && (curIP[3] == '/' && curIP[4] == '/')) == false + ) ++importFileSize; ZeroMemory(curIP, sizeof(curIP)); }; - ipsstartfl = new unsigned int*[importFileSize + 1]; - ipsendfl = new unsigned int*[importFileSize + 1]; + if (importFileSize == 0) { + fclose(fl); + return -1; + } + + ipsstartfl = new unsigned int*[importFileSize + 1000]; + ipsendfl = new unsigned int*[importFileSize + 1000]; + ZeroMemory(ipsstartfl, sizeof(ipsstartfl)); + ZeroMemory(ipsendfl, sizeof(ipsendfl)); for (int i = 0; i < importFileSize; ++i) { ipsstartfl[i] = new unsigned int[4]; ipsendfl[i] = new unsigned int[4]; + + ZeroMemory(ipsstartfl[i], sizeof(ipsstartfl[i])); + ZeroMemory(ipsendfl[i], sizeof(ipsendfl[i])); }; rewind(fl); @@ -157,7 +165,7 @@ void MainStarter::fileLoader(const char *fileName) { QString::number(MainStarter::flCounter) + "] String-> [" + QString(curIPCopy) + "]"); - return; + return -1; }; unsigned long ip1 = (ipsstartfl[MainStarter::flCounter][0] * 16777216) + @@ -179,9 +187,16 @@ void MainStarter::fileLoader(const char *fileName) { } else if (strstr(curIP, "/") != NULL) { + if (strlen(curIP) > 18) { + stt->doEmitionRedFoundData("[IP Loader]Wrong list format. Line-> [" + + QString::number(MainStarter::flCounter) + + "] String-> [" + + QString(curIPCopy) + + "]"); + continue; + } unsigned int ip[4] = { 0 }, ip_min[4] = { 0 }, ip_max[4] = { 0 }, tmp1, tmp2; unsigned int netmask = atoi(strstr(curIP, "/") + 1); - char ip_string[19]; std::vector tmpIPVec = splitToIntVector(curIP, '.'); @@ -238,18 +253,12 @@ void MainStarter::fileLoader(const char *fileName) { } else { - char tempMsg[256] = { 0 }; - strcpy(tempMsg, "[IP Loader]Wrong list format. Line-> ["); - strcat(tempMsg, std::to_string(MainStarter::flCounter).c_str()); - strcat(tempMsg, "] String-> ["); - strcat(tempMsg, curIPCopy); - strcat(tempMsg, "]"); stt->doEmitionRedFoundData("[IP Loader]Wrong list format. Line-> [" + QString::number(MainStarter::flCounter) + "] String-> [" + QString(curIPCopy) + "]"); - return; + return -1; }; ZeroMemory(curIP, sizeof(curIP)); }; @@ -270,7 +279,6 @@ int MainStarter::loadTargets(const char *data) { unsigned int ip[4] = { 0 }, ip_min[4] = { 0 }, ip_max[4] = { 0 }, tmp1, tmp2; unsigned int netmask = atoi(strstr(data, "/") + 1); - char ip_string[19]; std::vector tmpIPVec = splitToIntVector(data, '.'); @@ -341,7 +349,10 @@ int MainStarter::loadTargets(const char *data) { gTargetsNumber = gTargets; } else { - fileLoader(data); + if (fileLoader(data) == -1) { + stt->doEmitionRedFoundData("IP list is empty."); + return -1; + } sprintf(finalIP, "%d.%d.%d.%d", ipsendfl[gflIndex][0], ipsendfl[gflIndex][1], ipsendfl[gflIndex][2], ipsendfl[gflIndex][3]); } @@ -1306,7 +1317,14 @@ void MainStarter::runAuxiliaryThreads() { } } -void MainStarter::start() { +void MainStarter::start(const char* targets, const char* ports) { + + if (loadTargets(targets) == -1 || + loadPorts(ports, ',') == -1) { + stt->doEmitionKillSttThread(); + return; + } + globalScanFlag = true; runAuxiliaryThreads(); @@ -1317,9 +1335,7 @@ void MainStarter::start() { stt->doEmitionYellowFoundData("Stopping threads..."); stt->doEmitionChangeStatus("Stopping..."); - while (cons > 0 || jsonArr->size() > 0) { - Sleep(2000); - }; + while (cons > 0 || jsonArr->size() > 0) Sleep(2000); stt->doEmitionGreenFoundData("Done. Saved " + QString::number(saved) + " of " + QString::number(found) + " nodes."); diff --git a/MainStarter.h b/MainStarter.h index fabba06..44a3754 100644 --- a/MainStarter.h +++ b/MainStarter.h @@ -27,7 +27,7 @@ public: static bool savingBackUpFile; public: - MainStarter(const char* targets, const char* ports) + MainStarter() { horLineFlag = false; PieAnomC1 = 0, PieWF = 0, PieBA = 0, PieSusp = 0, PieLowl = 0, PieSSH = 0; @@ -45,9 +45,6 @@ public: 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__) @@ -115,8 +112,8 @@ public: void runAuxiliaryThreads(); void saver(); void saveBackupToFile(); - void fileLoader(const char *fileName); - void start(); + int fileLoader(const char *fileName); + void start(const char* targets, const char* ports); }; #endif // MAINSTARTER_H \ No newline at end of file diff --git a/STh.cpp b/STh.cpp index 9267691..fc168f9 100644 --- a/STh.cpp +++ b/STh.cpp @@ -85,8 +85,7 @@ void STh::setPorts(QString ports) { } void STh::run() { - MainStarter ms(this->target.toLocal8Bit().data(), - this->ports.toLocal8Bit().data() - ); - ms.start(); + MainStarter ms; + ms.start(this->target.toLocal8Bit().data(), + this->ports.toLocal8Bit().data()); } diff --git a/nesca_3.cpp b/nesca_3.cpp index 1bdd8d4..9b6400e 100644 --- a/nesca_3.cpp +++ b/nesca_3.cpp @@ -2157,7 +2157,7 @@ void nesca_3::ImportScanSeq() stt->setTarget(fileName); stt->setPorts(ui->importPorts->text().replace(" ", "")); stt->start(); - + startFlag = true; pbTh->start(); ui->importButton->setText("Stop"); diff --git a/progressbardrawer.cpp b/progressbardrawer.cpp index 15d879a..a1f07d4 100644 --- a/progressbardrawer.cpp +++ b/progressbardrawer.cpp @@ -9,6 +9,7 @@ void ProgressbarDrawer::update() int nesca_3::perc = 0; void ProgressbarDrawer::run() { + globalScanFlag = true; while(globalScanFlag) { msleep(1000); diff --git a/version b/version index db823ab..daa73e4 100644 --- a/version +++ b/version @@ -1 +1 @@ -24B92-6B8 \ No newline at end of file +24B93-2E \ No newline at end of file