/
beanshooter
391 lines (297 loc) · 12.3 KB
/
beanshooter
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
#!/bin/bash
type _comp_filter &> /dev/null || return
type _comp_contains &> /dev/null || return
type _comp_filter_shorts &> /dev/null || return
type _comp_get_parameter &> /dev/null || return
function _comp_beanstart()
{
if [[ $cur == -* ]]; then
opts="--help"
else
opts="$1"
fi
_upvars -v opts "$opts"
}
function _comp_beanoption()
{
if [[ $cur == -* ]] || [[ $args -ge $1 ]]; then
return 0
fi
return 1
}
function _beanshooter()
{
local cur prev words cword opts arg args gadgets value_options operations sasl_mechanisms tonka_actions mlet_actions
local tomcat_actios mbeans mbean_actions general_opts conn_opts stager_opts unguessable file_like diagnostic_actions
local hotspot_actions recorder_actions common_three auth_opts
_init_completion || return
file_like="--jar-file --config --plugin --export-dir --export-mlet --export-jar --username-file --password-file --yso --output-file"
file_like="$file_like --signature-file"
unguessable="--class-name --object-name --bound-name --objid-server --objid-connection --username --password --stager-port --threads"
unguessable="$unguessable --class-filter --obj-filter --cwd --env --signature --shell --jolokia-proxy --jolokia-proxy-user"
unguessable="$unguessable --jolokia-proxy-password --jolokia-endpoint --lookup"
value_options="$file_like $unguessable --stager-url --stager-host --sasl"
_count_args "" "@(${value_options// /|})"
_comp_get_parameter 3
COMPREPLY=()
gadgets="BeanShell1 C3P0 Clojure CommonsBeanutils1 CommonsCollections1 CommonsCollections2"
gadgets="$gadgets CommonsCollections3 CommonsCollections4 CommonsCollections5 CommonsCollections6"
gadgets="$gadgets CommonsCollections7 FileUpload1 Groovy1 Hibernate1 Hibernate2 JBossInterceptors1"
gadgets="$gadgets JRMPClient JRMPListener JSON1 JavassistWeld1 Jdk7u21 Jython1 MozillaRhino1 MozillaRhino2"
gadgets="$gadgets Myfaces1 Myfaces2 ROME Spring1 Spring2 URLDNS Vaadin1 Wicket1"
operations="attr brute deploy enum info invoke list serial stager undeploy diagnostic hotspot mlet recorder tomcat tonka jolokia model standard"
sasl_mechanisms="plain digest cram gssapi ntlm"
general_opts="--help --config --verbose --plugin --no-color --stack-trace"
conn_opts="--follow --ssl --jmxmp --sasl --jolokia --jolokia-proxy --jolokia-proxy-user --jolokia-proxy-password --jolokia-endpoint"
target_opts="--bound-name --objid-server --objid-connection"
stager_opts="--stager-host --stager-port --no-stager --stager-url"
common_three="${general_opts} ${conn_opts} ${target_opts}"
auth_opts="--username --password"
mbeans="diagnostic hotspot mlet recorder tomcat tonka "
mbean_actions="attr deploy info invoke stats status undeploy"
tonka_actions="version exec execarray shell upload download export ${mbean_actions}"
mlet_actions="load ${mbean_actions}"
tomcat_actions="dump list write ${mbean_actions}"
diagnostic_actions="read load logfile nolog cmdline props ${mbean_actions}"
hotspot_actions="dump list get set ${mbean_actions}"
recorder_actions="new start stop dump save ${mbean_actions}"
if [[ $cword -eq 1 ]]; then
_comp_beanstart "$operations"
elif [[ $prev == "--sasl" ]]; then
opts="${sasl_mechanisms}"
elif [[ $prev == "--stager-host" ]]; then
_ip_addresses
return 0
elif [[ $prev == "--stager-url" ]]; then
opts="http:// file:// ftp://"
compopt -o nospace
elif _comp_contains "$file_like" $prev; then
_filedir
return 0
elif _comp_contains "$unguessable" $prev; then
return 0
elif [[ ${words[1]} == "attr" ]] && _comp_beanoption 9; then
opts="$auth_opts"
opts="$opts --type"
opts="$opts $common_three"
elif [[ ${words[1]} == "brute" ]] && _comp_beanoption 4; then
opts="--threads"
opts="$opts $auth_opts"
opts="$opts --first"
opts="$opts --username-file"
opts="$opts --password-file"
opts="$opts --no-progress"
opts="$opts --bound-name"
opts="$opts --objid-server"
opts="$opts $conn_opts"
opts="$opts $general_opts"
elif [[ ${words[1]} == "invoke" ]] && _comp_beanoption 7; then
opts="--signature"
opts="$opts --no-wrap"
opts="$opts $auth_opts"
opts="$opts $common_three"
elif [[ ${words[1]} == "jolokia" ]] && _comp_beanoption 6; then
opts="--lookup"
opts="$opts --ldap"
opts="$opts --follow"
opts="$opts --ssl"
opts="$opts --jolokia"
opts="$opts --jolokia-endpoint"
opts="$opts $auth_opts"
opts="$opts $general_opts"
elif [[ ${words[1]} == "model" ]] && _comp_beanoption 7; then
opts="--all-methods"
opts="$opts --signature"
opts="$opts --signature-file"
opts="$opts $auth_opts"
opts="$opts $common_three"
elif [[ ${words[1]} == "standard" ]]; then
if [[ $cur == -* ]] || [[ $args -ge 6 ]] || [[ $args -ge 5 && ${words[4]} == "tonka" ]]; then
opts="$auth_opts"
opts="$opts $common_three"
if [[ ${words[4]} == "exec" ]]; then
opts="$opts --exec-array"
fi
elif [[ $args -eq 4 ]]; then
opts="exec tonka upload"
elif [[ $args -eq 5 ]] && [[ $prev == "upload" ]]; then
compopt -o nospace
_filedir
return
else
return 0
fi
elif [[ ${words[1]} == "deploy" ]] && _comp_beanoption 6; then
opts="$auth_opts"
opts="$opts --jar-file"
opts="$opts $stager_opts"
opts="$opts $common_three"
elif [[ ${words[1]} == "enum" ]] && _comp_beanoption 4; then
opts="$auth_opts"
opts="$opts $common_three"
elif [[ ${words[1]} == "list" ]] && _comp_beanoption 4; then
opts="$auth_opts"
opts="$opts --class-filter"
opts="$opts --obj-filter"
opts="$opts $common_three"
elif [[ ${words[1]} == "serial" ]] && _comp_beanoption 6; then
opts="--preauth"
opts="$opts --no-canary"
opts="$opts --yso"
opts="$opts $auth_opts"
opts="$opts $conn_opts"
opts="$opts $target_opts"
opts="$opts $general_opts"
elif [[ ${words[1]} == "serial" ]] && [[ $args -eq 4 ]]; then
opts="$gadgets"
elif [[ ${words[1]} == "stager" ]]; then
if [[ $cur == -* ]] || [[ $args -ge 5 ]]; then
opts="--class-name"
opts="$opts --jar-file"
opts="$opts --object-name"
opts="$opts --stager-url"
opts="$opts $general_opts"
elif [[ $args -eq 2 ]]; then
_ip_addresses
return 0
elif [[ $args -eq 4 ]]; then
opts="tonka custom"
else
return 0
fi
elif [[ ${words[1]} == "undeploy" ]] && _comp_beanoption 5; then
opts="$auth_opts"
opts="$opts $common_three"
elif _comp_contains "${mbeans}" "${words[1]}"; then
opts="$opts $auth_opts"
opts="$opts $common_three"
if [[ ${words[2]} == "deploy" ]] && _comp_beanoption 5; then
opts="$opts $stager_opts"
elif _comp_contains "info status undeploy" "${words[2]}" && _comp_beanoption 5; then
:
elif [[ ${words[2]} == "invoke" ]] && _comp_beanoption 5; then
opts="$opts --signature"
opts="$opts --no-wrap"
elif [[ ${words[2]} == "attr" ]] && _comp_beanoption 7; then
opts="$opts --type"
elif [[ ${words[2]} == "stats" ]] && _comp_beanoption 3; then
opts="$general_opts"
elif [[ ${words[1]} == "tonka" ]]; then
if [[ $cword -eq 2 ]]; then
_comp_beanstart "$tonka_actions"
elif [[ ${words[2]} == "exec" ]] && _comp_beanoption 6; then
opts="$opts --background"
opts="$opts --cwd"
opts="$opts --env"
opts="$opts --hex"
opts="$opts --output-file"
opts="$opts --raw"
opts="$opts --shell"
elif [[ ${words[2]} == "execarray" ]] && _comp_beanoption 6; then
opts="$opts --background"
opts="$opts --cwd"
opts="$opts --env"
opts="$opts --hex"
opts="$opts --output-file"
opts="$opts --raw"
elif [[ ${words[2]} == "shell" ]] && _comp_beanoption 6; then
opts="$opts --shell"
elif _comp_contains "upload download" ${words[2]} && _comp_beanoption 7; then
:
elif _comp_contains "upload download" ${words[2]} && [[ $args -eq 5 || $args -eq 6 ]]; then
_filedir
return
elif [[ ${words[2]} == "export" ]] && _comp_beanoption 3; then
opts="--export-dir"
opts="$opts --export-jar"
opts="$opts --export-mlet"
opts="$opts --stager-url"
opts="$opts $general_opts"
else
return 0
fi
elif [[ ${words[1]} == "mlet" ]]; then
if [[ $cword -eq 2 ]]; then
_comp_beanstart "$mlet_actions"
elif [[ ${words[2]} == "load" ]]; then
if _comp_beanoption 7; then
opts="$opts --class-name"
opts="$opts --jar-file"
opts="$opts --object-name"
opts="$opts --stager-port"
opts="$opts --stager-host"
opts="$opts --no-stager"
elif [[ $args -eq 5 ]]; then
opts="tonka custom"
elif [[ $args -eq 6 ]]; then
opts="http:// file:// ftp://"
compopt -o nospace
else
return 0
fi
else
return 0
fi
elif [[ ${words[1]} == "tomcat" ]]; then
if [[ $cword -eq 2 ]]; then
_comp_beanstart "$tomcat_actions"
elif [[ ${words[2]} == "list" ]] && _comp_beanoption 5; then
:
elif [[ ${words[2]} == "dump" ]] && _comp_beanoption 7; then
:
elif [[ ${words[2]} == "dump" ]] && [[ $args -eq 5 || $args -eq 6 ]]; then
_filedir
return 0
elif [[ ${words[2]} == "write" ]] && _comp_beanoption 7; then
:
elif [[ ${words[2]} == "write" ]] && [[ $args -eq 5 || $args -eq 6 ]]; then
_filedir
return 0
else
return 0
fi
elif [[ ${words[1]} == "diagnostic" ]]; then
if [[ $cword -eq 2 ]]; then
_comp_beanstart "$diagnostic_actions"
elif _comp_contains "read load logfile nolog cmdline props" ${words[2]} && _comp_beanoption 6; then
:
if [[ ${words[2]} == "read" ]]; then
opts="$opts --raw"
fi
else
return 0
fi
elif [[ ${words[1]} == "hotspot" ]]; then
if [[ $cword -eq 2 ]]; then
_comp_beanstart "$hotspot_actions"
elif [[ ${words[2]} == "list" ]] && _comp_beanoption 5; then
:
elif _comp_contains "dump get" ${words[2]} && _comp_beanoption 6; then
opts="$opts --live"
elif [[ ${words[2]} == "set" ]] && _comp_beanoption 7; then
:
else
return 0
fi
elif [[ ${words[1]} == "recorder" ]]; then
if [[ $cword -eq 2 ]]; then
_comp_beanstart "$recorder_actions"
elif [[ ${words[2]} == "new" ]] && _comp_beanoption 5; then
:
elif _comp_contains "start stop" ${words[2]} && _comp_beanoption 6; then
:
elif _comp_contains "dump save" ${words[2]} && _comp_beanoption 7; then
:
else
return 0
fi
fi
else
return 0
fi
_comp_filter "opts"
_comp_filter_shorts "opts"
mapfile -t COMPREPLY < <(compgen -W "${opts}" -- "${cur}")
return 0
}
complete -F _beanshooter beanshooter