紫水晶编程技术论坛 - 努力打造成全国最好的编程论坛

 找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 21888|回复: 28

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

  [复制链接]

854

主题

3482

帖子

2

精华

管理员

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

Rank: 125Rank: 125Rank: 125Rank: 125Rank: 125

积分
36101
发表于 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

主题

156

帖子

0

精华

铜牌会员

Rank: 2Rank: 2

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

280

主题

483

帖子

0

精华

版主

Rank: 7Rank: 7Rank: 7

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

71

主题

421

帖子

2

精华

钻石会员

Rank: 6Rank: 6

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

854

主题

3482

帖子

2

精华

管理员

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

Rank: 125Rank: 125Rank: 125Rank: 125Rank: 125

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

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

9

主题

126

帖子

0

精华

银牌会员

Rank: 3Rank: 3Rank: 3

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

854

主题

3482

帖子

2

精华

管理员

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

Rank: 125Rank: 125Rank: 125Rank: 125Rank: 125

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

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

9

主题

126

帖子

0

精华

银牌会员

Rank: 3Rank: 3Rank: 3

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

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

854

主题

3482

帖子

2

精华

管理员

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

Rank: 125Rank: 125Rank: 125Rank: 125Rank: 125

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

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

17

主题

106

帖子

0

精华

铜牌会员

Rank: 2Rank: 2

积分
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:}
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

手机版|Archiver|紫水晶工作室 ( 粤ICP备05020336号 )

GMT+8, 2024-5-31 15:01 , Processed in 0.028870 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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