x7code 发表于 2012-9-25 21:40:31

第四种 利用shellcode隐藏GetProcAddress和LoadLibrary

<p>#include "stdafx.h"

#include <Windows.h>

#include <WinBase.h>

#include <WinUser.h></p><p> int main()

{

//Get Kernel32 base addr

int Kernel32Base;

int a,b,c;

char *p;

__asm

    {

    mov eax,fs: //唯一用到的汇编指令

    mov b,eax;

    }

while (b!=-1)

    {

    a=b;

    b=*(int *)b;

    }

b=*(int *)(a+4);

p=(char *)b;

while (*p!='M' || *(p+1)!='Z')

    {

    p--;

    }

Kernel32Base=int(p);

//找到GetProcAddress的地址;

_IMAGE_EXPORT_DIRECTORY *k32Export;

//IMAGE_EXPORT_DIRECTORY::

k32Export=(IMAGE_EXPORT_DIRECTORY *)(Kernel32Base+int(*(int *)(Kernel32Base+0x160)));

c=k32Export->NumberOfNames;

int i=-1;

char *name;

char NameOfGetProcAddress[]={0x47,0x65,0x74,0x50,0x72,0x6F,0x63,0x41,0x64,0x64,0x72,0x65,0x73,0x73,0x00};

do
    {

    i++;

    int tmp;

    tmp=Kernel32Base+ k32Export->AddressOfNames+i*4;

    tmp=*(int *)tmp;

    tmp+=Kernel32Base;

    name=(char *)tmp;

    } while(strcmp(name,NameOfGetProcAddress)!=0);</p><p>    //获取GetProcAddress地址

    DWORD AddressOfGetProcAddress;

    AddressOfGetProcAddress=*(int *)(Kernel32Base+k32Export->AddressOfFunctions+i*4);

    AddressOfGetProcAddress=(Kernel32Base+AddressOfGetProcAddress);

    //typedef void DRAWF( int, int );

    FARPROC typedef WINAPI GetProcAddress (__in HMODULE hModule,__in LPCSTR lpProcName);

    GetProcAddress *HGetProcAddress;

    HGetProcAddress=*(GetProcAddress *)AddressOfGetProcAddress;

    //找到LoadLibrary的地址

    char str_LoadLibraryA[]={0x4C,0x6F,0x61,0x64,0x4C\

      ,0x69,0x62,0x72,0x61,0x72,0x79\

      ,0x41,0x00};//字符串oadLibraryA

    FARPROC AddressOfLoadLibrary;

    AddressOfLoadLibrary=HGetProcAddress(HMODULE(Kernel32Base),str_LoadLibraryA);

    char str_user32_dll[]={0x75,0x73,0x65,0x72,0x33\

      ,0x32,0x2E,0x64,0x6C,0x6C,0x00};//字符串:user32.dll;

    HMODULE typedef WINAPI LoadLibraryA(

      LPCTSTR lpFileName

      );

    //HMODULE AddressOfLoadLibrary;

    LoadLibraryA *HLoadLibrary;

    HLoadLibrary=(LoadLibraryA *)AddressOfLoadLibrary;

    HMODULE USER32;

    USER32=HLoadLibrary(str_user32_dll);

    FARPROC HMessageBox;

    char str_MessageBoxA[]={0x4D,0x65,0x73,0x73,0x61\

      ,0x67,0x65,0x42,0x6F,0x78,0x41,0x00};//字符串:MessageBoxA;

    HMessageBox= HGetProcAddress(USER32,str_MessageBoxA);

    char str_Title[]={0xCC,0xE1,0xCA,0xBE,0x00};//字符串:提示;

    char str_Data[]={0x53,0x68,0x65,0x6C,0x6C\

      ,0x43,0x6F,0x64,0x65,0xCC,0xE1\

      ,0xCA,0xBE,0xA3,0xBA,0xD,0xA\

      ,0x20,0x20,0x20,0x20,0x20,0xC4\

      ,0xE3,0xCF,0xD6,0xD4,0xDA,0xCA\

      ,0xC7,0xD4,0xDA,0x53,0x68,0x65\

      ,0x6C,0x6C,0x43,0x6F,0x64,0x65\

      ,0xB9,0xFD,0xB3,0xCC,0xD6,0xD0\

      ,0xA3,0xA1,0xD,0xA,0x20,0x20\

      ,0x20,0x20,0x20,0xCD,0xEA,0xC8\

      ,0xAB,0xB6,0xC0,0xC1,0xA2,0xB4\

      ,0xFA,0xC2,0xEB,0xA3,0xAC,0xC8\

      ,0xCE,0xBA,0xCE,0xB5,0xD8,0xB7\

      ,0xBD,0xD4,0xCB,0xD0,0xD0,0xA1\

      ,0xA3,0xD,0xA,0x20,0x20,0x20\

      ,0x20,0x20,0xCF,0xD4,0xCA,0xBE\

      ,0x53,0x68,0x65,0x6C,0x6C,0x43\

      ,0x6F,0x64,0x65,0xF7,0xC8,0xC1\

      ,0xA6,0xA3,0xA1,0x00};//字符串:ShellCode提示:

    //你现在是在ShellCode过程中!

    //完全独立代码,任何地方运行。

    //显示ShellCode魅力!;

    int typedefWINAPI MessageBox(          HWND hWnd,

      LPCTSTR lpText,

      LPCTSTR lpCaption,

      UINT uType

      );

    MessageBox *FMessageBox;

    FMessageBox=(MessageBox *)HMessageBox;

    FMessageBox(NULL,str_Data,str_Title,MB_ICONINFORMATION);

    //return AddressOfGetProcAddress;

    //如果是要潜入纯汇编代码 也就是不返回的 可以手动将后面的Retn 去掉

}</p><p>

</p>

Vastthus丶x 发表于 2012-9-26 19:44:34

这个是好玩意。。真的很好。

小凯无缘丶 发表于 2013-1-23 00:59:15

代码我就收了啊.
页: [1]
查看完整版本: 第四种 利用shellcode隐藏GetProcAddress和LoadLibrary