Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 当使用windbg在内核模式下进行调试时,如何中断程序的入口点?_Windows_Debugging_Windbg - Fatal编程技术网

Windows 当使用windbg在内核模式下进行调试时,如何中断程序的入口点?

Windows 当使用windbg在内核模式下进行调试时,如何中断程序的入口点?,windows,debugging,windbg,Windows,Debugging,Windbg,我想在内核模式下调试一个程序,我想中断程序的入口点,比如ollydbg。但是我不能用bp中断它,因为程序没有启动,符号无法加载。我已经找到了一些方法,但我觉得不太好 1.中断内核中的CreateProcess函数。但是我不知道应该破坏哪个函数,我认为CreateProcess和程序的入口点之间还有很长的路要走 2.使用cc更改程序的入口点。但它需要其他工具,我应该更改字节更改回的代码。我觉得很烦人 3.借助于ollydbg。在使用windbg调试的虚拟机中使用ollydbg调试程序。我认为这不是

我想在内核模式下调试一个程序,我想中断程序的入口点,比如
ollydbg
。但是我不能用
bp
中断它,因为程序没有启动,符号无法加载。我已经找到了一些方法,但我觉得不太好

1.中断内核中的
CreateProcess
函数。但是我不知道应该破坏哪个函数,我认为
CreateProcess
和程序的入口点之间还有很长的路要走

2.使用
cc
更改程序的入口点。但它需要其他工具,我应该更改字节更改回的代码。我觉得很烦人

3.借助于
ollydbg
。在使用windbg调试的虚拟机中使用
ollydbg
调试程序。我认为这不是一个好主意

4.使用
sxe ld
。可以在
中的
清单3.29
中找到它。我试过了,但我发现它只在第一次起作用。我不知道休息后我应该做什么

5.使用
bu
中断输入功能。但我也不知道该怎么办。例如,如何加载符号

6.使用
。创建
。我不知道按照我说的去做是否合适

我认为在内核模式下使用
windbg
进行调试时,中断程序的入口点是一种常见的做法,我认为使用功能强大的
windbg
一定有一种很好的方法可以做到这一点。最好的方法是什么


顺便说一下,我想在内核模式下调试一个程序,因为我想获得程序的令牌值。我发现windbg可以用
识别令牌!用户模式下的令牌
,但我不知道如何在用户模式下获取令牌的值。似乎我只能在内核模式下获取令牌的值,对还是错?

使用Windbg帮助文件中描述的方法调试WinLogon。将您的用户模式应用程序替换为WinLogon:

Windbg |帮助|内容| Windows调试|调试技术|专用调试技术|调试WinLogon

IFEO将启动您的用户模式应用程序并连接ntsd.exe。在ntsd.exe中,您可以使用
bu$exentry
在图像条目上设置断点,然后使用
g
继续


在ntsd.exe被中断到用户模式进程的任何时候,您都可以发出
.breakin
命令切换到内核模式调试。

使用Windbg帮助文件中描述的方法调试WinLogon。将您的用户模式应用程序替换为WinLogon:

Windbg |帮助|内容| Windows调试|调试技术|专用调试技术|调试WinLogon

IFEO将启动您的用户模式应用程序并连接ntsd.exe。在ntsd.exe中,您可以使用
bu$exentry
在图像条目上设置断点,然后使用
g
继续


在ntsd.exe被中断到用户模式进程的任何时候,您都可以发出
.breakin
命令切换到内核模式调试。

您可以通过ntsd-d运行目标中的任何exe,从主机中运行的内核模式调试程序对其进行调试

假设您正在myhost内运行虚拟机mytarget

在myhost中安装windbg
设置myhost viz srv*x:\xxxx*http:\xxxxxxxxxxx的符号路径
在主机中创建内核连接(选择下面显示的最佳连接方式为串行连接)

X:\xxxx\windbg.exe-k com:pipe,端口=\\。\pipe\debugPipe,resets=0,重新连接 在mytarget中安装windbg
打开共享文件夹z:\指向myhost中的symbolcache文件夹 在mytarget中设置指向共享文件夹的符号路径 运行ntsd-d calc.exe

kd将在calc.exe的$exentry上使用输入提示中断

只要显示输入提示,您就可以像使用本机用户模式调试器一样使用kd 所以如果你设置一个bp计算!Winmain和问题g kd将在calc.exe Winmain上中断

要进入kd会话,请使用.breakin

乱七八糟的东西,但一旦你习惯了就会很好用(即记住文件)

试运行

kd> g   <-------------- kd session running in myhost

CommandLine: calc.exe 
Symbol search path is: srv*z:\
*http://msdl.microsoft.com/download/symbols

ntdll!DbgBreakPoint:
7c90120e cc              int     3

.sympath
NOTE: The symbol path for this ntsd is relative to where
ntsd.exe is running, not where kd.exe is running.
Symbol search path is: srv*z:\
*http://msdl.microsoft.com/download/symbols
Expanded Symbol search path is: srv*z:\
*http://msdl.microsoft.com/download/symbols

.reload /f calc.exe

lm m calc
start    end        module name
01000000 0101f000   calc       (pdb symbols)          z:\calc.pdb\3B7D84101\calc.pdb

0:000> version  <--------------------usermode session in kd via ntsd -d 
version
Windows XP Version 2600 (Service Pack 3) UP Free x86 compatible

Live user mode: <Local>

command line: 'ntsd -d calc.exe'  Debugger Process 0x3F8 

? $exentry;? calc!WinmainCrtstartup
Evaluate expression: 16852085 = 01012475
Evaluate expression: 16852085 = 01012475
kd>g exe的版本标记是您不必运行任何kd会话的唯一要求

您可以通过本地内核调试会话(使用kd-kl或使用sysinternals中的livekd)获取myhost中所有正在运行的进程的令牌

下面是一个简单的脚本,它使用上述技术获取所有正在运行的进程的sid

:\>cat sid.txt
!for_each_process "r $t0 =(@@c++(((nt!_eprocess *) @#Process )->Token.Object)) &
 @@(~7); r $t1 = @@c++(((nt!_token *) @$t0 )->UserAndGroups->Sid);!sid @$t1 1; ?
? (char *)((nt!_eprocess *) @#Process )->ImageFileName "

:\>kd -kl -c "$$>a< sid.txt;q"
:\>cat sid.txt
!对于每个进程“r$t0=(@@c++)((nt!\U eprocess*)@#process)->Token.Object))&
@@(~7);r$t1=@@c++(((nt!_令牌*)@$t0)->UserAndGroups->Sid);!Sid@$t1 1?
?(字符*)((nt!_eprocess*)@#Process)->ImageFileName“
:\>kd-kl-c“$$>a
结果

WARNING: Local kernel debugging requires booting with kernel
debugging support (/debug or bcdedit -debug on) to work optimally.

lkd> kd: Reading initial command '$$>a< sid.txt;q'
SID is: S-1-5-18 (Well Known Group: NT AUTHORITY\SYSTEM)
char * 0x8ac729a4
 "System"
SID is: S-1-5-18 (Well Known Group: NT AUTHORITY\SYSTEM)
char * 0x8a35729c
 "smss.exe"

SID is: S-1-5-20 (Well Known Group: NT AUTHORITY\NETWORK SERVICE)
char * 0x8a3619ac
 "svchost.exe"

SID is: S-1-5-19 (Well Known Group: NT AUTHORITY\LOCAL SERVICE)
char * 0x8a36ef14
 "svchost.exe"

SID is: S-1-5-21-602162358-1801674531-1417001333-1003 (User: XXXXXX\Admin)
char * 0x8a261b64
 "explorer.exe"
警告:本地内核调试需要使用内核启动
调试支持(/debug或bcdedit-debug-on)以最佳方式工作。
lkd>kd:读取初始命令“$$>a
您可以通过ntsd-d运行目标中的任何exe,从主机中运行的内核模式调试器对其进行调试

假设您正在myhost内运行虚拟机mytarget

在myhost中安装windbg
设置myhost viz srv*x:\xxxx*http:\xxxxxxxxxxx的符号路径
在主机中创建内核连接(选择下面显示的最佳连接方式为串行连接)

X:\xxxx\windbg.exe-k com:pipe,port=\\\