本课是针对前第1-20课时的msfvenom生成payload的自动补全命令补充。虽msfvenom强大,同样有着非常繁琐的参数,参数强大,意味着会增加工作效率,但它并不像MSF有命令补全功能,故本课吸取前20课经验,自动补全msfvenom的参数。

需要zsh的支持:

  1. root@John:~# cat /etc/shells
  2. # /etc/shells: valid login shells
  3. /bin/sh
  4. /bin/dash
  5. /bin/bash
  6. /bin/rbash
  7. /usr/bin/screen
  8. /bin/zsh
  9. /usr/bin/zsh
  10. /usr/bin/tmux
  11. root@John:~# echo $SHELL
  12. /bin/bash

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

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

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

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

编辑~/.zshrc文件:

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

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

更新:

  1. root@John:~# source ~/.zshrc

效果如下:

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

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

附录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. ;;
  109. (‐o|‐‐out|‐x|‐‐template|‐c|‐‐addcode)
  110. _files
  111. ;;
  112. (*)
  113. ;;
  114. esac
  115. }
  116. __msfvenom_payloads(){
  117. local msf_payloads
  118. # we cache the list of packages (originally from the macports plugin)
  119. venomcachepayloads
  120. msf_payloads=`cat $VENOM_CACHE_FILE`
  121. for line in $msf_payloads; do
  122. echo "$line"
  123. done
  124. }
  125. __msfvenom_archs(){
  126. local archs
  127. archs=(
  128. 'aarch64'
  129. 'armbe'
  130. 'armle'
  131. 'cbea'
  132. 'cbea64'
  133. 'cmd'
  134. 'dalvik'
  135. 'firefox'
  136. 'java'
  137. 'mips'
  138. 'mips64'
  139. 'mips64le'
  140. 'mipsbe'
  141. 'mipsle'
  142. 'nodejs'
  143. 'php'
  144. 'ppc'
  145. 'ppc64'
  146. 'ppc64le'
  147. 'ppce500v2'
  148. 'python'
  149. 'r'
  150. 'ruby'
  151. 'sparc'
  152. 'sparc64'
  153. 'tty'
  154. 'x64'
  155. 'x86'
  156. 'x86_64'
  157. 'zarch'
  158. )
  159. for line in $archs; do
  160. echo "$line"
  161. done
  162. }
  163. __msfvenom_encoders(){
  164. local encoders
  165. encoders=(
  166. 'cmd/brace'
  167. 'cmd/echo'
  168. 'cmd/generic_sh'
  169. 'cmd/ifs'
  170. 'cmd/perl'
  171. 'cmd/powershell_base64'
  172. 'cmd/printf_php_mq'
  173. 'generic/eicar'
  174. 'generic/none'
  175. 'mipsbe/byte_xori'
  176. 'mipsbe/longxor'
  177. 'mipsle/byte_xori'
  178. 'mipsle/longxor'
  179. 'php/base64'
  180. 'ppc/longxor'
  181. 'ppc/longxor_tag'
  182. 'ruby/base64'
  183. 'sparc/longxor_tag'
  184. 'x64/xor'
  185. 'x64/xor_dynamic'
  186. 'x64/zutto_dekiru'
  187. 'x86/add_sub'
  188. 'x86/alpha_mixed'
  189. 'x86/alpha_upper'
  190. 'x86/avoid_underscore_tolower'
  191. 'x86/avoid_utf8_tolower'
  192. 'x86/bloxor'
  193. 'x86/bmp_polyglot'
  194. 'x86/call4_dword_xor'
  195. 'x86/context_cpuid'
  196. 'x86/context_stat'
  197. 'x86/context_time'
  198. 'x86/countdown'
  199. 'x86/fnstenv_mov'
  200. 'x86/jmp_call_additive'
  201. 'x86/nonalpha'
  202. 'x86/nonupper'
  203. 'x86/opt_sub'
  204. 'x86/service'
  205. 'x86/shikata_ga_nai'
  206. 'x86/single_static_bit'
  207. 'x86/unicode_mixed'
  208. 'x86/unicode_upper'
  209. 'x86/xor_dynamic'
  210. )
  211. for line in $encoders; do
  212. echo "$line"
  213. done
  214. }
  215. __msfvenom_platforms(){
  216. local platforms
  217. platforms=(
  218. 'aix'
  219. 'android'
  220. 'apple_ios'
  221. 'bsd'
  222. 'bsdi'
  223. 'cisco'
  224. 'firefox'
  225. 'freebsd'
  226. 'hardware'
  227. 'hpux'
  228. 'irix'
  229. 'java'
  230. 'javascript'
  231. 'juniper'
  232. 'linux'
  233. 'mainframe'
  234. 'multi'
  235. 'netbsd'
  236. 'netware'
  237. 'nodejs'
  238. 'openbsd'
  239. 'osx'
  240. 'php'
  241. 'python'
  242. 'r'
  243. 'ruby'
  244. 'solaris'
  245. 'unix'
  246. 'unknown'
  247. 'windows'
  248. )
  249. for line in $platforms; do
  250. echo "$line"
  251. done
  252. }
  253. __msfvenom_formats(){
  254. local formats
  255. formats=(
  256. 'asp'
  257. 'aspx'
  258. 'aspx‐exe'
  259. 'axis2'
  260. 'dll'
  261. 'elf'
  262. 'elf‐so'
  263. 'exe'
  264. 'exe‐only'
  265. 'exe‐service'
  266. 'exe‐small'
  267. 'hta‐psh'
  268. 'jar'
  269. 'jsp'
  270. 'loop‐vbs'
  271. 'macho'
  272. 'msi'
  273. 'msi‐nouac'
  274. 'osx‐app'
  275. 'psh'
  276. 'psh‐cmd'
  277. 'psh‐net'
  278. 'psh‐reflection'
  279. 'vba'
  280. 'vba‐exe'
  281. 'vba‐psh'
  282. 'vbs'
  283. 'war'
  284. 'bash'
  285. 'c'
  286. 'csharp'
  287. 'dw'
  288. 'dword'
  289. 'hex'
  290. 'java'
  291. 'js_be'
  292. 'js_le'
  293. 'num'
  294. 'perl'
  295. 'pl'
  296. 'powershell'
  297. 'ps1'
  298. 'py'
  299. 'python'
  300. 'raw'
  301. 'rb'
  302. 'ruby'
  303. 'sh'
  304. 'vbapplication'
  305. 'vbscript'
  306. )
  307. for line in $formats; do
  308. echo "$line"
  309. done
  310. }
  311. # For most common options, not accurately
  312. __msfvenom_options(){
  313. local options
  314. options=(
  315. LHOST= \
  316. LPORT= \
  317. EXITFUNC= \
  318. RHOST= \
  319. StageEncoder= \
  320. AutoLoadStdapi= \
  321. AutoRunScript= \
  322. AutoSystemInfo= \
  323. AutoVerifySession= \
  324. AutoVerifySessionTimeout= \
  325. EnableStageEncoding= \
  326. EnableUnicodeEncoding= \
  327. HandlerSSLCert= \
  328. InitialAutoRunScript= \
  329. PayloadBindPort= \
  330. PayloadProcessCommandLine= \
  331. PayloadUUIDName= \
  332. PayloadUUIDRaw= \
  333. PayloadUUIDSeed= \
  334. PayloadUUIDTracking= \
  335. PrependMigrate= \
  336. PrependMigrateProc= \
  337. ReverseAllowProxy= \
  338. ReverseListenerBindAddress= \
  339. ReverseListenerBindPort= \
  340. ReverseListenerComm= \
  341. ReverseListenerThreaded= \
  342. SessionCommunicationTimeout= \
  343. SessionExpirationTimeout= \
  344. SessionRetryTotal= \
  345. SessionRetryWait= \
  346. StageEncoder= \
  347. StageEncoderSaveRegisters= \
  348. StageEncodingFallback= \
  349. StagerRetryCount= \
  350. StagerRetryWait= \
  351. VERBOSE= \
  352. WORKSPACE=
  353. )
  354. echo $options
  355. }
  356. #_msfvenom "$@"

Micropoor