驅動層分別使用PEB和sectionObject擷取進程執行檔案全路徑的方法

來源:互聯網
上載者:User

本人是在WIN2003 SP2下開發的,請注意不同作業系統的位移量不同

 

PEB

 

EPROCESS->PEB(_PEB)->ProcessParameters((_RTL_USER_PROCESS_PARAMETERS)->ImagePathName(_UNICODE_STRING)

  1. void GetProcessName( IN OUT PCHAR pszName)
  2. {
  3.         int pebOffeset=0x1a0;
  4.         int RTLUSERPROCESSPARAMETERSOffset= 0x010;
  5.         int imagePathNameOffset=0x038;
  6.     ANSI_STRING astr;
  7.     UNICODE_STRING US;
  8.     PEPROCESS peCurProc;
  9.     ULONG* dwAddress;
  10.     peCurProc=PsGetCurrentProcess();//EPROCESS
  11.     dwAddress=(ULONG*)peCurProc;
  12.     
  13.     if(dwAddress!=NULL)
  14.     {
  15.         dwAddress=*((ULONG**)dwAddress+pebOffeset/sizeof(ULONG));//EPROCESS->PEB
  16.         if(dwAddress!=NULL)
  17.         {
  18.             dwAddress=*((ULONG**)dwAddress+RTLUSERPROCESSPARAMETERSOffset /sizeof(ULONG));//PEB->ProcessParameters(_RTL_USER_PROCESS_PARAMETERS)
  19.             if(dwAddress!=NULL)
  20.             {
  21.                 US=*((UNICODE_STRING*)dwAddress+imagePathNameOffset/sizeof(UNICODE_STRING));//PEB->ProcessParameters->ImagePathName(_UNICODE_STRING)
  22.                 if(RtlUnicodeStringToAnsiString(&astr,(PUNICODE_STRING)&US,TRUE)==STATUS_SUCCESS)
  23.                 {
  24.                     strcpy(pszName, astr.Buffer);
  25.                     RtlFreeAnsiString( &astr );
  26.                 }
  27.             }
  28.         }
  29.     
  30.     }
  31. }

 

SectionObject

EPROCESS->SectionObject(_SECTION_OBJECT)->Segment(_SEGMENT)->ControlArea (_CONTROL_AREA)->FilePointer( _FILE_OBJECT)

 

  1. PEPROCESS   peCurProc;
  2. ULONG* dwAddress;
  3. PFILE_OBJECT FileObject;
  4. UNICODE_STRING usDosName;
  5. STRING fileName; 
  6. STRING dosName;
  7. peCurProc = PsGetCurrentProcess();
  8. dwAddress=(ULONG*)peCurProc;
  9. if(MmIsAddressValid(dwAddress))
  10. {
  11.     dwAddress=*((ULONG**)dwAddress+0x124/sizeof(ULONG));//EPROCESS->SectionObject
  12.     if(MmIsAddressValid(dwAddress))
  13.     {
  14.         dwAddress=*((ULONG**)dwAddress+0x014/sizeof(ULONG));//EPROCESS->SectionObject->Segment
  15.         if(MmIsAddressValid(dwAddress))
  16.         {
  17.             dwAddress=*((ULONG**)dwAddress+0x000/sizeof(ULONG));//EPROCESS->SectionObject->Segment->ControlArea
  18.             if(MmIsAddressValid(dwAddress))
  19.             {
  20.                 FileObject=(PFILE_OBJECT)(*((ULONG**)dwAddress+0x024 /sizeof(ULONG)));//EPROCESS->SectionObject->Segment->ControlArea->FilePointer
  21.                 if(MmIsAddressValid(FileObject));
  22.                 {
  23.                       
  24.                     if(RtlVolumeDeviceToDosName(FileObject->DeviceObject,&usDosName)==STATUS_SUCCESS)//擷取磁碟邏輯名稱
  25.                     {
  26.                         RtlUnicodeStringToAnsiString(&dosName,&usDosName, TRUE); 
  27.                         RtlUnicodeStringToAnsiString(&fileName,&FileObject->FileName, TRUE);//檔案名稱
  28.                         DbgPrint(dosName.Buffer);
  29.                         DbgPrint(fileName.Buffer);
  30.                         DbgPrint("/n/n");
  31.                         RtlFreeAnsiString(&dosName);
  32.                         RtlFreeAnsiString(&fileName);
  33.                     }
  34.                 }
  35.             }
  36.         }
  37.     }
  38. }
  39.         

 

PEB可以通過某種方式擦除

 

相關連結:

EPROCESS 的結構匯出(WINXP和WIN2003)

PEB 結構匯出(WINXP和WIN2003)

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.