点饭的百度空间
银牌会员
     
积分 2315
发帖 2236
注册 2007-11-30
|
#1 [yeluosong] 嘿嘿 给主防来个了釜底抽薪 1-2
湖北 宜都市
生日: 1982年 09月28日 (天秤座)
目前居住地: 广东 - 深圳
学历: 大学
当前职业: 计算机/互联网
个人简介: 只要走在路上,就有希望..
试了下,给主防来个了釜底抽薪。哈哈,让它们所有的inlinehook控制点都失效,又不影响系统正常运行,完全是个摆设了00! nice!!!!
主防逆向系列-1
2010-05-20 21:20
PDEVICE_OBJECT __stdcall IoGetRelatedDeviceObject(PFILE_OBJECT FileObject)
{
PVPB vpb; // eax@1
PDEVICE_OBJECT DeviceObject; // eax@2
PDEVICE_OBJECT pDeviceObject; // edi@3
PVPB pvpb; // eax@5
vpb = FileObject->Vpb;
if ( vpb && (DeviceObject = (int)vpb->DeviceObject) != 0 )
{
pDeviceObject = DeviceObject;
}
else
{
if ( BYTE1(FileObject->Flags) & FO_DIRECT_DEVICE_OPEN
|| (pvpb = FileObject->DeviceObject->Vpb, !pvpb)
|| (pDeviceObject = (int)pvpb->DeviceObject, !pDeviceObject) )
pDeviceObject = (int)FileObject->DeviceObject;
}
if (pDeviceObject->AttachedDevice )
{
if ( BYTE2(FileObject->Flags) & FO_FILE_OBJECT_HAS_EXTENSION
&& FileObject[1].DeviceObject
&& IopVerifyDeviceObjectOnStack(pDeviceObject, (int)&FileObject[1].DeviceObject->Type) )
return FileObject[1].DeviceObject;
pDeviceObject = InlineHookStub(pDeviceObject);
}
return (PDEVICE_OBJECT)pDeviceObject;
}
微点InlineHook了 IoGetRelatedDeviceObject()函数,替换了此函数中的最后一个调用IoGetAttacedDevice。她让MpIoGetAttachedDevice来完成本应由IoGetAttacedDevice完成的任务,其中有些特殊处理:
当满足以下三个条件时
1)调用此函数的当前进程是MPSVC2.exe
2)FileObject->DeviceObject 或者 FileObject->FileObject->Vpb->DeviceObject 从属于名为\FileSystem\Ntfs的驱动对象
3)不是在IopPageReadInternal中调用IoGetRelatedDeviceObject
MpIoGetAttachedDevice(a)返回输入参数a对应设备对象而不是a所在栈的栈顶设备对象,其他情况与直接使用IoGetAttacedDevice无异。
她这样做的用意:MPSVC2.exe对Ntfs文件系统的访问可以绕过挂载在文件系统之上其他各类过滤驱动。
在分析过程中发现它利用栈回溯找到调用当前函数的父函数的调用入口比较有趣,她的姐妹在APC防护中也用了这招
f856bffc 896d08 mov dword ptr [ebp+8],ebp //ebp+8指向输入参数,此处已不再需要,用来临时保存ebp的值
f856bfff 8b4508 mov eax,dword ptr [ebp+8] //将ebp的值放入eax
f856c002 8b08 mov ecx,dword ptr [eax] //ecx是上层栈帧的ebp值,此ebp值由函数开头的push ebp产生
f856c004 85c9 test ecx,ecx
f856c006 7417 je mp110010!f4010+0x2fd (f856c01f)
f856c008 a100d456f8 mov eax,dword ptr [mp110010!f4003+0x8b2 (f856d400)]
f856c00d 85c0 test eax,eax
f856c00f 740e je mp110010!f4010+0x2fd (f856c01f)
f856c011 8b4904 mov ecx,dword ptr [ecx+4]//[ecx+4]上层栈帧的返回地址
f856c014 83e905 sub ecx,5 //调用IoGetRelatedDeviceObject对应指令所在地址,类似于0x80808080:call IoGetRelatedDeviceObject
f856c017 3bc8 cmp ecx,eax
再来看看她的InlineHookStub()函数的处理,写的比较晦涩,不是一目了然(故意的吧^_^!).她所有的InlineHook处理函数的函数地址都是保存在唯一对应的指针变量中。分析到这里,偶突然冒出一淫荡想法:若她发现了有调试软件启动,则将这些指针变量值全部换成原始函数地址。这样调试者只会发现这里的inlinehook只占坑不做事,徒然浪费好几个cpu周期绕了一圈又绕回来了。增加一下反调试难度!
_declspec _stdcall InlineHookStub (PDEVICE_OBJECT DeviceObject)
{
push ebp
mov ebp,esp
sub esp,10h
mov ebp,offset mp110010!f4010+0x28e (f856bfb0)
mov dword ptr [esp],ebp //栈顶放入InlineHOOK处理函数地址
mov ebp,dword ptr [esp+10h] //恢复ebp的值
ret 10h //跳转到InlineHOOK处理函数,并清除stub函数所占用的堆栈。ret 10h执行之后,栈顶值是输入参数。
}
int __stdcall MpIoGetAttachedDevice(PDEVICE_OBJECT DeviceObject)
{
PKTHREAD thread; // eax@1
int v2; // ecx@1
PEPROCESS process; // edi@1
PDEVICE_OBJECT v4; // esi@1
int status; // eax@10
int s; // [sp+8h] [bp+0h]@7
process = IoGetCurrentProcess();
thread = KeGetCurrentThread();
v4 = DeviceObject;
v2 = (int)DeviceObject->DriverObject;
//dword_13410 dword_133E8均为0
if ( (v2 == NtfsDriverObjectPointer || v2 == dword_133E8)
&& (process == (PEPROCESS)EPROCESS_MPSVC2_exe && thread != (PKTHREAD)dword_13410|| (unsigned __int8)sub_11C80(thread))
&& (process == (PEPROCESS)EPROCESS_MPSVC2_exe)
&& dword_13400
&& (v2 = *(_DWORD *)( 上层函数的ebp + 4) - 5, v2 != dword_13400)) )
//不是 在 IopPageReadInternal中调用IoGetRelatedDeviceObject
status = (int)v4;
else
status = IoGetAttachedDevice(v2, v4);
return status;
}
MpIoGetAttachedDevice :
f856bfb0 8bff mov edi,edi
f856bfb2 55 push ebp
f856bfb3 8bec mov ebp,esp
f856bfb5 56 push esi
f856bfb6 57 push edi
f856bfb7 ff15fccc56f8 call dword ptr [mp110010!f4003+0x1ae (f856ccfc)]
f856bfbd 8bf8 mov edi,eax
f856bfbf e8100c0000 call mp110010!f4003+0x86 (f856cbd4)
f856bfc4 8b7508 mov esi,dword ptr [ebp+8]
f856bfc7 8b4e08 mov ecx,dword ptr [esi+8]
f856bfca 3b0de4d356f8 cmp ecx,dword ptr [mp110010!f4003+0x896 (f856d3e4)]
f856bfd0 7408 je mp110010!f4010+0x2b8 (f856bfda)
f856bfd2 3b0de8d356f8 cmp ecx,dword ptr [mp110010!f4003+0x89a (f856d3e8)]
f856bfd8 7545 jne mp110010!f4010+0x2fd (f856c01f)
f856bfda 3b3d0cd456f8 cmp edi,dword ptr [mp110010!f4003+0x8be (f856d40c)]
f856bfe0 7508 jne mp110010!f4010+0x2c8 (f856bfea)
f856bfe2 3b0510d456f8 cmp eax,dword ptr [mp110010!f4003+0x8c2 (f856d410)]
f856bfe8 750a jne mp110010!f4010+0x2d2 (f856bff4)
f856bfea 50 push eax
f856bfeb e890fcffff call mp110010!f4008+0xe (f856bc80)
f856bff0 84c0 test al,al
f856bff2 742b je mp110010!f4010+0x2fd (f856c01f)
f856bff4 3b3d0cd456f8 cmp edi,dword ptr [mp110010!f4003+0x8be (f856d40c)]
f856bffa 741f je mp110010!f4010+0x2f9 (f856c01b)
f856bffc 896d08 mov dword ptr [ebp+8],ebp
f856bfff 8b4508 mov eax,dword ptr [ebp+8]
f856c002 8b08 mov ecx,dword ptr [eax]
f856c004 85c9 test ecx,ecx
f856c006 7417 je mp110010!f4010+0x2fd (f856c01f)
f856c008 a100d456f8 mov eax,dword ptr [mp110010!f4003+0x8b2 (f856d400)]
f856c00d 85c0 test eax,eax
f856c00f 740e je mp110010!f4010+0x2fd (f856c01f)
f856c011 8b4904 mov ecx,dword ptr [ecx+4]
f856c014 83e905 sub ecx,5
f856c017 3bc8 cmp ecx,eax
f856c019 7404 je mp110010!f4010+0x2fd (f856c01f)
f856c01b 8bc6 mov eax,esi
f856c01d eb07 jmp mp110010!f4010+0x304 (f856c026)
f856c01f 56 push esi
f856c020 ff1520cd56f8 call dword ptr [mp110010!f4003+0x1d2 (f856cd20)]
f856c026 5f pop edi
f856c027 5e pop esi
f856c028 5d pop ebp
f856c029 c20400 ret 4
//查看Thread是不是记录在MP110010数组Thread_Array中的值,若是则返回TRUE,否返回FALSE
_DWORD __stdcall sub_11C80(PKTHREAD Thread)
{
int v1; // ecx@1
char v2; // bl@1
unsigned int v3; // esi@1
int result; // eax@3
v1 = mp110010_5;
v2 = 0;
v3 = 0;
if ( mp110010_5 )
{
_EDX = &Thread_Array;
while ( 1 )
{
_EDI = Thread;
result = (int)Thread;
__asm { lock cmpxchg [edx], edi }
if ( Thread == (PKTHREAD)result )
break;
++v3;
++_EDX;
if ( v3 >= v1 )
goto LABEL_7;
}
v2 = 1;
}
LABEL_7:
LOBYTE(result) = v2;
return result;
}
主防逆向系列-2
2010-05-21 17:37
NTSTATUS IopCreateFile( ,, )
{
...........
IopUpdateOtherOperationCount();
status = InlineHookStub( ObjectAttributes,
(POBJECT_TYPE) NULL,
requestorMode,
NULL,
DesiredAccess,
openPacket,
&handle );
......
}
|
※ ※ ※ 本文纯属【点饭的百度空间】个人意见,与【 微点交流论坛 】立场无关※ ※ ※
|
 你的微笑 is 微点的骄傲!
http://hi.baidu.com/new/micropoint |
 |
|