Сейчас на форуме: UniSoft, laslo, bartolomeo (+5 невидимых)

 eXeL@B —› Программирование —› Windows7 Поиск базы kernel32.dll
Посл.ответ Сообщение


Ранг: 67.4 (постоянный)
Активность: 0.040
Статус: Участник

Создано: 18 июля 2009 10:42 · Поправил: Sunzer
· Личное сообщение · #1

Поставил себе вчера на виртуалку семерку, и столкнулся с проблемой.

Этот код получает базу kernel32.dll через PEB.
Code:
  1. MOV EAX,DWORD PTR FS:[30]
  2. MOV EAX,DWORD PTR DS:[EAX+0C]
  3. MOV ESI,DWORD PTR DS:[EAX+1C]
  4. LODS DWORD PTR DS:[ESI]
  5. MOV EAX,DWORD PTR DS:[EAX+8]


В Windows7 получается база kernelbase.dll.
Далее мой код парсит таблицу экспорта,находит адрес GetProcAddress.
После того как найдет, передает имя "LoadLibraryA" и базу которая нашлась через PEB.
Далее возратился ноль. В этом и проблема, я не долго думая взял саму либу kernelbase.dll
В экспорте не оказалось "LoadLibraryA", за то есть LoadLibraryExA и LoadLibraryExW для юникода соответственно.

Под Windows 2000, Windows 2003 Server, Windows XP SP3, Windows Vista,
код по поиску двух апи работает нормально.

Теперь решения

1) Как то найти базу kernel32.dll
- Скан памяти в лоб
- Как то еще хитро
- Через SEH или что-то
2) Заюзать через LoadLibraryExA
- Там какие то другие параметры, не юзал раньше но думаю тоже подойдет.

Желательно как-то без особых извращений найти базу кернеля.

PS Нашел по поиску по форуму похожий вопрос, но ответа там нет точного.
Там просили саму kernelbase.dll

c8ff_18.07.2009_CRACKLAB.rU.tgz - KernelBase.dll




Ранг: 2014.5 (!!!!), 1278thx
Активность: 1.340.25
Статус: Модератор
retired

Создано: 18 июля 2009 11:08
· Личное сообщение · #2

Чем ближе будешь держаться к документации, тем меньше придётся париться с новой ОС. Уже считал через пеб, теперь получил гемор. Может, на этот раз сделать через документированные функции лучше, чтоб снова потом не переписывать?




Ранг: 67.4 (постоянный)
Активность: 0.040
Статус: Участник

Создано: 18 июля 2009 11:09
· Личное сообщение · #3

Как именно?




Ранг: 355.4 (мудрец), 55thx
Активность: 0.320
Статус: Uploader
5KRT

Создано: 18 июля 2009 11:13 · Поправил: Coderess
· Личное сообщение · #4

2) Заюзать через LoadLibraryExA

Раз базу LoadLibraryEx получил, то используй её!

-----
Gutta cavat lapidem. Feci, quod potui. Faciant meliora potentes





Ранг: 67.4 (постоянный)
Активность: 0.040
Статус: Участник

Создано: 18 июля 2009 11:32
· Личное сообщение · #5

Еще идеи? Код должен быть базонезависим.




Ранг: 67.4 (постоянный)
Активность: 0.040
Статус: Участник

Создано: 18 июля 2009 12:14
· Личное сообщение · #6

По другому сделал

Code:
  1.  
  2. <ModuleEntryPoint>:
  3. PUSHAD
  4. MOV EAX,DWORD PTR SS:[ESP+020h]
  5. @test_00401005:
  6. DEC EAX
  7. CMP DWORD PTR DS:[EAX],0905A4Dh
  8. JNZ @test_00401005


Windows 2000 - ok
Windows 2003 Server - ok
Windows XP SP3 - ok
Windows Vista - ok
Windows 7 - ok



Ранг: 0.4 (гость)
Активность: 0=0
Статус: Участник

Создано: 18 июля 2009 12:57
· Личное сообщение · #7

мож все таки лучше предварительно и PAGE_SIZE вычислить?




Ранг: 67.4 (постоянный)
Активность: 0.040
Статус: Участник

Создано: 18 июля 2009 15:13
· Личное сообщение · #8

Зачем? У меня решение есть правдо оно базозависимо но везде работает.




Ранг: 462.8 (мудрец), 468thx
Активность: 0.280
Статус: Участник
Only One!

Создано: 18 июля 2009 16:11
· Личное сообщение · #9

Sunzer пишет:
По другому сделал


Это действительно только для ехе файлов...

-----
aLL rIGHTS rEVERSED!





Ранг: 67.4 (постоянный)
Активность: 0.040
Статус: Участник

Создано: 18 июля 2009 17:09
· Личное сообщение · #10

Знаю, может кто-то все же знает как найти базу kernel32.dll в Windows 7?
Нужен базанезависимый код.




Ранг: 462.8 (мудрец), 468thx
Активность: 0.280
Статус: Участник
Only One!

Создано: 18 июля 2009 17:22 · Поправил: DaRKSiDE
· Личное сообщение · #11

Sunzer пишет:
Знаю, может кто-то все же знает как найти базу kernel32.dll в Windows 7?


...ля ну полазь в отладчике по PEB... наверняка найдешь какойнить адрес из кернела... или под семеркой отладчик не пашет?

-----
aLL rIGHTS rEVERSED!




Ранг: 255.8 (наставник), 19thx
Активность: 0.150.01
Статус: Участник
vx

Создано: 18 июля 2009 20:08
· Личное сообщение · #12

Последовательность модулей из базы данных лоадера в студию.




Ранг: 673.3 (! !), 400thx
Активность: 0.40.31
Статус: Участник
CyberMonk

Создано: 19 июля 2009 00:54
· Личное сообщение · #13

For shellcode, a common method to resolve the addresses of library functions needed, is to get the base address of the kernel32.dll image in memory and retrieve the addresses of GetProcAddress and LoadLibraryA by parsing the kernel32 images Export Address Table (EAT). These two functions can then be used to resolve the remaining functions needed by the shellcode. To retrieve the kernel32.dll base address most shellcodes use the Process Environment Block (PEB) structure to retrieve a list of modules currently loaded in the processes address space. The InInitializationOrder module list pointed to by the PEB's Ldr structure holds a linked list of modules. Typically the second entry in this list has always been that of kernel32.dll. The code used to retrieve the kernel32 base address based on this method is shown below:

Code:
  1.  xor ebx, ebx             // clear ebx
  2.  mov ebx, fs:[ 0x30 ]     // get a pointer to the PEB
  3.  mov ebx, [ ebx + 0x0C ]  // get PEB->Ldr
  4.  mov ebx, [ ebx + 0x1C ]  // get PEB->Ldr.InInitializationOrderModuleList.Flink (1st entry)
  5.  mov ebx, [ ebx ]         // get the next entry (2nd entry)
  6.  mov ebx, [ ebx + 0x08 ]  // get the 2nd entries base address (kernel32.dll)


This method has worked for all versions of Windows from Windows 2000 up to and including Windows Vista. The introduction of Windows 7 (rc1) has broken this method of retrieving the kernel32 base address due to the new MinWin kernel structure employed by Windows 7. A new module kernelbase.dll is loaded before kernel32.dll and as such appears in the second entry of the InInitializationOrder module list.

To retrieve the kernel32.dll base address in a generic manner on all versions of Windows from Windows 2000 up to and including Windows 7 (rc1) a slightly modified approach can be used. Instead of parsing the PEB's InInitializationOrder module list, the InMemoryOrder module list can be parsed instead. The third entry in this list will always be that of kernel32.dll (The first being that of the main module and the second being that of ntdll.dll). The code used to retrieve the kernel32 base address based on this method is shown below:

Code:
  1.  xor ebx, ebx               // clear ebx
  2.  mov ebx, fs:[ 0x30 ]       // get a pointer to the PEB
  3.  mov ebx, [ ebx + 0x0C ]    // get PEB->Ldr
  4.  mov ebx, [ ebx + 0x14 ]    // get PEB->Ldr.InMemoryOrderModuleList.Flink (1st entry)
  5.  mov ebx, [ ebx ]           // get the next entry (2nd entry)
  6.  mov ebx, [ ebx ]           // get the next entry (3rd entry)
  7.  mov ebx, [ ebx + 0x10 ]    // get the 3rd entries base address (kernel32.dll)


Update: Their appears to be some cases on Windows 2000 whereby the above method will not yield the correct result. A more robust method, albeit a more lengthy one, can be seen below. We search the InMemoryOrder module list for the kernel32 module using a hash of the module name for comparison. We also normalise the module name to uppercase as some systems store module names in uppercase and some in lowercase.

Code:
  1.  cld                    // clear the direction flag for the loop
  2.   xor edx, edx           // zero edx
  3.  
  4.   mov edx, [fs:edx+0x30] // get a pointer to the PEB
  5.   mov edx, [edx+0x0C]    // get PEB->Ldr
  6.   mov edx, [edx+0x14]    // get the first module from the InMemoryOrder module list
  7. next_mod:
  8.   mov esi, [edx+0x28]    // get pointer to modules name (unicode string)
  9.   push byte 24           // push down the length we want to check
  10.   pop ecx                // set ecx to this length for the loop
  11.   xor edi, edi           // clear edi which will store the hash of the module name
  12. loop_modname:
  13.   xor eax, eax           // clear eax
  14.   lodsb                  // read in the next byte of the name
  15.   cmp al, 'a'            // some versions of Windows use lower case module names
  16.   jl not_lowercase
  17.   sub al, 0x20           // if so normalise to uppercase
  18. not_lowercase:
  19.   ror edi, 13            // rotate right our hash value
  20.   add edi, eax           // add the next byte of the name to the hash
  21.   loop loop_modname      // loop until we have read enough
  22.   cmp edi, 0x6A4ABC5B    // compare the hash with that of KERNEL32.DLL
  23.   mov ebx, [edx+0x10]    // get this modules base address
  24.   mov edx, [edx]         // get the next module
  25.   jne next_mod           // if it doesn't match, process the next module


// when we get here EBX is the kernel32 base (or change to suit).

his code has been verified on the following systems:

Windows 2000 SP4
Windows XP SP2
Windows XP SP3
Windows 2003 SP2
Windows Vista SP1
Windows 2008 SP1
Windows 7 RC1
The following WinDbg session shows how we can manually verify the above methods on a Windows 7 RC1 system:

Code:
  1. 0:004> version
  2. Windows 7 Version 7100 UP Free x86 compatible
  3. Product: WinNt, suite: SingleUserTS
  4. kernel32.dll version: 6.1.7100.0 (winmain_win7rc.090421-1700)
  5. ...
  6.  
  7. // list the loaded modules...
  8. 0:004> lm
  9. start end module name
  10. 00d20000 00de0000 calc (pdb symbols)
  11. 70930000 70a77000 msxml6 (pdb symbols)
  12. 725c0000 725fc000 oleacc (pdb symbols)
  13. 73e10000 73e42000 WINMM (pdb symbols)
  14. 73e50000 73f49000 WindowsCodecs (pdb symbols)
  15. 74170000 74183000 dwmapi (pdb symbols)
  16. 742c0000 74450000 gdiplus (pdb symbols)
  17. 74450000 74490000 UxTheme (pdb symbols)
  18. 745d0000 7476c000 COMCTL32 (pdb symbols)
  19. 74b50000 74b59000 VERSION (pdb symbols)
  20. 755a0000 755ac000 CRYPTBASE (pdb symbols)
  21. 756d0000 75718000 KERNELBASE (pdb symbols)
  22. 75950000 7596f000 IMM32 (pdb symbols)
  23. 75970000 759ff000 OLEAUT32 (pdb symbols)
  24. 75a00000 75ac9000 USER32 (pdb symbols)
  25. 75ae0000 75bac000 MSCTF (pdb symbols)
  26. 75d60000 75e02000 RPCRT4 (pdb symbols)
  27. 75e60000 75f0c000 msvcrt (pdb symbols)
  28. 75f50000 75ff0000 ADVAPI32 (pdb symbols)
  29. 75ff0000 7608d000 USP10 (pdb symbols)
  30. 76090000 76113000 CLBCatQ (pdb symbols)
  31. 76120000 7627b000 ole32 (pdb symbols)
  32. 76280000 762d7000 SHLWAPI (pdb symbols)
  33. 763e0000 77026000 SHELL32 (pdb symbols)
  34. 77030000 77049000 sechost (pdb symbols)
  35. 77050000 77124000 kernel32 (pdb symbols)
  36. 77160000 771ae000 GDI32 (pdb symbols)
  37. 77500000 7763c000 ntdll (pdb symbols)
  38. 77720000 7772a000 LPK (pdb symbols)
  39.  
  40. // dump the PEB...
  41. 0:004> !peb
  42. PEB at 7ffdc000
  43. InheritedAddressSpace: No
  44. ReadImageFileExecOptions: No
  45. BeingDebugged: Yes
  46. ImageBaseAddress: 00d20000
  47. Ldr 775d7880
  48. Ldr.Initialized: Yes
  49. Ldr.InInitializationOrderModuleList: 00221a28 . 002b13a0
  50. Ldr.InLoadOrderModuleList: 00221988 . 002b1390
  51. Ldr.InMemoryOrderModuleList: 00221990 . 002b1398
  52. ...
  53.  
  54. // show the Ldr.InInitializationOrderModuleList
  55. // dump the first entry...
  56. 0:004> dd 00221a28
  57. 00221a28 00221e68 775d789c 77500000 00000000 // 77500000 = ntdll.dll
  58. 00221a38 0013c000 003c003a 002218e8 00140012
  59. 00221a48 7756835c 00004004 0000ffff 775da680
  60. 00221a58 775da680 49eea66e 00000000 00000000
  61. // dump the second entry...
  62. 0:004> dd 00221e68
  63. 00221e68 00221d50 00221a28 756d0000 756d8005 // 756d0000 = KERNELBASE.dll
  64. 00221e78 00048000 00460044 00221df8 001e001c
  65. 00221e88 00221e20 00084004 0000ffff 0022a9b4
  66. 00221e98 775da690 49eea60f 00000000 00000000
  67. // we can see the second entry is for kernelbase.dll and not kernel32.dll
  68.  
  69. // show the Ldr.InMemoryOrderModuleList
  70. // dump the first entry...
  71. 0:004> dd 00221990
  72. 00221990 00221a20 775d7894 00000000 00000000
  73. 002219a0 00d20000 00d30140 000c0000 003a0038 // 00d20000 = calc.exe
  74. 002219b0 002217fa 00120010 00221822 00004000
  75. 002219c0 0000ffff 00222b84 775da6a8 49ee917f
  76. // dump the second entry...
  77. 0:004> dd 00221a20
  78. 00221a20 00221d48 00221990 00221e68 775d789c
  79. 00221a30 77500000 00000000 0013c000 003c003a // 77500000 = ntdll.dll
  80. 00221a40 002218e8 00140012 7756835c 00004004
  81. 00221a50 0000ffff 775da680 775da680 49eea66e
  82. // dump the third entry...
  83. 0:004> dd 00221d48
  84. 00221d48 00221e60 00221a20 002227e8 00221e68
  85. 00221d58 77050000 770a102d 000d4000 00420040 // 77050000 = kernel32.dll
  86. 00221d68 00221ce0 001a0018 00221d08 00084004
  87. 00221d78 0000ffff 002248a4 775da640 49eea60e
  88. // we can see the third entry is for kernel32.dll



bbb0_18.07.2009_CRACKLAB.rU.tgz - GetKernel32Base.zip

-----
RE In Progress [!] Coding Hazard [!] Stay Clear of this Cube




Ранг: 47.7 (посетитель), 17thx
Активность: 0.090
Статус: Участник

Создано: 08 ноября 2011 16:35 · Поправил: bowrouco
· Личное сообщение · #14

mak
Code:
  1. %NTCALL macro Id
  2.          mov eax,Id
  3.          mov edx,esp
  4.          Int 2Eh
  5. endm
  6.  
  7.          assume fs:nothing
  8. IsPcToNt proc C
  9.          pushad
  10.          xor ebx,ebx
  11.          mov esi,fs:[TEB.Peb]
  12.          push -4
  13.          mov esi,PEB.LoaderLock[esi]
  14.          push -4
  15. Id:
  16.          %NTCALL Ebx
  17.          cmp ax,(STATUS_INVALID_ADDRESS and 0000FFFFH)
  18.          je @f
  19.          inc ebx
  20.          bt ebx,12
  21.          jnb Id
  22.          inc eax
  23.          jmp Exit
  24. @@:
  25.          push esi
  26.          push esi
  27.          %NTCALL Ebx
  28.          add esp,2*4
  29.          test eax,eax
  30.          jnz Id
  31. @@:
  32.          push dword ptr [esp + 8*4 + 4 + 2*4]
  33.          push esi
  34.          %NTCALL Ebx
  35.          add esp,4*4
  36. Exit:
  37.          test eax,eax
  38.          popad
  39.          retn 4
  40. IsPcToNt endp



 eXeL@B —› Программирование —› Windows7 Поиск базы kernel32.dll
:: Ваш ответ
Жирный  Курсив  Подчеркнутый  Перечеркнутый  {mpf5}  Код  Вставить ссылку 
:s1: :s2: :s3: :s4: :s5: :s6: :s7: :s8: :s9: :s10: :s11: :s12: :s13: :s14: :s15: :s16:


Максимальный размер аттача: 500KB.
Ваш логин: german1505 » Выход » ЛС
   Для печати Для печати