找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 26395|回复: 28

[转载]Disable PatchGuard - the easy/lazy way

 火... [复制链接]

857

主题

2632

回帖

2

精华

管理员

此生无悔入华夏,  长居日耳曼尼亚。  

积分
36130
发表于 2011-12-12 14:25:55 | 显示全部楼层 |阅读模式
//Disable PatchGuard - the easy/lazy way.
//for Vista SP2 & Windows 7 (X64)
//
//by Fyyre (thank you Roxaz for helping me to test)
//http://fyyre.l2-fashion.de/
//http://twitter.com/Fyyre

last update: 19/03/2011

This txt file provides a general overview/outline for bypassing signature validation of critical system files (ntoskrnl, mainly) during
the Vista/Win 7 boot phase.  It is documentation of the steps taken from start to finish, to reach the desired goal of removing
kernel patch protection "PatchGuard" without use of a driver.  We will call this the 'lazy/easy' way to kill PatchGuard.

We cannot modify ntoskrnl without winload taking up issue...

winload.exe is the Windows loader for Vista & Windows 7.  Along with this, he makes some verification of digital signatures and
checking to make sure the files have not been modified.  If modification of ntoskrnl is detected, the result is winload *refusing*
to boot Windows and launching a WinPE looking "Recovery Mode".

//PART I { additional }: new way for patch of winload.exe
//
//Function ImgpValidateImageHash - signature we locate: 8B C3 49 8B 5B 20 49 8B 73 28 49 8B 7B 30 4D 8B -- you may play with this one to make him smaller.  as for this
//patching, use of dUP2... size of not a concern.  First bytes replaced with xor eax, eax (STATUS_SUCCESS) .. all validations successful.




PART I: disassembly and modification of winload.exe

Starting from OslpMain, after loading the System registry hives(registry)... occurs a call to OslInitializeCodeIntegrity:

.text:00000000004016C3                 call    OslpLoadSystemHive
.text:00000000004016C3
.text:00000000004016C8                 cmp     eax, ebx
.text:00000000004016CA                 mov     edi, eax
.text:00000000004016CC                 jl      loc_401A08
.text:00000000004016CC
.text:00000000004016D2                 mov     ecx, ebp
.text:00000000004016D4                 call    OslInitializeCodeIntegrity <<-- =(


.text:00000000004057E8 OslInitializeCodeIntegrity proc near

original code -->>

We will replace four bytes here:

48 8B C4 53
.text:00000000004057E8                 mov     rax, rsp
.text:00000000004057EB                 push    rbx
.text:00000000004057EC                 push    rbp


with: 0B0h, 01h, 0C3h, 090h ... which produce:

mov al, 1
ret
nop

Save as winload.exe as osloader.exe (or whatever..) & correct PE checksum (LordPE and/or CFF_Explorer will do).
Copy osloader.exe to \Windows\System32




PART II - new BCD entry:

bcdedit /copy {current} /d "PatchGuard Disabled"

"The entry was successfully copied to {01234567-89ab-cdef-00ff-fff000ffffff}" <<-- GUID of new entry.  each is different!

bcdedit /timeout 10 <<-- number of seconds to show boot menu.

bcdedit /set {01234567-89ab-cdef-00ff-fff000ffffff} nointegritychecks 1 <<-- no validation of winload

bcdedit /set {01234567-89ab-cdef-00ff-fff000ffffff} recoveryenabled 0 <<-- optional... i dislike this feature, therefore disable.

bcdedit /set {01234567-89ab-cdef-00ff-fff000ffffff} path \Windows\system32\osloader.exe

bcdedit /set {01234567-89ab-cdef-00ff-fff000ffffff} kernel ntkrnlmp.exe (name of modified ntos... =))




Part III: Skip Initialization of PatchGuard - - (driver not required)

As for this .txt, and PatchGuard... we are concerned with one function KiInitializePatchGuard(*1) which is called by KiFilterFiberContext.
KiInitializePatchGuard is a very large function located in the INIT section of ntoskrnl, you can easily locate him via two calls from
KiFilterFiberContext, by examination xrefs to exported dword InitSafeBootMode, searching for db 20h dup(90h) + db 044h ... or 48 81 EC 58 0F 00 00 to name a few...

PatchGuard does not initialize if we boot into safe mode.  So to disable we just patch one conditional jxx

KiInitializePatchGuard:

original code -->>
INIT:000000014055D359 sub     rsp, 0F58h
INIT:000000014055D360 xor     edi, edi
INIT:000000014055D362 cmp     cs:InitSafeBootMode, edi
INIT:000000014055D368 jz      short loc_14055D371
INIT:000000014055D368
INIT:000000014055D36A mov     al, 1
INIT:000000014055D36C jmp     loc_1405600D9

modified code -->>
INIT:000000014055D359                 sub     rsp, 0F58h
INIT:000000014055D360                 xor     edi, edi
INIT:000000014055D362                 cmp     cs:InitSafeBootMode, edi
INIT:000000014055D368                 nop
INIT:000000014055D369                 nop
INIT:000000014055D36A                 mov     al, 1
INIT:000000014055D36C                 jmp     loc_1405600D9 <<-- to end of KiInitializePatchGuard

and back to KiFilterFiberContext... and important detail:

The first jxx in KiInitializePatchGuard must not be taken & al == 1.  When we return to KiFilterFiberContext, the jxx must be taken,
and EBX must not be xor'd ... (unless enjoy BSOD).

INIT:0000000140567110 loc_140567110:
INIT:0000000140567110                 test    al, al
INIT:0000000140567112                 jnz     short loc_140567116
INIT:0000000140567112
INIT:0000000140567114
INIT:0000000140567114 loc_140567114:
INIT:0000000140567114                 xor     ebx, ebx <<-- bad
INIT:0000000140567114

Anyways... nop the first jxx in KiInitializePatchGuard... save modified ntoskrnl.exe with a different name (i.e. ntkrnlmp.exe) ... fix checksum (PE header).
Then copy your modified kernel to \Windows\system32 -- with bcdedit -->>

bcdedit /set {guid-of-new-entry} kernel ntkrnlmp.exe

When you reboot the system, loading your modified kernel should be a success... He will load without PatchGuard initializing, which will allow you to once again play in kernel mode without receiving BSOD as result...

This could be worked into mbr bootkit code as well... this is beyond the scope of our intention.

-Fyyre

references:
*1: Bypassing PatchGuard on Windows x64, by Skywing 12/1/2005

12

主题

144

回帖

0

精华

铜牌会员

积分
281
发表于 2011-12-14 12:10:49 | 显示全部楼层
怎么是鸟语?!

280

主题

203

回帖

0

精华

版主

积分
1808
发表于 2011-12-15 18:07:02 | 显示全部楼层
全是洋码子。

71

主题

350

回帖

2

精华

钻石会员

积分
4123
发表于 2011-12-17 10:24:29 | 显示全部楼层
只能读懂句子但读不懂代码。。

857

主题

2632

回帖

2

精华

管理员

此生无悔入华夏,  长居日耳曼尼亚。  

积分
36130
 楼主| 发表于 2011-12-17 12:04:34 | 显示全部楼层
yxd199512041 发表于 2011-12-17 10:24
只能读懂句子但读不懂代码。。

没什么,就是把几个地方打补丁而已。防止调用或者条件跳转。

9

主题

117

回帖

0

精华

银牌会员

积分
422
发表于 2011-12-17 13:31:33 | 显示全部楼层
开启win7 测试模式不是也可以么。

857

主题

2632

回帖

2

精华

管理员

此生无悔入华夏,  长居日耳曼尼亚。  

积分
36130
 楼主| 发表于 2011-12-18 22:27:10 | 显示全部楼层
xmlpull 发表于 2011-12-17 13:31
开启win7 测试模式不是也可以么。

测试模式只能免驱动正式签名(但是需要测试签名),不能关闭PG。

9

主题

117

回帖

0

精华

银牌会员

积分
422
发表于 2011-12-19 23:00:18 | 显示全部楼层
Tesla.Angela 发表于 2011-12-18 22:27
测试模式只能免驱动正式签名(但是需要测试签名),不能关闭PG。

那意思是说。把PG关了。 Win7 内核跟 Xp 一样可以随便乱搞了?

857

主题

2632

回帖

2

精华

管理员

此生无悔入华夏,  长居日耳曼尼亚。  

积分
36130
 楼主| 发表于 2011-12-20 11:17:57 | 显示全部楼层
xmlpull 发表于 2011-12-19 23:00
那意思是说。把PG关了。 Win7 内核跟 Xp 一样可以随便乱搞了?

不是把PG关了,是通过破解手段使PG失效,这样“Win7 内核跟 Xp 一样可以随便乱搞了”。

17

主题

89

回帖

0

精华

铜牌会员

积分
250
发表于 2012-2-24 13:26:41 | 显示全部楼层

  1. the result is winload *refusing*
  2. to boot Windows and launching a WinPE looking "Recovery Mode".
复制代码
这句怎么翻译?
是说如果发现ntoskrnl.exe被修改的话,那么winload就会拒绝重启电脑并且会寻找winPE的回复模式?

我晕,我发现我翻译的真烂.....{:soso_e106:}

17

主题

89

回帖

0

精华

铜牌会员

积分
250
发表于 2012-2-24 14:19:34 | 显示全部楼层
本帖最后由 wenh7788 于 2012-2-24 14:20 编辑

  1. As for this .txt, and PatchGuard... we are concerned with one function KiInitializePatchGuard(*1) which is called by KiFilterFiberContext.
复制代码
我来解释下这句吧,也是刚才看书看到的,方便大家理解。具体参见《bypassing patchguard on windows x64》 第10页中部。有错误的地方请指出

  1. nt!KiFilterFiberContext:
  2. 地址不写了太长了,直接写汇编代码了啊

  3. push    rbx
  4. sub      rsp,0x20
  5. lea       rax,[nt!KiDivide6432]
  6. mov     rbx,rcx
  7. add      rax,0xb
  8. cmp     [rcx+0xf8],rax
  9. jne       nt!KiFilterFiberContext+0x1d
  10. call       nt!KiDivide6432+0x570
复制代码
这块代码给人的感觉好像是在说:“是否错误发生的地址等于nt!KiDivde6432+0xb,如果正巧发生了“商溢出”,”如果某个寄存器的值+0xb ,那么一个无符号的调用 nt!KiDivide6432+0x570.而这个无符号的调用从此以后被称为nt!KiInitializePatchGuard.


这里主要是想说明 “nt!KiInitializePatchGuard”这个函数是这样来的。具体的还是需要书上面已经提到过了。谢谢。

17

主题

89

回帖

0

精华

铜牌会员

积分
250
发表于 2012-2-24 14:28:22 | 显示全部楼层
本帖最后由 wenh7788 于 2012-2-24 14:42 编辑

  1. KiFilterFiberContext, by examination xrefs to exported dword InitSafeBootMode, searching for db 20h dup(90h) + db 044h ... or 48 81 EC 58 0F 00 00 to name a few...
复制代码
继续补充
如果是在安全模式下启动的话那么代码就会有一些不同了。

  1. nt!KiDivede6432+0x570:
  2. fffff800'01423580  4881ecd8020000  sub rsp,0x2d8
  3.                              833d22dfd7ff00    cmp dword ptr[nt]
  4.                              0f85004770000        jne  nt!KiDivide6432+0x580


  5. nt!KiDivide6432+0x580:
  6. fffff800'0142ac98     b001                          mov  al,0x1
  7.                                 4881c4d8020000      add rsp,0x2d8
  8.                                 c3                              ret
复制代码

17

主题

89

回帖

0

精华

铜牌会员

积分
250
发表于 2012-2-24 14:52:38 | 显示全部楼层

  1. The first jxx in KiInitializePatchGuard must not be taken & al == 1.  When we return to KiFilterFiberContext, the jxx must be taken,
  2. and EBX must not be xor'd ... (unless enjoy BSOD).
复制代码
这句是什么意思,没有看懂,求解释!!!!谢谢!!!!

17

主题

89

回帖

0

精华

铜牌会员

积分
250
发表于 2012-2-24 15:09:11 | 显示全部楼层
本帖最后由 wenh7788 于 2012-2-24 15:11 编辑

大概过了下(当然有几个地方我没有看懂的),有几个疑问
1.如果这样的修改,电脑到底是以什么的模式去启动的呢?安全模式吗?
他不是把ntkrnlmp.exe给修改了吗?
2.那这样的方法岂不是导致其他的软件也可以对内核hook了?那么客户的电脑岂不是很不安全?
3.如果第一次不小心修改错误了,那么电脑还能正常启动吗?(这个很重要啊!!!!别说要重装系统)

17

主题

89

回帖

0

精华

铜牌会员

积分
250
发表于 2012-2-24 15:48:23 | 显示全部楼层

  1. //PART I { additional }: new way for patch of winload.exe
  2. //
  3. //Function ImgpValidateImageHash - signature we locate: 8B C3 49 8B 5B 20 49 8B 73 28 49 8B 7B 30 4D 8B -- you may play with this one to make him smaller.  as for this
  4. //patching, use of dUP2... size of not a concern.  First bytes replaced with xor eax, eax (STATUS_SUCCESS) .. all validations successful.




  5. PART I: disassembly and modification of winload.exe

  6. Starting from OslpMain, after loading the System registry hives(registry)... occurs a call to OslInitializeCodeIntegrity:

  7. .text:00000000004016C3                 call    OslpLoadSystemHive
  8. .text:00000000004016C3
  9. .text:00000000004016C8                 cmp     eax, ebx
  10. .text:00000000004016CA                 mov     edi, eax
复制代码
这里没有看懂啊,到底哪个才是真正的partI????

857

主题

2632

回帖

2

精华

管理员

此生无悔入华夏,  长居日耳曼尼亚。  

积分
36130
 楼主| 发表于 2012-2-24 16:40:23 | 显示全部楼层
wenh7788 发表于 2012-2-24 15:09
1.如果这样的修改,电脑到底是以什么的模式去启动的呢?安全模式吗?
他不是把ntkrnlmp.exe给修改了吗?
2.那这样的方法岂不是导致其他的软件也可以对内核hook了?那么客户的电脑岂不是很不安全?
3.如果第一次不小心修改错误了,那么电脑还能正常启动吗?(这个很重要啊!!!!别说要重装系统)
  1. //PART I { additional }: new way for patch of winload.exe

  2. //

  3. //Function ImgpValidateImageHash - signature we locate: 8B C3 49 8B 5B 20 49 8B 73 28 49 8B 7B 30 4D 8B -- you may play with this one to make him smaller.  as for this

  4. //patching, use of dUP2... size of not a concern.  First bytes replaced with xor eax, eax (STATUS_SUCCESS) .. all validations successful.









  5. PART I: disassembly and modification of winload.exe



  6. Starting from OslpMain, after loading the System registry hives(registry)... occurs a call to OslInitializeCodeIntegrity:



  7. .text:00000000004016C3                 call    OslpLoadSystemHive

  8. .text:00000000004016C3

  9. .text:00000000004016C8                 cmp     eax, ebx

  10. .text:00000000004016CA                 mov     edi, eax
复制代码
复制代码这里没有看懂啊,到底哪个才是真正的partI???? ...




1.普通模式,是把winload.exe和ntoskrnl.exe复制出来再修改。
2.是的,不安全。但是你能判断是谁修改了内核吗?
3.新建的那个内核启动项就不能启动了,就的内核启动项还可以。
4.下面的part1是最新的part1。


LZ其实我很佩服你的研究能力,你继续研究,都自己搞明白了我就给你这帖子加个精华和100水晶币。

17

主题

89

回帖

0

精华

铜牌会员

积分
250
发表于 2012-2-24 17:23:25 | 显示全部楼层
本帖最后由 wenh7788 于 2012-2-24 17:28 编辑

谢谢,我上面说的都是书上写的,我翻译的而已。

我不要100水晶,我只想讨论讨论patchguard的原理。谢谢啊!!!{:soso_e105:}要过掉啊~~~


PS
我刚才想了想,既然他的第二步骤里面 可以使用bcdedit的,还需要重启的话,那我直接用bcdedit把调试模式开启不一样吗?
我一样啥都可以做的啊。那这样有啥区别?

区别就是:
按照三步下来的话 他仍然是普通模式。

调试模式开启就是调试模式
????????

那这样貌似没有区别吧。

如果不重启就可以让pg的功能失效就好了。

17

主题

89

回帖

0

精华

铜牌会员

积分
250
发表于 2012-2-24 17:41:39 | 显示全部楼层
哥们啊,貌似还是回蓝吧,我快疯掉了,要过大概30分钟就会蓝的,疯了!!!!!!

857

主题

2632

回帖

2

精华

管理员

此生无悔入华夏,  长居日耳曼尼亚。  

积分
36130
 楼主| 发表于 2012-2-24 19:06:00 | 显示全部楼层
wenh7788 发表于 2012-2-24 17:41
哥们啊,貌似还是回蓝吧,我快疯掉了,要过大概30分钟就会蓝的,疯了!!!!!! ...

被你的文字搞糊涂了。。。
用fyyre的那个过PG的工具没有蓝过啊!

8

主题

149

回帖

2

精华

钻石会员

积分
3407
发表于 2012-2-25 10:23:16 | 显示全部楼层
Tesla.Angela 发表于 2012-2-24 19:06
被你的文字搞糊涂了。。。
用fyyre的那个过PG的工具没有蓝过啊!

没有蓝过+1

17

主题

89

回帖

0

精华

铜牌会员

积分
250
发表于 2012-2-27 09:36:44 | 显示全部楼层
他的那个应该仅仅是替换了两个文件,并没有做一些操作,比如hook ssdt 或是什么之类的。
你用完他的那个工具之后,你在使用我们论坛中隐藏进程的工具 可以尝试下
PS
据说360杀毒是有64位的。我用TA的工具看了下,貌似360并没有hook ssdt

857

主题

2632

回帖

2

精华

管理员

此生无悔入华夏,  长居日耳曼尼亚。  

积分
36130
 楼主| 发表于 2012-2-27 12:56:55 | 显示全部楼层
wenh7788 发表于 2012-2-27 09:36
他的那个应该仅仅是替换了两个文件,并没有做一些操作,比如hook ssdt 或是什么之类的。
你用完他的那个工 ...

谁说一定要用HOOK才能实现HIPS和自我保护。。。

17

主题

89

回帖

0

精华

铜牌会员

积分
250
发表于 2012-2-28 10:22:58 | 显示全部楼层
Tesla.Angela 发表于 2012-2-27 12:56
谁说一定要用HOOK才能实现HIPS和自我保护。。。

老大,比如呢?求指定,求提示~~

857

主题

2632

回帖

2

精华

管理员

此生无悔入华夏,  长居日耳曼尼亚。  

积分
36130
 楼主| 发表于 2012-2-28 15:30:40 | 显示全部楼层
wenh7788 发表于 2012-2-28 10:22
老大,比如呢?求指定,求提示~~

以前我给黑防投的稿:http://2817071.blog.51cto.com/2807071/733465
不知道怎么回事,这文章未经我同意就被转载了,而且那个傻逼转载者还不注明作者姓名!!!

17

主题

89

回帖

0

精华

铜牌会员

积分
250
发表于 2012-2-28 16:11:29 | 显示全部楼层
Tesla.Angela 发表于 2012-2-28 15:30
以前我给黑防投的稿:http://2817071.blog.51cto.com/2807071/733465
不知道怎么回事,这文章未经我同意 ...

哈哈,老大莫生气,你问下看看他们是否不是忘记了。

857

主题

2632

回帖

2

精华

管理员

此生无悔入华夏,  长居日耳曼尼亚。  

积分
36130
 楼主| 发表于 2012-2-29 12:42:21 | 显示全部楼层
wenh7788 发表于 2012-2-28 16:11
哈哈,老大莫生气,你问下看看他们是否不是忘记了。

对了,那篇文章我好像没说全。。。
如果仅从进线程、文件、注册表三个方面来说,都有非HOOK的方法:
进线程:ObRegisterCallbacks
文件:文件过滤驱动
注册表:Windows Filtering Platform(不确定)

10

主题

92

回帖

0

精华

银牌会员

积分
381
发表于 2012-12-8 12:40:00 | 显示全部楼层
看不懂!!!

7

主题

414

回帖

1

精华

铂金会员

积分
2173
发表于 2013-4-10 02:23:03 | 显示全部楼层
頂!

1

主题

35

回帖

0

精华

铜牌会员

积分
129
发表于 2015-4-24 08:39:39 | 显示全部楼层
硬编码很难啊,看不懂
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表