-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdirp
executable file
·299 lines (230 loc) · 6.73 KB
/
dirp
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
288
289
290
291
292
293
294
295
296
297
#!/usr/bin/env node
const Promise = require("bluebird");
const Sugar = require("sugar");
const _progress = require('cli-progress');
const glob = require("glob");
const globals = require("./modules/globals");
Sugar.extend();
const modifyExtPaths = require('./modules/modifyExtPaths');
const lowercase = require('./modules/lowercase');
let globalResults = require('./modules/discoveries.js');
let globalBar;
const log = console.log;
let http_enum;
try {
http_enum = require("./modules/http_enum");
} catch (err) {
}
var argv = require("yargs").argv,
genCustomBackupFiles = require('./modules/customBackupFiles'),
pathsToCheck = [],
color = require("cli-color"),
async = require("async"),
fs = require("fs"),
throttledQueue = require("throttled-queue"),
Table = require('cli-table'),
table = new Table(),
totalChecks = 0,
checkCounter = 0,
rate = 75,
lastPercent = 0,
testResults = [];
(testString = ""),
(debug = false),
(jobs = 0),
(jobsCount = 0),
(test = false),
(count = 0),
(wordDir = require.resolve("cli-color"));
wordDir = wordDir.split("node_modules");
wordDir = wordDir[0];
var dictionaryFile = wordDir + "wordlists/default.txt";
if (argv.input || argv.wordlist || argv.w) {
if (argv.input) {
dictionaryFile = argv.input;
}
else if (argv.wordlist) {
dictionaryFile = argv.wordlist;
}
else {
dictionaryFile = argv.w;
}
}
if (argv.rate) {
rate = parseInt(argv.rate);
}
if (argv.t) {
rate = parseInt(argv.t);
}
if (argv.delay){
rate = 1
}
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
async function prepPaths(payloadArray) {
if (argv.help || argv.h || !argv.u) {
console.log(color.green("\n--[Dirp Examples]--\n"));
console.log("./dirp -u 'https://foo.bar/' --wordlist=/path/to/wordlist.txt (or /path/to/*.txt)");
console.log("./dirp -u 'https://foo.bar/<INSERT>.jsp'");
console.log(
"./dirp -u 'https://foo.bar/' --cookie='sessionid=12345;foo=bar;'"
);
console.log("./dirp -u 'https://foo.bar/' --proxy='http://proxy.host:port'");
//console.log(" '--rate 50 (max number of requests per second - default 250)");
console.log(" -X or --method (use custom HTTP method)");
console.log(" --lowercase (lowercase all paths)");
console.log(" --ext .php (Replace any extensions in your wordlist(s) with a custom value)");
console.log(" --compare Use response comparison to determine status");
console.log(" --threshold [int] (Set threshold for comparison analysis, default 50)");
console.log(" --debug (debug mode and show every request/response)");
console.log();
process.exit(1);
} else if (argv.u) {
if (argv.string) {
testString = argv.string;
}
if (argv.debug) {
debug = true;
}
let customBackups = genCustomBackupFiles(argv.u.split('/')[2]);
payloadArray = payloadArray.reverse().concat(customBackups).reverse();
if (argv.ext) {
payloadArray = await modifyExtPaths(payloadArray, argv.ext);
}
if (argv.lowercase) {
payloadArray = await lowercase(payloadArray);
}
totalChecks = payloadArray.length;
const jobCount = payloadArray.length
console.log(
`\n[*] Preparing to run Dirp with ${dictionaryFile} (%s checks)\n`,
payloadArray.length
);
return payloadArray
}
}
async function dirpPath(checks, recurse, clibar) {
let bar;
if (typeof (recurse) != 'String') {
bar = recurse;
recurse = false;
} else {
bar = clibar;
}
if (!argv.debug) {
bar.start(checks.length, 1);
bar.update(0, {
reqPath: '...',
discoveries: '',
});
}
return Promise.map(checks, function (pay) {
if (recurse) {
pay = `${recurse}/${pay}`;
}
return new Promise(function (resolve) {
resolve(http_enum(argv.u, testString, debug, pay, bar))
})
}, { concurrency: rate })
}
function cleanResults(rawRes) {
return rawRes.filter(function (el) {
return el != null;
});
}
(async function () {
let data;
let payloadArray = [];
try {
let fileGlob = glob.sync(dictionaryFile);
for (i = 0; i < fileGlob.length; i++) {
data = fs.readFileSync(fileGlob[i], "utf8");
data.toString().split("\n")
payloadArray = payloadArray.concat(data.toString().split("\n"));
}
payloadArray = payloadArray.unique();
} catch (e) {
console.log(e);
}
let e = await prepPaths(payloadArray);
let bar = new _progress.Bar({
format: '{bar} {percentage}% ' + '| {value}/{total} | Discovered: {discoveries} ',
barCompleteChar: '\u2588',
forceRedraw: true,
clearOnComplete: true,
barIncompleteChar: '\u2591',
hideCursor: true
});
globalBar = bar;
await globals.initialize();
let results = await dirpPath(e, bar);
var filtered = cleanResults(results);
await asyncForEach(filtered, async (result) => {
if (!result.path.includes('//') && result.path != '/' && result.path.length > 2) {
pathsToCheck.push(result.path);
}
})
if (argv.recurse || argv.r || argv.recursive) {
await asyncForEach(pathsToCheck, async (num) => {
let results = await dirpPath(e, num, bar);
var filtered = cleanResults(results);
for (i = 0; i < filtered.length; i++) {
if (!filtered[i].path.includes('//') && filtered[i].path.length > 2) {
pathsToCheck.push(filtered[i].path)
}
}
})
} else {
if (!argv.debug) {
bar.increment(-1, {
reqPath: '...',
discoveries: '',
});
bar.increment(1, {
reqPath: '...',
discoveries: globalResults.getDiscoveries().length.toString(),
});
bar.stop();
}
}
process.on('exit', function () {
handle();
});
})()
function drawTable() {
var resultsTable = new Table({
head: ['Method', 'Url', 'Length', 'Status'],
style: { compact: true, 'padding-left': 1 }
});
let finalDiscoveries = globalResults.getDiscoveries();
for (i = 0; i < finalDiscoveries.length; i++) {
let resStrSplit = finalDiscoveries[i].split(" ");
resultsTable.push(
[resStrSplit[0], resStrSplit[1], resStrSplit[2], resStrSplit[3]]
);
}
console.log("");
console.log(resultsTable.toString());
}
let hasPrintedResults = false;
async function handle(signal) {
if (signal === "SIGINT") {
globalBar.stop();
//console.log(globalResults.getDiscoveries().join("\n"))
hasPrintedResults = true;
} else {
if (!hasPrintedResults) {
if (argv.table) {
drawTable();
}
hasPrintedResults = true;
}
}
process.exit(0);
}
process.on('SIGINT', handle);
process.on('SIGINT', handle);
process.on('SIGTERM', handle);