콘텐츠로 건너뛰기

WindowsKernel

ReadMe.txt

Reversing.Kr CrackMe – WindowsKernel

Please authenticate to lowercase.

Exeinfo PE

WindowKernel.exe

WinKer.sys

Analysis

WindowKernel.exe – sub_401110

HWND __thiscall sub_401110(HWND hDlg)
{
  HWND result; // eax
  HWND v3; // eax
  HWND v4; // eax
  HWND DlgItem; // eax
  WCHAR String[256]; // [esp+8h] [ebp-204h] BYREF

  GetDlgItemTextW(hDlg, 1003, String, 512);
  if ( lstrcmpW(String, L"Enable") )
  {
    result = (HWND)lstrcmpW(String, L"Check");
    if ( !result )
    {
      if ( ((int (__cdecl *)(int))sub_401280)(0x2000) == 1 )
        MessageBoxW(hDlg, L"Correct!", L"Reversing.Kr", 0x40u);
      else
        MessageBoxW(hDlg, L"Wrong", L"Reversing.Kr", 0x10u);
      SetDlgItemTextW(hDlg, 1002, &word_4021F0);
      DlgItem = GetDlgItem(hDlg, 1002);
      EnableWindow(DlgItem, 0);
      return (HWND)SetDlgItemTextW(hDlg, 1003, L"Enable");
    }
  }
  else if ( ((int (__cdecl *)(int))sub_401280)(0x1000) )
  {
    v3 = GetDlgItem(hDlg, 1002);
    EnableWindow(v3, 1);
    SetDlgItemTextW(hDlg, 1003, L"Check");
    SetDlgItemTextW(hDlg, 1002, &word_4021F0);
    v4 = GetDlgItem(hDlg, 1002);
    return SetFocus(v4);
  }
  else
  {
    return (HWND)MessageBoxW(hDlg, L"Device Error", L"Reversing.Kr", 0x10u);
  }
  return result;
}

sub_401280에서 반환된 리턴값이 1이면 Correct 문구를 띄우도록 되어있다.

WindowKernel.exe – sub_401280

int __usercall sub_401280@<eax>(HWND a1@<edi>, DWORD dwIoControlCode)
{
  HANDLE FileW; // esi
  DWORD BytesReturned; // [esp+4h] [ebp-8h] BYREF
  int OutBuffer; // [esp+8h] [ebp-4h] BYREF

  FileW = CreateFileW(L"\\\\.\\RevKr", 0xC0000000, 0, 0, 3u, 0, 0);
  if ( FileW == (HANDLE)-1 )
  {
    MessageBoxW(a1, L"[Error] CreateFile", L"Reversing.Kr", 0x10u);
    return 0;
  }
  else if ( DeviceIoControl(FileW, dwIoControlCode, 0, 0, &OutBuffer, 4u, &BytesReturned, 0) )
  {
    CloseHandle(FileW);
    return OutBuffer;
  }
  else
  {
    MessageBoxW(a1, L"[Error] DeviceIoControl", L"Reversing.Kr", 0x10u);
    return 0;
  }
}

https://learn.microsoft.com/ko-kr/windows/win32/api/ioapiset/nf-ioapiset-deviceiocontrol

“DeviceIoControl: 지정된 디바이스 드라이버에 직접 제어 코드를 보내 해당 디바이스가 해당 작업을 수행하도록 합니다.”

여기까지만 봐왔을때, WinKer.sys 드라이버 파일을 로드시켜서 제어 코드를 보내는 것으로 확인된다.

OutBuffer를 1로 만들어야 Correct 문구를 띄울 수 있을 것이다.

윈도우 커널모드 디버깅

Vmware Workstation 17.5.1 Pro, 윈도우7 32비트 기준으로
위와 같이 시리얼 포트를 구성하고,

WinDbg에서도 포트를 설정해준다음,

가상머신에서 윈도우를 부팅할때 F8키를 무한연타해서 “디버깅 모드”로 부팅한다.

그리고 다시 WinDbg의 Start debugging 창에서 OK 버튼을 눌러주면, 위 사진처럼 디버깅 환경 구성이 완성된다.

이 중 몇가지 명령어에 대해 살펴보자면,

sxe ld WinKer.sys
WinKer.sys가 로드될때 디버거가 멈춘다.

u WinKer+0x1266

해당 메모리 주소 지점의 어셈블리 코드를 보여준다.

bp WinKer+0x12B8

해당 메모리 주소에 브레이크포인트를 설치한다.

r <레지스터>, r <레지스터>=<값>

특정 레지스터값을 읽거나 쓸 수 있다.

WinKer.sys 드라이버를 다시 분석해보면,

WinKer.sys – sub_11288

dwIoControlCode가 0x2000일때 처리하는 코드는 sub_11288의 16줄에서 확인할 수 있다.

dword_13024의 값을 edx로 가져오고 난뒤의 브레이크포인트를 설치해서
edx값을 1로 임의로 바꾸면,

Correct 문구가 뜨는 것을 알 수 있었다.

따라서, dword_13024가 1로 지정되게끔 만들려면 어떻게 해야되는지 확인하기 위해 역참조해보았다.

sub_110D0+3A에서 1로 지정되는 것을 확인했다.

sub_110D0 함수는

DriverEntry -> sub_11266 -> sub_111DC -> sub_11156을 거쳐
최종 호출된다.

WinKer.syssub_11266

void __stdcall sub_11266(struct _KDPC *Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
{
  char v4; // al

  v4 = READ_PORT_UCHAR((PUCHAR)0x60);
  sub_111DC(v4);
}

READ_PORT_UCHAR 루틴은 지정된 포트 주소에서 바이트를 읽습니다.”

https://learn.microsoft.com/ko-kr/windows-hardware/drivers/ddi/wdm/nf-wdm-read_port_uchar

https://wiki.osdev.org/%228042%22_PS/2_Controller

https://ggangjo.tistory.com/32

0x60 번지를 읽으면 키보드에 전송한 데이터를 읽을 수 있다고 한다.

따라서 sub_11266 함수는 키보드에 대한 데이터를 읽어와서 sub_111DC 함수에서 처리한다고 보면 된다.

WinKer.sys – sub_111DC, sub_11156, sub_110D0

https://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/scancode.doc

스캔 코드 테이블을 확인하면 어떤 키를 입력해야 dword_13024가 1로 지정되게끔 만들 수 있는지 확인할 수 있다.

여기서 주의할 점은
sub_11156에서는 0x12을 한번 XOR,
sub_110D0에서는 0x12을 한번 XOR, 0x5를 한번 더 XOR을 해야 스캔 코드를 구할 수 있다.

Scan Code Table

The following table lists the full set of Scan Codes as presently recognized by the Microsoft operating systems. The US Key assignments are for reference to a type 101/102 Enhanced keyboard as supported by the Type 4 Keyboard layout. If there is no entry in the 101/102 Enhanced keyboard column, this scan code is currently not recognized by the operating system. The Key Location field has been added to aid in the placement of keys as illustrated in the

Recommended Physical Locations of the Windows Keys on page 10.

key location101/102 Enhanced Keyboardscan 1 makescan 1 breakscan 2 makescan 2 brake
 DO NOT USE008000F0 00
 DO NOT USEE0_00E0_80E0_00E0_F0 00
1~   `29A90EF0 0E
  E0_29E0_A9E0_0EE0_F0 0E
2!  1028216F0 16
  E0_02E0_82E0_16E0_F0 16
3@  203831EF0 1E
  E0_03E0_83E0_1EE0_F0 1E
4#  3048426F0 26
  E0_04E0_84E0_26E0_F0 26
5$  4058525F0 25
  E0_05E0_85E0_25E0_F0 25
6%  506862EF0 2E
  E0_06E0_86E0_2EE0_F0 2E
7^  6078736F0 36
  E0_07E0_87E0_36E0_F0 36
8&  708883DF0 3D
  E0_08E0_88E0_3DE0_F0 3D
9*  809893EF0 3E
  E0_09E0_89E0_3EE0_F0 3E
10(  90A8A46F0 46
  E0_0AE0_8AE0_46E0_F0 46
11)  00B8B45F0 45
  E0_0BE0_8BE0_45E0_F0 45
12_   –0C8C4EF0 4E
  E0_0CE0_8CE0_4EE0_F0 4E
13+   =0D8D55F0 55
  E0_0DE0_8DE0_55E0_F0 55
15Backspace0E8E66F0 66
  E0_0EE0_8EE0_66E0_F0 66
16Tab0F8F0DF0 0D
  E0_0FE0_8FE0_0DE0_F0 0D
17Q109015F0 15
  E0_10E0_90E0_15E0_F0 15
18W11911DF0 1D
  E0_11E0_91E0_1DE0_F0 1D
19E129224F0 24
  E0_12E0_92E0_24E0_F0 24
20R13932DF0 2D
  E0_13E0_93E0_2DE0_F0 2D
21T14942CF0 2C
  E0_14E0_94E0_2CE0_F0 2C
22Y159535F0 35
  E0_15E0_95E0_35E0_F0 35
23U16963CF0 3C
  E0_16E0_96E0_3CE0_F0 3C
24I179743F0 43
  E0_17E0_97E0_43E0_F0 43
25O189844F0 44
  E0_18E0_98E0_44E0_F0 44
26P19994DF0 4D
  E0_19E0_99E0_4DE0_F0 4D
27{  [1A9A54F0 54
  E0_1AE0_9AE0_54E0_F0 54
28}  ]1B9B5BF0 5B
  E0_1BE0_9BE0_5BE0_F0 5B
29*|  \2BAB5DF0 5D
  E0_2BE0_ABE0_5DE0_F0 5D
30Caps Lock3ABA58F0 58
  E0_3AE0_BAE0_58E0_F0 58
31A1E9E1CF0 1C
  E0_1EE0_9EE0_1CE0_F0 1C
32S1F9F1BF0 1B
  E0_1FE0_9FE0_1BE0_F0 1B
33D20A023F0 23
  E0_20E0_A0E0_23E0_F0 23
34F21A12BF0 2B
  E0_21E0_A1E0_2BE0_F0 2B
35G22A234F0 34
  E0_22E0_A2E0_34E0_F0 34
36H23A333F0 33
  E0_23E0_A3E0_33E0_F0 33
37J24A43BF0 3B
  E0_24E0_A4E0_3BE0_F0 3B
38K25A542F0 42
  E0_25E0_A5E0_42E0_F0 42
39L26A64BF0 4B
  E0_26E0_A6E0_4BE0_F0 4B
40:   ;27A74CF0 4C
  E0_27E0_A7E0_4CE0_F0 4C
41“  ‘28A852F0 52
  E0_28E0_A8E0_52E0_F0 52
42** 2BAB5DF0 5D
  E0_2BE0_ABE0_5DE0_F0 5D
43Enter1C9C5AF0 5A
44L SHIFT2AAA12F0 12
  E0_2AE0_AAE0_12E0_F0 12
45** 56D661F0 61
  E0_56E0_D6E0_61E0_F0 61
46Z2CAC1AF0 1A
  E0_2CE0_ACE0_1AE0_F0 1A
47X2DAD22F0 22
  E0_2DE0_ADE0_22E0_F0 22
48C2EAE21F0 21
  E0_2EE0_AEE0_21E0_F0 21
49V2FAF2AF0 2A
  E0_2FE0_AFE0_2AE0_F0 2A
50B30B032F0 32
  E0_30E0_B0E0_32E0_F0 32
51N31B131F0 31
  E0_31E0_B1E0_31E0_F0 31
52M32B23AF0 3A
  E0_32E0_B2E0_3AE0_F0 3A
53<  ,33B341F0 41
  E0_33E0_B3E0_41E0_F0 41
54>  .34B449F0 49
  E0_34E0_B4E0_49E0_F0 49
55?  /35B54AF0 4A
  E0_35E0_B5E0_4AE0_F0 4A
56*** 73F351F0 51
  E0_73E0_F3E0_51E0_F0 51
57R SHIFT36B659F0 59
  E0_36E0_B6E0_59E0_F0 59
58L CTRL1D9D14F0 14
60L ALT38B811F0 11
  E0_38E0_B8E0_11E0_F0 11
61Space Bar39B929F0 29
  E0_39E0_B9E0_29E0_F0 29
62R ALTE0 38E0 B8E0 11E0 F0 11
64R CTRLE0 1DE0 9DE0 14E0 F0 14
75InsertNote 1Note 1Note 2Note 2
76DeleteNote 1Note 1Note 2Note 2
79L ArrowNote 1Note 1Note 2Note 2
80HomeNote 1Note 1Note 2Note 2
81EndNote 1Note 1Note 2Note 2
83Up ArrowNote 1Note 1Note 2Note 2
84Dn ArrowNote 1Note 1Note 2Note 2
85Page UpNote 1Note 1Note 2Note 2
86Page DownNote 1Note 1Note 2Note 2
89R ArrowNote 1Note 1Note 2Note 2
90Num Lock45C577F0 77
  E0_45E0_C5E0_77E0_F0 77
91Numeric 747C76CF0 6C
92Numeric 44BCB6BF0 6B
93Numeric 14FCF69F0 69
95Numeric /Note 3Note 3Note 3Note 3
96Numeric 848C875F0 75
97Numeric 54CCC73F0 73
98Numeric 250D072F0 72
99Numeric 052D270F0 70
100Numeric *37B77CF0 7C
  E0_37E0_B7E0_7CE0_F0 7C
101Numeric 949C97DF0 7D
102Numeric 64DCD74F0 74
103Numeric 351D17AF0 7A
104Numeric .53D371F0 71
105Numeric –4ACA7BF0 7B
106Numeric +4ECE79F0 79
107*** 7EFE6DF0 6D
 DO NOT USEE0_7EE0_FEE0_6DE0_F0 6D
108Numeric EnterE0 1CE0 9CE0 5AE0 F0 5A
110Esc018176F0 76
  E0_01E0_81E0_76E0_F0 76
112F13BBB05F0 05
  E0_3BE0_BBE0_05E0_F0 05
113F23CBC06F0 06
  E0_3CE0_BCE0_06E0_F0 06
114F33DBD04F0 05
  E0_3DE0_BDE0_04E0_F0 05
115F43EBE0CF0 0C
  E0_3EE0_BEE0_0CE0_F0 0C
116F53FBF03F0 03
  E0_3FE0_BFE0_03E0_F0 03
117F640C00BF0 0B
  E0_40E0_C0E0_0BE0_F0 0B
118F741C183F0 83
  E0_41E0_C1E0_83E0_F0 83
119F842C20AF0 0A
  E0_42E0_C2E0_0AE0_F0 0A
120F943C301F0 01
  E0_43E0_C3E0_01E0_F0 01
121F1044C409F0 09
  E0_44E0_C4E0_09E0_F0 09
122F1157D778F0 78
123F1258D807F0 07
124Print ScreenNote 4Note 4Note 4Note 4
125Scroll Lock46C67EF0 7E
  E0_46E0_C6E0_7EE0_F0 7E
126PauseNote 5Note 5Note 5Note 5
  59D90FF0 0F
  E0_59E0_D9E0_0FE0_F0 0F
  5BDB1FF0 1F
 Left WinE0_5BE0_DBE0_1FE0_F0 1F
  5CDC27F0 27
 Right WinE0_5CE0_DCE0_27E0_F0 27
  5DDD2FF0 2F
 ApplicationE0_5DE0_DDE0_2FE0_F0 2F
  5EDE37F0 37
 ACPI PowerE0_5EE0_DEE0_37E0_F0 37
  5FDF3FF0 3F
 ACPI SleepE0_5FE0_DFE0_3FE0_F0 3F
 DO NOT USE60E047F0 47
 DO NOT USEE0_60E0_E0E0_47E0_F0 47
 DO NOT USE61E14FF0 4F
 DO NOT USEE0_61E0_E1E0_4FE0_F0 4F
  62E256F0 56
  E0_62E0_E2E0_56E0_F0 56
  63E35EF0 5E
 ACPI WakeE0_63E0_E3E0_5EE0_F0 5E
  64E408F0 08
  E0_64E0_E4E0_08E0_F0 08
  65E510F0 10
  E0_65E0_E5E0_10E0_F0 10
  66E618F0 18
  E0_66E0_E6E0_18E0_F0 18
  67E720F0 20
  E0_67E0_E7E0_20E0_F0 20
  68E828F0 28
  E0_68E0_E8E0_28E0_F0 28
  69E930F0 30
  E0_69E0_E9E0_30E0_F0 30
  6AEA38F0 38
  E0_6AE0_EAE0_38E0_F0 38
  6BEB40F0 40
  E0_6BE0_EBE0_40E0_F0 40
  6CEC48F0 48
  E0_6CE0_ECE0_48E0_F0 48
  6DED50F0 50
  E0_6DE0_EDE0_50E0_F0 50
  6EEE57F0 57
  E0_6EE0_EEE0_57E0_F0 57
  6FEF6FF0 6F
  E0_6FE0_EFE0_6FE0_F0 6F
 DBE_KATAKANA‡70F013F0 13
  E0_70E0_F0E0_13E0_F0 13
  71F119F0 19
  E0_71E0_F1E0_19E0_F0 19
  72F239F0 39
  E0_72E0_F2E0_39E0_F0 39
  74F453F0 53
  E0_74E0_F4E0_53E0_F0 53
  75F55CF0 5C
  E0_75E0_F5E0_5CE0_F0 5C
  76F65FF0 5F
  E0_76E0_F6E0_5FE0_F0 5F
 DBE_SBCSCHAR‡77F762F0 62
  E0_77E0_F7E0_62E0_F0 62
  78F863F0 63
  E0_78E0_F8E0_63E0_F0 63
 CONVERT‡79F964F0 64
  E0_79E0_F9E0_64E0_F0 64
 DO NOT USE7AFA65F0 65
 DO NOT USEE0_7AE0_FAE0_65E0_F0 65
 NONCONVERT‡7BFB67F0 67
 DO NOT USEE0_7BE0_FBE0_67E0_F0 67
 DO NOT USE7CFC68F0 68
 DO NOT USEE0_7CE0_FCE0_68E0_F0 68
 DO NOT USE7DFD6AF0 6A
 DO NOT USEE0_7DE0_FDE0_6AE0_F0 6A
 DO NOT USE7FFF6EF0 6E
 DO NOT USEE0_7FE0_FFE0_6EE0_F0 6E
scancode.doc

FLAG

keybdinthook

태그:

답글 남기기