Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

(시리즈 글이 7개 있습니다.)
디버깅 기술: 3. 원격 컴퓨터 디버깅 - VPC 설정
; https://www.sysnet.pe.kr/2/0/265

디버깅 기술: 3.1. Managed 원격 디버깅과 WinDBG 원격 디버깅
; https://www.sysnet.pe.kr/2/0/314

디버깅 기술: 27. Windbg - Local Kernel Debug 모드
; https://www.sysnet.pe.kr/2/0/934

디버깅 기술: 29. Windbg - Hyper-V 윈도우 7 원격 디버깅 구성
; https://www.sysnet.pe.kr/2/0/938

Windows: 57. 새로 추가된 네트워크 커널 디버깅 및 PowerShell 3.0
; https://www.sysnet.pe.kr/2/0/1259

디버깅 기술: 62. windbg - 사용자 모드 원격 디버깅
; https://www.sysnet.pe.kr/2/0/1602

디버깅 기술: 192. Windbg - Hyper-V VM으로 이더넷 원격 디버깅 연결하는 방법
; https://www.sysnet.pe.kr/2/0/13343




Windbg - Hyper-V VM으로 이더넷 원격 디버깅 연결하는 방법

예전에는 COM 포트를 이용했었는데요,

Windbg - Hyper-V 윈도우 7 원격 디버깅 구성
; https://www.sysnet.pe.kr/2/0/938

이번에는 이더넷을 이용한 연결 방법을 시도해 봤습니다. 사실 이에 대해서는 아래의 공식 문서에서 잘 설명하고 있습니다.

BCDEdit /dbgsettings
; https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/bcdedit--dbgsettings

Setting Up Network Debugging of a Virtual Machine - KDNET
; https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/setting-up-network-debugging-of-a-virtual-machine-host

문서에 따라, Windbg가 설치돼 있는 호스트 측에서 다음의 경로에 있는 (같은 위치의 VerifiedNICList.xml을 사용하는) kdnet.exe로,

C:\Program Files (x86)\Windows Kits\10\Debuggers\x64

자신의 PC에 장착한 이더넷 카드가 네트워크 디버깅을 지원하는지 알아볼 수 있습니다.

C:\Program Files (x86)\Windows Kits\10\Debuggers\x64> kdnet

Network debugging is supported on the following NICs:
busparams=9.0.0, Realtek PCIe 2.5GbE Family Controller #2, Cable status unknown.

Network debugging is supported on the following USB controllers:
busparams=4.0.0, AMD USB 3.10 eXtensible Host Controller - 1.10 (Microsoft)
busparams=10.0.4, AMD USB 3.10 eXtensible Host Controller - 1.10 (Microsoft)
busparams=10.0.3, AMD USB 3.10 eXtensible Host Controller - 1.10 (Microsoft)

This Microsoft hypervisor supports using KDNET in guest VMs.

위의 결과에서는 9.0.0 버스에 연결된 Realtek 어댑터가 지원하고, 그 외에도 USB 컨트롤러도 네트워크 디버깅을 지원한다고 나옵니다.




따라서 호스트 측에서는 windbg를 실행해 두고 임의의 포트와 Key를 선정해 다음과 같이 대기해 둡니다.

hyperv_windbg_net_1.png

특이하게도 Key의 경우에는 '.'을 구분자로 (마치 IP처럼) 4개의 값을 줘야 한다고 합니다. 그래서 위의 경우 "test"라고 하지 않고 "t.e.s.t"라고 설정한 것입니다.

그다음, Debuggee 측에서는 호스트 측에서 대기하고 있는 설정대로 연결할 수 있도록 연결 정보를 전달해 kdnet.exe를 실행합니다. 이때 kdnet 실행을 위해 Windows SDK를 설치할 필요 없이 호스트 측에 있는 kdnet.exe와 VerifiedNICList.xml 파일을 복사해 실행하면 됩니다.

// 호스트 측의 IP가 192.168.100.50이라고 가정

c:\temp> kdnet 192.168.100.50 65100

Enabling network debugging on Network debugging is supported by this Microsoft Hypervisor Virtual Machine.

To debug this vm, run the following command on your debugger host machine.
windbg -k net:port=65100,key=xxxxxxx.xxxxxxx.xxxxxxx.xxxxxxx

Then restart this VM by running shutdown -r -t 0 from this command prompt.

이때 key 값이 무작위로 "xxxxxxx.xxxxxxx.xxxxxxx.xxxxxxx" 긴 문자열이 나오는데요, 이것을 다음의 명령어로 (호스트 측에 지정한 것과 동일하게) 새롭게 지정합니다.

c:\temp> bcdedit /set "{dbgsettings}" key t.e.s.t

잘 설정이 되었는지 마지막으로 확인해 주고,

c:\temp> bcdedit /dbgsettings
key                     t.e.s.t
debugtype               NET
hostip                  192.168.100.50
port                    65100
badmemoryaccess         Yes
dhcp                    Yes
The operation completed successfully.

재부팅합니다. 일단, 호스트 측에 실행해 둔 windbg는 다음의 출력과 함께 멈춰 있을 텐데요,

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

Using NET for debugging
Opened WinSock 2.0
Waiting to reconnect...

Debuggee 측이 재부팅하면 곧바로 192.168.100.50:65100으로 연결하게 되고 다음과 같은 호스트 측의 출력을 확인할 수 있습니다.

Connected to target 192.168.100.100 on port 65100 on local IP 192.168.100.50.
You can get the target MAC address by running .kdtargetmac command.
Connected to Windows 10 19041 x64 target at (Tue May  9 11:59:21.915 2023 (UTC + 9:00)), ptr64 TRUE
Kernel Debugger connection established.

...[생략]...

*******************************************************************************
*                                                                             *
*   You are seeing this message because you pressed either                    *
*       CTRL+C (if you run console kernel debugger) or,                       *
*       CTRL+BREAK (if you run GUI kernel debugger),                          *
*   on your debugger machine's keyboard.                                      *
*                                                                             *
*                   THIS IS NOT A BUG OR A SYSTEM CRASH                       *
*                                                                             *
* If you did not intend to break into the debugger, press the "g" key, then   *
* press the "Enter" key now.  This message might immediately reappear.  If it *
* does, press "g" and "Enter" again.                                          *
*                                                                             *
*******************************************************************************
nt!DbgBreakPointWithStatus:
fffff804`114051b0 cc              int     3

이때, Debuggee 측의 운영체제 자체가 멈춰버리기 때문에 호스트 측의 windbg 명령행에서 'g' 키를 입력해 실행을 계속하면 됩니다.

(참고로, 이때의 통신은 TCP가 아닌 UDP입니다.)




그런데, kdnet.exe를 Debuggee PC 측에서 실행했을 때 다음과 같은 오류가 나올 수 있습니다.

c:\temp> kdnet

Network debugging is supported by this Microsoft Hypervisor Virtual Machine

KDNET transport initialization failed during a previous boot.  Status = 0xC00000B5.
InitializeNetwork failed to get the MAC address of the host debugger. Check the dbgsettings hostip!

이런 오류가 Hyper-V VM 환경에서 발생한다면, VM 측에 할당한 네트워크 유형을 살펴야 합니다. 문서에도 나오지만, 이더넷을 이용한 디버깅은 이것을 지원하는 "물리 어댑터"의 기능을 이용하는 것이기 때문에 반드시 그 어댑터와 연결된 Virtual Switch를 VM에 할당해 줘야 합니다. 기본적으로 External 유형에만 물리 어댑터가 연결되므로 그 외의 "Internal", "Private" 유형을 VM에 할당한 경우에는 동작하지 않습니다.




경우에 따라, Internal과 External 2개의 어댑터를 연결한 VM에서도 kdnet.exe가 0xC00000B5 오류를 보고할 수 있습니다. 이럴 때 ipconfig을 실행해 보면,

c:\temp> ipconfig

Windows IP Configuration

Ethernet adapter Ethernet (Kernel Debugger):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::eab0:c8d9:e6d1:8bc0%4
   Autoconfiguration IPv4 Address. . : 169.254.169.55
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . :

Ethernet adapter Ethernet 2:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::7fc9:901c:7365:5f2f%6
   IPv4 Address. . . . . . . . . . . : 192.168.100.100
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.100.1

"Kernel Debugger"가 "Internal" 네트워크로 설정한 어댑터로 연결되었을 것입니다. 이것을 물리 어댑터와 연결된 External 네트워크로 변경해야 하는데요, 위의 경우 "Ethernet adapter Ethernet 2"로 붙여야 합니다.

그런데, 딱히 이게 kdnet.exe 측에서는 설정하는 방법이 없습니다. 일단은, 저 규칙을 보면 우선순위가 높은 네트워크로 붙는 건데요, 따라서 다음의 글에 따라,

윈도우 - (네트워크 어댑터의 우선순위로 인한) 열거되는 IP 주소 순서를 조정하는 방법
; https://www.sysnet.pe.kr/2/0/12304

PowerShell을 이용해 InterfaceMetric을 확인하고,

PS C:\Windows\System32> Get-NetIPInterface | where {$_.ConnectionState -eq "Connected" -and $_.AddressFamily -eq "IPv4" } | select ifIndex,InterfaceAlias,InterfaceMetric,AddressFamily,ConnectionState | sort InterfaceMetric | FT

ifIndex InterfaceAlias              InterfaceMetric AddressFamily ConnectionState
------- --------------              --------------- ------------- ---------------
      6 Ethernet                                 15          IPv4       Connected
     11 Ethernet 2                               35          IPv4       Connected
      1 Loopback Pseudo-Interface 1              75          IPv4       Connected

위에서 6번 우선순위를 "Ethernet 2"보다 낮게(숫자는 크게) 설정하면 됩니다.

PS C:\Windows\System32> Set-NetIPInterface -InterfaceIndex 6 -InterfaceMetric 45

이후 ipconfig으로 우선순위가 바뀐 것을 확인하고,

c:\temp> ipconfig

Windows IP Configuration

Ethernet adapter Ethernet 2:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::5245:f089:a376:aca5%11
   IPv4 Address. . . . . . . . . . . : 192.168.100.100
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.100.1

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::7fc9:901c:7365:5f2f%6
   Autoconfiguration IPv4 Address. . : 169.254.169.55
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . :

재부팅하면 정상적으로 동작하게 됩니다. 제 경우에 일단 "bcdedit /dbgsettings ..."로 해둔 설정을 삭제 및 재부팅 후 저 설정을 한 다음에 다시 "bcdedit /dbgsettings ..." 설정을 했는데요, 아마 저 상태에서 재부팅해도 잘되지 않을까... 싶습니다.




"bcdedit /dbgsettings ..."를 삭제하고 싶다면 /deletevalue 옵션을 4개의 값에 대해 일일이 지워야 합니다.

bcdedit /deletevalue {dbgsettings} key
bcdedit /deletevalue {dbgsettings} debugtype
bcdedit /deletevalue {dbgsettings} hostip 
bcdedit /deletevalue {dbgsettings} port

아니면, 그냥 LOCAL 설정으로 덮어쓰는 것도 좋겠고!

bcdedit /dbgsettings LOCAL

참고로, 본문에서는 "kdnet + bcdedit" 번에 걸쳐서 Debuggee 측의 설정을 했지만 그냥 다음과 같이 bcdedit 한 번으로 끝낼 수 있습니다.

bcdedit /dbgsettings NET HOSTIP:ip PORT:port [KEY:key]





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







[최초 등록일: ]
[최종 수정일: 5/9/2023]

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

비밀번호

댓글 작성자
 




... 31  32  33  34  35  [36]  37  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
12752정성태8/4/20216714개발 환경 구성: 592. JetBrains의 IDE(예를 들어, PyCharm)에서 Visual Studio 키보드 매핑 적용
12751정성태8/4/20219798개발 환경 구성: 591. Windows 10 WSL2 환경에서 docker-compose 빌드하는 방법
12750정성태8/3/20216575디버깅 기술: 181. windbg - 콜 스택의 "Call Site" 오프셋 값이 가리키는 위치
12749정성태8/2/20215988개발 환경 구성: 590. Visual Studio 2017부터 단위 테스트에 DataRow 특성 지원
12748정성태8/2/20216645개발 환경 구성: 589. Azure Active Directory - tenant의 관리자(admin) 계정 로그인 방법
12747정성태8/1/20217211오류 유형: 748. 오류 기록 - MICROSOFT GRAPH – HOW TO IMPLEMENT IAUTHENTICATIONPROVIDER파일 다운로드1
12746정성태7/31/20219251개발 환경 구성: 588. 네트워크 장비 환경을 시뮬레이션하는 Packet Tracer 프로그램 소개
12745정성태7/31/20217094개발 환경 구성: 587. Azure Active Directory - tenant의 관리자 계정 로그인 방법
12744정성태7/30/20217721개발 환경 구성: 586. Azure Active Directory에 연결된 App 목록을 확인하는 방법?
12743정성태7/30/20218426.NET Framework: 1083. Azure Active Directory - 외부 Token Cache 저장소를 사용하는 방법파일 다운로드1
12742정성태7/30/20217590개발 환경 구성: 585. Azure AD 인증을 위한 사용자 인증 유형
12741정성태7/29/20218836.NET Framework: 1082. Azure Active Directory - Microsoft Graph API 호출 방법파일 다운로드1
12740정성태7/29/20217456오류 유형: 747. SharePoint - InvalidOperationException 0x80131509
12739정성태7/28/20217420오류 유형: 746. Azure Active Directory - IDW10106: The 'ClientId' option must be provided.
12738정성태7/28/20218058오류 유형: 745. Azure Active Directory - Client credential flows must have a scope value with /.default suffixed to the resource identifier (application ID URI).
12737정성태7/28/20216985오류 유형: 744. Azure Active Directory - The resource principal named api://...[client_id]... was not found in the tenant
12736정성태7/28/20217556오류 유형: 743. Active Azure Directory에서 "API permissions"의 권한 설정이 "Not granted for ..."로 나오는 문제
12735정성태7/27/20218101.NET Framework: 1081. C# - Azure AD 인증을 지원하는 데스크톱 애플리케이션 예제(Windows Forms) [2]파일 다운로드1
12734정성태7/26/202124118스크립트: 20. 특정 단어로 시작하거나/끝나는 문자열을 포함/제외하는 정규 표현식 - Look-around
12733정성태7/23/202111404.NET Framework: 1081. Self-Contained/SingleFile 유형의 .NET Core/5+ 실행 파일을 임베딩한다면? [1]파일 다운로드2
12732정성태7/23/20216649오류 유형: 742. SharePoint - The super user account utilized by the cache is not configured.
12731정성태7/23/20217950개발 환경 구성: 584. Add Internal URLs 화면에서 "Save" 버튼이 비활성화 된 경우
12730정성태7/23/20219371개발 환경 구성: 583. Visual Studio Code - Go 코드에서 입력을 받는 경우
12729정성태7/22/20218346.NET Framework: 1080. xUnit 단위 테스트에 메서드/클래스 수준의 문맥 제공 - Fixture
12728정성태7/22/20217752.NET Framework: 1079. MSTestv2 단위 테스트에 메서드/클래스/어셈블리 수준의 문맥 제공
12727정성태7/21/20218795.NET Framework: 1078. C# 단위 테스트 - MSTestv2/NUnit의 Assert.Inconclusive 사용법(?) [1]
... 31  32  33  34  35  [36]  37  38  39  40  41  42  43  44  45  ...