复制附录A到~/.oh-my-zsh/custom/plugins/msfvenom文件夹下(注:没有msfvenom目录,创建即可)

    1. /root/.ohmyzsh/custom/plugins/msfvenom
    2. root@John:~/.ohmyzsh/custom/plugins/msfvenom# ls
    3. _msfvenom

    编辑~/.zshrc文件:

    1. root@John:~# nano ~/.zshrc
    2. root@John:~# cat ~/.zshrc
    3. plugins=(msfvenom)

    第三十课:解决msfvenom命令自动补全 - 图1

    效果如下:

    附录A:

    1. #compdef msfvenom
    2. #autoload
    3. #
    4. # zsh completion for msfvenom in Metasploit Framework Project (https://www.metasploit.com)
    5. #
    6. # github: https://github.com/Green‐m/msfvenom‐zsh‐completion
    7. #
    8. # author: Green‐m (greenm.xxoo@gmail.com)
    9. #
    10. # license: GNU General Public License v3.0
    11. #
    12. # Copyright (c) 2018, Green‐m
    13. # All rights reserved.
    14. #
    15. VENOM_CACHE_FILE=~/.zsh/venomcache
    16. venomclearcache() {
    17. rm $VENOM_CACHE_FILE
    18. }
    19. venomcachepayloads() {
    20. if [ x "$(command ‐v msfvenom)" ]
    21. then
    22. VENOM="msfvenom"
    23. elif [ n "$_comp_command1" ]
    24. then
    25. VENOM=$_comp_command1
    26. else
    27. echo "Cound not find msfvenom path in system env, please run msfvenom with path."
    28. fi
    29. if [[ ! d ${VENOM_CACHE_FILE:h} ]]; then
    30. mkdir p ${VENOM_CACHE_FILE:h}
    31. fi
    32. if [[ ! f $VENOM_CACHE_FILE ]]; then
    33. echo n "(...caching Metasploit Payloads...)"
    34. $VENOM ‐‐list payload|grep e "^.*\/" | awk '{print $1}' >>
    35. $VENOM_CA CHE_FILE
    36. fi
    37. }
    38. _msfvenom() {
    39. local curcontext="$curcontext" state line
    40. typeset A opt_args
    41. _arguments C \
    42. '(‐h ‐‐help)'{‐h,‐‐help}'[show help]' \
    43. '(‐l ‐‐list)'{‐l,‐‐list}'[List all modules for type. Types are: paylo
    44. ads, encoders, nops, platforms, archs, encrypt, formats, all]' \
    45. '(‐p ‐‐payload)'{‐p,‐‐payload}'[Payload to use (‐‐list payloads to list,
    46. ‐‐list‐options for arguments). Specify ‐ or STDIN for custom]' \
    47. '(‐‐list‐options)‐‐list‐options[List ‐‐payload <value> standard, adva
    48. nced and evasion options]' \
    49. '(‐f ‐‐format)'{‐f,‐‐format}'[Output format (use ‐‐list formats to li
    50. st)]' \
    51. '(‐e ‐‐encoder)'{‐e,‐‐encoder}'[The encoder to use (use ‐‐list encoders
    52. to list)]' \
    53. '(‐‐smallest)‐‐smallest[Generate the smallest possible payload using all
    54. available encoders]' \
    55. '(‐‐encrypt)‐‐encrypt[The type of encryption or encoding to apply to the
    56. shellcode (use ‐‐list encrypt to list)]' \
    57. '(‐‐encrypt‐key)‐‐encrypt‐key[A key to be used for ‐‐encrypt]' \
    58. '(‐‐encrypt‐iv)‐‐encrypt‐iv[An initialization vector for ‐‐encrypt]' \
    59. '(‐a ‐‐arch)'{‐a,‐‐arch}'[the architecture to use for ‐‐payload and ‐
    60. ‐encoders (use ‐‐list archs to list)]' \
    61. '(‐‐platform)‐‐platform[The platform for ‐‐payload (use ‐‐list platfo rms
    62. to list)]' \
    63. '(‐o ‐‐out)'{‐o,‐‐out}'[Save the payload to a file]' \
    64. '(‐b ‐‐bad‐chars)'{‐b,‐‐badchars}'[Characters to avoid example: "\x0
    65. 0\xff"]' \
    66. '(‐n ‐‐nopsled)'{‐n,‐‐nopsled}'[Prepend a nopsled of \[length\] size on
    67. to the payload]' \
    68. '(‐‐encoder‐space)‐‐encoder‐space[The maximum size of the encoded pay
    69. load (defaults to the ‐s value)]' \
    70. '(‐i ‐‐iterations)'{‐i,‐‐iterations}'[The number of times to encode t he
    71. payload]' \
    72. '(‐c ‐‐add‐code)'{‐c,‐‐addcode}'[Specify an additional win32 shellcode
    73. file to include]' \
    74. '(‐x ‐‐template)'{‐x,‐‐template}'[Specify a custom executable file to use
    75. as a template]' \
    76. '(‐k ‐‐keep)'{‐k,‐‐keep}'[Preserve the ‐‐template behaviour and inject
    77. the payload as a new thread]' \
    78. '(‐v ‐‐var‐name)'{‐v,‐‐varname}'[Specify a custom variable name to use
    79. for certain output formats]' \
    80. '(‐t ‐‐timeout)'{‐t,‐‐timeout}'[The number of seconds to wait when re
    81. ading the payload from STDIN (default 30, 0 to disable)]' \
    82. '*: :($(__msfvenom_options))' && ret=0
    83. lastword=${words[${#words[@]}‐1]}
    84. case "$lastword" in
    85. (‐p|‐‐payload)
    86. _values 'payload' $(__msfvenom_payloads)
    87. ;;
    88. (‐l|‐‐list)
    89. local lists=('payloads' 'encoders' 'nops' 'platforms' 'archs' 'encrypt'
    90. 'formats' 'all')
    91. _values 'list' $lists
    92. ;;
    93. (‐encrypt)
    94. local encrypts=('aes256' 'base64' 'rc4' 'xor')
    95. _values 'encrypt' $encrypts
    96. ;;
    97. (‐a|‐‐arch)
    98. _values 'arch' $(__msfvenom_archs)
    99. ;;
    100. (‐platform)
    101. _values 'platform' $(__msfvenom_platforms)
    102. ;;
    103. (‐f|‐‐format)
    104. _values 'format' $(__msfvenom_formats)
    105. ;;
    106. (‐e|‐‐encoder)
    107. _values 'encoder' $(__msfvenom_encoders)
    108. (‐o|‐‐out|‐x|‐‐template|‐c|‐‐addcode)
    109. _files
    110. ;;
    111. (*)
    112. ;;
    113. esac
    114. }
    115. __msfvenom_payloads(){
    116. local msf_payloads
    117. # we cache the list of packages (originally from the macports plugin)
    118. venomcachepayloads
    119. msf_payloads=`cat $VENOM_CACHE_FILE`
    120. for line in $msf_payloads; do
    121. echo "$line"
    122. done
    123. }
    124. __msfvenom_archs(){
    125. local archs
    126. archs=(
    127. 'aarch64'
    128. 'armbe'
    129. 'armle'
    130. 'cbea'
    131. 'cbea64'
    132. 'cmd'
    133. 'dalvik'
    134. 'firefox'
    135. 'java'
    136. 'mips'
    137. 'mips64'
    138. 'mips64le'
    139. 'mipsbe'
    140. 'mipsle'
    141. 'nodejs'
    142. 'php'
    143. 'ppc'
    144. 'ppc64'
    145. 'ppc64le'
    146. 'ppce500v2'
    147. 'python'
    148. 'r'
    149. 'ruby'
    150. 'sparc'
    151. 'sparc64'
    152. 'tty'
    153. 'x64'
    154. 'x86'
    155. 'x86_64'
    156. 'zarch'
    157. )
    158. for line in $archs; do
    159. echo "$line"
    160. done
    161. }
    162. __msfvenom_encoders(){
    163. local encoders
    164. encoders=(
    165. 'cmd/brace'
    166. 'cmd/echo'
    167. 'cmd/generic_sh'
    168. 'cmd/ifs'
    169. 'cmd/perl'
    170. 'cmd/powershell_base64'
    171. 'cmd/printf_php_mq'
    172. 'generic/eicar'
    173. 'generic/none'
    174. 'mipsbe/byte_xori'
    175. 'mipsbe/longxor'
    176. 'mipsle/byte_xori'
    177. 'mipsle/longxor'
    178. 'php/base64'
    179. 'ppc/longxor'
    180. 'ppc/longxor_tag'
    181. 'ruby/base64'
    182. 'sparc/longxor_tag'
    183. 'x64/xor'
    184. 'x64/xor_dynamic'
    185. 'x64/zutto_dekiru'
    186. 'x86/add_sub'
    187. 'x86/alpha_mixed'
    188. 'x86/alpha_upper'
    189. 'x86/avoid_underscore_tolower'
    190. 'x86/avoid_utf8_tolower'
    191. 'x86/bloxor'
    192. 'x86/bmp_polyglot'
    193. 'x86/call4_dword_xor'
    194. 'x86/context_cpuid'
    195. 'x86/context_stat'
    196. 'x86/context_time'
    197. 'x86/countdown'
    198. 'x86/fnstenv_mov'
    199. 'x86/jmp_call_additive'
    200. 'x86/nonalpha'
    201. 'x86/nonupper'
    202. 'x86/opt_sub'
    203. 'x86/service'
    204. 'x86/shikata_ga_nai'
    205. 'x86/single_static_bit'
    206. 'x86/unicode_mixed'
    207. 'x86/unicode_upper'
    208. 'x86/xor_dynamic'
    209. )
    210. for line in $encoders; do
    211. echo "$line"
    212. done
    213. }
    214. __msfvenom_platforms(){
    215. local platforms
    216. platforms=(
    217. 'aix'
    218. 'android'
    219. 'apple_ios'
    220. 'bsd'
    221. 'bsdi'
    222. 'cisco'
    223. 'firefox'
    224. 'freebsd'
    225. 'hardware'
    226. 'hpux'
    227. 'irix'
    228. 'javascript'
    229. 'juniper'
    230. 'linux'
    231. 'mainframe'
    232. 'multi'
    233. 'netbsd'
    234. 'netware'
    235. 'nodejs'
    236. 'openbsd'
    237. 'osx'
    238. 'php'
    239. 'python'
    240. 'r'
    241. 'ruby'
    242. 'solaris'
    243. 'unix'
    244. 'unknown'
    245. 'windows'
    246. )
    247. for line in $platforms; do
    248. echo "$line"
    249. done
    250. }
    251. __msfvenom_formats(){
    252. local formats
    253. formats=(
    254. 'asp'
    255. 'aspx'
    256. 'aspx‐exe'
    257. 'axis2'
    258. 'dll'
    259. 'elf'
    260. 'elf‐so'
    261. 'exe'
    262. 'exe‐only'
    263. 'exe‐service'
    264. 'exe‐small'
    265. 'hta‐psh'
    266. 'jar'
    267. 'jsp'
    268. 'loop‐vbs'
    269. 'macho'
    270. 'msi'
    271. 'msi‐nouac'
    272. 'osx‐app'
    273. 'psh'
    274. 'psh‐cmd'
    275. 'psh‐net'
    276. 'psh‐reflection'
    277. 'vba'
    278. 'vba‐exe'
    279. 'vba‐psh'
    280. 'vbs'
    281. 'war'
    282. 'bash'
    283. 'c'
    284. 'csharp'
    285. 'dw'
    286. 'dword'
    287. 'hex'
    288. 'java'
    289. 'js_be'
    290. 'js_le'
    291. 'num'
    292. 'perl'
    293. 'pl'
    294. 'powershell'
    295. 'ps1'
    296. 'py'
    297. 'python'
    298. 'raw'
    299. 'rb'
    300. 'ruby'
    301. 'sh'
    302. 'vbapplication'
    303. 'vbscript'
    304. )
    305. for line in $formats; do
    306. echo "$line"
    307. done
    308. }
    309. # For most common options, not accurately
    310. __msfvenom_options(){
    311. local options
    312. options=(
    313. LHOST= \
    314. LPORT= \
    315. EXITFUNC= \
    316. RHOST= \
    317. StageEncoder= \
    318. AutoLoadStdapi= \
    319. AutoRunScript= \
    320. AutoSystemInfo= \
    321. AutoVerifySession= \
    322. AutoVerifySessionTimeout= \
    323. EnableStageEncoding= \
    324. EnableUnicodeEncoding= \
    325. HandlerSSLCert= \
    326. InitialAutoRunScript= \
    327. PayloadBindPort= \
    328. PayloadProcessCommandLine= \
    329. PayloadUUIDName= \
    330. PayloadUUIDRaw= \
    331. PayloadUUIDSeed= \
    332. PayloadUUIDTracking= \
    333. PrependMigrate= \
    334. PrependMigrateProc= \
    335. ReverseAllowProxy= \
    336. ReverseListenerBindAddress= \
    337. ReverseListenerBindPort= \
    338. ReverseListenerComm= \
    339. ReverseListenerThreaded= \
    340. SessionCommunicationTimeout= \
    341. SessionExpirationTimeout= \
    342. SessionRetryTotal= \
    343. SessionRetryWait= \
    344. StageEncoder= \
    345. StageEncoderSaveRegisters= \
    346. StageEncodingFallback= \
    347. StagerRetryCount= \
    348. StagerRetryWait= \
    349. VERBOSE= \
    350. WORKSPACE=
    351. )
    352. echo $options
    353. }