retrieving full process image path name in kernel mode

Home Forums Discussions General Discussion retrieving full process image path name in kernel mode

This topic contains 13 replies, has 6 voices, and was last updated by  Vadim Smirnov 10 years, 2 months ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #4973

    zector
    Participant

    Hi all,

    I want to retrieve, in a kernel driver , the full image path name for the current process, without using PSAPI.lib (only works in user mode).

    I use the following strategy:
    I use ZwQueryInformationProcess to retrieve a pointer to PROCESS_BASIC_INFORMATION structure. Now, from here we obtain the PebBAseAddress field; from this we retrieve a pointer to a RTL_USER_PROCESS_PARAMETERS structure called ProcessParametes. from this structure is possible to extract the ImagePathName.Buffer field (the type is WCHAR).

    Here is my code:


    PROCESS_BASIC_INFORMATION ProcInfo;
    PPEB myPEB;
    PRTL_USER_PROCESS_PARAMETERS pupp = NULL;
    RTL_USER_PROCESS_PARAMETERS procParams;
    ULONG cbRet, ret;
    CHAR s3[256];
    WCHAR wstr[MAX_PATH];

    hProcess = NtCurrentProcess();

    if( ProcessNameOffset )
    {
    pid = (ULONG)PsGetCurrentProcessId();
    if(pid==4) //System process
    {
    strcpy( PathImage, “System – no path” );
    return;
    }

    if(!NT_SUCCESS(ntStatus = ZwQueryInformationProcess(
    hProcess,
    ProcessBasicInformation,
    &ProcInfo,
    sizeof(ProcInfo),
    &cbRet))) {
    DbgPrint(“Error1”);
    return; }

    if ((myPEB = (PEB*)ProcInfo.PebBaseAddress)!=NULL) {
    pupp = myPEB->ProcessParameters;
    if (pupp) {
    DbgPrint(“%ws”, pupp->ImagePathName.Buffer);
    }

    /* in this way the complete path is correctly printed on DbgView,
    when I try to access it I get BSOD: e.g. if I try to do sprintf(s3,”%ws”,pupp->ImagePathName.Buffer)
    I get BSOD.
    */

    /* Adding this code… */

    if(!NT_SUCCESS(ntStatus = ZwReadVirtualMemory(
    hProcess,
    pupp->ImagePathName.Buffer,
    &wstr,
    pupp->ImagePathName.Length,
    &cbRet)))
    {
    sprintf(PathImage, “Error2 – code: %dn”, ntStatus);
    return; }

    wstr[procParams.ImagePathName.Length / sizeof(WCHAR)] = 0;

    //DbgPrint( “%ws”,wstr);

    sprintf(s3,”%ws”,wstr);
    /*


    */

    …with ZwReadVirtualMemory I retrieve in wstr a copy of the path , and I can use it in any way. The problem is that this method doesn’t work for every calling process; this function often returns the NTSTATUS code -1073741819 (corrisponding to STATUS_ACCESS_VIOLATION).

    I just want to discover how to avoid this error, and why this is generated…

    If someone knows any other working solution to my problem , or an alternative way to get the complete image path forma kernel driver please tell me…

    Alexander

    #5874

    Vadim Smirnov
    Moderator

    Well, this topic was already discussed before (http://www.ntkernel.com/forum/viewtopic.php?t=52&highlight=sectionobject) but in Russian. There is a more reliable way to get full image name for the process, but it requires knowledge of some undocumented structures. Here is short translation of the main approach:

    1. Obtain EPROCESS pointer through IoGetCurrentProcess().
    2. For NT 4.0 and 5.0 take section handle from EPROCESS(SectionHandle) and using ObReferenceObjectByHandle() we obtain SectionObject; for NT 5.1 we can take SectionObject from EPROCESS directly.
    3. From SectionObject we obtain SegmentObject.
    4. From SegmentObject we obtain ControlArea.
    5. From ControlArea we obtain FilePointer (this is FileObject pointer).
    6. Using ObQueryNameString() we obtain full process name
    All operations should be performed on PASSIVE_LEVEL and in the context of the process we obtain full path for.

    #5875

    bitshaker
    Participant

    Hi,

    I like to get the full image file name that a section is backed up by. I intercept calls to NtMapViewOfSection, and want to retrieve this information from the section handle I get here (as I read from your posts in case of process image, maybe there is even a better way to do this on 2k/XP).

    I first reference the Handle with ObReferenceObjByHandle() to get a pointer to the objbody, this seems to work. Also the segment filed of section structure seems to be valid. but the Control area in the segment structure contains no valid pointer, just some small value (0x4C) in some cases.

    Hope someone can help,

    Thx!

    #5876

    bitshaker
    Participant

    Hi,

    I found my mistake, I need to use _SEGMENT instead of _SEGMENT_OBJECT, even if it is written different while analyzing structures from kernel debugger. I found that in calls to MapViewOfSection, there are some ControlAreas that have no FileObject associated? Can someone tell me why?

    Many Thx!

    #5877

    Ryu
    Participant

    Hello,

    I also needing a way to get the full image path, however the problem I’m facing is that I cannot open some processes with only PROCESS_QUERY_INFORMATION access.

    @SerpentFly wrote:

    1. Obtain EPROCESS pointer through IoGetCurrentProcess().
    2. For NT 4.0 and 5.0 take section handle from EPROCESS(SectionHandle) and using ObReferenceObjectByHandle() we obtain SectionObject; for NT 5.1 we can take SectionObject from EPROCESS directly.

    I’m not sure where you get SectionHandle from in EPROCESS, or perhaps my EPROCESS structure is lacking some fields. Also isn’t IoGetCurrentProcess() is a kernel routine not user mode? And can show me your EPROCESS structure?

    #5878

    Vadim Smirnov
    Moderator

    Also isn’t IoGetCurrentProcess() is a kernel routine not user mode?

    It is kernel routine but see the topic title “retrieving full process image path name in kernel mode”. 8)

    And can show me your EPROCESS structure?

    EPROCESS definitions for NT 4.0, 2000, XP, 2003 are below:

    typedef struct _EPROCESS_NT4
    {
    KPROCESS_NT4 Pcb;
    NTSTATUS ExitStatus;
    KEVENT LockEvent;
    ULONG LockCount;
    LARGE_INTEGER CreateTime;
    LARGE_INTEGER ExitTime;
    PKTHREAD_NT4 LockOwner;
    ULONG UniqueProcessId;
    LIST_ENTRY ActiveProcessLinks;
    ULONGLONG QuotaPeakPoolUsage;
    ULONGLONG QuotaPoolUsage;
    ULONG PagefileUsage;
    ULONG CommitCharge;
    ULONG PeakPagefileUsage;
    ULONG PeakVirtualSize;
    ULONGLONG VirtualSize;
    MMSUPPORT_NT4 Vm;
    ULONG LastProtoPteFault;
    ULONG DebugPort;
    ULONG ExceptionPort;
    PHANDLE_TABLE ObjectTable;
    PACCESS_TOKEN Token;
    FAST_MUTEX WorkingSetLock;
    ULONG WorkingSetPage;
    BOOLEAN ProcessOutswapEnabled;
    BOOLEAN ProcessOutswapped;
    BOOLEAN AddressSpaceInitialized;
    BOOLEAN AddressSpaceDeleted;
    FAST_MUTEX AddressCreationLock;
    KSPIN_LOCK HyperSpaceLock;
    PETHREAD_NT4 ForkInProgress;
    USHORT VmOperation;
    BOOLEAN ForkWasSuccessful;
    UCHAR MmAgressiveWsTrimMask;
    PKEVENT VmOperationEvent;
    HARDWARE_PTE PageDirectoryPte;
    ULONG LastFaultCount;
    ULONG ModifiedPageCount;
    PVOID VadRoot;
    PVOID VadHint;
    ULONG CloneRoot;
    ULONG NumberOfPrivatePages;
    ULONG NumberOfLockedPages;
    USHORT NextPageColor;
    BOOLEAN ExitProcessCalled;
    BOOLEAN CreateProcessReported;
    HANDLE SectionHandle;
    PPEB Peb;
    PVOID SectionBaseAddress;
    PEPROCESS_QUOTA_BLOCK QuotaBlock;
    NTSTATUS LastThreadExitStatus;
    PPROCESS_WS_WATCH_INFORMATION WorkingSetWatch;
    HANDLE Win32WindowStation;
    HANDLE InheritedFromUniqueProcessId;
    ACCESS_MASK GrantedAccess;
    ULONG DefaultHardErrorProcessing;
    PVOID LdtInformation;
    PVOID VadFreeHint;
    PVOID VdmObjects;
    KMUTANT ProcessMutant;
    UCHAR ImageFileName[16];
    ULONG VmTrimFaultValue;
    UCHAR SetTimerResolution;
    UCHAR PriorityClass;
    union
    {
    struct
    {
    UCHAR SubSystemMinorVersion;
    UCHAR SubSystemMajorVersion;
    };
    USHORT SubSystemVersion;
    };
    PVOID Win32Process;
    } EPROCESS_NT4, *PEPROCESS_NT4;

    typedef struct _EPROCESS_W2K
    {
    KPROCESS_W2K Pcb;
    NTSTATUS ExitStatus;
    KEVENT LockEvent;
    ULONG LockCount;
    LARGE_INTEGER CreateTime;
    LARGE_INTEGER ExitTime;
    PKTHREAD_W2K LockOwner;
    ULONG UniqueProcessId;
    LIST_ENTRY ActiveProcessLinks;
    ULONGLONG QuotaPeakPoolUsage;
    ULONGLONG QuotaPoolUsage;
    ULONG PagefileUsage;
    ULONG CommitCharge;
    ULONG PeakPagefileUsage;
    ULONG PeakVirtualSize;
    ULONGLONG VirtualSize;
    MMSUPPORT_W2K Vm;
    LIST_ENTRY SessionProcessLinks;
    ULONG DebugPort;
    ULONG ExceptionPort;
    PHANDLE_TABLE ObjectTable;
    PACCESS_TOKEN Token;
    FAST_MUTEX WorkingSetLock;
    ULONG WorkingSetPage;
    BOOLEAN ProcessOutswapEnabled;
    BOOLEAN ProcessOutswapped;
    BOOLEAN AddressSpaceInitialized;
    BOOLEAN AddressSpaceDeleted;
    FAST_MUTEX AddressCreationLock;
    KSPIN_LOCK HyperSpaceLock;
    PETHREAD_W2K ForkInProgress;
    USHORT VmOperation;
    BOOLEAN ForkWasSuccessful;
    UCHAR MmAgressiveWsTrimMask;
    PKEVENT VmOperationEvent;
    PVOID PaeTop;
    ULONG LastFaultCount;
    ULONG ModifiedPageCount;
    PVOID VadRoot;
    PVOID VadHint;
    ULONG CloneRoot;
    ULONG NumberOfPrivatePages;
    ULONG NumberOfLockedPages;
    USHORT NextPageColor;
    BOOLEAN ExitProcessCalled;
    BOOLEAN CreateProcessReported;
    HANDLE SectionHandle;
    PPEB Peb;
    PVOID SectionBaseAddress;
    PEPROCESS_QUOTA_BLOCK QuotaBlock;
    NTSTATUS LastThreadExitStatus;
    PPROCESS_WS_WATCH_INFORMATION WorkingSetWatch;
    HANDLE Win32WindowStation;
    HANDLE InheritedFromUniqueProcessId;
    ACCESS_MASK GrantedAccess;
    ULONG DefaultHardErrorProcessing;
    PVOID LdtInformation;
    PVOID VadFreeHint;
    PVOID VdmObjects;
    PDEVICE_MAP DeviceMap;
    ULONG SessionId;
    LIST_ENTRY PhysicalVadList;
    HARDWARE_PTE PageDirectoryPte;
    ULONG Filler;
    ULONG PaePageDirectoryPage;
    UCHAR ImageFileName[16];
    ULONG VmTrimFaultValue;
    UCHAR SetTimerResolution;
    UCHAR PriorityClass;
    union
    {
    struct
    {
    UCHAR SubSystemMinorVersion;
    UCHAR SubSystemMajorVersion;
    };
    USHORT SubSystemVersion;
    };
    PVOID Win32Process;
    PEJOB Job;
    ULONG JobStatus;
    LIST_ENTRY JobLinks;
    PVOID LockedPageList;
    PVOID SecurityPort;
    PWOW64_PROCESS Wow64Process;
    LARGE_INTEGER ReadOperationCount;
    LARGE_INTEGER WriteOperationCount;
    LARGE_INTEGER OtherOperationCount;
    LARGE_INTEGER ReadTransferCount;
    LARGE_INTEGER WriteTransferCount;
    LARGE_INTEGER OtherTransferCount;
    ULONG CommitChargeLimit;
    ULONG CommitChargePeek;
    LIST_ENTRY ThreadListHead;
    PRTL_BITMAP VadPhysicalPagesBitMap;
    ULONG VadPhysicalPages;
    ULONG AweLock;
    } EPROCESS_W2K, *PEPROCESS_W2K;

    typedef struct _EPROCESS_XP
    {
    KPROCESS_XP Pcb;
    EX_PUSH_LOCK ProcessLock;
    LARGE_INTEGER CreateTime;
    LARGE_INTEGER ExitTime;
    EX_RUNDOWN_REF RundownProtect;
    PVOID UniqueProcessId;
    LIST_ENTRY ActiveProcessLinks;
    ULONG QuotaUsage[3];
    ULONG QuotaPeak[3];
    ULONG CommitCharge;
    ULONG PeakVirtualSize;
    ULONG VirtualSize;
    LIST_ENTRY SessionProcessLinks;
    PVOID DebugPort;
    PVOID ExceptionPort;
    PHANDLE_TABLE ObjectTable;
    EX_FAST_REF Token;
    FAST_MUTEX WorkingSetLock;
    ULONG WorkingSetPage;
    FAST_MUTEX AddressCreationLock;
    KSPIN_LOCK HyperSpaceLock;
    PETHREAD_XP ForkInProgress;
    ULONG HardwareTrigger;
    PVOID VadRoot;
    PVOID VadHint;
    PVOID CloneRoot;
    ULONG NumberOfPrivatePages;
    ULONG NumberOfLockedPages;
    PVOID Win32Process;
    PEJOB Job;
    PSECTION_OBJECT SectionObject;
    PVOID SectionBaseAddress;
    PEPROCESS_QUOTA_BLOCK QuotaBlock;
    PPAGEFAULT_HISTORY WorkingSetWatch;
    PVOID Win32WindowStation;
    PVOID InheritedFromUniqueProcessId;
    PVOID LdtInformation;
    PVOID VadFreeHint;
    PVOID VdmObjects;
    PDEVICE_MAP DeviceMap;
    LIST_ENTRY PhysicalVadList;
    union
    {
    HARDWARE_PTE PageDirectoryPte;
    ULONGLONG Filler;
    };
    PVOID Session;
    UCHAR ImageFileName[16];
    LIST_ENTRY JobLinks;
    PVOID LockedPageList;
    LIST_ENTRY ThreadListHead;
    PVOID SecurityPort;
    PVOID PaeTop;
    ULONG ActiveThreads;
    ULONG GrantedAccess;
    ULONG DefaultHardErrorProcessing;
    NTSTATUS LastThreadExitStatus;
    PPEB Peb;
    EX_FAST_REF PrefetchTrace;
    LARGE_INTEGER ReadOperationCount;
    LARGE_INTEGER WriteOperationCount;
    LARGE_INTEGER OtherOperationCount;
    LARGE_INTEGER ReadTransferCount;
    LARGE_INTEGER WriteTransferCount;
    LARGE_INTEGER OtherTransferCount;
    ULONG CommitChargeLimit;
    ULONG CommitChargePeek;
    PVOID AweInfo;
    SE_AUDIT_PROCESS_CREATION_INFO SeAuditProcessCreationInfo;
    MMSUPPORT_XP Vm;
    ULONG LastFaultCount;
    ULONG ModifiedPageCount;
    ULONG NumberOfVads;
    ULONG JobStatus;
    union
    {
    ULONG Flags;
    struct
    {
    ULONG CreateReported : 1;
    ULONG NoDebugInherit : 1;
    ULONG ProcessExiting : 1;
    ULONG ProcessDelete : 1;
    ULONG Wow64SplitPages : 1;
    ULONG VmDeleted : 1;
    ULONG OutswapEnabled : 1;
    ULONG Outswapped : 1;
    ULONG ForkFailed : 1;
    ULONG HasPhysicalVad : 1;
    ULONG AddressSpaceInitialized : 2;
    ULONG SetTimerResolution : 1;
    ULONG BreakOnTermination : 1;
    ULONG SessionCreationUnderway : 1;
    ULONG WriteWatch : 1;
    ULONG ProcessInSession : 1;
    ULONG OverrideAddressSpace : 1;
    ULONG HasAddressSpace : 1;
    ULONG LaunchPrefetched : 1;
    ULONG InjectInpageErrors : 1;
    ULONG Unused : 11;
    };
    };
    NTSTATUS ExitStatus;
    USHORT NextPageColor;
    union
    {
    struct
    {
    UCHAR SubSystemMinorVersion;
    UCHAR SubSystemMajorVersion;
    };
    USHORT SubSystemVersion;
    };
    UCHAR PriorityClass;
    BOOLEAN WorkingSetAcquiredUnsafe;
    } EPROCESS_XP, *PEPROCESS_XP;

    typedef struct _EPROCESS_2K3
    {
    /*+0x000*/ KPROCESS_2K3 Pcb;
    /*+0x06c*/ EX_PUSH_LOCK ProcessLock;
    /*+0x070*/ LARGE_INTEGER CreateTime;
    /*+0x078*/ LARGE_INTEGER ExitTime;
    /*+0x080*/ EX_RUNDOWN_REF RundownProtect;
    /*+0x084*/ PVOID UniqueProcessId;
    /*+0x088*/ LIST_ENTRY ActiveProcessLinks;
    /*+0x090*/ ULONG QuotaUsage[3];
    /*+0x09c*/ ULONG QuotaPeak[3];
    /*+0x0a8*/ ULONG CommitCharge;
    /*+0x0ac*/ ULONG PeakVirtualSize;
    /*+0x0b0*/ ULONG VirtualSize;
    /*+0x0b4*/ LIST_ENTRY SessionProcessLinks;
    /*+0x0bc*/ PVOID DebugPort;
    /*+0x0c0*/ PVOID ExceptionPort;
    /*+0x0c4*/ PHANDLE_TABLE ObjectTable;
    /*+0x0c8*/ EX_FAST_REF Token;
    /*+0x0cc*/ ULONG WorkingSetPage;
    /*+0x0d0*/ KGUARDED_MUTEX AddressCreationLock;
    /*+0x0f0*/ KSPIN_LOCK HyperSpaceLock;
    /*+0x0f4*/ PETHREAD_2K3 ForkInProgress;
    /*+0x0f8*/ ULONG HardwareTrigger;
    /*+0x0fc*/ PMM_AVL_TABLE PhysicalVadRoot;
    /*+0x100*/ PVOID CloneRoot;
    /*+0x104*/ ULONG NumberOfPrivatePages;
    /*+0x108*/ ULONG NumberOfLockedPages;
    /*+0x10c*/ PVOID Win32Process;
    /*+0x110*/ PEJOB Job;
    /*+0x114*/ PSECTION_OBJECT SectionObject;
    /*+0x118*/ PVOID SectionBaseAddress;
    /*+0x11c*/ PEPROCESS_QUOTA_BLOCK QuotaBlock;
    /*+0x120*/ PPAGEFAULT_HISTORY WorkingSetWatch;
    /*+0x124*/ PVOID Win32WindowStation;
    /*+0x128*/ PVOID InheritedFromUniqueProcessId;
    /*+0x12c*/ PVOID LdtInformation;
    /*+0x130*/ PVOID VadFreeHint;
    /*+0x134*/ PVOID VdmObjects;
    /*+0x138*/ PVOID DeviceMap;
    /*+0x13c*/ PVOID Spare0[3];
    union {
    /*+0x148*/HARDWARE_PTE PageDirectoryPte;
    /*+0x148*/ULONGLONG Filler;
    };
    /*+0x150*/ PVOID Session;
    /*+0x154*/ UCHAR ImageFileName[16];
    /*+0x164*/ LIST_ENTRY JobLinks;
    /*+0x16c*/ PVOID LockedPagesList;
    /*+0x170*/ LIST_ENTRY ThreadListHead;
    /*+0x178*/ PVOID SecurityPort;
    /*+0x17c*/ PVOID PaeTop;
    /*+0x180*/ ULONG ActiveThreads;
    /*+0x184*/ ULONG GrantedAccess;
    /*+0x188*/ ULONG DefaultHardErrorProcessing;
    /*+0x18c*/ NTSTATUS LastThreadExitStatus;
    /*+0x190*/ PPEB Peb;
    /*+0x194*/ EX_FAST_REF PrefetchTrace;
    /*+0x198*/ LARGE_INTEGER ReadOperationCount;
    /*+0x1a0*/ LARGE_INTEGER WriteOperationCount;
    /*+0x1a8*/ LARGE_INTEGER OtherOperationCount;
    /*+0x1b0*/ LARGE_INTEGER ReadTransferCount;
    /*+0x1b8*/ LARGE_INTEGER WriteTransferCount;
    /*+0x1c0*/ LARGE_INTEGER OtherTransferCount;
    /*+0x1c8*/ ULONG CommitChargeLimit;
    /*+0x1cc*/ ULONG CommitChargePeak;
    /*+0x1d0*/ PVOID AweInfo;
    /*+0x1d4*/ SE_AUDIT_PROCESS_CREATION_INFO SeAuditProcessCreationInfo;
    /*+0x1d8*/ MMSUPPORT_2K3 Vm;
    /*+0x238*/ LIST_ENTRY MmProcessLinks;
    /*+0x240*/ ULONG ModifiedPageCount;
    /*+0x244*/ ULONG JobStatus;
    union{
    /*+0x248*/ ULONG Flags;
    struct{
    /*+0x248*/ ULONG CreateReported : 1;
    /*+0x248*/ ULONG NoDebugInherit : 1;
    /*+0x248*/ ULONG ProcessExiting : 1;
    /*+0x248*/ ULONG ProcessDelete : 1;
    /*+0x248*/ ULONG Wow64SplitPages : 1;
    /*+0x248*/ ULONG VmDeleted : 1;
    /*+0x248*/ ULONG OutswapEnabled : 1;
    /*+0x248*/ ULONG Outswapped : 1;
    /*+0x248*/ ULONG ForkFailed : 1;
    /*+0x248*/ ULONG Wow64VaSpace4Gb : 1;
    /*+0x248*/ ULONG AddressSpaceInitialized :2;
    /*+0x248*/ ULONG SetTimerResolution : 1;
    /*+0x248*/ ULONG BreakOnTermination : 1;
    /*+0x248*/ ULONG SessionCreationUnderway :1;
    /*+0x248*/ ULONG WriteWatch : 1;
    /*+0x248*/ ULONG ProcessInSession : 1;
    /*+0x248*/ ULONG OverrideAddressSpace : 1;
    /*+0x248*/ ULONG HasAddressSpace : 1;
    /*+0x248*/ ULONG LaunchPrefetched : 1;
    /*+0x248*/ ULONG InjectInpageErrors : 1;
    /*+0x248*/ ULONG VmTopDown : 1;
    /*+0x248*/ ULONG ImageNotifyDone : 1;
    /*+0x248*/ ULONG PdeUpdateNeeded : 1;
    /*+0x248*/ ULONG VdmAllowed : 1;
    /*+0x248*/ ULONG Unused : 7;
    };
    };
    /*+0x24c*/ NTSTATUS ExitStatus;
    /*+0x250*/ USHORT NextPageColor;
    union {
    struct {
    /*+0x252*/ UCHAR SubSystemMinorVersion;
    /*+0x253*/ UCHAR SubSystemMajorVersion;
    };
    /*+0x252*/ USHORT SubSystemVersion;
    };

    /*+0x254*/ UCHAR PriorityClass;
    /*+0x258*/ MM_AVL_TABLE VadRoot;
    } EPROCESS_2K3, *PEPROCESS_2K3;
    #5879

    DaveMidgley
    Participant

    I have started to use SerpentFly’s suggestions, thus:
    PEPROCESS pEprocess = PsGetCurrentProcess();
    HANDLE SectionHandle = pEprocess->SectionHandle;
    The first line is fine, but I immediately get a compiler error “error C2037: left of ‘SectionHandle’ specifies undefined struct/union ‘_EPROCESS'” on the second line.
    Although
    typedef struct _EPROCESS *PEPROCESS;
    occurs in several header files in the DDK, I can’t find a definition of _EPROCESS anywhere. I’m new to kernal mode programming and have obviously misunderstood something. Any help please.

    #5880

    Vadim Smirnov
    Moderator

    I have started to use SerpentFly’s suggestions, thus:
    PEPROCESS pEprocess = PsGetCurrentProcess();
    HANDLE SectionHandle = pEprocess->SectionHandle;

    I guess you are going to create a driver which supports all NT operating systems, so first of all you have to determine operating system version and then depending of it use the matching EPROCESS definition (from one post above). An example for Windows 2000 it would be as the following:

    PEPROCESS_W2K pEprocess = (PEPROCESS_W2K)PsGetCurrentProcess();
    HANDLE SectionHandle = pEprocess->SectionHandle;
    #5881

    dkg0414
    Participant

    Hi Serpent,

    What if I have to get the Full ImagePathName of other processes in the system.
    On XP and 2003 I m able to get the Full ImagePathName from SeAuditInformationInfo struture of EPROCESS block.
    But on 2000 there is no structure like that…
    Yes there is last field EPROCESS block which points to a UNICODE_STRING which gives me the FullPathName , but still I am not able to get the Drive Letters form there.
    I had one more query ,what does DEVICEMAP field in EPROCESS strucure signify…?
    Does this strucure contains any information abt Drive mapping and all.
    Please reply asap , As I m reaching deadline for my college project.

    Kind Regards
    Deepak Gutpa

    #5882

    Vadim Smirnov
    Moderator

    Yes there is last field EPROCESS block which points to a UNICODE_STRING which gives me the FullPathName , but still I am not able to get the Drive Letters form there.

    Drive letter is a symbolic link to disk object, so you can enumerate symbolic links to get the exact mappings.

    I had one more query ,what does DEVICEMAP field in EPROCESS strucure signify…?

    Devicemap is used when object manager sees a name beginning from ?? for getting the object directory to use for the particular process.

    #5883

    dkg0414
    Participant

    But How to enumerate Symbolic links
    I guess you are talking about these mapping

    C:


    DeviceHardDiskVolume1
    D:


    DeviceHardDiskVolume2 .

    But in Win2000 I don’t get anything like DeviceHardDiskVolume1 frm EPROCESS block.

    Please correct me if i m wrong.

    Kind Regards
    Deepak Gupta

    #5884

    Vadim Smirnov
    Moderator

    Yes there is last field EPROCESS block which points to a UNICODE_STRING which gives me the FullPathName , but still I am not able to get the Drive Letters form there.

    You have not explained in what form you get full path name here and I supposed you have got volume device name instead drive letter. Seems I got wrong 😳

    Anyways, why won’t you use the approach I posted above in this thread:

    1. Obtain EPROCESS pointer through IoGetCurrentProcess().
    2. For NT 4.0 and 5.0 take section handle from EPROCESS(SectionHandle) and using ObReferenceObjectByHandle() we obtain SectionObject; for NT 5.1 we can take SectionObject from EPROCESS directly.
    3. From SectionObject we obtain SegmentObject.
    4. From SegmentObject we obtain ControlArea.
    5. From ControlArea we obtain FilePointer (this is FileObject pointer).
    6. Using ObQueryNameString() we obtain full process name
    All operations should be performed on PASSIVE_LEVEL and in the context of the process we obtain full path for.

    This one is proved to work.

    #5885

    dkg0414
    Participant

    You are absolutely correct serpent that this would work….
    But Problems in my case are following—

    1.)I have to support for 2000, XP and 2003.
    2.)I have to get the Full Image Path name of each process running in system (not just Current Process) .

    On XP and 2003 I don’t have to open the handle as I am directly getting the Address of SECTION_OBJECT. But on 2000 I have only SectionHandle and that handle is valid in the HANDLE_TABLE of corresponding process not in process in the context of which my driver is getting called.

    I have integrated the machanism u mentioned in my code and it is working fine on XP and 2k3.I m able to read FullImagePathname of all the processes.

    But on 2000 I have only SectionHandle and not the pointer to SectionObject.
    To get it working I will have to search another process handle table and i think that would be very tedious task.

    So my only worry is with Win2000.

    Also I don’t wanna use ZwQuerySystemInformation and ZwOpenProcess bcoz these API’s have got chances of being Hooked.
    I think you got all my doubts.

    Kind Regards
    Deepak Gupta

    #5886

    Vadim Smirnov
    Moderator

    But on 2000 I have only SectionHandle and that handle is valid in the HANDLE_TABLE of corresponding process not in process in the context of which my driver is getting called.

    KeAttachProcess/KeDetachProcess should help 8)

Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.