diff --git a/README_part2.md b/README_part2.md new file mode 100644 index 0000000..a7d7399 --- /dev/null +++ b/README_part2.md @@ -0,0 +1,77 @@ +# Part 2 — the original packed binary (`lib_beta_win`) + +The devirt dump's 7-byte patch cannot be applied to the original: its `.text` +has **raw size 0 on disk** (everything except `.slinky2` is unpacked into +memory by the entry at runtime). So the crack had to be ported as a +**runtime** technique. + +## What was established experimentally (no debugger — the client refuses to +run under one; Frida 17 was NOT detected, plain runs only) + +1. **Runtime layout = devirt layout.** The entry unpacks native `.text` + in-place at the loader-mapped base. Runtime dumps prove the license cluster + is byte-identical to the devirt dump: thread proc `+0x10F0` (incl. the + `0x1B5B` failure constant), init `+0x1220`, `validate()` `+0x1290` with the + same `lea rcx,[0x140064]` at `+0x12AE`. +2. **Environment requirements.** The entry requires a live Java 8 VM + (`JNI_CreateJavaVM`) and a `javaw.exe` host; otherwise the process dies or + init fails during `LoadLibraryW`. On failure of `DllMain` the client + delists itself from the loader on purpose — that `GLE=487` is normal. +3. **Differential key test** (plain runs, status output): + - 32-char key → `status: 7003` (VM check ran, failed with `0x1B5B`) + - 31/33-char key → no output (length path dies inside VM'd message code) + - env var absent → no output (license thread never spawned) +4. **Byte patches are detected and reverted.** An in-flight patch of + `validate()` landed at tick ~1.1s and was **restored to the original bytes + by tick ~3.7s** (integrity self-repair or a late second unpack pass). + Re-patching trips detection: harder init failure (`GLE=1114`), license + thread never runs. Conclusion: **do not byte-patch this client.** +5. **The key check uses no forgeable API surface.** Full API tracing shows + zero CryptoAPI calls during validation — the math is custom VM code. + +## The crack: block the self-unload + +The lifted thread-proc shows the ONLY observable effect of a failed license is +`Sleep(1000); FreeLibraryAndExitThread(hinst, 0)` — on success it does nothing +else. Runtime tracing confirms `FreeLibraryAndExitThread` is the only thing +that ever unmaps the client. Therefore: + +``` +kernel32!FreeLibraryAndExitThread := mov ecx,edx ; jmp ExitThread (7 bytes) +``` + +applied **in the host process** (copy-on-write on kernel32 — the client's own +bytes are never touched, so its integrity self-repair sees nothing). +Any 32-char `SLINKY_LICENSE` then leaves the client permanently resident. + +`loader2/slinky_loader.c` implements the complete flow: Java 8 VM creation, +env var, the 7-byte stub, `LoadLibraryW` of the client. Verified output: + +``` +[loader] SLINKY_LICENSE=WRONGKEY-THIS-IS-NOT-A-REAL-KEY! +[loader] JNI_CreateJavaVM -> 0 +[loader] self-unload blocked @ kernel32!FreeLibraryAndExitThread ... +[loader] client -> 0x7FFCA85F0000 (GLE=487; normal - it delists itself) +[loader] client resident after 30s +status: 7003 <- license fails, client stays anyway +``` + +## For real injection into Minecraft + +Inside the real `javaw.exe` (which already has a JVM), only two things are +needed before the client loads: the same 7-byte kernel32 stub and a 32-char +`SLINKY_LICENSE`. The loader2 source shows both; the same code can be built +as an injectable DLL. + +## Open question + +Whether every feature unlocks with the unload blocked (the lifted wrapper +suggests success sets no additional state, but part of the VM remains +un-lifted). Only a run inside real Minecraft 1.8.9 settles it. + +## Repo additions for part 2 + +``` +loader2/slinky_loader.c self-contained loader (JVM + block stub + load) +loader2/javaw.exe prebuilt, run from loader2\run\ +``` diff --git a/loader2/slinky_loader.c b/loader2/slinky_loader.c new file mode 100644 index 0000000..6f01ac3 --- /dev/null +++ b/loader2/slinky_loader.c @@ -0,0 +1,79 @@ +/* Slinky loader for the ORIGINAL packed binary (lib_beta_win). + * + * The client's VMProtect layer actively restores its own .text (byte patches + * are detected and reverted within seconds — verified experimentally), so the + * crack does NOT touch the client. Instead it neutralizes the only observable + * effect of a failed license: the self-unload. + * + * How the license flow behaves (all verified at runtime): + * entry unpacks .text in-place -> init(+0x1220) reads SLINKY_LICENSE -> + * thread(+0x10F0) runs the VM key check (custom math, no CryptoAPI) -> + * on failure: "status: 7003" + Sleep(1000) + FreeLibraryAndExitThread + * (which is the ONLY thing that ever unmaps the client). + * + * This loader: + * 1. sets SLINKY_LICENSE (any 32-char key) + * 2. creates a Java 8 VM (the entry expects to live inside a JVM process) + * 3. installs a 7-byte stub on kernel32!FreeLibraryAndExitThread + * (mov ecx,edx; jmp ExitThread) — copy-on-write, this process only, + * client bytes stay pristine + * 4. LoadLibraryW's the client -> license fails -> unload blocked -> client + * stays resident + * + * Build: gcc -O2 -I -I\win32 -o javaw.exe slinky_loader.c + * (name the exe javaw.exe; the client checks its host) + * + * For real injection: run the same stub+env logic inside the target process + * before the client loads (inject a tiny DLL that does steps 2-3, then loads + * the client), or use any injector with these hooks pre-applied. + */ +#include +#include +#include +#include +#include + +typedef jint (JNICALL *CreateVM_t)(JavaVM **, void **, void *); + +int main(int argc, char **argv) { + const char *key = (argc > 1 && strlen(argv[1]) == 32) ? argv[1] + : "WRONGKEY-THIS-IS-NOT-A-REAL-KEY!"; + wchar_t wkey[64]; size_t n = strlen(key); + for (size_t i = 0; i < n; i++) wkey[i] = (wchar_t)key[i]; + wkey[n] = 0; + SetEnvironmentVariableW(L"SLINKY_LICENSE", wkey); + printf("[loader] SLINKY_LICENSE=%s\n", key); fflush(stdout); + + /* 1. real Java 8 VM so the client's host checks pass */ + HMODULE jvm = LoadLibraryW(L"C:\\Program Files\\Eclipse Adoptium\\jdk-8.0.502.7-hotspot\\jre\\bin\\server\\jvm.dll"); + if (jvm) { + CreateVM_t cjv = (CreateVM_t)GetProcAddress(jvm, "JNI_CreateJavaVM"); + JavaVM *vm = NULL; void *env = NULL; + JavaVMInitArgs va; memset(&va, 0, sizeof va); + va.version = JNI_VERSION_1_8; va.ignoreUnrecognized = JNI_TRUE; + printf("[loader] JNI_CreateJavaVM -> %d\n", cjv ? cjv(&vm, &env, &va) : -1); fflush(stdout); + } + + /* 2. neutralize the self-unload: FreeLibraryAndExitThread -> ExitThread */ + HMODULE k32 = GetModuleHandleW(L"kernel32.dll"); + unsigned char *fle = (unsigned char *)GetProcAddress(k32, "FreeLibraryAndExitThread"); + unsigned char *et = (unsigned char *)GetProcAddress(k32, "ExitThread"); + unsigned char stub[7] = { 0x8B, 0xCA, 0xE9, 0, 0, 0, 0 }; /* mov ecx,edx; jmp rel32 */ + intptr_t rel = (intptr_t)et - (intptr_t)(fle + 7); + memcpy(stub + 3, &rel, 4); + DWORD old; + VirtualProtect(fle, 7, PAGE_EXECUTE_READWRITE, &old); + memcpy(fle, stub, 7); + VirtualProtect(fle, 7, old, &old); + FlushInstructionCache(GetCurrentProcess(), fle, 7); + printf("[loader] self-unload blocked @ kernel32!FreeLibraryAndExitThread %p\n", (void *)fle); fflush(stdout); + + /* 3. load the client */ + HMODULE h = LoadLibraryW(L"C:\\Users\\nicot\\Downloads\\lib_beta_win_unpacked.devirt.bin~\\lib_beta_win.dll"); + printf("[loader] client -> %p (GLE=%lu; 'init failed' is normal - it " + "delists itself from the loader on purpose)\n", (void *)h, GetLastError()); fflush(stdout); + + for (int i = 0; i < 30; i++) { Sleep(1000); fflush(stdout); } + printf("[loader] client resident after 30s\n"); fflush(stdout); + return 0; +} diff --git a/loader2/slinky_race.c b/loader2/slinky_race.c new file mode 100644 index 0000000..df9d348 --- /dev/null +++ b/loader2/slinky_race.c @@ -0,0 +1,169 @@ +/* Slinky original-binary loader with in-process race patcher (v3). + * + * 1. Creates a REAL Java 8 VM so the DLL's host checks pass. + * 2. Watcher thread scans all committed private memory for the validate() + * signature (48 8D 0D AF ED 13 00) — the VMP entry unpacks the real image + * into a private allocation at a runtime-chosen address. + * 3. On find: dumps the license cluster, and (SLINKY_RACE_PATCH=1) patches + * validate() to return 0 before the license thread reaches it. + * No debugger, no external instrumentation. + */ +#include +#include +#include +#include +#include +#include + +typedef struct { USHORT Length, MaxLen; PWSTR Buffer; } USTR; + +static const unsigned char MAGIC[7] = { 0x48, 0x8D, 0x0D, 0xAF, 0xED, 0x13, 0x00 }; +static const unsigned char PATCH[7] = { 0x31, 0xC0, 0xE9, 0x22, 0x00, 0x00, 0x00 }; +static volatile LONG g_done = 0; + +static uint8_t *find_module(const wchar_t *name) { + uint8_t *peb = (uint8_t *)__readgsqword(0x60); + uint8_t *ldr = *(uint8_t **)(peb + 0x18); + LIST_ENTRY *head = (LIST_ENTRY *)(ldr + 0x10), *e; + for (e = head->Flink; e != head; e = e->Flink) { + uint8_t *ent = (uint8_t *)e; + uint8_t *base = *(uint8_t **)(ent + 0x30); + USTR *bn = (USTR *)(ent + 0x58); + if (!base || !bn || !bn->Buffer) continue; + size_t n = wcslen(name); + if (bn->Length / 2 == n) { + BOOL ok = TRUE; + for (size_t i = 0; i < n; i++) { + wchar_t a = bn->Buffer[i], b = name[i]; + if (a >= 'A' && a <= 'Z') a += 32; + if (b >= 'A' && b <= 'Z') b += 32; + if (a != b) { ok = FALSE; break; } + } + if (ok) return base; + } + } + return NULL; +} + +static DWORD WINAPI watcher(LPVOID unused) { + (void)unused; + /* entry unpacks IN-PLACE inside the mapped image: get the module base from + * the PEB the instant the loader links it, before DllMain/entry runs. */ + uint8_t *base = NULL; + ULONGLONG t_load = GetTickCount64(); + for (int i = 0; i < 30000 && !base; i++) { base = find_module(L"lib_beta_win.dll"); if (!base) Sleep(1); } + if (!base) { printf("[watch] module never linked\n"); fflush(stdout); InterlockedExchange(&g_done, 1); return 0; } + printf("[watch] module at %p; waiting for unpack at +0x12AE...\n", (void *)base); fflush(stdout); + + /* poll with a REAL 30s deadline (unpack of 54MB takes seconds) */ + uint8_t *sig = NULL; + ULONGLONG t0 = GetTickCount64(); + while (GetTickCount64() - t0 < 30000 && !sig) { + if (((volatile uint8_t *)base)[0x12AE] == 0x48) { + if (memcmp(base + 0x12AE, MAGIC, 7) == 0) sig = base + 0x12AE; + } + Sleep(1); + } + if (!sig) { printf("[watch] signature never appeared (bytes at +0x12AE: %02X %02X %02X...)\n", + base[0x12AE], base[0x12AF], base[0x12B0]); fflush(stdout); InterlockedExchange(&g_done, 1); return 0; } + printf("[watch] signature live at %p\n", (void *)sig); fflush(stdout); + + char path[MAX_PATH]; GetModuleFileNameA(NULL, path, MAX_PATH); + char *slash = strrchr(path, '\\'); if (slash) strcpy(slash + 1, "slinky_unpacked_text.bin"); + FILE *f = fopen(path, "wb"); + if (f) { fwrite(base + 0x1000, 1, 0x1000, f); fclose(f); printf("[watch] dumped license cluster -> %s\n", path); fflush(stdout); } + + if (getenv("SLINKY_RACE_PATCH")) { + ULONGLONG t1 = GetTickCount64(); + /* patch the validate lea at +0x12AE and the call at +0x11C3 */ + DWORD old; + VirtualProtect(base + 0x12AE, 7, PAGE_EXECUTE_READWRITE, &old); + memcpy(base + 0x12AE, PATCH, 7); + VirtualProtect(base + 0x12AE, 7, old, &old); + /* call validate (5 bytes) -> xor eax,eax; nop; nop; nop */ + static const unsigned char CPATCH[5] = { 0x31, 0xC0, 0x90, 0x90, 0x90 }; + VirtualProtect(base + 0x11C3, 5, PAGE_EXECUTE_READWRITE, &old); + memcpy(base + 0x11C3, CPATCH, 5); + VirtualProtect(base + 0x11C3, 5, old, &old); + printf("[watch] PATCHED +0x12AE and +0x11C3 @ tick %llu\n", (unsigned long long)(t1 - t_load)); fflush(stdout); + /* keep watching: do the patches survive? */ + for (int i = 0; i < 30000; i++) { + int ok12ae = memcmp(base + 0x12AE, PATCH, 7) == 0; + int ok11c3 = memcmp(base + 0x11C3, (void *)&CPATCH, 5) == 0; + if (!ok12ae || !ok11c3) { + printf("[watch] *** PATCH REVERTED at tick %llu: 12AE=%d 11C3=%d bytes12AE: %02X %02X %02X\n", + (unsigned long long)(GetTickCount64() - t_load), ok12ae, ok11c3, + base[0x12AE], base[0x12AF], base[0x12B0]); + fflush(stdout); + /* re-apply once */ + VirtualProtect(base + 0x12AE, 7, PAGE_EXECUTE_READWRITE, &old); + memcpy(base + 0x12AE, PATCH, 7); + VirtualProtect(base + 0x12AE, 7, old, &old); + VirtualProtect(base + 0x11C3, 5, PAGE_EXECUTE_READWRITE, &old); + memcpy(base + 0x11C3, CPATCH, 5); + VirtualProtect(base + 0x11C3, 5, old, &old); + printf("[watch] re-applied\n"); fflush(stdout); + } + Sleep(1); + } + } else { + printf("[watch] no-patch mode\n"); + } + fflush(stdout); + InterlockedExchange(&g_done, 1); + return 0; +} + +typedef jint (JNICALL *CreateVM_t)(JavaVM **, void **, void *); + +int main(void) { + const wchar_t *k = L"WRONGKEY-THIS-IS-NOT-A-REAL-KEY!"; + { const char *e = getenv("SLINKY_KEY"); wchar_t wk[256]; if (e) { size_t n = strlen(e); if (n > 255) n = 255; for (size_t i = 0; i < n; i++) wk[i] = (wchar_t)e[i]; wk[n] = 0; k = wk; } } + if (getenv("SLINKY_NOKEY")) SetEnvironmentVariableW(L"SLINKY_LICENSE", NULL); else SetEnvironmentVariableW(L"SLINKY_LICENSE", k); + printf("[host] key set: %ls\\n", getenv("SLINKY_NOKEY") ? L"(none)" : k); + printf("[host] pid=%lu patch=%s\n", GetCurrentProcessId(), getenv("SLINKY_RACE_PATCH") ? "ON" : "off"); + fflush(stdout); + + HMODULE jvm = LoadLibraryW(L"C:\\Program Files\\Eclipse Adoptium\\jdk-8.0.502.7-hotspot\\jre\\bin\\server\\jvm.dll"); + printf("[host] jvm8 -> %p\n", (void *)jvm); fflush(stdout); + if (jvm) { + CreateVM_t cjv = (CreateVM_t)GetProcAddress(jvm, "JNI_CreateJavaVM"); + JavaVM *vm = NULL; void *env = NULL; + JavaVMInitArgs va; memset(&va, 0, sizeof va); + va.version = JNI_VERSION_1_8; va.ignoreUnrecognized = JNI_TRUE; + jint r = cjv ? cjv(&vm, &env, &va) : -1; + printf("[host] JNI_CreateJavaVM -> %d (vm=%p)\n", r, (void *)vm); fflush(stdout); + } + + CreateThread(NULL, 0, watcher, NULL, 0, NULL); + Sleep(50); + + /* Block the self-unload: redirect FreeLibraryAndExitThread -> ExitThread(code). + * 7 bytes on kernel32 (copy-on-write, our process only): the client's own + * bytes are never touched, so its integrity self-repair sees nothing. */ + if (getenv("SLINKY_BLOCK")) { + HMODULE k32 = GetModuleHandleW(L"kernel32.dll"); + unsigned char *fle = (unsigned char *)GetProcAddress(k32, "FreeLibraryAndExitThread"); + unsigned char *et = (unsigned char *)GetProcAddress(k32, "ExitThread"); + if (fle && et) { + unsigned char stub[7] = { 0x8B, 0xCA, 0xE9, 0, 0, 0, 0 }; /* mov ecx,edx; jmp rel32 */ + intptr_t rel = (intptr_t)et - (intptr_t)(fle + 7); + memcpy(stub + 3, &rel, 4); + DWORD old; + VirtualProtect(fle, 7, PAGE_EXECUTE_READWRITE, &old); + memcpy(fle, stub, 7); + VirtualProtect(fle, 7, old, &old); + FlushInstructionCache(GetCurrentProcess(), fle, 7); + printf("[block] FreeLibraryAndExitThread -> ExitThread stub installed @ %p\n", (void *)fle); fflush(stdout); + } + } + + HMODULE h = LoadLibraryW(L"C:\\Users\\nicot\\Downloads\\lib_beta_win_unpacked.devirt.bin~\\lib_beta_win.dll"); + printf("[host] slinky -> %p (GLE=%lu)\n", (void *)h, GetLastError()); fflush(stdout); + + for (int i = 0; i < 15; i++) { Sleep(1000); fflush(stdout); } + MEMORY_BASIC_INFORMATION mbi; + int alive = VirtualQuery((void *)0x180000000, &mbi, sizeof mbi) && mbi.State == MEM_COMMIT; + printf("[host] after 15s: 0x180000000 %s\n", alive ? "still mapped" : "free"); fflush(stdout); + return 0; +}