-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse.js
164 lines (160 loc) · 4.6 KB
/
parse.js
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
//Arg parser - written from scratch, but this was a good example to learn from:
//https://github.com/eveningkid/args-parser/blob/master/parse.js
//TODO: fix usage of -l flag
const opt = {
named: [
{
'flag': 'l',
'name': 'login',
'description': 'login credentials (username:password)',
'samplevalue': 'username:password'
},
{
'flag': 't',
'name': 'token',
'description': 'existing login token (run localStorage[\'Meteor.loginToken\'] in your browser console)',
'samplevalue': 'abcdef0123465789'
},
{
'flag': 'b',
'name': 'burpfile',
'description': 'Burp file to read from',
'samplevalue': 'app.burp'
},
{
'flag': 'u',
'name': 'urlbase',
'description': 'base URL of application',
'samplevalue': 'https://meteor.example.com/'
},
{
'flag': 'm',
'name': 'messagefile',
'description': 'file with JSON dump of messages (generate with "confusertargets -b burp.burp" or "dumpmessages method unique -b burp.burp")',
'samplevalue': 'messages.json'
},
{
'flag': 'w',
'name': 'wordlist',
'description': 'wordlist for brute forcing methods (./ehf.js methodbuster -w wordlist.txt) or subscriptions (./ehf.js subbuster -w wordlist.txt)',
'samplevalue': 'directories.txt'
},
{
'flag': 'U',
'name': 'username',
'description': 'username for brute forcing passwords (./ehf.js passwordbuster -U admin -w wordlist.txt)',
'samplevalue': 'passwords.txt'
},
{
'flag': 'P',
'name': 'proxy',
'description': 'proxy server for websocket traffic (e.g., -p 127.0.0.1:8080)',
'samplevalue': '127.0.0.1:8080'
},
{
'flag': 'c',
'name': 'concurrency',
'description': 'number of concurrent probes for one probe manager (see also -p/--parallelism; total concurrent messages = concurrency * parallelism)',
'samplevalue': '5'
},
{
'flag': 'p',
'name': 'parallelism',
'description': 'number of parallel probe managers for one brute forcing task (see also -c/--concurrency; total concurrent messages = concurrency * parallelism)',
'samplevalue': '3'
},
{
'flag': 'r',
'name': 'replace',
'description': 'string to replace with fuzzing inputs',
'samplevalue': 'FUZZME'
},
{
'flag': 'L',
'name': 'port',
'description': 'port for harness server to listen on',
'samplevalue': '9010'
},
],
flags: [
{
'flag': 'v',
'name': 'verbose',
'description': 'verbose (use -vv or -vvv for even more output)'
}
]
};
function argParse(args) {
let results = {
pos: []
};
let onlyPositional = false;
let openParam = undefined;
args.forEach((arg) => {
if (onlyPositional) {
results.pos.push(arg);
return;
}
if (openParam !== undefined) {
results[openParam.name] = arg;
openParam = undefined;
return;
}
let ticks = 0;
while (arg.length > ticks && arg[ticks] == '-') {
++ticks;
}
arg = arg.substring(ticks);
if (ticks === 2) {
if (arg === '') {
onlyPositional = true;
return;
}
let namedMatch = opt.named.find((f) => f.name == arg);
if (namedMatch !== undefined) {
results[namedMatch.name] = null;
openParam = namedMatch;
}
}
if (ticks == 1) {
for (var i = 0; i < arg.length; ++i) {
let ch = arg[i];
let flagMatch = opt.flags.find((f) => f.flag == ch);
let namedMatch = opt.named.find((f) => f.flag == ch);
if (flagMatch !== undefined && (namedMatch === undefined || i < arg.length - 1)) {
if (!results.hasOwnProperty(flagMatch.name)) {
results[flagMatch.name] = 0;
}
++results[flagMatch.name];
} else if (namedMatch !== undefined) {
results[namedMatch.name] = null;
openParam = namedMatch;
}
}
} else {
results.pos.push(arg);
}
});
if (openParam !== undefined) {
console.error("Parameter " + openParam.name + " (-" + openParam.flag + ") needs a value");
return null;
}
return results;
}
function required(args, requiredArgs) {
if (typeof requiredArgs == 'string') {
requiredArgs = [requiredArgs];
}
let anyMissing = false;
requiredArgs.forEach((a) => {
if (!args[a]) {
anyMissing = true;
const arg = opt.named.find((x) => x.name == a);
console.error("error: missing argument", arg.name, "(-" + arg.flag + ")");
}
});
if (anyMissing) {
process.exit(1);
}
}
module.exports = {argParse, required};