Kernel mode - برمجة Driver Filter
#23
السلام عليكم

واجهت مشكلة أثناء تحميل ZwCreateFileHook هذا كود الدريفر من موقع
:rtfm: KMD

PHP كود :
unit ZwCreateFileHook;

interface

uses
    nt_status
, ntoskrnl, native, winioctl,fcall, macros;

function 
_DriverEntry(pDriverObject: PDRIVER_OBJECT;
    
pusRegistryPath: PUNICODE_STRING): NTSTATUS; stdcall;

implementation

type
    TfnZwCreateFile 
= function(FileHandle: PHANDLE; DesiredAccess: ACCESS_MASK;
        
ObjectAttributes: POBJECT_ATTRIBUTES; IoStatusBlock: PIO_STATUS_BLOCK;
        
AllocationSize: PLARGE_INTEGER; FileAttributes: ULONG; ShareAccess: ULONG;
        
CreateDisposition: ULONG; CreateOptions: ULONG; EaBuffer: PVOID;
        
EaLength: ULONG): NTSTATUS; stdcall;

var
    
m_UserTime      : LARGE_INTEGER;
    
m_KernelTime    : LARGE_INTEGER;
    
o_ZwCreateFile  : TfnZwCreateFile;
    
g_pmdlSystemCall: PMDL;
    
MappedSystemCallTable: Pointer;
    
lpKeServiceDescriptorTable: PServiceDescriptorEntry;

function 
GetImportFunAddr(lpImportAddr: Pointer): Pointer; stdcall; 
begin
    Result 
:= PPointer(PPointer(Cardinal(lpImportAddr) + 2)^)^;
end;

function 
SystemServiceName(AFunc: Pointer): PLONG; stdcall;
begin
    Result 
:= PLONG(Cardinal(lpKeServiceDescriptorTable^.ServiceTableBase) + (SizeOf(ULONG)
        * 
PULONG(ULONG(AFunc) + 1)^));
end;


function 
NewZwCreateFile(FileHandle: PHANDLE; DesiredAccess: ACCESS_MASK;
    
ObjectAttributes: POBJECT_ATTRIBUTES; IoStatusBlock: PIO_STATUS_BLOCK;
    
AllocationSize: PLARGE_INTEGER; FileAttributes: ULONG; ShareAccess: ULONG;
    
CreateDisposition: ULONG; CreateOptions: ULONG; EaBuffer: PVOID;
    
EaLength: ULONG): NTSTATUS; stdcall;
begin
    DbgPrint
('NewZwCreateFile enter ...');
    
Result := o_ZwCreateFile(FileHandle, DesiredAccess, ObjectAttributes,
        
IoStatusBlock, AllocationSize, FileAttributes, ShareAccess,
        
CreateDisposition, CreateOptions, EaBuffer, EaLength);
    
DbgPrint('NewZw Leave.');
end;

procedure OnUnload(pDriverObject: PDRIVER_OBJECT); stdcall;
begin
    DbgPrint
('ROOTKIT: OnUnload called'#13#10);

    
InterlockedExchange(SystemServiceName(GetImportFunAddr(@ZwCreateFile)),
        
LONG(@o_ZwCreateFile));

    if 
g_pmdlSystemCall <> nil then
    begin
        MmUnmapLockedPages
(MappedSystemCallTable, g_pmdlSystemCall);
        
IoFreeMdl(g_pmdlSystemCall);
    
end;
end;

function 
_DriverEntry(pDriverObject: PDRIVER_OBJECT;
    
pusRegistryPath: PUNICODE_STRING): NTSTATUS;stdcall;
begin

    lpKeServiceDescriptorTable 
:= GetImportFunAddr(@KeServiceDescriptorTable);

    
pDriverObject^.DriverUnload := @OnUnload;

    
DbgPrint('ROOTKIT: load called'#13#10);

    
m_UserTime.QuadPart := 0;
    
m_KernelTime.QuadPart := 0;


    
o_ZwCreateFile :=
        
TfnZwCreateFile(SystemServiceName(GetImportFunAddr(@ZwCreateFile)));


    
g_pmdlSystemCall := MmCreateMdl(nil, lpKeServiceDescriptorTable^.ServiceTableBase,
        
lpKeServiceDescriptorTable^.NumberOfServices * 4);
    if 
g_pmdlSystemCall = nil then
    begin
        Result 
:= STATUS_UNSUCCESSFUL;
        Exit;
    
end;

    
MmBuildMdlForNonPagedPool(g_pmdlSystemCall);

    
g_pmdlSystemCall^.MdlFlags := g_pmdlSystemCall^.MdlFlags or MDL_MAPPED_TO_SYSTEM_VA;

    
MappedSystemCallTable := MmMapLockedPages(g_pmdlSystemCall, KernelMode);

    
o_ZwCreateFile :=
        
TfnZwCreateFile(InterlockedExchange(SystemServiceName(GetImportFunAddr(@ZwCreateFile)),
        
LONG(@NewZwCreateFile)));

    
Result := STATUS_SUCCESS;
end;

end. 
السؤال هنا أن صاحب الموضوع و المشاركين نجحو في تشغيله دون Bsod
على عكسي
:frusty: لدا أعدة مراجعه الموضوع, هل من الممكن :
الداكرة المخصصة لـ SSDT داكرة للقراءة فقط , و نحن نريد التغير في مسار الإستدعاء
:crazy:؟؟.
I'M Fly Like A G6

الرد


الردود في هذا الموضوع
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 15-01-2010, 10:12 AM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 21-01-2010, 09:18 AM
Kernel mode - برمجة Driver Filter - بواسطة mohfa - 21-01-2010, 11:13 AM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 21-01-2010, 11:44 AM
Kernel mode - برمجة Driver Filter - بواسطة mohfa - 21-01-2010, 12:47 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 23-01-2010, 11:29 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 25-01-2010, 12:14 PM
Kernel mode - برمجة Driver Filter - بواسطة GamingMasteR - 27-01-2010, 03:53 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 27-01-2010, 06:23 PM
Kernel mode - برمجة Driver Filter - بواسطة GamingMasteR - 28-01-2010, 01:09 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 28-01-2010, 02:28 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 28-01-2010, 06:55 PM
Kernel mode - برمجة Driver Filter - بواسطة o15s19 - 29-01-2010, 10:52 AM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 30-01-2010, 08:56 AM
Kernel mode - برمجة Driver Filter - بواسطة Ahmed18 - 01-02-2010, 12:55 AM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 01-02-2010, 01:41 PM
Kernel mode - برمجة Driver Filter - بواسطة GamingMasteR - 01-02-2010, 02:11 PM
Kernel mode - برمجة Driver Filter - بواسطة GamingMasteR - 01-02-2010, 08:09 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 20-02-2010, 10:12 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 21-02-2010, 10:31 AM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 21-02-2010, 11:11 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 22-02-2010, 01:29 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 22-02-2010, 03:35 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 22-02-2010, 04:25 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 22-02-2010, 04:55 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 22-02-2010, 05:09 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 22-02-2010, 05:36 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 22-02-2010, 05:44 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 22-02-2010, 05:49 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 22-02-2010, 06:00 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 22-02-2010, 06:39 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 25-01-2010, 12:33 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 25-01-2010, 12:45 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 29-01-2010, 12:07 PM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم