Skip to content

Commit

Permalink
Partial refactoring of filter and neg-file module.
Browse files Browse the repository at this point in the history
  • Loading branch information
cora32 committed Apr 16, 2015
1 parent 2f26648 commit ad71357
Show file tree
Hide file tree
Showing 33 changed files with 484 additions and 736 deletions.
30 changes: 15 additions & 15 deletions BasicAuth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
#include "FileUpdater.h"

bool BA::checkOutput(const string *buffer, const char *ip, const int port) {
if((Utils::ci_find_substr(*buffer, "200 ok") != -1 ||
Utils::ci_find_substr(*buffer, "http/1.0 200") != -1 ||
Utils::ci_find_substr(*buffer, "http/1.1 200") != -1)
&& Utils::ci_find_substr(*buffer, "http/1.1 401 ") == -1
&& Utils::ci_find_substr(*buffer, "http/1.0 401 ") == -1
&& Utils::ci_find_substr(*buffer, "<statusValue>401</statusValue>") == -1
&& Utils::ci_find_substr(*buffer, "<statusString>Unauthorized</statusString>") == -1
&& Utils::ci_find_substr(*buffer, "íåïðàâèëüíû") == -1
&& Utils::ci_find_substr(*buffer, "Неправильны") == -1
if((Utils::ustrstr(*buffer, "200 ok") != -1 ||
Utils::ustrstr(*buffer, "http/1.0 200") != -1 ||
Utils::ustrstr(*buffer, "http/1.1 200") != -1)
&& Utils::ustrstr(*buffer, "http/1.1 401 ") == -1
&& Utils::ustrstr(*buffer, "http/1.0 401 ") == -1
&& Utils::ustrstr(*buffer, "<statusValue>401</statusValue>") == -1
&& Utils::ustrstr(*buffer, "<statusString>Unauthorized</statusString>") == -1
&& Utils::ustrstr(*buffer, "íåïðàâèëüíû") == -1
&& Utils::ustrstr(*buffer, "Неправильны") == -1
) {
return true;
}
else if (Utils::ci_find_substr(*buffer, "503 service unavailable") != -1
|| Utils::ci_find_substr(*buffer, "http/1.1 503") != -1
|| Utils::ci_find_substr(*buffer, "http/1.0 503") != -1
|| Utils::ci_find_substr(*buffer, "400 BAD_REQUEST") != -1
|| Utils::ci_find_substr(*buffer, "400 bad request") != -1
|| Utils::ci_find_substr(*buffer, "403 Forbidden") != -1
else if (Utils::ustrstr(*buffer, "503 service unavailable") != -1
|| Utils::ustrstr(*buffer, "http/1.1 503") != -1
|| Utils::ustrstr(*buffer, "http/1.0 503") != -1
|| Utils::ustrstr(*buffer, "400 BAD_REQUEST") != -1
|| Utils::ustrstr(*buffer, "400 bad request") != -1
|| Utils::ustrstr(*buffer, "403 Forbidden") != -1
)
{
stt->doEmition_BARedData("[.] 503/400/403 - Waiting 30sec (" + QString(ip) + ":" + QString::number(port) + ")");
Expand Down
13 changes: 7 additions & 6 deletions CheckKey_Th.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,23 @@ int KeyCheckerMain()
Connector::nConnect((url + std::string("/api/checkaccount?key=") + std::string(trcPersKey)).c_str(),
std::stoi(trcSrvPortLine), &buffer, NULL, &headerVector);

if(Utils::ci_find_substr(buffer, std::string("202 Accepted")) != -1) {
if(Utils::ustrstr(buffer, std::string("202 Accepted")) != -1) {
stt->doEmitionGreenFoundData("Key is valid.");
if(emitIfOK == 0) stt->doEmitionStartScanIP();
else if(emitIfOK == 1) stt->doEmitionStartScanDNS();
else if(emitIfOK == 2) stt->doEmitionStartScanImport();
return 1;
} else if(Utils::ci_find_substr(buffer, std::string("400 Bad Request")) != -1) {
QString errorDef = GetNSErrorDefinition(buffer.c_str(), "notify");
} else if(Utils::ustrstr(buffer, std::string("400 Bad Request")) != -1) {
QString errorDef = Utils::GetNSErrorDefinition(buffer.c_str(), "notify");
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] Key is unauthorized. A valid key is required.");
else stt->doEmitionYellowFoundData("[Key check] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(buffer.c_str(), "notify") + "]");
} else if(Utils::ci_find_substr(buffer, std::string("503 Bad Gateway")) != -1) {
else stt->doEmitionYellowFoundData("[Key check] FAIL! [400 Bad Request : " +
Utils::GetNSErrorDefinition(buffer.c_str(), "notify") + "]");
} else if(Utils::ustrstr(buffer, std::string("503 Bad Gateway")) != -1) {
stt->doEmitionYellowFoundData("[Key check] 503 Backend not responding!");
} else {
char header[64] = {0};
getSubStrEx(buffer.c_str(), "http/1.1 ", "\r\n", header, 64);
stt->doEmitionRedFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: <u>" + QString::fromLocal8Bit(header) + "</u>");
stt->doEmitionRedFoundData("[Key check] FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: <u>" + QString::fromLocal8Bit(header) + "</u>");
if(gDebugMode) stt->doEmitionDebugFoundData(QString(buffer.c_str()));
};
} else {
Expand Down
13 changes: 8 additions & 5 deletions Connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,7 @@ int Connector::_ConnectToPort(char* ip, int port)
{
if(gPingNScan)
{
if(_pingMyTarget(ip) == 0)
{
return -2;
};
if(_pingMyTarget(ip) == 0) return -2;
};

std::string buffer;
Expand All @@ -254,7 +251,13 @@ int Connector::_ConnectToPort(char* ip, int port)
++Alive;//ME2
++found;//PieStat
Lexems lx;
lx._filler(port, buffer.c_str(), ip, size, &lx);
lx._filler(port, buffer, ip, size, &lx);

//if (Filter::negativeFilter(&buffer)) {
// if (Filter::resultFilter(&buffer)) {
// saveNode();
// }
//}
}
else if (size == -2) return -2;
return 0;
Expand Down
4 changes: 2 additions & 2 deletions DrawerTh_ME2Scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int MakePolygonLine(int gWidth)
AnomC1 = 0;
WF = 0;
baCount = 0;
Filt = 0;
filtered = 0;
Overl = 0;
Lowl = 0;
Alive = 0;
Expand Down Expand Up @@ -151,7 +151,7 @@ void DrawerTh_ME2Scanner::run()
AnomC1 = 0;
WF = 0;
baCount = 0;
Filt = 0;
filtered = 0;
Overl = 0;
Lowl = 0;
Alive = 0;
Expand Down
6 changes: 4 additions & 2 deletions DrawerTh_QoSScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "STh.h"
#include "externData.h"

int DrawerTh_QoSScanner::MaxDataVal = 1;

void DrawerTh_QoSScanner::run()
{
while(QoSScanFlag)
Expand Down Expand Up @@ -30,7 +32,7 @@ void DrawerTh_QoSScanner::run()
AnomC1 = 0;
WF = 0;
baCount = 0;
Filt = 0;
filtered = 0;
Overl = 0;
Lowl = 0;
Alive = 0;
Expand All @@ -41,7 +43,7 @@ void DrawerTh_QoSScanner::run()
AnomC1 = 0;
WF = 0;
baCount = 0;
Filt = 0;
filtered = 0;
Overl = 0;
Lowl = 0;
Alive = 0;
Expand Down
2 changes: 2 additions & 0 deletions DrawerTh_QoSScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class DrawerTh_QoSScanner : public QThread
{
Q_OBJECT

public:
static int MaxDataVal;
public:
static void doEmitionAddLine();

Expand Down
4 changes: 2 additions & 2 deletions DrawerTh_VoiceScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void DrawerTh_VoiceScanner::run()
Alive = 0;
AnomC1 = 0;
WF = 0;
Filt = 0;
filtered = 0;
Lowl = 0;
baCount = 0;
Overl = 0;
Expand All @@ -124,7 +124,7 @@ void DrawerTh_VoiceScanner::run()
Alive = 0;
AnomC1 = 0;
WF = 0;
Filt = 0;
filtered = 0;
Lowl = 0;
baCount = 0;
Overl = 0;
Expand Down
2 changes: 1 addition & 1 deletion FTPAuth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "FileUpdater.h"

bool FTPA::checkOutput(const string *buffer) {
if(Utils::ci_find_substr(*buffer, "230") != -1) {
if(Utils::ustrstr(*buffer, "230") != -1) {

return true;
}
Expand Down
125 changes: 6 additions & 119 deletions FileUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,135 +10,22 @@ 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<std::mutex> FileUpdater::lk;

void ReadUTF8(FILE* nFile, char *cp) {
char buffFG[256] = {0};
int i = 0;
GlobalNegativeSize = 0;

if(nFile != NULL)
{
while(fgets((char*)buffFG, sizeof(buffFG), nFile) != NULL)
{
if(buffFG[0] != '#' && buffFG[0] != ' ' && buffFG[0] != '\n' && buffFG[0] != '\r' && strcmp(buffFG, "") != 0 &&
((buffFG[0] == '/' && buffFG[1] == '/') == false) && ((buffFG[0] == '\t' && buffFG[1] == '\t' && buffFG[2] == '\t' && (buffFG[3] == 13 || buffFG[3] == 10 || buffFG[3] == '#')) == false)
&& (buffFG[0] == '\t' && buffFG[1] == '\t' && buffFG[2] == '\t' && (buffFG[3] == '/' && buffFG[4] == '/')) == false)
{
++GlobalNegativeSize;
}
ZeroMemory(buffFG, sizeof(buffFG));
};

rewind(nFile);
if(strcmp(cp, "UTF") == 0) fseek(nFile, 3, 0);

GlobalNegatives = new char*[GlobalNegativeSize + 2];

while(fgets(buffFG, sizeof(buffFG), nFile) != NULL)
{
if(buffFG[0] == '#' || buffFG[0] == ' ' || buffFG[0] == '\n' || buffFG[0] == '\r' || strcmp(buffFG, "") == 0 ||
(buffFG[0] == '/' && buffFG[1] == '/'))
{
ZeroMemory(buffFG, sizeof(buffFG));
continue;
};

if(buffFG[0] == '\t' && buffFG[1] == '\t' && buffFG[2] == '\t')
{
char buffFGT[256] = {0};
strcpy(buffFGT, buffFG);
char *ptr1 = strstr(buffFGT, "\t\t\t");
ZeroMemory(buffFG, sizeof(buffFG));
strcpy(buffFG, ptr1 + 3);
};

int bSz = strlen(buffFG);
if((bSz == 2 && buffFG[0] == 13 && buffFG[1] == 10) || (bSz == 1 && (buffFG[0] == 13 || buffFG[0] == 10)))
{
ZeroMemory(buffFG, sizeof(buffFG));
continue;
};
if(buffFG[bSz] == 13 || buffFG[bSz] == 10)
{
buffFG[bSz] = '\0';
};
if(buffFG[bSz - 1] == 13 || buffFG[bSz - 1] == 10)
{
buffFG[bSz - 1] = '\0';
};
if(buffFG[bSz - 2] == 13 || buffFG[bSz - 2] == 10)
{
buffFG[bSz - 2] = '\0';
};

if(strstr((char*)buffFG, "\n") != 0)
{
std::string res = std::string(buffFG);
int sz = res.size();
GlobalNegatives[i] = new char[sz + 1];
ZeroMemory(GlobalNegatives[i], sizeof(*GlobalNegatives[i]));
memcpy(GlobalNegatives[i], toLowerStr(res.c_str()).c_str(), sz - 1);
memset(GlobalNegatives[i] + sz - 1, '\0', 1);
++i;
}
else
{
std::string res = std::string(buffFG);
int sz = res.size();
GlobalNegatives[i] = new char[sz + 1];
ZeroMemory(GlobalNegatives[i], sizeof(*GlobalNegatives[i]));
memcpy(GlobalNegatives[i], toLowerStr(res.c_str()).c_str(), sz);
memset(GlobalNegatives[i] + sz, '\0', 1);
++i;
};
ZeroMemory(buffFG, sizeof(buffFG));
};

if(FileUpdater::oldNegLstSize == 0) stt->doEmitionGreenFoundData("Negative list loaded (" + QString::number(GlobalNegativeSize) + " entries)");
else stt->doEmitionFoundData("<font color=\"Pink\">Negative list updated (" + QString::number(GlobalNegativeSize) + " entries)</font>");

ZeroMemory(buffFG, sizeof(buffFG));
fclose(nFile);
}
else
{
stt->doEmitionRedFoundData("No negative list found");
stt->doEmitionKillSttThread();
};
}
std::vector<std::string> FileUpdater::negativeVector;

void negativeLoader() {
FILE *nFile = fopen("negatives.txt", "rb, ccs=UTF-8");
std::ifstream file("negatives.txt");
std::string line;

if( nFile != NULL)
{
unsigned char b[3] = {0};
fread(b,1,2, nFile);
if( b[0] == 0xEF && b[1] == 0xBB)
{
fread(b,1,1,nFile); // 0xBF
ReadUTF8(nFile, "UTF");
}
else
{
rewind(nFile);
ReadUTF8(nFile, "1251");
};
}
while (std::getline(file, line)) FileUpdater::negativeVector.push_back(line);
}

void updateNegatives() {
if(GlobalNegatives != NULL)
{
for(int i = 0; i < GlobalNegativeSize; ++i) delete []GlobalNegatives[i];
delete []GlobalNegatives;
GlobalNegatives = NULL;
};

FileUpdater::negativeVector.clear();
negativeLoader();
}
void updateLogin() {
Expand Down
5 changes: 3 additions & 2 deletions FileUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#include <fstream>
#include <mutex>
#include <condition_variable>
#include "externData.h"
#include "externFunctions.h"
#include <vector>

class FileUpdater {
public:
Expand All @@ -20,6 +19,8 @@ class FileUpdater {
static std::condition_variable cv;
static std::mutex filesUpdatingMutex;
static std::unique_lock<std::mutex> lk;
static int gNegativeSize;
static std::vector<std::string> negativeVector;

public:
static void updateLists();
Expand Down
5 changes: 5 additions & 0 deletions Filter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "Filter.h"

bool Filter::resultFilter() {
return false;
}
9 changes: 9 additions & 0 deletions Filter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef MAINSTARTER_H
#define MAINSTARTER_H

class Filter {
public:
bool resultFilter();
};

#endif // MAINSTARTER_H
2 changes: 1 addition & 1 deletion IPCAuth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ lopaStr IPC::IPCBrute(const char *ip, int port, char *SPEC)
else if (res != -1) {
for (int i = 0; i < negVector.size(); ++i)
{
if (Utils::ci_find_substr(buffer, negVector[i]) != -1)
if (Utils::ustrstr(buffer, negVector[i]) != -1)
{
result = false;
break;
Expand Down
Loading

0 comments on commit ad71357

Please sign in to comment.