Cara menemukan malware (tidak) dengan WinDbg
pengantar
Dalam artikel ini saya akan menunjukkan bagaimana, misalnya, menggunakan WinDbg untuk menemukan malware mana (atau tidak) menggantikan alamat pemanggilan fungsi sistem dalam DLL yang dimuat oleh beberapa aplikasi. Jadi, misalnya, saya mencari mengapa modul perlindungan tidak dimuat ke dalam konfigurasi 1C .
Untuk menunjukkan, kita memerlukan aplikasi yang memuat beberapa DLL: salah satunya disebut korban ( korban ), yang lain -predator injektor . Yang terakhir diperkenalkan ke korban, menggantikan panggilan ke fungsi sistem (untuk kesederhanaan, ambil Tidur ), dan akan memanggil AV dalam kondisi tertentu (yang akan diperlukan dalam artikel berikutnya).
Karena aplikasi yang ditulis dalam Delphi tidak "jatuh" ke dalam core-dump karena pengecualian tidak tertangani, maka aplikasi utama kami (DLLInjectionDemo) ditulis dalam C, dihubungkan dengan pengikatan awal dengan DLL korban, dan untuk memudahkan mereproduksi situasi, itu akan memuat DLL-injector melewati opsi saat startup, dan memanggil metode di dalamnya yang akan membahayakan korban. Khusus untuk artikel ini, aplikasi yang ditulis dalam bahasa pemrograman apa pun akan cocok untuk kita, tetapi kita akan membunuh dua burung dengan satu batu.
Kode sumber aplikasi ditulis dalam C dan Delphi 10.3 Rio Community Edition, dan MinGW dan Delphi dikompilasi, seperti untuk Win32, dan untuk Win64 (serta FPC di Lazarus).
Jadi kami mengkompilasi DLL dan aplikasi utama
> msbuild /t:build victim.dproj /p:Platform=Win32;Config=Debug;DCC_Exeoutput=.
> msbuild /t:build injector.dproj /p:Platform=Win32;Config=Debug;DCC_Exeoutput=.
> mingw32-make
Untuk membuat dengan MinGW make, Anda harus mendaftarkannya di PATH, tentu saja
:
C:\Users\demo>DLLInjectionDemo.exe
Sleeping 100 milliseconds
Done!
-L injector
(, , , - )
c:\Users\demo>DLLInjectionDemo.exe -L injector
Loading injector
Searching...
oleaut32.dll
advapi32.dll
user32.dll
kernel32.dll
kernel32.dll
user32.dll
version.dll
kernel32.dll
kernel32.dll
netapi32.dll
oleaut32.dll
Injected
Sleeping 100 milliseconds
New sleep instead of 100
Done!
, , Sleep - . ( , ). ( , GUI-, , , , -i
(interactive)).
c:\Users\demo>DLLInjectionDemo.exe -i -L injector
Loading injector
Searching...
oleaut32.dll
advapi32.dll
user32.dll
kernel32.dll
kernel32.dll
user32.dll
version.dll
kernel32.dll
kernel32.dll
netapi32.dll
oleaut32.dll
Injected
Sleeping 100 milliseconds
New sleep instead of 100
Done!
Press ENTER...
( ). : , , , , " ...", .
WinDbg, :
File
β Open Crash Dump (Ctrl+D)
:
%PROGRAM FILES%\Windows Kits\10\Debuggers\x64\windbg.exe" -z C:\Users\demo\App Data\Local\Temp\DLLInjectionDemo.DMP
Loading Dump File [C:\Users\alex\AppData\Local\Temp\DLLInjectionDemo.DMP]
User Mini Dump File with Full Memory: Only application data is available
Symbol search path is: srv*
Executable search path is:
Windows 7 Version 7601 (Service Pack 1) MP (4 procs) Free x64
Product: WinNt, suite: SingleUserTS
Machine Name:
Debug session time: Thu Jul 4 08:46:18.000 2019 (UTC + 3:00)
System Uptime: 17 days 12:25:45.404
Process Uptime: 0 days 0:00:10.000
........................
For analysis of this file, run !analyze -v
ntdll!NtRequestWaitReplyPort+0xa:
00000000`77bcddfa c3 ret
For analysis of this file, run !analyze -v
( , ).
IAT β (Import Address Table) β DLL, (? , IAT ;) ). , PE- ( DLL ) WinDbg Windows 10 SDK ( Windows 7) , " ", WinDbg 6, .
. :
lm
0:000> lm
start end module name
00000000`003b0000 00000000`003db000 injector (deferred)
00000000`00400000 00000000`00412000 DLLInjectionDemo (deferred)
00000000`00520000 00000000`00616000 victim (deferred)
00000000`6e580000 00000000`6e5b4000 libmingwex_2 (deferred)
00000000`72870000 00000000`72886000 netapi32 (deferred)
...
Nota bene: 32- , 64-...
, DLL , IAT , !dh
-a
:
!dh 009c0000 -a
!dh victim -a0:000> !dh victim -a
File Type: DLL
FILE HEADER VALUES
14C machine (i386)
A number of sections
5E5F4251 time date stamp Wed Mar 4 09:53:21 2020
0 file pointer to symbol table
0 number of symbols
E0 size of optional header
A18E characteristics
Executable
Line numbers stripped
Symbols stripped
Bytes reversed
32 bit word machine
DLL
OPTIONAL HEADER VALUES
10B magic #
2.25 linker version
CE400 size of code
1BA00 size of initialized data
0 size of uninitialized data
CF79C address of entry point
1000 base of code
----- new -----
0000000000400000 image base
1000 section alignment
200 file alignment
2 subsystem (Windows GUI)
5.00 operating system version
0.00 image version
5.00 subsystem version
F6000 size of image
400 size of headers
0 checksum
0000000000000000 size of stack reserve
0000000000000000 size of stack commit
0000000000100000 size of heap reserve
0000000000001000 size of heap commit
0 DLL characteristics
DD000 [ A4] address [size] of Export Directory
DA000 [ 105C] address [size] of Import Directory
F3000 [ 2A00] address [size] of Resource Directory
0 [ 0] address [size] of Exception Directory
0 [ 0] address [size] of Security Directory
...
kernel32.dll ( Sleep)
Nota bene: 32- _IMAGE_IMPORT_DESCRIPTOR 64-. , , Delphi .
...
_IMAGE_IMPORT_DESCRIPTOR 00000000005fa03c
kernel32.dll
005FA398 Import Address Table
005FA11C Import Name Table
0 time date stamp
0 Index of first forwarder reference
003C7C7C 0 Sleep
76EE184A 0 VirtualFree
76EE1832 0 VirtualAlloc
76EE16DC 0 lstrlenW
76EE4422 0 VirtualQuery
76EE110C 0 GetTickCount
...
,
`kernel32.dll`0:000> !dh kernel32
File Type: DLL
FILE HEADER VALUES
14C machine (i386)
4 number of sections
5708A7E3 time date stamp Sat Apr 9 10:57:39 2016
...
----- new -----
0000000076ed0000 image base
...
itu. 0000000076ed0000
, β ?
WinDbg lm
:
0:000> lma 003C7C7C
Browse full module list
start end module name
00000000`003b0000 00000000`003db000 injector (deferred)
, ! . ( v
lm
)
0:000> lma 003C7C7C v
Browse full module list
start end module name
00000000`003b0000 00000000`003db000 injector (deferred)
Image path: z:\habr\DLLInjectionDemo\injector.dll
Image name: injector.dll
Browse all global symbols functions data
Timestamp: Wed Mar 4 09:53:12 2020 (5E5F4248)
CheckSum: 00000000
ImageSize: 0002B000
Translations: 0000.04b0 0000.04e4 0409.04b0 0409.04e4
Information from resource tables:
!
Image path: C:\Users\demo\injector.dll
, .
Jadi dalam kondisi nyata, saya dengan cepat berhasil menemukan beberapa DLL aneh pada OS yang sudah diinstal dari pabrikan yang menyadap panggilan fungsi WriteFile
.
Saya menggunakan aplikasi dari artikel ini di yang berikutnya, di mana saya ingin menunjukkan kepada pembaca bagaimana menggunakan WinDbg untuk mencari tahu mengapa (atau setidaknya di suatu tempat) aplikasi jatuh dengan Pelanggaran Akses, yang terjadi dalam DLL yang ditulis dalam Delphi ketika debugging jarak jauh tidak tersedia karena beberapa alasan. apa pun alasannya. Terlepas dari kenyataan bahwa Delphi tidak memiliki alat untuk menganalisis dump aplikasi, dan tidak dapat menghasilkan file PDB.