티스토리 뷰
Original Question
Hello guys!!
I'm trying to hook the ZwDeleteFile. I coded a Kernel module and it can hook the ZwDeleteFunction. I see in a "SSDT hook viewer" that the function is hooked correctly, but when I use the DeleteFile API I don't get the "Hello World from a Hooked Function" string in the DebugView
Thanks for posting your code!
The problem doesn't lie with your (Hoglund's) code, as far as I can tell.
Try running your working driver alongside DbgView 4.74, making sure kernel output is captured and with the tool's verbose kernel output option turned on (Capture -> Enable Verbose Kernel Output). Tweaking DbgView worked for me, and I am guessing that you will now see output too.
Seems to be a bug in the dbgv code.
CODE
#include "ntddk.h"
Seems to be a bug in the dbgv code.
CODE
#include "ntddk.h"
#pragma pack(1)
typedef struct ServiceDescriptorEntry {
unsigned int *ServiceTableBase;
unsigned int *ServiceCounterTableBase;
unsigned int NumberOfServices;
unsigned char *ParamTableBase;
} ServiceDescriptorTableEntry_t, *PServiceDescriptorTableEntry_t;
#pragma pack()
typedef struct ServiceDescriptorEntry {
unsigned int *ServiceTableBase;
unsigned int *ServiceCounterTableBase;
unsigned int NumberOfServices;
unsigned char *ParamTableBase;
} ServiceDescriptorTableEntry_t, *PServiceDescriptorTableEntry_t;
#pragma pack()
__declspec(dllimport) ServiceDescriptorTableEntry_t KeServiceDescriptorTable;
#define SYSTEMSERVICE(_function) KeServiceDescriptorTable.ServiceTableBase[ *(PULONG)((PUCHAR)_function+1)]
#define SYSTEMSERVICE(_function) KeServiceDescriptorTable.ServiceTableBase[ *(PULONG)((PUCHAR)_function+1)]
PMDL g_pmdlSystemCall;
PVOID *MappedSystemCallTable;
#define SYSCALL_INDEX(_Function) *(PULONG)((PUCHAR)_Function+1)
#define HOOK_SYSCALL(_Function, _Hook, _Orig ) \
_Orig = (PVOID) InterlockedExchange( (PLONG) &MappedSystemCallTable[SYSCALL_INDEX(_Function)], (LONG) _Hook)
#define UNHOOK_SYSCALL(_Function, _Hook, _Orig ) \
InterlockedExchange( (PLONG) &MappedSystemCallTable[SYSCALL_INDEX(_Function)], (LONG) _Hook)
InterlockedExchange( (PLONG) &MappedSystemCallTable[SYSCALL_INDEX(_Function)], (LONG) _Hook)
NTSYSAPI
NTSTATUS
NTAPI ZwDeleteFile(IN POBJECT_ATTRIBUTES ObjectAttributes);
typedef NTSTATUS (*typeZwDeleteFile)(IN POBJECT_ATTRIBUTES ObjectAttributes);
typeZwDeleteFile ZwDeleteFileIni;
NTSTATUS ZwDeleteFileRep(IN POBJECT_ATTRIBUTES ObjectAttributes)
{
NTSTATUS ntStatus;
ANSI_STRING strf;
ANSI_STRING strf;
DbgPrint("Hello World from a Hooked Function");
ntStatus = ((typeZwDeleteFile)(ZwDeleteFileIni)) (ObjectAttributes);
if (ntStatus!=STATUS_SUCCESS) return ntStatus;
ntStatus = ((typeZwDeleteFile)(ZwDeleteFileIni)) (ObjectAttributes);
if (ntStatus!=STATUS_SUCCESS) return ntStatus;
RtlUnicodeStringToAnsiString(&strf,ObjectAttributes->ObjectName,TRUE);
DbgPrint(strf.Buffer);
DbgPrint(strf.Buffer);
return ntStatus;
}
}
VOID OnUnload(IN PDRIVER_OBJECT DriverObject)
{
DbgPrint("Driver Unloaded");
{
DbgPrint("Driver Unloaded");
UNHOOK_SYSCALL(ZwDeleteFile, ZwDeleteFileIni, ZwDeleteFileRep);
if(g_pmdlSystemCall)
{
MmUnmapLockedPages(MappedSystemCallTable, g_pmdlSystemCall);
IoFreeMdl(g_pmdlSystemCall);
}
}
{
MmUnmapLockedPages(MappedSystemCallTable, g_pmdlSystemCall);
IoFreeMdl(g_pmdlSystemCall);
}
}
NTSTATUS DriverEntry(IN PDRIVER_OBJECT theDriverObject, IN PUNICODE_STRING theRegistryPath)
{
theDriverObject->DriverUnload = OnUnload;
DbgPrint("Driver Loaded");
ZwDeleteFileIni =(typeZwDeleteFile)(SYSTEMSERVICE(ZwDeleteFile));
DbgPrint("Old Address: 0x%x", ZwDeleteFileIni);
DbgPrint("Hook Address: 0x%x", ZwDeleteFileRep);
DbgPrint("Hook Address: 0x%x", ZwDeleteFileRep);
g_pmdlSystemCall = MmCreateMdl(NULL, KeServiceDescriptorTable.ServiceTableBase, KeServiceDescriptorTable.NumberOfServices*4);
if(!g_pmdlSystemCall)
return STATUS_UNSUCCESSFUL;
MmBuildMdlForNonPagedPool(g_pmdlSystemCall);
g_pmdlSystemCall->MdlFlags =
g_pmdlSystemCall->MdlFlags | MDL_MAPPED_TO_SYSTEM_VA;
g_pmdlSystemCall->MdlFlags | MDL_MAPPED_TO_SYSTEM_VA;
MappedSystemCallTable = MmMapLockedPages(g_pmdlSystemCall, KernelMode);
HOOK_SYSCALL(ZwDeleteFile, ZwDeleteFileRep, ZwDeleteFileIni);
return STATUS_SUCCESS;
}
Can anyone help me?
Can anyone help me?
The Answer
Well, I found the problem many days ago, the problem was that the API ZwDeleteFile is only in the NT Windows (is a new API) and the programs that use the DeleteFile API don't call the ZwDeleteFile API, they call the ZwOpenFile and ZwSetInformationFile API. Now I try to hook the ZwOpenFile with this code and it work perfectly. The problem are solved
'보안 > 분석' 카테고리의 다른 글
SDT Hooking 무력화에 대한 연구 (By Dual5651, dualpage.muz.ro) (0) | 2008.04.11 |
---|---|
Using Files In A Driver [펌 MSDN] (0) | 2008.04.08 |
PhantOm Plugin 1.20 (0) | 2008.04.04 |
Windows syscall lister (0) | 2008.04.04 |
How to send IOCTLs to a filter driver (0) | 2008.04.02 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
- 지루박멸연구센타
- 열정의 힘을 믿는다
- Le4rN TO Cr4cK
- 디버깅에관한모든것(DebugLab)
- sysinternals
- FoundStone
- hashtab
- 보안-coderant
- 디바이스드라이버 개발자 포럼
- dualpage.muz.ro
- osronline.com - 드라이버 관련 정보 사이트
- NtInternals - NativeAPI Refere…
- pcthreat - spyware 정보 제공
- rootkit.com - 루트킷 관련 정보
- www.ntinternals.net
- WINE CrossRef. - source.winehq…
- tuts4you
- hex-rays
- idapalace
- idefense
- immunityinc
- threatexpert
- hdp.null2root.org
- www.crackstore.com
- crackmes.de
- www.who.is
- www.cracklab.ru
- community.reverse-engineering.…
- video.reverse-engineering.net
- SnD
- 클레이 키위
- reversengineering.wordpress.co…
- www.openrce.org
- www.woodmann.com
- PEID.Plusins.BobSoft
- roxik.com/pictaps/
- regexlib.com
- spyware-browser.com
- www.usboffice.kr
- regulator
- www.txt2re.com
- ietab.mozdev.org
- zesrever.xstone.org
- www.heaventools.com/PE-file-he…
- www.heaventools.com
- www.innomp3.com
- 울지않는벌새
- exetools.com-forum
- exetools.com
- utf8 conv
- robtex - IP trace
- onsamehost - same IP sites
- JpopSuki
- jsunpack.jeek.org
- wepawet.iseclab.org
- www.jswiff.com
- www.hackeroo.com
- winesearcher.co.kr
- khpga.org
- malwareurl.com
- anubis.iseclab.org
- www.crummy.com-eautifulSoup
- malwarebytes.org/forums
- bbs.janmeng.com
- blackip.ustc.edu.cn
- eureka.cyber-ta.org
- exploit-db.com
TAG
- 피봇
- logrotate
- 공공인프라
- 자동트래이딩
- INVOICE
- 주식트래이딩
- ubuntu
- 실시간트래이딩
- O365
- 레고랜드
- SBI저축은행
- 맥쿼리인프라
- 매매가격지수
- CriticalSection
- Pivot
- 사회간접자본
- 군함도
- 시스템트래이딩
- 미국주식
- ChatGPT
- ElasticSearch
- systemd
- ROA
- 주택구매력지수
- 주식
- 전세매매지수
- 신한저축은행
- 다올저축은행
- hai
- PIR
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함