-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkekpath.cpp
More file actions
287 lines (255 loc) · 11.2 KB
/
kekpath.cpp
File metadata and controls
287 lines (255 loc) · 11.2 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#include "kekpath.h"
int main(int argc, char* argv[]) {
string url;
string port = "80";
string ua;
string tmout;
string threads;
string rate;
string networkInterface;
string outputPath;
if (argc == 2 && (string(argv[1]) == "-h" || string(argv[1]) == "-help")) {
cout << "=============================================================\n";
cout << " kekpath - Recursive Web Scanner\n";
cout << "=============================================================\n";
cout << "Usage: " << argv[0] << " [OPTIONS]\n";
cout << "Options:\n";
cout << " -u <URL> : Set the target URL (required)\n";
cout << " -p <PORT> : Set the port number (default: 80)\n";
cout << " -excl <EXTS> : Exclude certain file extensions (comma-separated, e.g., .php,.js)\n";
cout << " -t <TIMEOUT> : Set the request timeout in milliseconds (500-10000)\n";
cout << " -ua <USER_AGENT> : Set the User-Agent string (or use 'rand' for random)\n";
cout << " -dbg : Enable debug mode\n";
cout << " -tr <THREADS> : Set the number of threads (1-5)\n";
cout << " -rl <RATE> : Set the max request rate per second (1-50)\n";
cout << " -n <INTERFACE> : Specify the network interface to use\n";
cout << " -o <OUTPUT> : Specify the output file path or filename (.txt file)\n";
cout << " -h, -help : Show this help message\n";
cout << "=============================================================\n";
return 0;
}
for (int i = 1; i < argc; ++i) {
string arg = argv[i];
if (arg == "-u" && i + 1 < argc) {
url = argv[++i];
if (!isValidUrl(url)) {
say("Invalid URL. Please provide a valid URL starting with http:// or https://.", "err");
return 1;
}
}
else if (arg == "-p" && i + 1 < argc) {
port = argv[++i];
if (!isValidPort(port)) {
say("Invalid port. Please provide a valid port number between 1 and 65535.", "err");
return 1;
}
}
else if (arg == "-excl" && i + 1 < argc) {
string extensions = argv[++i];
size_t pos = 0;
while ((pos = extensions.find(',')) != std::string::npos) {
config::excludedExtensions.push_back(extensions.substr(0, pos));
extensions.erase(0, pos + 1);
}
if (!extensions.empty()) {
config::excludedExtensions.push_back(extensions);
}
dbg("Excluded extensions:");
for (const auto& ext : config::excludedExtensions) {
dbg(" - " + ext);
}
}
else if (arg == "-t" && i + 1 < argc) {
tmout = argv[++i];
try {
long timeout = std::stol(tmout);
if (timeout < 500 || timeout > 10000) {
say("Timeout must be between 500 and 10000 milliseconds.", "err");
return 1;
}
config::defaultTimeout = timeout;
dbg("Timeout set to " + to_string(config::defaultTimeout) + " milliseconds");
}
catch (const std::invalid_argument&) {
say("Invalid timeout value. Please provide a valid number.", "err");
return 1;
}
catch (const std::out_of_range&) {
say("Timeout value out of range. Please provide a value between 500 and 10000 milliseconds.", "err");
return 1;
}
}
else if (arg == "-ua" && i + 1 < argc) {
ua = argv[++i];
if (ua == "random" || ua == "r" || ua == "rand") {
config::ua = "rand";
}
else if (!ua.empty()) {
config::ua = ua;
}
else {
config::ua = "default";
}
}
else if (arg == "-dbg") {
config::debug = true;
}
else if (arg == "-tr" && i + 1 < argc) {
threads = argv[++i];
try {
int numThreads = std::stoi(threads);
if (numThreads < 1 || numThreads > 200) {
say("Number of threads must be between 1 and 200.", "err");
return 1;
}
config::numThreads = numThreads;
dbg("Number of threads set to " + to_string(config::numThreads));
}
catch (const std::invalid_argument&) {
say("Invalid number of threads. Please provide a valid number.", "err");
return 1;
}
catch (const std::out_of_range&) {
say("Number of threads out of range. Please provide a value between 1 and 32.", "err");
return 1;
}
}
else if (arg == "-rl" && i + 1 < argc) {
rate = argv[++i];
try {
int nrate = std::stoi(rate);
if (nrate < 1 || nrate > 50) {
say("Rate must be between 1 and 50.", "err");
return 1;
}
config::maxrps = nrate;
dbg("Number of rq/s set to " + to_string(config::maxrps));
}
catch (const std::invalid_argument&) {
say("Invalid rate value. Please provide a valid number.", "err");
return 1;
}
catch (const std::out_of_range&) {
say("Number of rq/s out of range. Please provide a value between 1 and 50.", "err");
return 1;
}
}
else if (arg == "-n" && i + 1 < argc) {
networkInterface = argv[++i];
config::network_interface = networkInterface;
dbg("Network interface set to " + config::network_interface);
}
else if (arg == "-o" && i + 1 < argc) {
outputPath = argv[++i];
if (outputPath.empty() || outputPath.find(".txt") == std::string::npos) {
say("Invalid output file. Please provide a valid .txt file.", "err");
return 1;
}
if (outputPath.find("/") == std::string::npos && outputPath.find("\\") == std::string::npos) {
std::string currentPath = std::filesystem::current_path().string();
config::outputpath = currentPath + "/" + outputPath;
}
else {
config::outputpath = outputPath;
}
dbg("Output path set to: " + config::outputpath);
}
else {
say("Unknown or malformed argument: " + arg, "err");
return 1;
}
}
if (config::outputpath.empty()) {
setOutputPath();
}
if (url.empty()) {
say("The -u argument (URL) is required.", "err");
return 1;
}
dbg("Parsing URL: " + url);
string protocol, host, path;
parseUrl(url, protocol, host, path);
target::protocol = protocol;
target::host = host;
target::port = port;
target::startingPath = path;
dbg("Parsed URL details: Protocol = " + protocol + ", Host = " + host + ", Port = " + port + ", Path = " + path);
if (target::port == "80" && target::protocol == "https") target::port = "443";
if (target::port == "80" || target::port == "443") {
target::targetUrl = protocol + "://" + host;
}
else {
target::targetUrl = protocol + "://" + host + ":" + port;
}
dbg("Constructed target URL: " + target::targetUrl);
while (true) {
say("Checking if " + target::targetUrl + target::startingPath + " is alive...");
WebRequestResult result = performWebRequest(target::targetUrl + target::startingPath, config::defaultTimeout);
if (!result.status) {
say("Your target is dead!", "err");
dbg("Target did not respond.");
return 1;
}
dbg("Dumping request result...");
printRequestDump(result);
if (result.statusCode >= 300 && result.statusCode < 400) {
if (!isValidUrl(result.redirectUrl)) {
say("Invalid redirection URL, can't follow!", "err");
dbg("Invalid redirection URL detected: " + result.redirectUrl);
return 1;
}
string follow_input = say("Want to follow (" + result.redirectUrl + ") and continue? (y/n)", "get");
dbg("User input for redirection follow: " + follow_input);
if (!(follow_input == "y" || follow_input == "Y" || follow_input == "Yes" || follow_input == "yes")) {
say("Not following redirection...", "err");
dbg("Redirection not followed.");
return 0;
}
string protocol_new, host_new, path_new;
parseUrl(result.redirectUrl, protocol_new, host_new, path_new);
target::protocol = protocol_new;
target::host = host_new;
target::startingPath = path_new;
dbg("Parsed redirection URL: Protocol = " + protocol_new + ", Host = " + host_new + ", Path = " + path_new);
if (target::port == "80" || target::port == "443") {
target::targetUrl = protocol_new + "://" + host_new;
}
else {
target::targetUrl = protocol_new + "://" + host_new + ":" + target::port;
}
dbg("Constructed new target URL after redirection: " + target::targetUrl);
}
else if (result.statusCode < 200 || result.statusCode >= 300) {
say("Request failed based on status code.", "err");
dbg("Request failed with status code: " + to_string(result.statusCode));
return 0;
}
else {
say("Target alive, let's get started...");
dbg("Target responded successfully with status code: " + to_string(result.statusCode));
break;
}
}
if (target::startingPath == "" || target::startingPath == " ") target::startingPath = "/";
if (config::maxrps > 5) {
bool clean = probeTarget(target::targetUrl + target::startingPath);
if (clean) {
string start = say("Probing finished, start enumaration? (y/n)", "get");
if (!(start == "y" || start == "Y" || start == "Yes" || start == "yes")) {
say("Enumaration aborted!", "err");
return 0;
}
}
else {
say("Ratelimit detected, it is adviced to wait a few seconds... (press enter)", "get");
string start = say("Probing finished, start enumaration? (y/n)", "get");
if (!(start == "y" || start == "Y" || start == "Yes" || start == "yes")) {
say("Enumaration aborted!", "err");
return 0;
}
}
}
calcAttackVector();
crawlLinks();
return 0;
}