#include "FileUpdater.h" #include "externFunctions.h" #include "STh.h" #include "mainResources.h" bool FileUpdater::running = false; long FileUpdater::oldNegLstSize = 0; long FileUpdater::oldLoginLstSize = 0; long FileUpdater::oldPassLstSize = 0; long FileUpdater::oldSSHLstSize = 0; long FileUpdater::oldWFLoginLstSize = 0; long FileUpdater::oldWFPassLstSize = 0; int FileUpdater::gNegativeSize = 0; std::mutex FileUpdater::filesUpdatingMutex; std::condition_variable FileUpdater::cv; bool FileUpdater::ready = false; std::unique_lock FileUpdater::lk; std::vector FileUpdater::negativeVector; void negativeLoader() { std::ifstream file("negatives.txt"); std::string line; while (std::getline(file, line)) FileUpdater::negativeVector.push_back(line); } void updateNegatives() { FileUpdater::negativeVector.clear(); negativeLoader(); } void updateLogin() { if(loginLst != NULL) { for(int i = 0; i < MaxLogin; ++i) delete []loginLst[i]; delete []loginLst; loginLst = NULL; }; MaxLogin = 0; char buffFG[32] = {0}; FILE *loginList = fopen("login.txt", "r"); if(loginList != NULL) { while(fgets(buffFG, 32, loginList) != NULL) { MaxLogin++; ZeroMemory(buffFG, sizeof(buffFG)); }; rewind(loginList); loginLst = new char*[MaxLogin]; for(int j = 0; j < MaxLogin; j++) { loginLst[j] = new char[32]; }; int i = 0; while(fgets(buffFG, 32, loginList) != NULL) { memset(loginLst[i], 0, strlen(buffFG) + 1); if(strstr(buffFG, "\n") != NULL) strncat(loginLst[i++], buffFG, strlen(buffFG) - 1); else strncat(loginLst[i++], buffFG, strlen(buffFG)); ZeroMemory(buffFG, sizeof(buffFG)); }; if(FileUpdater::oldLoginLstSize == 0) stt->doEmitionGreenFoundData("Login list loaded (" + QString::number(MaxLogin) + " entries)"); else stt->doEmitionFoundData("Login list updated (" + QString::number(MaxLogin) + " entries)"); fclose(loginList); } else { stt->doEmitionRedFoundData("No login list found"); stt->doEmitionKillSttThread(); }; } void updatePass() { if(passLst != NULL) { for(int i = 0; i < MaxPass; ++i) delete []passLst[i]; delete []passLst; passLst = NULL; }; MaxPass = 0; char buffFG[32] = {0}; FILE *passList = fopen("pass.txt", "r"); if(passList != NULL) { while(fgets(buffFG, 32, passList) != NULL) { MaxPass++; ZeroMemory(buffFG, sizeof(buffFG)); }; rewind(passList); passLst = new char*[MaxPass]; for(int j = 0; j < MaxPass; j++) { passLst[j] = new char[32]; }; int i = 0; while(fgets(buffFG, 32, passList) != NULL) { memset(passLst[i], 0, strlen(buffFG) + 1); if(strstr(buffFG, "\n") != NULL) strncat(passLst[i++], buffFG, strlen(buffFG) - 1); else strncat(passLst[i++], buffFG, strlen(buffFG)); ZeroMemory(buffFG, sizeof(buffFG)); }; if(FileUpdater::oldPassLstSize == 0) stt->doEmitionGreenFoundData("Password list loaded (" + QString::number(MaxPass) + " entries)"); else stt->doEmitionFoundData("Password list updated (" + QString::number(MaxPass) + " entries)"); fclose(passList); } else { stt->doEmitionRedFoundData("No password list found"); stt->doEmitionKillSttThread(); }; } void updateSSH() { if(sshlpLst != NULL) { for(int i = 0; i < MaxSSHPass; ++i) delete []sshlpLst[i]; delete []sshlpLst; sshlpLst = NULL; }; MaxSSHPass = 0; char buffFG[32] = {0}; ZeroMemory(buffFG, sizeof(buffFG)); FILE *sshlpList = fopen("sshpass.txt", "r"); if(sshlpList != NULL) { while(fgets(buffFG, 32, sshlpList) != NULL) { ++MaxSSHPass; ZeroMemory(buffFG, sizeof(buffFG)); }; rewind(sshlpList); sshlpLst = new char*[MaxSSHPass]; for(int j = 0; j < MaxSSHPass; j++) { sshlpLst[j] = new char[32]; }; int i = 0; while(fgets(buffFG, 32, sshlpList) != NULL) { memset(sshlpLst[i], 0, strlen(buffFG) + 1); if(strstr(buffFG, "\n") != NULL) strncat(sshlpLst[i++], buffFG, strlen(buffFG) - 1); else strncat(sshlpLst[i++], buffFG, strlen(buffFG)); ZeroMemory(buffFG, sizeof(buffFG)); }; if(FileUpdater::oldSSHLstSize == 0) stt->doEmitionGreenFoundData("SSH Password list loaded (" + QString::number(MaxSSHPass) + " entries)"); else stt->doEmitionFoundData("SSH list updated (" + QString::number(MaxSSHPass) + " entries)"); fclose(sshlpList); } else { stt->doEmitionRedFoundData("No password/login list found"); stt->doEmitionKillSttThread(); }; } void updateWFLogin() { if(wfLoginLst != NULL) { for(int i = 0; i < MaxWFLogin; ++i) delete []wfLoginLst[i]; delete []wfLoginLst; wfLoginLst = NULL; }; MaxWFLogin = 0; char buffFG[32] = {0}; ZeroMemory(buffFG, sizeof(buffFG)); FILE *wfLoginList = fopen("wflogin.txt", "r"); if(wfLoginList != NULL) { while(fgets(buffFG, 32, wfLoginList) != NULL) { MaxWFLogin++; ZeroMemory(buffFG, sizeof(buffFG)); }; rewind(wfLoginList); wfLoginLst = new char*[MaxWFLogin]; for(int j = 0; j < MaxWFLogin; j++) { wfLoginLst[j] = new char[32]; }; int i = 0; while(fgets(buffFG, 32, wfLoginList) != NULL) { memset(wfLoginLst[i], 0, strlen(buffFG) + 1); if(strstr(buffFG, "\n") != NULL) strncat(wfLoginLst[i++], buffFG, strlen(buffFG) - 1); else strncat(wfLoginLst[i++], buffFG, strlen(buffFG)); ZeroMemory(buffFG, sizeof(buffFG)); }; if(FileUpdater::oldWFLoginLstSize == 0) stt->doEmitionGreenFoundData("WFLogin list loaded (" + QString::number(MaxWFLogin) + " entries)"); else stt->doEmitionFoundData("WFLogin list updated (" + QString::number(MaxWFLogin) + " entries)"); fclose(wfLoginList); } } void updateWFPass() { if(wfPassLst != NULL) { for(int i = 0; i < MaxWFPass; ++i) delete []wfPassLst[i]; delete []wfPassLst; wfPassLst = NULL; }; MaxWFPass = 0; char buffFG[32] = {0}; ZeroMemory(buffFG, sizeof(buffFG)); FILE *wfPassList = fopen("wfpass.txt", "r"); if(wfPassList != NULL) { while(fgets(buffFG, 32, wfPassList) != NULL) { MaxWFPass++; ZeroMemory(buffFG, sizeof(buffFG)); }; rewind(wfPassList); wfPassLst = new char*[MaxWFPass]; for(int j = 0; j < MaxWFPass; j++) { wfPassLst[j] = new char[32]; }; int i = 0; while(fgets(buffFG, 32, wfPassList) != NULL) { memset(wfPassLst[i], 0, strlen(buffFG) + 1); if(strstr(buffFG, "\n") != NULL) strncat(wfPassLst[i++], buffFG, strlen(buffFG) - 1); else strncat(wfPassLst[i++], buffFG, strlen(buffFG)); ZeroMemory(buffFG, sizeof(buffFG)); }; if(FileUpdater::oldWFPassLstSize == 0) stt->doEmitionGreenFoundData("WFPassword list loaded (" + QString::number(MaxWFPass) + " entries)"); else stt->doEmitionFoundData("WFPassword list updated (" + QString::number(MaxWFPass) + " entries)"); fclose(wfPassList); } } long getFileSize(const char *fileName) { std::ifstream in(fileName, std::ifstream::ate | std::ifstream::binary); return in.tellg(); } void updateList(const char *fileName, long *szPtr, void *funcPtr(void)) { long sz = getFileSize(fileName); if(sz != *szPtr) { FileUpdater::lk = std::unique_lock (FileUpdater::filesUpdatingMutex); funcPtr(); *szPtr = sz; FileUpdater::lk.unlock(); FileUpdater::ready = true; FileUpdater::cv.notify_one(); } } void FileUpdater::updateLists() { running = true; while(globalScanFlag) { Sleep(600000); if(!globalScanFlag) break; loadOnce(); } running = false; } void FileUpdater::loadOnce() { updateList("negatives.txt", &oldNegLstSize, (void*(*)(void))updateNegatives); updateList("login.txt", &oldLoginLstSize, (void*(*)(void))updateLogin); updateList("pass.txt", &oldPassLstSize, (void*(*)(void))updatePass); updateList("sshpass.txt", &oldSSHLstSize, (void*(*)(void))updateSSH); updateList("wflogin.txt", &oldWFLoginLstSize, (void*(*)(void))updateWFLogin); updateList("wfpass.txt", &oldWFPassLstSize, (void*(*)(void))updateWFPass); } void FileUpdater::FUClear() { running = false; oldNegLstSize = 0; oldLoginLstSize = 0; oldPassLstSize = 0; oldSSHLstSize = 0; oldWFLoginLstSize = 0; oldWFPassLstSize = 0; }