Skip to content

Commit

Permalink
FTP & BA refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
forsdev1 committed Mar 16, 2015
1 parent a527c6d commit 235db21
Show file tree
Hide file tree
Showing 14 changed files with 1,182 additions and 1,250 deletions.
55 changes: 43 additions & 12 deletions BasicAuth.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,55 @@
#include <BasicAuth.h>

lopaStr BA::_BABrute(char *cookie,
char *ip,
int port,
char *pathT,
char *method)
{
bool BA::checkOutput(const string *buffer) {
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
) {

return true;
}

return false;
}

lopaStr BA::_BABrute(const char *ip, const int port) {
string buffer;
string lpString;
lopaStr lps;
ZeroMemory(lps.login, sizeof(lps.login));
ZeroMemory(lps.pass, sizeof(lps.pass));
ZeroMemory(lps.other, sizeof(lps.other));

strcpy(lps.login, "UNKNOWN");

for(int i = 0; i < MaxLogin; ++i) {
if(!globalScanFlag) return lps;
for (int j = 0; j < MaxPass; ++j) {
if (!globalScanFlag) return lps;

lpString = string(loginLst[i]) + ":" + string(passLst[j]);

Connector::nConnect(ip, port, &buffer, NULL, NULL, &lpString);

if(checkOutput(&buffer) != 0) {
strcpy(lps.login, loginLst[i]);
strcpy(lps.pass, passLst[j]);
return lps;
};

Sleep(70);
}
}

return lps;
}

lopaStr BA::_BALobby(char *cookie,
char *ip,
int port,
char *path,
char *method)
lopaStr BA::_BALobby(const char *ip, const int port)
{
while(BrutingThrds >= gMaxBrutingThreads) Sleep(700);

BruteUtils::BConInc();
lopaStr res = _BABrute(cookie, ip, port, path, method);
const lopaStr &res = _BABrute(ip, port);
BruteUtils::BConDec();

return res;
Expand Down
17 changes: 7 additions & 10 deletions BasicAuth.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
#ifndef BASICAUTH_H
#define BASICAUTH_H

#include <Connector.h>
#include <BruteUtils.h>
#include <Utils.h>
#include <externData.h>
#include <mainResources.h>

class BA : BruteUtils{
private:
lopaStr _BABrute(char *cookie,
char *ip,
int port,
char *pathT,
char *method);
static bool checkOutput(const string *buffer);
static lopaStr _BABrute(const char *ip, const int port);

lopaStr _BALobby(char *cookie,
char *ip,
int port,
char *path,
char *method);
public:
static lopaStr _BALobby(const char *ip, const int port);
};

#endif // BASICAUTH_H
34 changes: 20 additions & 14 deletions Connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ int _EstablishSSHConnection(char *host, int port, std::string *buffer, const cha
char login[32] = {0};
char pass[32] = {0};
char temp[64] = {0};
isActive = 1;
BruteUtils::BConInc();
int sz = 0;
char *ptr1 = 0;
Expand All @@ -193,19 +192,16 @@ int _EstablishSSHConnection(char *host, int port, std::string *buffer, const cha
{
if(i == 0) return -2; //Failhit
BruteUtils::BConDec();
isActive = 0;
return 1;
}
else if(res == -2)
{
BruteUtils::BConDec();
isActive = 0;
return -2;
};
Sleep(500);
};
BruteUtils::BConDec();
isActive = 0;
return -1;
}

Expand All @@ -232,9 +228,11 @@ int my_trace(CURL *handle, curl_infotype type,
void *userp)
{
switch (type) {
case CURLINFO_HEADER_OUT:
data[strstr(data, "\r\n\r\n") - data] = '\0';
stt->doEmitionAddOutData(QString(data));
case CURLINFO_HEADER_OUT: {
data[strstr(data, "\r\n\r\n") - data] = '\0';
stt->doEmitionAddOutData(QString(data));
break;
}
}

return 0;
Expand All @@ -248,22 +246,25 @@ static size_t nWriteCallback(void *contents, size_t size, size_t nmemb, void *us

int Connector::nConnect(const char *ip, const int port, std::string *buffer,
const char *postData,
const std::vector<std::string> *customHeaders){

const std::vector<std::string> *customHeaders,
const std::string *lpString){
buffer->clear();
CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 0L);

if (curl)
{
if (MapWidgetOpened) {
struct data config;
config.trace_ascii = 1; /* enable ascii tracing */
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &config);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &config);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
}
curl_easy_setopt(curl, CURLOPT_URL, ip);
curl_easy_setopt(curl, CURLOPT_PORT, port);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0");
curl_easy_setopt(curl, CURLOPT_USERAGENT,
"Mozilla/5.0 (X11; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0");
curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
Expand Down Expand Up @@ -296,14 +297,19 @@ int Connector::nConnect(const char *ip, const int port, std::string *buffer,
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
}

if(lpString != NULL) {
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
curl_easy_setopt(curl, CURLOPT_USERPWD, lpString);
};

curl_easy_perform(curl);
if(MapWidgetOpened) stt->doEmitionAddIncData(QString(ip), QString(buffer->c_str()));
curl_easy_cleanup(curl);
} else {
stt->doEmitionRedFoundData("Curl error.");
return -1;
};

if(MapWidgetOpened) stt->doEmitionAddIncData(QString(ip), QString(buffer->c_str()));
return buffer->size();
}
int Connector::_ConnectToPort(char *ip, int port, char *hl)
Expand Down
5 changes: 3 additions & 2 deletions Connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class Connector {

public:
static int nConnect(const char *ip, const int port, std::string *buffer,
const char *postData = NULL,
const std::vector<std::string> *customHeaders = NULL);
const char *postData = NULL,
const std::vector<std::string> *customHeaders = NULL,
const string *lpString = NULL);
static int _ConnectToPort(char *ip, int port, char *hl);
static int _SSHLobby(char *ip, int port, std::string *buffer);
};
Expand Down
62 changes: 62 additions & 0 deletions FTPAuth.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "FTPAuth.h"

bool FTPA::checkOutput(const string *buffer) {
//Login or password incorrect!

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
) {

return true;
}

return false;
}

lopaStr FTPA::_FTPBrute(const char *ip, const int port, const PathStr *ps) {
string buffer;
string lpString;
lopaStr lps;
ZeroMemory(lps.login, sizeof(lps.login));
ZeroMemory(lps.pass, sizeof(lps.pass));
ZeroMemory(lps.other, sizeof(lps.other));

strcpy(lps.login, "UNKNOWN");

for(int i = 0; i < MaxLogin; ++i)
{
if(!globalScanFlag) return lps;
if(strlen(loginLst[i]) <= 1) continue;

for(int j = 0; j < MaxPass; ++j)
{
if(!globalScanFlag) return lps;
if(strlen(passLst[j]) <= 1) continue;

lpString = string(loginLst[i]) + ":" + string(passLst[j]);

Connector::nConnect(ip, port, &buffer, NULL, NULL, &lpString);

if(checkOutput(&buffer) != 0) {
strcpy(lps.login, loginLst[i]);
strcpy(lps.pass, passLst[j]);
return lps;
};

Sleep(70);
}
}

return lps;
}

lopaStr FTPA::_FTPLobby(const char *ip, const int port, const PathStr *ps){
while(BrutingThrds >= gMaxBrutingThreads) Sleep(700);

BruteUtils::BConInc();
const lopaStr &lps = _FTPBrute(ip, port, ps);
BruteUtils::BConDec();

return lps;
}
19 changes: 19 additions & 0 deletions FTPAuth.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef FTPAUTH_H
#define FTPAUTH_H

#include <Connector.h>
#include <BruteUtils.h>
#include <Utils.h>
#include <externData.h>
#include <mainResources.h>

class FTPA {
private:
static bool checkOutput(const string *buffer);
static lopaStr _FTPBrute(const char *ip, const int port, const PathStr *ps);

public:
static lopaStr _FTPLobby(const char *ip, const int port, const PathStr *ps);
};

#endif // FTPAUTH_H
Loading

0 comments on commit 235db21

Please sign in to comment.