-
Notifications
You must be signed in to change notification settings - Fork 14
/
msfvenom_bc_generator.rb
134 lines (107 loc) · 3.67 KB
/
msfvenom_bc_generator.rb
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
#!/usr/bin/env ruby
# -*- coding: binary -*-
# created by @nopernik
#
# this file should be run from metasploit-framwork installation path
#
msfbase = __FILE__
while File.symlink?(msfbase)
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
end
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), 'lib')))
require 'msfenv'
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
require 'msf/base'
def init_framework(create_opts={})
create_opts[:module_types] ||= [
::Msf::MODULE_PAYLOAD, ::Msf::MODULE_ENCODER, ::Msf::MODULE_NOP
]
@framework = ::Msf::Simple::Framework.create(create_opts.merge('DisableDatabase' => true))
end
def framework
return @framework if @framework
init_framework
@framework
end
if __FILE__ == $0
$stdout.puts ' '
$stdout.puts "[+] Collecting output formats"
formats = ::Msf::Util::EXE.to_executable_fmt_formats + ::Msf::Simple::Buffer.transform_formats
formats = formats.join(' ')
$stdout.puts "[+] Collecting payloads"
init_framework(:module_types => [ ::Msf::MODULE_PAYLOAD ])
tbl = []
framework.payloads.each_module { |name|
tbl += [ "\t"+name+" \\\n" ]
}
payloads = tbl.join('')
tbl = []
$stdout.puts "[+] Collecting encoders"
init_framework(:module_types => [ ::Msf::MODULE_ENCODER ])
framework.encoders.each_module { |name|
tbl += [ "\t"+name+" \\\n" ]
}
encoders = tbl.join('')
tbl = []
$stdout.puts "[+] Collecting nops"
init_framework(:module_types => [ ::Msf::MODULE_NOP ])
framework.nops.each_module { |name|
tbl += [ "\t"+name+" \\\n" ]
}
nops = tbl.join('')
$stdout.puts "[+] Generating bash_completion file"
comp = '
# bash completion for msfvenom by Korznikov Alexander
_msfvenom()
{
local cur prev
COMPREPLY=()
cur=`_get_cword`
prev=`_get_pword`
case $prev in
-f|--format)
COMPREPLY=( $( compgen -W \' %s \' -- "$cur" ) )
return 0
;;
-e|--encoder)
COMPREPLY=( $( compgen -W \' %s \' -- "$cur" ) )
return 0
;;
-p|--payload)
COMPREPLY=( $( compgen -W \' %s \' -- "$cur" ) )
return 0
;;
esac
if [[ "$cur" == * ]]; then
COMPREPLY=( $( compgen -W \' -p --payload -l --list -n --nopsled -f --format -e --encoder \
-a --arch --platform -s --space -b --bad-chars -i --iterations \
-c --add-code -x --template -k --keep --payload-options -o \
--out -v --var-name -h --help --help-formats \' -- "$cur" ) )
onlyonce=\' -p --payload -l --list -n --nopsled -f --format -e --encoder \
-a --arch --platform -s --space -b --bad-chars -i --iterations \
-c --add-code -x --template -k --keep --payload-options -o \
--out -v --var-name -h --help --help-formats \'
COMPREPLY=( $( \
(while read -d \' \' i; do
[[ -z "$i" || "${onlyonce/ ${i%%%% *} / }" == "$onlyonce" ]] &&
continue
# flatten array with spaces on either side,
# otherwise we cannot grep on word boundaries of
# first and last word
COMPREPLY=" ${COMPREPLY[@]} "
# remove word from list of completions
COMPREPLY=( ${COMPREPLY/ ${i%%%% *} / } )
done
printf \'%%s \' "${COMPREPLY[@]}") <<<"${COMP_WORDS[@]}"
) )
# else
# _filedir
fi
} &&
complete -F _msfvenom msfvenom
' % [formats, encoders, payloads]
$stdout.puts "[+] Writing out /etc/bash_completion.d/msfvenom"
File.write('/etc/bash_completion.d/msfvenom', comp)
$stdout.puts "[+] Done. Open a new terminal and type msfvenom TABTAB :)"
exit(0)
end