日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

在内存中读取函数的ShellCode并执行

發(fā)布時(shí)間:2024/4/18 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在内存中读取函数的ShellCode并执行 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在內(nèi)存中讀取函數(shù)的ShellCode并執(zhí)行

下面是一個(gè)例子,實(shí)現(xiàn)的效果是將fun1函數(shù)的十六進(jìn)制讀取出來(lái),在內(nèi)存中將str1的地址改成str2,分配一塊內(nèi)存,將改好的函數(shù)的ShellCode寫(xiě)入并執(zhí)行。

// FunTest.cpp : 定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。 // // #include "stdafx.h" #include <windows.h>#pragma comment(lib,"user32.lib")char *str1 = "aaaa"; //字符串指針1 char *str2 = "bbbb"; //字符串指針2void fun1() {MessageBox(0,str1,0,0); }void fun2() {MessageBox(0,"2",0,0); }int _tmain(int argc, _TCHAR* argv[]) {fun1(); //調(diào)用fun1函數(shù)測(cè)試一下//獲取fun1函數(shù)的大小int iFun1Size = ((DWORD)fun2) - ((DWORD)fun1);printf("fun1 size: %d\n",iFun1Size);//獲取fun1函數(shù)的十六進(jìn)制內(nèi)容BYTE *pFun1Body = new BYTE [iFun1Size];memcpy(pFun1Body,&fun1,iFun1Size);for (int i=0;i<=iFun1Size;i++){printf("%x",*(pFun1Body+i));}printf("\n");//打印字符指針地址DWORD dwstrAddress1 = (DWORD)&str1;DWORD dwstrAddress2 = (DWORD)&str2;printf("Address1 %x\n",dwstrAddress1);printf("Address2 %x\n",dwstrAddress2);//判斷for (int i=0;i<(iFun1Size-4);i++){DWORD *dwPtr = (DWORD *)((BYTE *)pFun1Body + i);//找str1的地址if (*dwPtr == dwstrAddress1) {*dwPtr = (DWORD)dwstrAddress2; //替換字符串指針地址printf("dwstrAddress1 found\n");}else if (*dwPtr == dwstrAddress2){printf("dwstrAddress2 found\n");}}//分配內(nèi)存PVOID pData = VirtualAlloc(NULL,iFun1Size,MEM_COMMIT,PAGE_EXECUTE_READWRITE);if(!pData){DWORD dwError = GetLastError();printf("VirtualAllocEx error %d \n",dwError);return 0;}//寫(xiě)內(nèi)存HANDLE h = OpenProcess(PROCESS_ALL_ACCESS,0,GetCurrentProcessId());if(!WriteProcessMemory(h,pData,pFun1Body,iFun1Size,0)){DWORD dwError = GetLastError();printf("WriteProcessMemory error %d\n",dwError);return 0;}//執(zhí)行_asm{mov eax,pData;call eax}//釋放內(nèi)存VirtualFree(pData,0,MEM_RELEASE);delete []pFun1Body;getchar();return 0; }


?

總結(jié)

以上是生活随笔為你收集整理的在内存中读取函数的ShellCode并执行的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。