浓毛老太交欧美老妇热爱乱,蜜臀性色av免费,妺妺窝人体色www看美女,久久久久久久久久久大尺度免费视频,麻豆人妻无码性色av专区

位置:51電子網(wǎng) » 技術(shù)資料 » EDA/PLD

用Visual C++實(shí)現(xiàn)遠(yuǎn)程線程嵌入技術(shù)

發(fā)布時(shí)間:2008/6/5 0:00:00 訪問次數(shù):500

  遠(yuǎn)程線程技術(shù)指的是通過在另一個(gè)進(jìn)程中創(chuàng)建遠(yuǎn)程線程的方法進(jìn)入那個(gè)進(jìn)程的內(nèi)存地址空間。我們知道,在進(jìn)程中,可以通過createthread函數(shù)創(chuàng)建線程,被創(chuàng)建的新線程與主線程(就是進(jìn)程啟動(dòng)時(shí)被同時(shí)自動(dòng)建立的那個(gè)線程)共享地址空間以及其他的資源。 但是很少有人知道,通過createremotethread也同樣可以在另一個(gè)進(jìn)程內(nèi)創(chuàng)建新線程,被創(chuàng)建的遠(yuǎn)程線程同樣可以共享遠(yuǎn)程進(jìn)程(是遠(yuǎn)程進(jìn)程耶!)的地址空間,所以,實(shí)際上,我們通過一個(gè)遠(yuǎn)程線程,進(jìn)入了遠(yuǎn)程進(jìn)程的內(nèi)存地址空間,也就擁有了那個(gè)遠(yuǎn)程進(jìn)程相當(dāng)?shù)臋?quán)限。例如在遠(yuǎn)程進(jìn)程內(nèi)部啟動(dòng)一個(gè)dll木馬(與進(jìn)入進(jìn)程內(nèi)部相比,啟動(dòng)一個(gè)dll木馬是小意思,實(shí)際上我們可以隨意篡改那個(gè)遠(yuǎn)程進(jìn)程的數(shù)據(jù))。

  首先,我們通過openprocess 來(lái)打開我們?cè)噲D嵌入的進(jìn)程(如果遠(yuǎn)程進(jìn)程不允許打開,那么嵌入就無(wú)法進(jìn)行了,這往往是由于權(quán)限不足引起的,解決方法是通過種種途徑提升本地進(jìn)程的權(quán)限)

  hremoteprocess = openprocess( process_create_thread | file://允許遠(yuǎn)程創(chuàng)建線程
                process_vm_operation | file://允許遠(yuǎn)程vm操作
                process_vm_write,//允許遠(yuǎn)程vm寫
                false, dwremoteprocessid )

  由于我們后面需要寫入遠(yuǎn)程進(jìn)程的內(nèi)存地址空間并建立遠(yuǎn)程線程,所以需要申請(qǐng)足夠的權(quán)限(process_create_thread、vm_operation、vm_write)。

  然后,我們可以建立loadlibraryw函數(shù)這個(gè)線程來(lái)啟動(dòng)我們的dll木馬,loadlibraryw函數(shù)是在kernel32.dll中定義的,用來(lái)加載dll文件,它只有一個(gè)參數(shù),就是dll文件的絕對(duì)路徑名pszlibfilename,(也就是木馬dll的全路徑文件名),但是由于木馬dll是在遠(yuǎn)程進(jìn)程內(nèi)調(diào)用的,所以我們首先還需要將這個(gè)文件名復(fù)制到遠(yuǎn)程地址空間:(否則遠(yuǎn)程線程是無(wú)法讀到這個(gè)參數(shù)的)

 file://計(jì)算dll路徑名需要的內(nèi)存空間
 int cb = (1 + lstrlenw(pszlibfilename)) * sizeof(wchar);
 file://使用virtualallocex函數(shù)在遠(yuǎn)程進(jìn)程的內(nèi)存地址空間分配dll文件名緩沖區(qū)
 pszlibfileremote = (pwstr) virtualallocex( hremoteprocess, null, cb,
            mem_commit, page_readwrite);
 file://使用writeprocessmemory函數(shù)將dll的路徑名復(fù)制到遠(yuǎn)程進(jìn)程的內(nèi)存空間
 ireturncode = writeprocessmemory(hremoteprocess,
            pszlibfileremote, (pvoid) pszlibfilename, cb, null);
 file://計(jì)算loadlibraryw的入口地址
 pthread_start_routine pfnstartaddr = (pthread_start_routine)
     getprocaddress(getmodulehandle(text("kernel32")), "loadlibraryw");

  萬(wàn)事俱備,我們通過建立遠(yuǎn)程線程時(shí)的地址pfnstartaddr(實(shí)際上就是loadlibraryw的入口地址)和傳遞的參數(shù)pszlibfileremote(實(shí)際上是我們復(fù)制過去的木馬dll的全路徑文件名)在遠(yuǎn)程進(jìn)程內(nèi)啟動(dòng)我們的木馬dll:

 file://啟動(dòng)遠(yuǎn)程線程loadlibraryw,通過遠(yuǎn)程線程調(diào)用用戶的dll文件
 hremotethread = createremotethread( hremoteprocess, null, 0,
                 pfnstartaddr, pszlibfileremote, 0, null);
  至此,遠(yuǎn)程嵌入順利完成,為了試驗(yàn)我們的dll是不是已經(jīng)正常的在遠(yuǎn)程線程運(yùn)行,我編寫了以下的測(cè)試dll:

 bool apientry dllmain(handle hmodule, dword reason, lpvoid lpreserved)
   {
    char szprocessid[64] ;
    switch ( reason )
     {
      case dll_process_attach:
       {
         file://獲取當(dāng)前進(jìn)程id
         _itoa ( getcurrentprocessid(), szprocessid, 10 );
         messagebox ( null, szprocessid, "remotedll", mb_ok );
       }
      default:
      return true;
     }
   }

  當(dāng)我使用rmtdll.exe程序?qū)⑦@個(gè)testdll.dll嵌入explorer.exe進(jìn)程后(pid=1208),該測(cè)試dll彈出了1208字樣的確認(rèn)框,同時(shí)使用ps工具也能看到

   process id: 1208
   c:\winnt\explorer.exe (0x00400000)
   ……
   c:\testdll.d

  遠(yuǎn)程線程技術(shù)指的是通過在另一個(gè)進(jìn)程中創(chuàng)建遠(yuǎn)程線程的方法進(jìn)入那個(gè)進(jìn)程的內(nèi)存地址空間。我們知道,在進(jìn)程中,可以通過createthread函數(shù)創(chuàng)建線程,被創(chuàng)建的新線程與主線程(就是進(jìn)程啟動(dòng)時(shí)被同時(shí)自動(dòng)建立的那個(gè)線程)共享地址空間以及其他的資源。 但是很少有人知道,通過createremotethread也同樣可以在另一個(gè)進(jìn)程內(nèi)創(chuàng)建新線程,被創(chuàng)建的遠(yuǎn)程線程同樣可以共享遠(yuǎn)程進(jìn)程(是遠(yuǎn)程進(jìn)程耶。┑牡刂房臻g,所以,實(shí)際上,我們通過一個(gè)遠(yuǎn)程線程,進(jìn)入了遠(yuǎn)程進(jìn)程的內(nèi)存地址空間,也就擁有了那個(gè)遠(yuǎn)程進(jìn)程相當(dāng)?shù)臋?quán)限。例如在遠(yuǎn)程進(jìn)程內(nèi)部啟動(dòng)一個(gè)dll木馬(與進(jìn)入進(jìn)程內(nèi)部相比,啟動(dòng)一個(gè)dll木馬是小意思,實(shí)際上我們可以隨意篡改那個(gè)遠(yuǎn)程進(jìn)程的數(shù)據(jù))。

  首先,我們通過openprocess 來(lái)打開我們?cè)噲D嵌入的進(jìn)程(如果遠(yuǎn)程進(jìn)程不允許打開,那么嵌入就無(wú)法進(jìn)行了,這往往是由于權(quán)限不足引起的,解決方法是通過種種途徑提升本地進(jìn)程的權(quán)限)

  hremoteprocess = openprocess( process_create_thread | file://允許遠(yuǎn)程創(chuàng)建線程
                process_vm_operation | file://允許遠(yuǎn)程vm操作
                process_vm_write,//允許遠(yuǎn)程vm寫
                false, dwremoteprocessid )

  由于我們后面需要寫入遠(yuǎn)程進(jìn)程的內(nèi)存地址空間并建立遠(yuǎn)程線程,所以需要申請(qǐng)足夠的權(quán)限(process_create_thread、vm_operation、vm_write)。

  然后,我們可以建立loadlibraryw函數(shù)這個(gè)線程來(lái)啟動(dòng)我們的dll木馬,loadlibraryw函數(shù)是在kernel32.dll中定義的,用來(lái)加載dll文件,它只有一個(gè)參數(shù),就是dll文件的絕對(duì)路徑名pszlibfilename,(也就是木馬dll的全路徑文件名),但是由于木馬dll是在遠(yuǎn)程進(jìn)程內(nèi)調(diào)用的,所以我們首先還需要將這個(gè)文件名復(fù)制到遠(yuǎn)程地址空間:(否則遠(yuǎn)程線程是無(wú)法讀到這個(gè)參數(shù)的)

 file://計(jì)算dll路徑名需要的內(nèi)存空間
 int cb = (1 + lstrlenw(pszlibfilename)) * sizeof(wchar);
 file://使用virtualallocex函數(shù)在遠(yuǎn)程進(jìn)程的內(nèi)存地址空間分配dll文件名緩沖區(qū)
 pszlibfileremote = (pwstr) virtualallocex( hremoteprocess, null, cb,
            mem_commit, page_readwrite);
 file://使用writeprocessmemory函數(shù)將dll的路徑名復(fù)制到遠(yuǎn)程進(jìn)程的內(nèi)存空間
 ireturncode = writeprocessmemory(hremoteprocess,
            pszlibfileremote, (pvoid) pszlibfilename, cb, null);
 file://計(jì)算loadlibraryw的入口地址
 pthread_start_routine pfnstartaddr = (pthread_start_routine)
     getprocaddress(getmodulehandle(text("kernel32")), "loadlibraryw");

  萬(wàn)事俱備,我們通過建立遠(yuǎn)程線程時(shí)的地址pfnstartaddr(實(shí)際上就是loadlibraryw的入口地址)和傳遞的參數(shù)pszlibfileremote(實(shí)際上是我們復(fù)制過去的木馬dll的全路徑文件名)在遠(yuǎn)程進(jìn)程內(nèi)啟動(dòng)我們的木馬dll:

 file://啟動(dòng)遠(yuǎn)程線程loadlibraryw,通過遠(yuǎn)程線程調(diào)用用戶的dll文件
 hremotethread = createremotethread( hremoteprocess, null, 0,
                 pfnstartaddr, pszlibfileremote, 0, null);
  至此,遠(yuǎn)程嵌入順利完成,為了試驗(yàn)我們的dll是不是已經(jīng)正常的在遠(yuǎn)程線程運(yùn)行,我編寫了以下的測(cè)試dll:

 bool apientry dllmain(handle hmodule, dword reason, lpvoid lpreserved)
   {
    char szprocessid[64] ;
    switch ( reason )
     {
      case dll_process_attach:
       {
         file://獲取當(dāng)前進(jìn)程id
         _itoa ( getcurrentprocessid(), szprocessid, 10 );
         messagebox ( null, szprocessid, "remotedll", mb_ok );
       }
      default:
      return true;
     }
   }

  當(dāng)我使用rmtdll.exe程序?qū)⑦@個(gè)testdll.dll嵌入explorer.exe進(jìn)程后(pid=1208),該測(cè)試dll彈出了1208字樣的確認(rèn)框,同時(shí)使用ps工具也能看到

  • <thead id="5tjxl"></thead>
       process id: 1208
       c:\winnt\explorer.exe (0x00400000)
       ……
       c:\testdll.d
    相關(guān)IC型號(hào)
    版權(quán)所有:51dzw.COM
    深圳服務(wù)熱線:13692101218  13751165337
    粵ICP備09112631號(hào)-6(miitbeian.gov.cn)
    公網(wǎng)安備44030402000607
    深圳市碧威特網(wǎng)絡(luò)技術(shù)有限公司
    付款方式


     復(fù)制成功!