Arama butonu
Bu konudaki kullanıcılar: 1 misafir
6
Cevap
686
Tıklama
0
Öne Çıkarma
C Handle is invalid hatası (Kernel Module Driver Loader) (ÇÖZÜLDÜ!)
G
5 yıl
Yüzbaşı
Konu Sahibi

Bir kernel driver'ı yazdım ve processimi çalıştıracağım. Fakat loader'ımda "Handle is invalid" hatası alıyorum bu neden oluyor ? araştırdım ama bir şeyler bulamadım maalesef


int call_kernel_driver(char * pid,HANDLE hDevice){


printf("%s %d", "[+] Calling Driver, hiding PID:", atoi(pid));

DWORD bytes_returned;
char * retbuf;

BOOL call_result = DeviceIoControl(
hDevice,
0x815,
pid,
strlen(pid) + 1,
&retbuf,
sizeof(retbuf),
&bytes_returned,
(LPOVERLAPPED) NULL);

if (!call_result) {
printf("%d",call_result);

printf("Error Code : %d",GetLastError());

printf("[-] Error sending IRP to driver: %s ", GetLastErrorAsString());
return -1;
}

printf("[+] IRP Sent, look for your process!");

}



DeviceIoControl 0 döndürüyor ve "Error Code 6 : Handle is invalid"hatasını alıyorum.

int main de HANDLE hDevice oluşturup servis installer fonksiyonunu ona eşliyorum HANDLE hDevice = installer(); ve call_kernel_driver'ın hDevice değerine onu veriyorum.





< Bu mesaj bu kişi tarafından değiştirildi Guest-8F0924900 -- 4 Şubat 2020; 10:24:14 >


Bu mesajda bahsedilenler: @vonderplanitz
T
5 yıl
Yarbay

En son yıllar evvel tutorial dan bakarak deneme amaçlı kernel module yazmıştım, insmod ile yüklenip hello world rmmod ile ayrılıp goodbye world mesajını veriyordu fakat onu derleyene kadar bayağı bir uğraşmıştım, derleme işlemi için kernel tree gerekiyordu.



< Bu ileti mini sürüm kullanılarak atıldı >

G
5 yıl
Yüzbaşı

kod sorunlu. DeviceIoControl api bildirimi

BOOL DeviceIoControl(

HANDLE hDevice, // handle to device of interest
DWORD dwIoControlCode, // control code of operation to perform
LPVOID lpInBuffer, // pointer to buffer to supply input data
DWORD nInBufferSize, // size of input buffer
LPVOID lpOutBuffer, // pointer to buffer to receive output data
DWORD nOutBufferSize, // size of output buffer
LPDWORD lpBytesReturned, // pointer to variable to receive output byte count
LPOVERLAPPED lpOverlapped // pointer to overlapped structure for asynchronous operation
);


win api yardım dosyası -https://sourceforge.net/projects/win32-help-chm/


Bu mesaja 1 cevap geldi.
G
5 yıl
Yüzbaşı
Konu Sahibi

BOOL call_result DeviceIoControl(

hDevice, // handle to device of interest
0x815, // control code of operation to perform
pid, // pointer to buffer to supply input data
strlen(pid)+1, // size of input buffer
&retbuf, // pointer to buffer to receive output data
sizeof(retbuf), // size of output buffer
&bytes_returned, // pointer to variable to receive output byte count
(LPOVERLAPPED) NULL // pointer to overlapped structure for asynchronous operation
);



Kodum böyle ve denilen commentler ile eşleşiyor.


Handle = hDevice

IoControlCode = 0x815

Pointer to buffer to input data = pid

size of input buffer = strlen(pid)+1

Pointer to buffer to recv output data = &retbuf

size of output buffer = sizeof(retbuf)

pointer to recv output byte count = &bytes_returned

pointer to overlapped structure for asynchronous = (LPOVERLAPPED) NULL



Nerede hata var ki ?





< Bu mesaj bu kişi tarafından değiştirildi Guest-8F0924900 -- 2 Şubat 2020; 11:11:12 >


Bu mesajda bahsedilenler: @Determinist
T
5 yıl
Yarbay

Dokumantasyondaki kodla eşleşti, çalışması gerekli. Öyle birşey yok. İlerleme yöntemin yanlış. Windows için sürücü yazmadan önce Win32 ile bir helloworld yazmalısın (WPF, MFC gibi framework kullanmadan salt Win32 ile) sonra Windows sürücü temellerini öğrenmen gerekli; Microsoft'un Windows Internals adlı belgesi var, orada tüm detaylar anlatılıyor. Ondan sonra Windows Drivers üzerine yazılmış bir belge ve tutorialdan çalışmalısın. Bu adımlardan geçmeden Harvard CompSci mezunu gelsin o da Windows sürücü yazamaz.



< Bu ileti mini sürüm kullanılarak atıldı >
Bu mesaja 2 cevap geldi.
G
5 yıl
Yüzbaşı

giriş ve çıkış bufferlar ve buffer boyutları sorunlu gibi. c++ deviceiocontrol example diye aratırsan örnek kodlar var -https://github.com/microsoft/Windows-driver-samples/blob/master/general/ioctl/wdm/exe/testapp.c




Bu mesajda bahsedilenler: @vonderplanitz
G
5 yıl
Yüzbaşı
Konu Sahibi

Sorun çözüldü. vonderplanitz'in dediği gibi illa dökümantasyondaki kodla eşleşecek diye bir şey yok.

Nasıl mı çözdüm ?


Driver'ımı kontrol ederken gözden kaçırdığım bir nokta vardı.


UNICODE_STRING olarak belirtilen usDeviceName ve usSymbolicLink'in adları loader'daki DEVICE değişkenindekinden farklıydı. Bu yüzden HANDLE doğru gösterilmediğinden bağlanamadığı için hata alıyordum fakat aldığım hata bir compiler hatası değil program içindeki bir hata idi.


Yeniden 5 dakikalık bir hata günlerime mâl oldu. Sorun değil, tecrübelendim.


Determinist ve vonderplanitz'e teşekkürler.





< Bu mesaj bu kişi tarafından değiştirildi Guest-8F0924900 -- 4 Şubat 2020; 10:17:6 >


Bu mesajda bahsedilenler: @vonderplanitz
DH Mobil uygulaması ile devam edin. Mobil tarayıcınız ile mümkün olanların yanı sıra, birçok yeni ve faydalı özelliğe erişin. Gizle ve güncelleme çıkana kadar tekrar gösterme.