Port crack to the original packed binary (runtime, no client byte patches)
- original's .text is unpacked in-place at runtime; license cluster is byte-identical to the devirt dump (verified via runtime dumps) - byte patches on the client are DETECTED AND REVERTED (~2.5s) by its integrity self-repair; re-patching hard-fails init -> don't patch bytes - license check uses zero CryptoAPI calls (custom VM math, not forgeable) - crack: 7-byte stub on kernel32!FreeLibraryAndExitThread -> ExitThread in the host process; failed license then leaves the client resident - loader2/slinky_loader.c: full verified flow (Java 8 VM + env + stub + load) - differential key tests, dry-run host requirements documented in README_part2.md
This commit is contained in:
1 parent
593391f215
commit
f5225a7fec
3 files changed
+325
No files matched your search
@@ -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 <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <intrin.h>
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in new issue
Block a user