π‘οΈ BLA (Blind LLM Agents) β Adversarial defense shield that protects binaries, Electron apps, JS bundles, Python, and WebAssembly against AI reverse-engineering agents like REA. Poison -> Exhaust -> Hallucinate.
JavaScript adversarial-aiclaude-codecursorelectron-securityllm-securitymcpmcp-serverobfuscationreverse-engineeringwebassembly
feat(shields): plant Go buildinfo and Flutter pool into mapped ELF sections
qybaiheedac5a086952
diff --git a/src/index.ts b/src/index.tsindex 5a4921d..b06a0f8 100644--- a/src/index.ts+++ b/src/index.ts@@ -180,8 +180,12 @@ export {inspectGpuPtx,protectGpuPtxText,FIRMWARE_HARDENING_SKIP_REASON,+ GPU_OBJECT_HARDENING_SKIP_REASON,} from "./shields/formats/gpu-ptx.js";export {buildGoBuildInfoExhaustionPayload,buildFlutterPoolExhaustionPayload,+ buildMappedGoBuildInfoPlant,+ buildMappedFlutterIsolatePoolPlant,+ buildMappedGoFlutterElfFixture,} from "./shields/formats/go-flutter-exhaustion.js";diff --git a/src/shields/formats/go-flutter-exhaustion.ts b/src/shields/formats/go-flutter-exhaustion.tsindex 6cfaba7..d4a31a7 100644--- a/src/shields/formats/go-flutter-exhaustion.ts+++ b/src/shields/formats/go-flutter-exhaustion.ts@@ -13,14 +13,18 @@ function writeGoUvarint(value: number): Buffer {return Buffer.from(out);}+const GO_MAGIC = Buffer.from("ff20476f206275696c64696e663a", "hex");+const MODULE_START = Buffer.from("3077af0c9274080241e1c107e6d618e6", "hex");+const MODULE_END = Buffer.from("f932433186182072008242104116d8f2", "hex");+/*** Framed Go buildinfo (magic `\xff Go buildinf:` + inline encoding) with* MODULE_START/END wrapping, plus `.gopclntab` / `runtime.moduledata` bait.* Bankrupt/maximum pad the module past `MAX_BUILD_INFO_BYTES` (1 MiB).*- * Note: REA only parses buildinfo inside mapped `.go.buildinfo` / writable- * load regions. Trailer placement still poisons whole-file scanners and is- * ready for mapped-section injection; the framed blob stays structurally valid.+ * Trailer placement poisons whole-file scanners. Prefer+ * {@link buildMappedGoBuildInfoPlant} inside a real `.go.buildinfo` section /+ * writable PT_LOAD so REA's mapped parser (`GoBuildInfoSearch`) trips.*/export function buildGoBuildInfoExhaustionPayload(prng: SeededPrng,@@ -30,9 +34,6 @@ export function buildGoBuildInfoExhaustionPayload(readonly exceedsMaxBuildInfoBytes: boolean;readonly moduleBytes: number;} {- const MAGIC = Buffer.from("ff20476f206275696c64696e663a", "hex");- const MODULE_START = Buffer.from("3077af0c9274080241e1c107e6d618e6", "hex");- const MODULE_END = Buffer.from("f932433186182072008242104116d8f2", "hex");const padAlign = Buffer.alloc(16, 0);const version = Buffer.from("go1.22.5", "utf8");@@ -53,7 +54,8 @@ export function buildGoBuildInfoExhaustionPayload(if (version.length + moduleBody.length < target) {const need = target - version.length - moduleBody.length;const noise = Buffer.from(- `\npath\tgithub.com/bla/tarpit/${prng.hex(8)}\n` + "A".repeat(Math.max(0, need - 40)),+ `\npath\tgithub.com/bla/tarpit/${prng.hex(8)}\n` ++ "A".repeat(Math.max(0, need - 40)),"utf8",);moduleBody = Buffer.concat([moduleBody, noise]);@@ -69,7 +71,7 @@ export function buildGoBuildInfoExhaustionPayload(REA_INTERNAL_LIMITS.GO_MAX_BUILD_INFO_BYTES;const header = Buffer.alloc(32, 0);- MAGIC.copy(header, 0);+ GO_MAGIC.copy(header, 0);header[14] = 8; // ptrSizeheader[15] = 2; // flags: bit1 => inline encoding@@ -93,6 +95,138 @@ export function buildGoBuildInfoExhaustionPayload(};}+/**+ * Compact plant for a real mapped `.go.buildinfo` / writable PT_LOAD region.+ * Bankrupt claims an inline version length past `MAX_BUILD_INFO_BYTES` so REA's+ * mapped parser resource-fails without needing a 1 MiB section. Balanced writes+ * a valid small framed module. Capacity is respected (never overflows the section).+ */+export function buildMappedGoBuildInfoPlant(+ intensity: ProtectionIntensity,+ capacity: number,+): {+ readonly buffer: Buffer;+ readonly tripsMaxBuildInfoBytes: boolean;+} {+ if (capacity < 40) {+ return { buffer: Buffer.alloc(0), tripsMaxBuildInfoBytes: false };+ }+ const header = Buffer.alloc(32, 0);+ GO_MAGIC.copy(header, 0);+ header[14] = 8;+ header[15] = 2;+ const marker = Buffer.from("\0[BLA-GO-MAPPED]\0", "latin1");++ if (intensity === "bankrupt" || intensity === "maximum") {+ const claim = writeGoUvarint(+ REA_INTERNAL_LIMITS.GO_MAX_BUILD_INFO_BYTES + 1,+ );+ const plant = Buffer.concat([header, claim, marker]);+ return {+ buffer: plant.subarray(0, Math.min(plant.length, capacity)),+ tripsMaxBuildInfoBytes: true,+ };+ }++ const version = Buffer.from("go1.22.5", "utf8");+ const module = Buffer.from(+ "path\tgithub.com/bla/mapped-buildinfo\nbuild\t-compiler=gc\n",+ "utf8",+ );+ const plant = Buffer.concat([+ header,+ writeGoUvarint(version.length),+ version,+ writeGoUvarint(module.length),+ module,+ marker,+ ]);+ return {+ buffer: plant.subarray(0, Math.min(plant.length, capacity)),+ tripsMaxBuildInfoBytes: false,+ };+}++/**+ * Dense NUL-terminated package:/dart:/class-like pool sized to fit `capacity`,+ * for planting inside a real Dart isolate snapshot data region.+ */+export function buildMappedFlutterIsolatePoolPlant(+ capacity: number,+ prng: SeededPrng,+ options: { readonly includeSnapshotHeader?: boolean } = {},+): {+ readonly buffer: Buffer;+ readonly packageAndDartUris: number;+ readonly classLikeTokens: number;+ readonly snapshotHeaderBytes: number;+} {+ if (capacity <= 0) {+ return {+ buffer: Buffer.alloc(0),+ packageAndDartUris: 0,+ classLikeTokens: 0,+ snapshotHeaderBytes: 0,+ };+ }+ const parts: Buffer[] = [];+ let headerBytes = 0;+ if (options.includeSnapshotHeader !== false && capacity >= 52) {+ const rec = Buffer.alloc(52, 0);+ rec[0] = 0xf5;+ rec[1] = 0xf5;+ rec[2] = 0xdc;+ rec[3] = 0xdc;+ rec.writeBigUInt64LE(64n, 4);+ rec.writeBigUInt64LE(3n, 12);+ rec.write(prng.hex(32), 20, "ascii");+ parts.push(rec);+ headerBytes = 52;+ }+ let used = headerBytes;+ let uris = 0;+ let tokens = 0;+ const marker = Buffer.from("\0[BLA-FLUTTER-MAPPED]\0", "utf8");+ if (used + marker.length <= capacity) {+ parts.push(marker);+ used += marker.length;+ }+ let i = 0;+ while (used < capacity && uris < REA_INTERNAL_LIMITS.DART_MAX_POOL_URIS + 32) {+ const pkg = `package:enclave_mapped_${i}/lib/bridge_${prng.hex(3)}.dart\0`;+ const dart = `dart:enclave_iso_${i}\0`;+ const pkgBuf = Buffer.from(pkg, "utf8");+ const dartBuf = Buffer.from(dart, "utf8");+ if (used + pkgBuf.length + dartBuf.length > capacity) break;+ parts.push(pkgBuf, dartBuf);+ used += pkgBuf.length + dartBuf.length;+ uris += 2;+ i++;+ }+ let t = 0;+ while (+ used < capacity &&+ tokens < REA_INTERNAL_LIMITS.DART_MAX_POOL_TOKENS + 32+ ) {+ const tok = `MappedEnclaveNode_${t}_${prng.hex(2)}\0`;+ const tokBuf = Buffer.from(tok, "utf8");+ if (used + tokBuf.length > capacity) break;+ parts.push(tokBuf);+ used += tokBuf.length;+ tokens++;+ t++;+ }+ if (used < capacity) {+ parts.push(Buffer.alloc(capacity - used, 0));+ }+ return {+ buffer: Buffer.concat(parts).subarray(0, capacity),+ packageAndDartUris: uris,+ classLikeTokens: tokens,+ snapshotHeaderBytes: headerBytes,+ };+}+/*** Dart snapshot-hash overflow (>64) plus string-pool URI/token flood past* `MAX_POOL_URIS` (500) and `MAX_POOL_TOKENS` (2000).@@ -151,3 +285,123 @@ export function buildFlutterPoolExhaustionPayload(prng: SeededPrng): {classLikeTokens: tokenCount,};}++/**+ * Synthetic ELF64 with a mapped `.go.buildinfo` section and an isolate-data+ * region (plus dynsym for `_kDartIsolateSnapshotData`) so REA's real Go /+ * Flutter parsers can be exercised in tests and the benchmark.+ */+export function buildMappedGoFlutterElfFixture(): Buffer {+ const FILE_SIZE = 8192;+ const bytes = Buffer.alloc(FILE_SIZE, 0);+ // ELF64 LE header+ bytes.set([0x7f, 0x45, 0x4c, 0x46, 2, 1, 1], 0);+ bytes.writeUInt16LE(3, 16); // ET_DYN+ bytes.writeUInt16LE(0x3e, 18); // EM_X86_64+ bytes.writeUInt32LE(1, 20);+ bytes.writeBigUInt64LE(0x400000n, 24); // e_entry+ bytes.writeBigUInt64LE(64n, 32); // e_phoff+ bytes.writeBigUInt64LE(128n, 40); // e_shoff+ bytes.writeUInt16LE(64, 52);+ bytes.writeUInt16LE(56, 54);+ bytes.writeUInt16LE(1, 56); // e_phnum+ bytes.writeUInt16LE(64, 58);+ bytes.writeUInt16LE(6, 60); // e_shnum: null + shstrtab + go.buildinfo + isolate + dynsym + dynstr+ bytes.writeUInt16LE(1, 62); // e_shstrndx++ // PT_LOAD R|W covering whole file (writable non-exec β Go fallback eligible)+ bytes.writeUInt32LE(1, 64); // PT_LOAD+ bytes.writeUInt32LE(6, 68); // PF_R|PF_W+ bytes.writeBigUInt64LE(0n, 72); // p_offset+ bytes.writeBigUInt64LE(0x400000n, 80); // p_vaddr+ bytes.writeBigUInt64LE(0x400000n, 88); // p_paddr+ bytes.writeBigUInt64LE(BigInt(FILE_SIZE), 96); // p_filesz+ bytes.writeBigUInt64LE(BigInt(FILE_SIZE), 104); // p_memsz+ bytes.writeBigUInt64LE(0x1000n, 112); // p_align++ const names = Buffer.from(+ "\0.shstrtab\0.go.buildinfo\0.isolate\0.dynsym\0.dynstr\0",+ "utf8",+ );+ const shstrOff = 512;+ names.copy(bytes, shstrOff);++ const goOff = 1024;+ const goSize = 512;+ const goAddr = 0x400000n + BigInt(goOff); // 0x400400 β 16-aligned+ const isoOff = 2048;+ const isoSize = 2048;+ const isoAddr = 0x400000n + BigInt(isoOff);+ const dynsymOff = 4096;+ const dynsymSize = 48; // 2 entries Γ 24+ const dynstrOff = 4200;+ const dynstr = Buffer.from("\0_kDartIsolateSnapshotData\0", "utf8");+ dynstr.copy(bytes, dynstrOff);++ // dynsym: null entry + isolate symbol (STT_OBJECT, STB_GLOBAL, size=isoSize)+ // Elf64_Sym: st_name(4) st_info(1) st_other(1) st_shndx(2) st_value(8) st_size(8)+ const sym1 = dynsymOff + 24;+ bytes.writeUInt32LE(1, sym1); // st_name β _kDartIsolateSnapshotData+ bytes[sym1 + 4] = (1 << 4) | 1; // STB_GLOBAL | STT_OBJECT+ bytes.writeUInt16LE(3, sym1 + 6); // st_shndx = .isolate (index 3)+ bytes.writeBigUInt64LE(isoAddr, sym1 + 8);+ bytes.writeBigUInt64LE(BigInt(isoSize), sym1 + 16);++ // Seed isolate with a real snapshot header so protect can append pool after it+ bytes[isoOff] = 0xf5;+ bytes[isoOff + 1] = 0xf5;+ bytes[isoOff + 2] = 0xdc;+ bytes[isoOff + 3] = 0xdc;+ bytes.writeBigUInt64LE(64n, isoOff + 4);+ bytes.writeBigUInt64LE(3n, isoOff + 12);+ bytes.write("0123456789abcdef0123456789abcdef", isoOff + 20, "ascii");++ // Section headers at 128 (64 bytes each)+ // 0: NULL+ // 1: .shstrtab+ const sh1 = 128 + 64;+ bytes.writeUInt32LE(1, sh1); // name β .shstrtab+ bytes.writeUInt32LE(3, sh1 + 4); // SHT_STRTAB+ bytes.writeBigUInt64LE(BigInt(shstrOff), sh1 + 24);+ bytes.writeBigUInt64LE(BigInt(names.length), sh1 + 32);+ // 2: .go.buildinfo+ const sh2 = 128 + 128;+ const goNameOff = names.indexOf(Buffer.from(".go.buildinfo\0"));+ bytes.writeUInt32LE(goNameOff, sh2);+ bytes.writeUInt32LE(1, sh2 + 4); // SHT_PROGBITS+ bytes.writeBigUInt64LE(3n, sh2 + 8); // SHF_WRITE|SHF_ALLOC+ bytes.writeBigUInt64LE(goAddr, sh2 + 16);+ bytes.writeBigUInt64LE(BigInt(goOff), sh2 + 24);+ bytes.writeBigUInt64LE(BigInt(goSize), sh2 + 32);+ // 3: .isolate+ const sh3 = 128 + 192;+ const isoNameOff = names.indexOf(Buffer.from(".isolate\0"));+ bytes.writeUInt32LE(isoNameOff, sh3);+ bytes.writeUInt32LE(1, sh3 + 4);+ bytes.writeBigUInt64LE(3n, sh3 + 8);+ bytes.writeBigUInt64LE(isoAddr, sh3 + 16);+ bytes.writeBigUInt64LE(BigInt(isoOff), sh3 + 24);+ bytes.writeBigUInt64LE(BigInt(isoSize), sh3 + 32);+ // 4: .dynsym+ const sh4 = 128 + 256;+ const dynsymNameOff = names.indexOf(Buffer.from(".dynsym\0"));+ bytes.writeUInt32LE(dynsymNameOff, sh4);+ bytes.writeUInt32LE(11, sh4 + 4); // SHT_DYNSYM+ bytes.writeBigUInt64LE(2n, sh4 + 8); // SHF_ALLOC+ bytes.writeBigUInt64LE(0x400000n + BigInt(dynsymOff), sh4 + 16);+ bytes.writeBigUInt64LE(BigInt(dynsymOff), sh4 + 24);+ bytes.writeBigUInt64LE(BigInt(dynsymSize), sh4 + 32);+ bytes.writeUInt32LE(5, sh4 + 40); // sh_link β .dynstr+ bytes.writeBigUInt64LE(24n, sh4 + 48); // sh_entsize+ // 5: .dynstr+ const sh5 = 128 + 320;+ const dynstrNameOff = names.indexOf(Buffer.from(".dynstr\0"));+ bytes.writeUInt32LE(dynstrNameOff, sh5);+ bytes.writeUInt32LE(3, sh5 + 4); // SHT_STRTAB+ bytes.writeBigUInt64LE(2n, sh5 + 8);+ bytes.writeBigUInt64LE(0x400000n + BigInt(dynstrOff), sh5 + 16);+ bytes.writeBigUInt64LE(BigInt(dynstrOff), sh5 + 24);+ bytes.writeBigUInt64LE(BigInt(dynstr.length), sh5 + 32);++ return bytes;+}diff --git a/src/shields/formats/native.ts b/src/shields/formats/native.tsindex 90f2109..270011a 100644--- a/src/shields/formats/native.ts+++ b/src/shields/formats/native.ts@@ -15,6 +15,8 @@ import {import {buildGoBuildInfoExhaustionPayload,buildFlutterPoolExhaustionPayload,+ buildMappedGoBuildInfoPlant,+ buildMappedFlutterIsolatePoolPlant,} from "./go-flutter-exhaustion.js";export class InvalidNativeBinaryError extends Error {@@ -482,6 +484,123 @@ export function buildDecoyRustAuditablePayload(prng: SeededPrng): Buffer {);}++/** Resolve ELF64 section names from the section-header string table. */+export function resolveElf64SectionNames(+ bytes: Buffer,+ layout: Elf64LayoutSummary,+): Map<string, Elf64SectionHeaderSummary> {+ const map = new Map<string, Elf64SectionHeaderSummary>();+ if (+ layout.shnum === 0 ||+ layout.shstrndx === 0 ||+ layout.shstrndx >= layout.shnum+ ) {+ return map;+ }+ const strSec = layout.sectionHeaders[layout.shstrndx];+ if (!strSec || strSec.size === 0 || strSec.offset + strSec.size > bytes.length) {+ return map;+ }+ const strtab = bytes.subarray(strSec.offset, strSec.offset + strSec.size);+ for (const sh of layout.sectionHeaders) {+ if (sh.index === 0) continue;+ if (sh.nameOffset >= strtab.length) continue;+ let end = sh.nameOffset;+ while (end < strtab.length && strtab[end] !== 0) end++;+ const name = strtab.subarray(sh.nameOffset, end).toString("utf8");+ if (name.length > 0) map.set(name, sh);+ }+ return map;+}++/**+ * Plant framed Go buildinfo into `.go.buildinfo` (preferred) or the first+ * writable non-executable PT_LOAD file range so REA's mapped parser trips.+ * Never mutates program/section header fields β only file-backed bytes.+ */+function injectMappedGoBuildInfo(+ working: Buffer,+ layout: Elf64LayoutSummary,+ intensity: ProtectionIntensity,+): { planted: boolean; tripsMax: boolean; offset: number; size: number } {+ // Only mutate a named `.go.buildinfo` PROGBITS section. Generic PT_LOAD+ // fallback would rewrite arbitrary ELF fixtures and violate the+ // trailer-only / section-integrity red line for non-Go binaries.+ const names = resolveElf64SectionNames(working, layout);+ const named = names.get(".go.buildinfo");+ if (!named || named.type !== 1 || named.size < 48) {+ return { planted: false, tripsMax: false, offset: -1, size: 0 };+ }+ const alignPad = Number((16n - (named.addr % 16n)) % 16n);+ const writeAt = named.offset + alignPad;+ const room = named.size - alignPad;+ if (room < 48) {+ return { planted: false, tripsMax: false, offset: -1, size: 0 };+ }+ const plant = buildMappedGoBuildInfoPlant(intensity, room);+ if (plant.buffer.length === 0) {+ return { planted: false, tripsMax: false, offset: -1, size: 0 };+ }+ // Clear the section then plant so prior padding cannot confuse parsers.+ working.fill(0, named.offset, named.offset + named.size);+ plant.buffer.copy(working, writeAt);+ return {+ planted: true,+ tripsMax: plant.tripsMaxBuildInfoBytes,+ offset: writeAt,+ size: plant.buffer.length,+ };+}++/**+ * Plant Flutter pool strings inside `.isolate` / isolate snapshot data regions+ * (or after an embedded Dart snapshot magic) so REA's string-pool projection+ * from isolate data observes the decoys.+ */+function injectMappedFlutterIsolatePool(+ working: Buffer,+ layout: Elf64LayoutSummary,+ prng: SeededPrng,+): { planted: boolean; uris: number; tokens: number; offset: number } {+ // Only plant into an explicitly named `.isolate` section so generic+ // `.rodata` / ELF fixtures stay byte-identical under trailer-only protect.+ const names = resolveElf64SectionNames(working, layout);+ const named = names.get(".isolate");+ if (!named || named.type !== 1 || named.size < 64) {+ return { planted: false, uris: 0, tokens: 0, offset: -1 };+ }+ let plantAt = named.offset;+ let includeHeader = true;+ if (+ named.size >= 52 &&+ working[named.offset] === 0xf5 &&+ working[named.offset + 1] === 0xf5 &&+ working[named.offset + 2] === 0xdc &&+ working[named.offset + 3] === 0xdc+ ) {+ plantAt = named.offset + 52;+ includeHeader = false;+ }+ const capacity = named.offset + named.size - plantAt;+ if (capacity < 64) {+ return { planted: false, uris: 0, tokens: 0, offset: -1 };+ }+ const plant = buildMappedFlutterIsolatePoolPlant(capacity, prng, {+ includeSnapshotHeader: includeHeader,+ });+ if (plant.buffer.length === 0) {+ return { planted: false, uris: 0, tokens: 0, offset: -1 };+ }+ plant.buffer.copy(working, plantAt);+ return {+ planted: true,+ uris: plant.packageAndDartUris,+ tokens: plant.classLikeTokens,+ offset: plantAt,+ };+}+/*** Protects a Native Binary (ELF / Mach-O / PE) against REA's native & desktop analyzers* while strictly preserving ELF64 `PT_LOAD` (`p_offset`, `p_filesz`, `p_memsz` / BSS) and@@ -503,6 +622,8 @@ export function protectNativeBinary(readonly dartPoolUrisInjected: number;readonly dartPoolTokensInjected: number;readonly goBuildInfoExceedsLimit: boolean;+ readonly mappedGoBuildInfoPlanted: boolean;+ readonly mappedFlutterPoolPlanted: boolean;readonly chaffPayloadsEmbedded: number;readonly binarySectionsPatched: number;readonly electronHardeningReport?: ElectronHardeningReport;@@ -540,6 +661,21 @@ export function protectNativeBinary(decoySentinelsInjected,);+ let mappedGoBuildInfoPlanted = false;+ let mappedFlutterPoolPlanted = false;+ let mappedGoTripsMax = false;+ if (elfBefore) {+ const goPlant = injectMappedGoBuildInfo(workingInput, elfBefore, intensity);+ mappedGoBuildInfoPlanted = goPlant.planted;+ mappedGoTripsMax = goPlant.tripsMax;+ const flutterPlant = injectMappedFlutterIsolatePool(+ workingInput,+ elfBefore,+ prng,+ );+ mappedFlutterPoolPlanted = flutterPlant.planted;+ }+// 1. Generate 68 distinct `/rustc/<40-hex>/` strings (> REA's MAX_RUSTC_HASHES = 64!)const rustcCount = 68;const rustcLines: string[] = [];@@ -631,7 +767,10 @@ export function protectNativeBinary(dartSnapshotHashesInjected: flutterPool.snapshotHashes,dartPoolUrisInjected: flutterPool.packageAndDartUris,dartPoolTokensInjected: flutterPool.classLikeTokens,- goBuildInfoExceedsLimit: goBuildInfo.exceedsMaxBuildInfoBytes,+ goBuildInfoExceedsLimit:+ goBuildInfo.exceedsMaxBuildInfoBytes || mappedGoTripsMax,+ mappedGoBuildInfoPlanted,+ mappedFlutterPoolPlanted,chaffPayloadsEmbedded: chaffPayloads.length,binarySectionsPatched,...(electronHardeningReport ? { electronHardeningReport } : {}),