Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
(연관된 글이 1개 있습니다.)

Patch Guard로 인해 블루 스크린(BSOD)가 발생하는 사례

한때는, 악성 프로그램들이 자신의 존재를 감추려 실행 프로그램을 Task Manager에서 안 보이게 만드는 것이 유행이었습니다.

ActiveProcessLinks---hide/src/hide.cpp
; https://github.com/irp/ActiveProcessLinks---hide/blob/master/src/hide.cpp

AntiForensics techniques : Process hiding in Kernel Mod
; https://www.cert-devoteam.fr/en/antiforensics-techniques-process-hiding-in-kernel-mode/

그런데, 지금은 저렇게 해서 감추었다가는 BSOD(Microsoft’s Blue Screen of Death)가 발생하게 됩니다. 왜냐하면 64비트 윈도우 운영체제에 Patch Guard라는 것이 동작하고 있기 때문입니다. 실제로 테스트 삼아 ActiveProcessLinks를 건드려 프로세스를 숨겨 보면, 곧바로 BSOD가 발생하지 않고 특정할 수 없는 순간에, 그러니까 불시에 ^^; 운영체제가 재부팅해 버립니다.

이후 다음과 같은 덤프 내역을 확인할 수 있는데,

Problem signature:
  Problem Event Name:   BlueScreen
  OS Version:   6.1.7601.2.1.0.256.1
  Locale ID:    1042

Additional information about the problem:
  BCCode:   109
  BCP1: A3A039DB9503D4FA
  BCP2: B3B74661E781EB91
  BCP3: FFFFFA830436A670
  BCP4: 0000000000000005
  OS Version:   6_1_7601
  Service Pack: 1_0
  Product:  256_1

Files that help describe the problem:
  C:\Windows\Minidump\011020-24281-01.dmp
  C:\Users\kevin\AppData\Local\Temp\WER-290406-0.sysdata.xml

Read our privacy statement online:
  http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline:
  C:\Windows\system32\en-US\erofflps.txt

이것만 봐도 사실 대략 원인을 알 수 있습니다. 중요한 것은 "BCCode"가 109라는 것인데 이것은 "CRITICAL_STRUCTURE_CORRUPTION" 오류로 Patch Guard에 의한 덤프였으며 세세한 오류 원인은 "BCP4"로 알 수 있습니다. 위에서는 "BCP4 == 5"인데, 이에 대한 오류 원인은 dmp 파일을 windbg로 보면 좀 더 쉽게 파악할 수 있습니다.

다음은 이 글에 첨부한 011020-24281-01.dmp 미니 덤프 파일을 windbg로 열어본 것입니다.

Microsoft (R) Windows Debugger Version 10.0.19528.1000 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.

Loading Dump File [c:\kernel\011020-24281-01.dmp]
Mini Kernel Dump File: Only registers and stack trace are available

************* Path validation summary **************
Response                         Time (ms)     Location
Deferred                                       srv*
OK                                             c:\symbols
Deferred                                       SRV*c:\Symbols*https://msdl.microsoft.com/download/symbols
Symbol search path is: srv*;c:\symbols;SRV*c:\Symbols*https://msdl.microsoft.com/download/symbols
Executable search path is: 
Windows 7 Kernel Version 7601 (Service Pack 1) MP (8 procs) Free x64
Product: WinNt, suite: TerminalServer SingleUserTS
7601.24511.amd64fre.win7sp1_ldr_escrow.190729-1700
Machine Name:
Kernel base = 0xfffff800`02611000 PsLoadedModuleList = 0xfffff800`0284ac90
Debug session time: Fri Jan 10 10:07:39.889 2020 (UTC + 9:00)
System Uptime: 0 days 0:37:31.330
Loading Kernel Symbols
.........
Loading User Symbols
Loading unloaded module list
.....
For analysis of this file, run !analyze -v
nt!KeBugCheckEx:
fffff800`026a4ca0 48894c2408      mov     qword ptr [rsp+8],rcx ss:0018:fffff880`033e94a0=0000000000000109

출력에 따라 "!analyze -v" 명령어를 입력하면 "BCP4 == 5"에 대한 의미를 알게 됩니다.

7: kd> !analyze -v
*******************************************************************************
*                                                                             *
*                        Bugcheck Analysis                                    *
*                                                                             *
*******************************************************************************

CRITICAL_STRUCTURE_CORRUPTION (109)
This bugcheck is generated when the kernel detects that critical kernel code or
data have been corrupted. There are generally three causes for a corruption:
1) A driver has inadvertently or deliberately modified critical kernel code
 or data. See http://www.microsoft.com/whdc/driver/kernel/64bitPatching.mspx
2) A developer attempted to set a normal kernel breakpoint using a kernel
 debugger that was not attached when the system was booted. Normal breakpoints,
 "bp", can only be set if the debugger is attached at boot time. Hardware
 breakpoints, "ba", can be set at any time.
3) A hardware corruption occurred, e.g. failing RAM holding kernel code or data.
Arguments:
Arg1: a3a039db9503d4fa, Reserved
Arg2: b3b74661e781eb91, Reserved
Arg3: fffffa830436a670, Failure type dependent information
Arg4: 0000000000000005, Type of corrupted region, can be
    0   : A generic data region
    1   : Modification of a function or .pdata
    2   : A processor IDT
    3   : A processor GDT
    4   : Type 1 process list corruption
    5   : Type 2 process list corruption
    6   : Debug routine modification
    7   : Critical MSR modification
    8   : Object type
    9   : A processor IVT
    a   : Modification of a system service function
    b   : A generic session data region
    c   : Modification of a session function or .pdata
    d   : Modification of an import table
    e   : Modification of a session import table
    f   : Ps Win32 callout modification
    10  : Debug switch routine modification
    11  : IRP allocator modification
    12  : Driver call dispatcher modification
    13  : IRP completion dispatcher modification
    14  : IRP deallocator modification
    15  : A processor control register
    16  : Critical floating point control register modification
    17  : Local APIC modification
    18  : Kernel notification callout modification
    19  : Loaded module list modification
    1a  : Type 3 process list corruption
    1b  : Type 4 process list corruption
    1c  : Driver object corruption
    1d  : Executive callback object modification
    1e  : Modification of module padding
    1f  : Modification of a protected process
    20  : A generic data region
    21  : A page hash mismatch
    22  : A session page hash mismatch
    23  : Load config directory modification
    24  : Inverted function table modification
    25  : Session configuration modification
    26  : An extended processor control register
    27  : Type 1 pool corruption
    28  : Type 2 pool corruption
    29  : Type 3 pool corruption
    2a  : Type 4 pool corruption
    2b  : Modification of a function or .pdata
    2c  : Image integrity corruption
    2d  : Processor misconfiguration
    2e  : Type 5 process list corruption
    2f  : Process shadow corruption
    30  : Retpoline code page corruption
    101 : General pool corruption
    102 : Modification of win32k.sys

Debugging Details:
------------------

fffff800027f30e8: Unable to get Flags value from nt!KdVersionBlock
GetUlongPtrFromAddress: unable to read from fffff800028ae300

KEY_VALUES_STRING: 1

    Key  : Analysis.CPU.Sec
    Value: 2

    Key  : Analysis.DebugAnalysisProvider.CPP
    Value: Create: 8007007e on THEMYTH9

    Key  : Analysis.DebugData
    Value: CreateObject

    Key  : Analysis.DebugModel
    Value: CreateObject

    Key  : Analysis.Elapsed.Sec
    Value: 2

    Key  : Analysis.Memory.CommitPeak.Mb
    Value: 57

    Key  : Analysis.System
    Value: CreateObject


ADDITIONAL_XML: 1

VIRTUAL_MACHINE:  HyperV

BUGCHECK_CODE:  109

BUGCHECK_P1: a3a039db9503d4fa

BUGCHECK_P2: b3b74661e781eb91

BUGCHECK_P3: fffffa830436a670

BUGCHECK_P4: 5

CUSTOMER_CRASH_COUNT:  1

PROCESS_NAME:  System

STACK_TEXT:  
fffff880`033e9498 00000000`00000000 : 00000000`00000109 a3a039db`9503d4fa b3b74661`e781eb91 fffffa83`0436a670 : nt!KeBugCheckEx


SYMBOL_NAME:  ANALYSIS_INCONCLUSIVE

MODULE_NAME: Unknown_Module

IMAGE_NAME:  Unknown_Image

STACK_COMMAND:  .thread ; .cxr ; kb

FAILURE_BUCKET_ID:  BAD_STACK_0x109

OS_VERSION:  7.1.7601.24511

BUILDLAB_STR:  win7sp1_ldr_escrow

OSPLATFORM_TYPE:  x64

OSNAME:  Windows 7

FAILURE_ID_HASH:  {b4d7023a-05c3-49b2-3ea4-6240fe57d90e}

Followup:     MachineOwner
---------

그러니까, (정확한 원인은 담고 있지 않지만) "Type 2 process list corruption" 유형의 문제로 인해 BSOD를 발생시켰던 것이며 개발자 입장에서는 ActiveProcessLinks 값을 변조하면 안 된다는 것을 알게 되는 것입니다.




windbg 덤프 분석 화면에도 나오지만 CRITICAL_STRUCTURE_CORRUPTION BSOD가 발생하는 것은 다음의 3가지 원인 때문에 그런 것입니다.

  1. A driver has inadvertently or deliberately modified critical kernel code or data. See http://www.microsoft.com/whdc/driver/kernel/64bitPatching.mspx
  2. A developer attempted to set a normal kernel breakpoint using a kernel debugger that was not attached when the system was booted. Normal breakpoints, "bp", can only be set if the debugger is attached at boot time. Hardware breakpoints, "ba", can be set at any time.
  3. A hardware corruption occurred, e.g. failing RAM holding kernel code or data.

현실적인 기준으로 봤을 때, 일반적인 환경에서 이런 BSOD를 경험한다면 대부분은 "잘못 작성된 드라이버"를 설치한 경우이거나, "악성코드를 담은 드라이버"일 가능성이 높습니다.

전자의 경우라면 해당 제품의 이전 버전을 설치하거나 버그 픽스를 한 새로운 버전의 드라이버를 설치하면 되지만, 최근에 설치한 새로운 드라이버가 없는 상황에서 CRITICAL_STRUCTURE_CORRUPTION BSOD를 만난다면 자신의 운영체제에 소위 말하는 바이러스가 설치되었을 확률이 높습니다. 이런 경우, 커널 모드에서 활동하는 driver의 특성상 삭제하는 것이 쉽지 않으므로 자신이 전문가가 아니라면 운영체제를 포맷 후 새로 설치하는 것이 편할 것입니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 7/31/2024]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2020-08-30 10시31분
[윈공부] 안녕하세요~ 프로세스를 숨기는 방법에 대해 여러번 질문드리고 해결되었습니다.
하지만, 일정시간이 지나면 블루스크린이 뜨면서 재부팅되는데요.
이걸 해결할 수 있는 방법이 있는지 궁금합니다.
감사합니다~!!!

현재 윈10프로 64비트인데요. 여기서 테스트 모드로 진입하여 동작 테스트를 했습니다.
시간은 특정할 수 없지만 짧으면 10분에서 길면 1시간 30분정도 지나면 블루스크린이 뜹니다.
[guest]
2020-08-30 02시00분
이 글의 설명 자체가 Win10 x64에서는 사실상 프로세스를 커널 레벨에서 숨길 수 없다는 것입니다. 만약, 저렇게 커널 레벨에서 숨기고 싶다면 커널에서 활동 중인 PatchGuard를 무력화시켜야 합니다. 이 부분에 대해서는 웹 검색을 해보시면 나오지만 대부분 '어둠의 경로'에 해당하는 것으로 공식적인 방법은 아닙니다. 예를 들어, 다음의 글에서도,

windbg - 필터 드라이버 확인하는 확장 명령어(!fltkd)
; https://www.sysnet.pe.kr/2/0/12283

"WdFilter!MpAmPreCreate" 함수의 진입점에서 그냥 ret 기계어로 패치시켜 Patch Guard가 활성화하지 않도록 변경하고 있습니다. (물론, 이렇게 하면 사용자 컴퓨터의 윈도우 디펜더가 정상 동작하지 않으므로 프로세스를 숨기려고 사용자 컴퓨터의 보안을 내리는 것과 다를 바 없습니다.)
정성태
2020-08-30 05시09분
[윈공부] 답변 감사합니다~!!!
처음부터 정독하지 않았기에... 앞서 설명한 내용을 미처 확인하지 못했네요.
^^b
[guest]
2020-10-02 05시29분
[guest] 혹시 os업뎃에 의한 기능 추가인지, 아니면 초기버전부터 패치가드가 차단한건지 궁금하네요~
[guest]
2020-10-02 11시35분
PatchGuard는 x64 운영체제에서 Windows Server 2003부터 이미 도입이 되었습니다. 단지 이 글의 "Arg4"에 나오는 기능 코드 별로 구현이 점점 늘어난 것인데, 다음의 글을 보면,

x64 kernel patch guard and GDT corruption
; https://community.osr.com/discussion/77568/x64-kernel-patch-guard-and-gdt-corruption

적어도 Type 7까지는 Windows Server 2003 x64부터 제공하는 듯합니다.
정성태

... 136  137  138  139  [140]  141  142  143  144  145  146  147  148  149  150  ...
NoWriterDateCnt.TitleFile(s)
1554정성태12/26/201335296Windows: 78. 마음에 드는 윈도우 8.1 태블릿 - 델 베뉴 8 프로 5830 [4]
1553정성태12/26/201322328개발 환경 구성: 206. JNBridgePro와 한글 인코딩 문제파일 다운로드1
1552정성태12/25/201327504개발 환경 구성: 205. JNBridgePro를 이용해 C#에서 Java메서드 호출 테스트파일 다운로드1
1551정성태12/24/201322650.NET Framework: 398. tech-days 미니 토요세미나 - 3회 C#편 PPT 자료파일 다운로드1
1550정성태12/13/201324990Windows: 77. Windows 8 - 잠시 사용을 안하는 경우 화면 잠김 상태로 빠지는 문제
1549정성태12/13/201328589VC++: 73. IIS - ISAPI 필터 제작하는 방법 [2]
1548정성태12/10/201321271오류 유형: 198. C# - 제네릭 covariance/contravariance 사용할 때 컴파일 오류가 발생한다면?
1547정성태12/10/201330821.NET Framework: 397. C# - OCX 컨트롤에 구현된 메서드에 배열을 in, out으로 전달하는 방법파일 다운로드2
1546정성태11/28/201324700.NET Framework: 396. C# - 프로퍼티로 정의하면 필드보다 느릴까요? - windbg / ollydbg [3]
1545정성태11/28/201328628.NET Framework: 395. C# - 프로퍼티로 정의하면 필드보다 느릴까요? [3]
1544정성태11/27/201325113개발 환경 구성: 204. Visual Studio Online "Monaco" 서비스와 github 연동
1543정성태11/27/201329856오류 유형: 197. error MSB8008: Specified platform toolset (v120) is not installed or invalid. [1]
1542정성태11/27/201335412오류 유형: 196. The procedure entry point InitializeCriticalSectionEx could not be located in the dynamic link library KERNEL32.dll
1541정성태11/22/201336627.NET Framework: 394. async/await 사용 시 hang 문제가 발생하는 경우 [7]파일 다운로드1
1540정성태11/20/201325098개발 환경 구성: 203. Azure - WEB SITES 서비스 소개 [4]
1539정성태11/19/201329100VS.NET IDE: 83. 형상 관리 서버 운영을 대신해 주는 Visual Studio 온라인 서비스
1538정성태11/19/201329960오류 유형: 195. 웹 사이트의 모든 정적 컨텐츠 요청에 대해 "Internal Server Error" 응답
1537정성태11/19/201321583오류 유형: 194. 윈도우 서버 백업으로 인해 Hyper-V VM들의 상태가 모두 "Backing up..." 상태로 오래 지속되는 문제
1536정성태11/19/201326378오류 유형: 193. 윈도우 서버 백업 - Hyper-V 가상 머신이 백업되지 않는 경우
1535정성태11/18/201326507.NET Framework: 393. Internet Explorer 11에서 ASP.NET 컨트롤의 크기가 달라지는 문제 [1]
1534정성태11/13/201326514.NET Framework: 392. .NET 스레드 콜 스택 덤프 (6) - MDbg를 이용한 방법 [2]파일 다운로드1
1533정성태11/12/201333743기타: 39. Internet Explorer 11에서 유튜브 동영상의 1080p 옵션이 보이지 않는 경우 [5]
1532정성태11/5/201334643Phone: 8. 안드로이드용 Xamarin 개발 시 겪을 만한 시행 착오 정리 [6]
1531정성태11/5/201326049VS.NET IDE: 82. Visual Studio에서 Attach 메서드를 이용해 디버깅을 시작한 경우 Breakpoint가 안 잡힌다면?
1530정성태11/5/201327408기타: 38. 오픈소스로 풀린 하드 디스크 관리 도구 - WindowSMART
1529정성태11/5/201323301오류 유형: 192. SQL 서버 - The transaction log for database '...' is full due to 'LOG_BACKUP'.
... 136  137  138  139  [140]  141  142  143  144  145  146  147  148  149  150  ...