Threadpool refactoring.

This commit is contained in:
cora32 2015-04-04 15:43:22 +03:00
parent 4f8cb2c53b
commit e3407a5e11
20 changed files with 131 additions and 147 deletions

View File

@ -26,14 +26,15 @@ void ActivityDrawerTh_HorNet::run()
adtHN->doEmitDrawGrid();
int maxAct = Activity + 1;
int nm = 0;
while(true)
while (true)
{
if(maxAct < Activity) maxAct = Activity;
if(maxAct > 1000) nm = maxAct-=1000;
else if(maxAct > 10) nm = maxAct-=10;
makeActLine(((float)Activity/(nm != 0 ? nm : 1)) * 10);
if (maxAct < Activity) maxAct = Activity;
if (maxAct > 1000) nm = maxAct -= 1000;
else if (maxAct > 10) nm = maxAct -= 10;
makeActLine(((float)Activity / (nm != 0 ? nm : 1)) * 10);
adtHN->doEmitDrawActivityLine(QString::number(Activity) + "b");
Activity = 0;
msleep(130);
msleep(150);
};
}

View File

@ -33,10 +33,7 @@ bool BA::checkOutput(const string *buffer, const char *ip, const int port) {
lopaStr BA::BABrute(const char *ip, const int port) {
string buffer;
string lpString;
lopaStr lps{"UNKNOWN", "", ""};
ZeroMemory(lps.login, sizeof(lps.login));
ZeroMemory(lps.pass, sizeof(lps.pass));
ZeroMemory(lps.other, sizeof(lps.other));
lopaStr lps = {"UNKNOWN", "", ""};
int passCounter = 0;
int res = 0;
@ -73,13 +70,16 @@ lopaStr BA::BALobby(const char *ip, const int port) {
while(BrutingThrds >= gMaxBrutingThreads) Sleep(1000);
BruteUtils::BConInc();
++baCount;
++BrutingThrds;
//BruteUtils::BConInc();
const lopaStr &lps = BABrute(ip, port);
BruteUtils::BConDec();
//BruteUtils::BConDec();
--BrutingThrds;
return lps;
} else {
lopaStr lps{"UNKNOWN", "", ""};
lopaStr lps = {"UNKNOWN", "", ""};
return lps;
}
}

View File

@ -4,30 +4,30 @@
void BruteUtils::BConInc()
{
++BA;
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
__asm
{
lock inc BrutingThrds;
};
#else
asm("lock incl BrutingThrds");
#endif
stt->doEmitionUpdateArc(gTargets);
// ++BA;
//#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
//__asm
// {
// lock inc BrutingThrds;
// };
//#else
// asm("lock incl BrutingThrds");
//#endif
// stt->doEmitionUpdateArc(gTargets);
}
void BruteUtils::BConDec()
{
if(BrutingThrds > 0)
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
__asm
{
lock dec BrutingThrds;
};
#else
asm("lock decl BrutingThrds");
#endif
}
stt->doEmitionUpdateArc(gTargets);
// if(BrutingThrds > 0)
// {
//#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
// __asm
// {
// lock dec BrutingThrds;
// };
//#else
// asm("lock decl BrutingThrds");
//#endif
// }
// stt->doEmitionUpdateArc(gTargets);
}

View File

@ -61,9 +61,9 @@ int MakePolygonLine(int gWidth)
if(xtx > 74 && xtx < 112)
{
qp = QPointF(xtx, state ? qrand() % 3 + ME2YPOS - BA * 2 - fact3 : ME2YPOS);
qp = QPointF(xtx, state ? qrand() % 3 + ME2YPOS - baCount * 2 - fact3 : ME2YPOS);
if(BA > 0)
if (baCount > 0)
{
if(xtx < 92 ) fact3+=2;
else fact3-=2;
@ -120,7 +120,7 @@ int MakePolygonLine(int gWidth)
AnomC1 = 0;
WF = 0;
BA = 0;
baCount = 0;
Filt = 0;
Overl = 0;
Lowl = 0;
@ -150,7 +150,7 @@ void DrawerTh_ME2Scanner::run()
msleep(1000);
AnomC1 = 0;
WF = 0;
BA = 0;
baCount = 0;
Filt = 0;
Overl = 0;
Lowl = 0;

View File

@ -14,7 +14,7 @@ void DrawerTh_QoSScanner::run()
lstOfLabels.append(WF);
lstOfLabels.append(Susp);
lstOfLabels.append(Lowl);
lstOfLabels.append(BA);
lstOfLabels.append(baCount);
lstOfLabels.append(Overl);
lstOfLabels.append(ssh);
@ -29,7 +29,7 @@ void DrawerTh_QoSScanner::run()
msleep(500);
AnomC1 = 0;
WF = 0;
BA = 0;
baCount = 0;
Filt = 0;
Overl = 0;
Lowl = 0;
@ -40,7 +40,7 @@ void DrawerTh_QoSScanner::run()
AnomC1 = 0;
WF = 0;
BA = 0;
baCount = 0;
Filt = 0;
Overl = 0;
Lowl = 0;

View File

@ -104,13 +104,13 @@ void DrawerTh_VoiceScanner::run()
{
if(widgetIsHidden == false && tray->isVisible() == false)
{
makeVoiceLine(Alive, AnomC1, WF, Susp, Lowl, BA, Overl, WF, ssh);
makeVoiceLine(Alive, AnomC1, WF, Susp, Lowl, baCount, Overl, WF, ssh);
Alive = 0;
AnomC1 = 0;
WF = 0;
Filt = 0;
Lowl = 0;
BA = 0;
baCount = 0;
Overl = 0;
Susp = 0;
ssh = 0;
@ -126,7 +126,7 @@ void DrawerTh_VoiceScanner::run()
WF = 0;
Filt = 0;
Lowl = 0;
BA = 0;
baCount = 0;
Overl = 0;
Susp = 0;
ssh = 0;

View File

@ -13,9 +13,8 @@ bool FTPA::checkOutput(const string *buffer) {
lopaStr FTPA::FTPBrute(const char *ip, const int port, PathStr *ps) {
string buffer;
string lpString;
lopaStr lps{"UNKNOWN", "", ""};
lopaStr lps = {"UNKNOWN", "", ""};
strcpy(lps.login, "UNKNOWN");
int res = 0;
int passCounter = 0;
@ -68,13 +67,16 @@ lopaStr FTPA::FTPLobby(const char *ip, const int port, PathStr *ps) {
if(gMaxBrutingThreads > 0) {
while(BrutingThrds >= gMaxBrutingThreads) Sleep(1000);
BruteUtils::BConInc();
++baCount;
//BruteUtils::BConInc();
++BrutingThrds;
const lopaStr &lps = FTPBrute(ip, port, ps);
BruteUtils::BConDec();
--BrutingThrds;
//BruteUtils::BConDec();
return lps;
} else {
lopaStr lps{"UNKNOWN", "", ""};;
lopaStr lps = {"UNKNOWN", "", ""};;
return lps;
}
}

View File

@ -5,7 +5,7 @@
lopaStr IPC::IPCBrute(const char *ip, int port, char *SPEC)
{
lopaStr lps{"UNKNOWN", "", ""};
lopaStr lps = {"UNKNOWN", "", ""};
bool result = true;
char login[128] = {0};
char pass[128] = {0};
@ -177,13 +177,16 @@ lopaStr IPC::IPCLobby(const char *ip, int port, char *SPEC) {
if(gMaxBrutingThreads > 0) {
while(BrutingThrds >= gMaxBrutingThreads) Sleep(1000);
BruteUtils::BConInc();
//BruteUtils::BConInc();
++baCount;
++BrutingThrds;
lopaStr lps = IPCBrute(ip, port, SPEC);
BruteUtils::BConDec();
--BrutingThrds;
//BruteUtils::BConDec();
return lps;
} else {
lopaStr lps{"UNKNOWN", "", ""};
lopaStr lps = {"UNKNOWN", "", ""};
return lps;
}
}

View File

@ -178,9 +178,11 @@ int SSHAuth::SSHLobby(const char *ip, int port, std::string *buffer)
const char &banner = _get_ssh_banner(ip, port);
if(strlen(&banner) > 0)
{
BruteUtils::BConInc();
//BruteUtils::BConInc();
++BrutingThrds;
int res = SSHBrute(ip, port, buffer, &banner);
BruteUtils::BConDec();
--BrutingThrds;
//BruteUtils::BConDec();
return res;
};
return -1;

View File

@ -23,7 +23,9 @@ void Threader::fireThread(std::string ip, void *func(void)) {
void Threader::cleanUp() {
ready = true;
cv.notify_one();
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

@ -158,7 +158,7 @@ lopaStr WFClass::_WFBrute( const char *ip,
char *passVal,
char *formVal) {
lopaStr lps{"UNKNOWN", "", ""};
lopaStr lps = {"UNKNOWN", "", ""};
if(strstri(methodVal, "get") != NULL) {
lps = doGetCheck(ip, port, actionVal, userVal, passVal, formVal);

View File

@ -25,13 +25,17 @@ public:
while(BrutingThrds >= gMaxBrutingThreads) Sleep(700);
++WF;
BConInc();
++BrutingThrds;
//BConInc();
passCounter = 1;
}
}
~WFClass(){
BConDec();
//BConDec();
--BrutingThrds;
}
lopaStr _WFBrute(const char *ip,

View File

@ -35,7 +35,7 @@ extern int found, indexIP, gMode,
gThreadDelay, AnomC1, Filt, Overl, Lowl, Alive, saved,
Susp,
WF,
BA,
baCount,
offlines, ssh, globalPinger, gPingTimeout, nickFlag, offlineFlag;
extern unsigned int Activity;
extern char trcSrv[256], trcScr[256], trcProxy[128], trcPersKey[64],

View File

@ -2,13 +2,7 @@
#define EF_H
extern std::string toLowerStr(const char *str);
extern int recvS(int lSock, char *recvBuffT, int len);
extern int sendS(int lSock, char *msg, int len, int mode);
extern void UserNickInit();
extern void GetNicks();
extern int startScan(char* argv);
extern void BConInc();
extern void BConDec();
extern QString GetNSErrorDefinition(const char *str, const char *defin);
extern void _SaveBackupToFile();
extern char* strstri(const char *_Str, const char *_SubStr);
@ -17,7 +11,6 @@ extern void getSubStr(char *src, char *startStr, char *endStr, char *dest, int s
extern void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest);
extern void _SaveBackupToFile();
extern char *_findFirst(const char *str, char *delim);
//extern int nConnect(char *ip, int port, std::string *buffer);
#endif // EF_H

View File

@ -61,8 +61,30 @@ char *_findLast(char *str, char *delim)
char *GetCodePage(const char *str)
{
char cdpg[32] = {0};
char *ptr1 = strstri(str, "<meta ");
char *ptr1 = strstri(str, "charset=");
if (ptr1 != NULL)
{
char *temp3 = _findFirst((char *)(ptr1 + 8), " \"'\n\r");
if (temp3 != NULL)
{
int ln = (int)(temp3 - ptr1 - 8);
if (ln > 16)
{
return "WTF?";
};
strncpy(cdpg, (char *)(ptr1 + 8), (ln > 32) ? 32 : ln);
if (strstri(cdpg, "%s") != NULL) return "UTF-8";
return cdpg;
}
else
{
stt->doEmitionRedFoundData("[GetCodePage] [" + QString(temp3).mid(0, 16) + "]");
return "NULL";
};
}
ptr1 = strstri(str, "<meta ");
if(ptr1 != NULL)
{
char *ptr2 = strstri(ptr1 + 6, "charset=");
@ -159,28 +181,6 @@ char *GetCodePage(const char *str)
};
};
}
ptr1 = strstri(str, "charset=");
if(ptr1 != NULL)
{
char *temp3 = _findFirst((char *)(ptr1 + 8), " \"'\n\r");
if(temp3 != NULL)
{
int ln = (int)(temp3 - ptr1 - 8);
if(ln > 16)
{
return "WTF?";
};
strncpy(cdpg, (char *)(ptr1 + 8), (ln > 32) ? 32 : ln );
if(strstri(cdpg, "%s") != NULL) return "UTF-8";
return cdpg;
}
else
{
stt->doEmitionRedFoundData("[GetCodePage] [" + QString(temp3).mid(0, 16) + "]");
return "NULL";
};
}
else
{
return "NULL";
@ -1164,7 +1164,7 @@ void _specWFBrute(const char *ip, int port, const char *buff, int flag, char *pa
void _specWEBIPCAMBrute(const char *ip, int port, char *finalstr, int flag, char *comment, char *cp, int size, char *SPEC)
{
lopaStr lps{"UNKNOWN", "", ""};
lopaStr lps = {"UNKNOWN", "", ""};
ZeroMemory(lps.login, sizeof(lps.login));
ZeroMemory(lps.pass, sizeof(lps.pass));
ZeroMemory(lps.other, sizeof(lps.other));

View File

@ -1,3 +1,5 @@
бесплатный хост
антивирус
403 forbidden
êóïèòü
X-Adblock-Key

View File

@ -2813,9 +2813,12 @@ void nesca_3::mouseMoveEvent(QMouseEvent * event)
void nesca_3::exitButtonClicked()
{
STTTerminate();
while (__savingBackUpFile) Sleep(100);
//nCleanup();
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
WSACleanup();
#endif
// stt->terminate();
qApp->quit();
}
@ -2854,25 +2857,21 @@ void nesca_3::ChangePingerOK(bool val)
void nesca_3::STTTerminate()
{
while (__savingBackUpFile) Sleep(100);
importFileName = "";
startFlag = false;
globalScanFlag = false;
nCleanup();
startFlag = false;
importFileName = "";
ui->tabMainWidget->setTabEnabled(0, true);
ui->tabMainWidget->setTabEnabled(1, true);
ui->tabMainWidget->setTabEnabled(2, true);
ui->tabMainWidget->setTabEnabled(3, true);
stt->doEmitionUpdateArc(0);
BrutingThrds = 0;
cons = 0;
stt->doEmitionUpdateArc(0);
setButtonStyleArea();
ui->startScanButton_3->setText("Start");
ui->startScanButton_4->setText("Start");
ui->importButton->setText("Import&&Scan");
ui->labelStatus_Value->setText("Idle");
stt->terminate();
}
void nesca_3::startScanButtonClicked()

View File

@ -25,7 +25,7 @@ int gMode;
int MaxPass = 0, MaxLogin = 0, MaxTags = 0, MaxWFLogin = 0, MaxWFPass = 0, MaxSSHPass = 0;
int ipsstart[4], ipsend[4],
overallPorts, flCounter, octet[4];
int BA = 0;
int baCount = 0;
int gPingTimeout = 1;
int gMaxBrutingThreads = 50;
unsigned int Activity = 0;
@ -358,7 +358,7 @@ void _timer() {
void _tracker() {
while (true) {
while (!trackerOK) Sleep(1000);
while (globalScanFlag && !trackerOK) Sleep(1000);
if (!globalScanFlag && jsonArr->size() == 0) break;
char rBuffT[250000] = { 0 };
@ -1592,66 +1592,40 @@ int _getChunkCount(char *data) {
return secondPos - firstPos + 1;
}
void ConInc()
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
__asm
{
lock inc cons;
};
#else
asm("lock; incl cons");
#endif
}
void ConDec()
{
if (cons > 0)
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
__asm
{
lock dec cons;
};
#else
asm("lock; decl cons");
#endif
};
stt->doEmitionUpdateArc(gTargets);
}
void _connect() {
std::string ip = "";
std::unique_lock<std::mutex> lk;
while (globalScanFlag) {
std::unique_lock<std::mutex> lk(Threader::m);
lk = std::unique_lock<std::mutex>(Threader::m);
Threader::cv.wait(lk, []{return Threader::ready; });
if (!globalScanFlag || Threader::threadId > gThreads) {
--Threader::threadId;
Threader::ready = false;
lk.unlock();
Threader::cv.notify_one();
Threader::ready = true;
Threader::cv.notify_all();
return;
}
Threader::ready = false;
if (!Threader::ipQueue.empty()) {
ip = Threader::ipQueue.front();
Threader::ipQueue.pop();
Threader::ready = false;
lk.unlock();
Threader::cv.notify_one();
++ipCounter;
ConInc();
++cons;
for (int i = 0; i <= overallPorts; ++i)
{
if (!globalScanFlag) break;
if (Connector::_ConnectToPort((char*)ip.c_str(), portArr[i]) == -2) break;
};
ConDec();
--cons;
}
else lk.unlock();
}
}
@ -1749,7 +1723,7 @@ int startScan(char* args) {
horLineFlag = false;
flCounter = 0;
PieAnomC1 = 0, PieWF = 0, PieBA = 0, PieSusp = 0, PieLowl = 0, PieSSH = 0;
AnomC1 = 0, BA = 0, Filt = 0, Overl = 0, Lowl = 0, Alive = 0, Activity = 0, saved = 0, Susp = 0, WF = 0, offlines = 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;
@ -2073,8 +2047,10 @@ int startScan(char* args) {
stt->doEmitionGreenFoundData("Done. Saved: " + QString::number(saved) + "; Alive: " + QString::number(found) + ".");
stt->doEmitionChangeStatus("Idle");
Sleep(1000); //Wait for lock release
while (__savingBackUpFile) Sleep(100);
nCleanup();
stt->doEmitionKillSttThread();
//stt->terminate();
}
void nCleanup(){

View File

@ -13,7 +13,7 @@ void PieStat::run()
psTh->doEmitUpdatePie();
AnomC1 = 0;
WF = 0;
BA = 0;
baCount = 0;
Filt = 0;
Overl = 0;
Lowl = 0;

View File

@ -1 +1 @@
24B84-3FA
24B84-5FC