Part 3: verdict plumbing (stderr is ground truth), elimination matrix, inert-by-construction proof for Route-1, honest ceiling

This commit is contained in:
2rax committed 2026-11-08 17:05:27 -05:00
1 parent f5225a7fec
commit cca4ff16cf
8 files changed
+550

No files matched your search

+90
View File
@@ -0,0 +1,90 @@
/* apc_injector2: two modes.
* mode "dll": queue LoadLibraryW(path) APCs (env-driven start)
* mode "init": LoadLibraryW via one APC, then queue
* slinky_init(keyw) APCs on all threads (loader-style start)
* usage: apc_injector2.exe dll <pid> <dll path>
* apc_injector2.exe init <pid> <dll path> <32-char key>
*/
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <tlhelp32.h>
static int queue_all(DWORD pid, void *func, ULONG_PTR param) {
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (snap == INVALID_HANDLE_VALUE) { printf("snap fail\n"); return -1; }
THREADENTRY32 te; te.dwSize = sizeof te;
int queued = 0;
if (Thread32First(snap, &te)) {
do {
if (te.th32OwnerProcessID != pid) continue;
HANDLE th = OpenThread(THREAD_SET_CONTEXT, FALSE, te.th32ThreadID);
if (!th) continue;
if (QueueUserAPC((PAPCFUNC)func, th, param)) queued++;
CloseHandle(th);
} while (Thread32Next(snap, &te));
}
CloseHandle(snap);
return queued;
}
static HMODULE find_remote_module(DWORD pid, const char *name) {
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid);
if (snap == INVALID_HANDLE_VALUE) return NULL;
MODULEENTRY32W me; me.dwSize = sizeof me;
HMODULE base = NULL;
wchar_t wname[128]; MultiByteToWideChar(CP_ACP, 0, name, -1, wname, 128);
if (Module32FirstW(snap, &me)) {
do {
if (_wcsicmp(me.szModule, wname) == 0) { base = me.hModule; break; }
} while (Module32NextW(snap, &me));
}
CloseHandle(snap);
return base;
}
int main(int argc, char **argv) {
if (argc < 4) { printf("usage: apc2 dll|init pid path [key]\n"); return 1; }
const char *mode = argv[1];
DWORD pid = (DWORD)atoi(argv[2]);
HANDLE pr = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_QUERY_INFORMATION, FALSE, pid);
if (!pr) { printf("OpenProcess fail GLE=%lu\n", GetLastError()); return 1; }
if (strcmp(mode, "dll") == 0) {
wchar_t wpath[512];
int wl = MultiByteToWideChar(CP_ACP, 0, argv[3], -1, wpath, 512);
void *mem = VirtualAllocEx(pr, NULL, (SIZE_T)wl * 2, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (!mem || !WriteProcessMemory(pr, mem, wpath, (SIZE_T)wl * 2, NULL)) { printf("write fail\n"); return 1; }
FARPROC llw = GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "LoadLibraryW");
int n = queue_all(pid, (void *)llw, (ULONG_PTR)mem);
printf("dll mode: %d APCs\n", n);
} else {
/* init mode: step 1 load, step 2 call export */
wchar_t wpath[512];
int wl = MultiByteToWideChar(CP_ACP, 0, argv[3], -1, wpath, 512);
void *mem = VirtualAllocEx(pr, NULL, (SIZE_T)wl * 2, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (!mem || !WriteProcessMemory(pr, mem, wpath, (SIZE_T)wl * 2, NULL)) { printf("write fail\n"); return 1; }
FARPROC llw = GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "LoadLibraryW");
int n = queue_all(pid, (void *)llw, (ULONG_PTR)mem);
printf("init mode: %d load APCs queued, waiting for module...\n", n);
HMODULE base = NULL;
for (int i = 0; i < 40 && !base; i++) {
Sleep(500);
base = find_remote_module(pid, "lib_beta_win.dll");
}
if (!base) { printf("client never mapped (no alertable thread?)\n"); return 1; }
printf("client base = %p\n", (void *)base);
void *slinky_init = (void *)((ULONG_PTR)base + 0x1000); /* export RVA */
const char *key = argv[4];
wchar_t wkey[64];
int kl = MultiByteToWideChar(CP_ACP, 0, key, -1, wkey, 64);
void *kmem = VirtualAllocEx(pr, NULL, (SIZE_T)kl * 2, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (!kmem || !WriteProcessMemory(pr, kmem, wkey, (SIZE_T)kl * 2, NULL)) { printf("key write fail\n"); return 1; }
int n2 = queue_all(pid, slinky_init, (ULONG_PTR)kmem);
printf("init mode: %d slinky_init APCs queued (key=%s)\n", n2, key);
}
CloseHandle(pr);
return 0;
}