bug引入
我们在驱动中引入一个错误 ,在0x0地址位置写入数据
在用户态这样做,进程会崩溃,但是在驱动里这样写,系统会挂掉
先把符号文件加载到windebug,用分号隔开,勾选reload

#include <ntddk.h>VOID Unload(IN PDRIVER_OBJECT DriverObject) {DbgPrint("driver unload\r\n");}NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegisteryPath) {PCHAR string;DriverObject->DriverUnload = Unload;//在 0x0的位置写入 'a'string = 0;*string = 'a';DbgPrint("hello driver\r\n");return STATUS_SUCCESS;}
加载驱动运行调试
分析调试信息
使用 !analyze -v 命令自动分析,需要等一小会
******************************************************************************** ** Bugcheck Analysis ** ********************************************************************************SYSTEM_THREAD_EXCEPTION_NOT_HANDLED (7e)This is a very common bugcheck. Usually the exception address pinpointsthe driver/function that caused the problem. Always note this addressas well as the link date of the driver/image that contains this address.Arguments:Arg1: c0000005, The exception code that was not handledArg2: 94407018, The address that the exception occurred atArg3: 807ed8fc, Exception Record AddressArg4: 807ed360, Context Record AddressDebugging Details:------------------DBGHELP: Timeout to store: e:\symbol*http://msdl.microsoft.com/download/symbolsKEY_VALUES_STRING: 1Key : AV.DereferenceValue: NullPtrKey : AV.FaultValue: WriteKey : Analysis.CPU.mSecValue: 14609Key : Analysis.DebugAnalysisManagerValue: CreateKey : Analysis.Elapsed.mSecValue: 181920Key : Analysis.Init.CPU.mSecValue: 8046Key : Analysis.Init.Elapsed.mSecValue: 840119Key : Analysis.Memory.CommitPeak.MbValue: 68Key : WER.OS.BranchValue: win7sp1_ldr_escrowKey : WER.OS.TimestampValue: 2019-02-20T18:00:00ZKey : WER.OS.VersionValue: 7.1.7601.24384BUGCHECK_CODE: 7eBUGCHECK_P1: ffffffffc0000005BUGCHECK_P2: ffffffff94407018BUGCHECK_P3: ffffffff807ed8fcBUGCHECK_P4: ffffffff807ed360EXCEPTION_RECORD: 807ed8fc -- (.exr 0xffffffff807ed8fc)ExceptionAddress: 94407018 (helloDriver!DriverEntry+0x00000018)ExceptionCode: c0000005 (Access violation)ExceptionFlags: 00000000NumberParameters: 2Parameter[0]: 00000001Parameter[1]: 00000000Attempt to write to address 00000000CONTEXT: 807ed360 -- (.cxr 0xffffffff807ed360)eax=85b0d0f8 ebx=00000000 ecx=00000000 edx=00002351 esi=85b0d0f8 edi=86cd7000eip=94407018 esp=807ed9c4 ebp=807ed9c8 iopl=0 nv up ei pl nz na pe nccs=0008 ss=0010 ds=0023 es=0023 fs=0030 gs=0000 efl=00010206helloDriver!DriverEntry+0x18:94407018 c60161 mov byte ptr [ecx],61h ds:0023:00000000=??Resetting default scopePROCESS_NAME: SystemWRITE_ADDRESS: 00000000ERROR_CODE: (NTSTATUS) 0xc0000005 - 0x%p 0x%p %sEXCEPTION_CODE_STR: c0000005EXCEPTION_PARAMETER1: 00000001EXCEPTION_PARAMETER2: 00000000EXCEPTION_STR: 0xc0000005STACK_TEXT:807ed9c8 840227b2 85b0d0f8 86cd7000 00000000 helloDriver!DriverEntry+0x18 [E:\codemix\windowsDevelopment\helloDriver\helloDriver\Source.c @ 18]807edbac 840262c1 00000001 00000000 807edbd4 nt!IopLoadDriver+0x7ed807edbf4 83ebdb4b 8d427bd0 855c38c8 855d84c0 nt!IopLoadUnloadDriver+0x70807edc44 84068b38 00000001 9cdb13d2 00000000 nt!ExpWorkerThread+0x10d807edc90 83f06301 83ebda3e 00000001 00000000 nt!PspSystemThreadStartup+0x15900000000 00000000 00000000 00000000 00000000 nt!KiThreadStartup+0x19CHKIMG_EXTENSION: !chkimg -lo 50 -d !nt83eb76a7 - nt!SwapContext_XRstorBegin+2[ 89:a9 ]83eb794d - nt!EnlightenedSwapContext_XRstorBegin+2 (+0x2a6)[ 89:a9 ]2 errors : !nt (83eb76a7-83eb794d)MODULE_NAME: memory_corruptionIMAGE_NAME: memory_corruptionMEMORY_CORRUPTOR: ONE_BIT_LARGESTACK_COMMAND: .cxr 0xffffffff807ed360 ; kbFAILURE_BUCKET_ID: MEMORY_CORRUPTION_ONE_BIT_LARGEOS_VERSION: 7.1.7601.24384BUILDLAB_STR: win7sp1_ldr_escrowOSPLATFORM_TYPE: x86OSNAME: Windows 7FAILURE_ID_HASH: {31545515-196b-fab5-2300-9ce714226f43}Followup: memory_corruption---------************* Path validation summary **************Response Time (ms) LocationOK E:\codemix\windowsDevelopment\helloDriver\helloDriver************* Path validation summary **************Response Time (ms) LocationOK E:\codemix\windowsDevelopment\helloDriver\helloDriverkd> gShutdown occurred at (Wed Jul 13 21:01:42.441 2022 (UTC + 8:00))...unloading all symbol tables.************* Path validation summary **************Response Time (ms) LocationDeferred SRV*E:\symbol*http://msdl.microsoft.com/download/symbolsDeferred srv*c:\symbols* http://msdl.microsoft.com/download/symbolsOK E:\codemix\windowsDevelopment\helloDriver\DebugDeferred SRV*E:\symboll* http://msdl.microsoft.com/download/symbolsWaiting to reconnect...BD: Boot Debugger InitializedConnected to Windows Boot Debugger 7601 x86 compatible target at (Wed Jul 13 21:01:54.082 2022 (UTC + 8:00)), ptr64 FALSEKernel Debugger connection established.************* Path validation summary **************Response Time (ms) LocationDeferred SRV*E:\symbol*http://msdl.microsoft.com/download/symbolsDeferred srv*c:\symbols* http://msdl.microsoft.com/download/symbolsOK E:\codemix\windowsDevelopment\helloDriver\DebugDeferred SRV*E:\symboll* http://msdl.microsoft.com/download/symbolsSymbol search path is: SRV*E:\symbol*http://msdl.microsoft.com/download/symbols;srv*c:\symbols* http://msdl.microsoft.com/download/symbols;E:\codemix\windowsDevelopment\helloDriver\Debug;SRV*E:\symboll* http://msdl.microsoft.com/download/symbolsExecutable search path is:ReadVirtual() failed in GetXStateConfiguration() first read attempt (error == 0.)Windows Boot Debugger Kernel Version 7601 UP Free x86 compatibleMachine Name:Primary image base = 0x00539000 Loaded module list = 0x005dbd60System Uptime: not available************* Path validation summary **************Response Time (ms) LocationDeferred SRV*E:\symbol*http://msdl.microsoft.com/download/symbolsDeferred srv*c:\symbols* http://msdl.microsoft.com/download/symbolsOK E:\codemix\windowsDevelopment\helloDriver\DebugDeferred SRV*E:\symboll* http://msdl.microsoft.com/download/symbols************* Path validation summary **************Response Time (ms) LocationOK E:\codemix\windowsDevelopment\helloDriver\helloDriverwinload!DbgLoadImageSymbols+0x44:0056f93d cc int 3kd> gShutdown occurred at (Wed Jul 13 21:02:18.377 2022 (UTC + 8:00))...unloading all symbol tables.************* Path validation summary **************Response Time (ms) LocationDeferred SRV*E:\symbol*http://msdl.microsoft.com/download/symbolsDeferred srv*c:\symbols* http://msdl.microsoft.com/download/symbolsOK E:\codemix\windowsDevelopment\helloDriver\DebugDeferred SRV*E:\symboll* http://msdl.microsoft.com/download/symbolsWaiting to reconnect...Connected to Windows 7 7601 x86 compatible target at (Wed Jul 13 21:02:19.339 2022 (UTC + 8:00)), ptr64 FALSEKernel Debugger connection established.************* Path validation summary **************Response Time (ms) LocationDeferred SRV*E:\symbol*http://msdl.microsoft.com/download/symbolsDeferred srv*c:\symbols* http://msdl.microsoft.com/download/symbolsOK E:\codemix\windowsDevelopment\helloDriver\DebugDeferred SRV*E:\symboll* http://msdl.microsoft.com/download/symbolsSymbol search path is: SRV*E:\symbol*http://msdl.microsoft.com/download/symbols;srv*c:\symbols* http://msdl.microsoft.com/download/symbols;E:\codemix\windowsDevelopment\helloDriver\Debug;SRV*E:\symboll* http://msdl.microsoft.com/download/symbolsExecutable search path is:Windows 7 Kernel Version 7601 MP (1 procs) Free x86 compatibleEdition build lab: 7601.24384.x86fre.win7sp1_ldr_escrow.190220-1800Machine Name:Kernel base = 0x83e4c000 PsLoadedModuleList = 0x83fa1730System Uptime: not available************* Path validation summary **************Response Time (ms) LocationDeferred SRV*E:\symbol*http://msdl.microsoft.com/download/symbolsDeferred srv*c:\symbols* http://msdl.microsoft.com/download/symbolsOK E:\codemix\windowsDevelopment\helloDriver\DebugDeferred SRV*E:\symboll* http://msdl.microsoft.com/download/symbols************* Path validation summary **************Response Time (ms) LocationOK E:\codemix\windowsDevelopment\helloDriver\helloDrivernt!DbgLoadImageSymbols+0x47:83e64d0e cc int 3
报错参数

arg1 : 错误代码 c000005
arg2:94407018 发生错误的内存地址
报错位置
发生错误的代码在 helloDriver!DriverEntry+0x00000018 的位置
错误码:c0000005 (Access violation)
原因,尝试在0x0 地址写入数据 :Attempt to write to address 00000000
寄存器状态
寄存器状态:
发生错误代码
94407018 c60161 mov byte ptr [ecx],61h ds:0023:00000000=??
调用栈

在E:\codemix\windowsDevelopment\helloDriver\helloDriver\Source.c @ 18 第18行发生错误
