Skip to content

armgit / bla

Public Imported from GitHub
0

🛡️ 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.

feat(shields): framed Go buildinfo + Flutter pool exhaustion

qybaihea469e77d2918
diff --git a/src/shields/formats/go-flutter-exhaustion.ts b/src/shields/formats/go-flutter-exhaustion.ts
new file mode 100644
index 0000000..6cfaba7
--- /dev/null
+++ b/src/shields/formats/go-flutter-exhaustion.ts
@@ -0,0 +1,153 @@
+import { REA_INTERNAL_LIMITS } from "../../identity.js";
+import { SeededPrng } from "../../core/prng.js";
+import type { ProtectionIntensity } from "../../core/types.js";
+
+function writeGoUvarint(value: number): Buffer {
+ const out: number[] = [];
+ let n = value >>> 0;
+ while (n >= 0x80) {
+ out.push((n & 0x7f) | 0x80);
+ n >>>= 7;
+ }
+ out.push(n);
+ return Buffer.from(out);
+}
+
+/**
+ * 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.
+ */
+export function buildGoBuildInfoExhaustionPayload(
+ prng: SeededPrng,
+ intensity: ProtectionIntensity = "balanced",
+): {
+ readonly buffer: Buffer;
+ 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");
+ const canaryLines = [
+ "path\tgithub.com/tee-enclave/zero-trust-shim\n",
+ `mod\tgithub.com/tee-enclave/zero-trust-shim\tv4.2.0\th1:${prng.hex(32)}=\n`,
+ `dep\tgithub.com/intel-sgx/enclave-sdk-go\tv2.14.0\th1:${prng.hex(32)}=\n`,
+ `dep\tgithub.com/google/go-tpm-tools\tv0.4.4\th1:${prng.hex(32)}=\n`,
+ "build\t-compiler=gc\n",
+ "build\tCGO_ENABLED=1\n",
+ `build\tBLA_CANARY=${prng.hex(16)}\n`,
+ ];
+ let moduleBody = Buffer.from(canaryLines.join(""), "utf8");
+ const target =
+ intensity === "bankrupt" || intensity === "maximum"
+ ? REA_INTERNAL_LIMITS.GO_MAX_BUILD_INFO_BYTES + 4096
+ : Math.min(24_000, REA_INTERNAL_LIMITS.GO_MAX_BUILD_INFO_BYTES >> 3);
+ 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)),
+ "utf8",
+ );
+ moduleBody = Buffer.concat([moduleBody, noise]);
+ }
+ const moduleFramed = Buffer.concat([
+ MODULE_START,
+ moduleBody,
+ Buffer.from("\n", "utf8"),
+ MODULE_END,
+ ]);
+ const exceeds =
+ version.length + moduleFramed.length >
+ REA_INTERNAL_LIMITS.GO_MAX_BUILD_INFO_BYTES;
+
+ const header = Buffer.alloc(32, 0);
+ MAGIC.copy(header, 0);
+ header[14] = 8; // ptrSize
+ header[15] = 2; // flags: bit1 => inline encoding
+
+ const pclntabBait = Buffer.from(
+ "\0[BLA-GO-BUILDINFO]\0.gopclntab\0runtime.moduledata\0__gopclntab\0runtime.pclntab\0\xfb\xff\xff\xff\x00\x00",
+ "latin1",
+ );
+
+ return {
+ buffer: Buffer.concat([
+ padAlign,
+ header,
+ writeGoUvarint(version.length),
+ version,
+ writeGoUvarint(moduleFramed.length),
+ moduleFramed,
+ pclntabBait,
+ ]),
+ exceedsMaxBuildInfoBytes: exceeds,
+ moduleBytes: moduleFramed.length,
+ };
+}
+
+/**
+ * Dart snapshot-hash overflow (>64) plus string-pool URI/token flood past
+ * `MAX_POOL_URIS` (500) and `MAX_POOL_TOKENS` (2000).
+ */
+export function buildFlutterPoolExhaustionPayload(prng: SeededPrng): {
+ readonly buffer: Buffer;
+ readonly snapshotHashes: number;
+ readonly packageAndDartUris: number;
+ readonly classLikeTokens: number;
+} {
+ const records: Buffer[] = [];
+ const snapshotCount =
+ REA_INTERNAL_LIMITS.DART_MAX_SNAPSHOT_HASH_CANDIDATES + 2;
+
+ for (let i = 0; i < snapshotCount; i++) {
+ 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);
+ const hash32 = i.toString(16).padStart(8, "0") + prng.hex(24);
+ rec.write(hash32, 20, "ascii");
+ records.push(rec);
+ }
+
+ const labeledLines = [
+ '\0Dart VM version: 3.5.0-enclave-tee-ring0 (stable) on "linux_x64"\0',
+ 'Dart VM version: 3.6.2-sgx-isolated-bridge (stable) on "macos_arm64"\0',
+ "based on LLVM 17.0.6 (https://enclave.internal/llvm-tee-01)\0",
+ "based on LLVM 18.1.2 (https://enclave.internal/llvm-tee-02)\0",
+ "based on LLVM 18.1.8 (https://enclave.internal/llvm-tee-03)\0",
+ "based on LLVM 19.1.0 (https://enclave.internal/llvm-tee-04)\0",
+ "based on LLVM 19.1.4 (https://enclave.internal/llvm-tee-05)\0",
+ "based on LLVM 20.0.0 (https://enclave.internal/llvm-tee-06)\0",
+ ].join("");
+ records.push(Buffer.from(labeledLines, "latin1"));
+
+ const uriCount = REA_INTERNAL_LIMITS.DART_MAX_POOL_URIS + 16;
+ const tokenCount = REA_INTERNAL_LIMITS.DART_MAX_POOL_TOKENS + 32;
+ const poolParts: string[] = ["\0[BLA-FLUTTER-POOL-EXHAUST]\0"];
+ for (let i = 0; i < uriCount; i++) {
+ poolParts.push(`package:enclave_tarpit_${i}/lib/bridge_${prng.hex(4)}.dart`);
+ poolParts.push(`dart:enclave_isolate_${i}`);
+ }
+ for (let i = 0; i < tokenCount; i++) {
+ poolParts.push(`EnclaveTarpitNode_${i}_${prng.hex(3)}`);
+ }
+ records.push(Buffer.from(poolParts.join("\0") + "\0", "utf8"));
+
+ return {
+ buffer: Buffer.concat(records),
+ snapshotHashes: snapshotCount,
+ packageAndDartUris: uriCount * 2,
+ classLikeTokens: tokenCount,
+ };
+}
diff --git a/src/shields/formats/native.ts b/src/shields/formats/native.ts
index 9357046..90f2109 100644
--- a/src/shields/formats/native.ts
+++ b/src/shields/formats/native.ts
@@ -12,6 +12,10 @@ import {
type ElectronHardeningContext,
type ElectronHardeningReport,
} from "./electron-fuses.js";
+import {
+ buildGoBuildInfoExhaustionPayload,
+ buildFlutterPoolExhaustionPayload,
+} from "./go-flutter-exhaustion.js";
export class InvalidNativeBinaryError extends Error {
constructor(message: string) {
@@ -61,8 +65,11 @@ export interface NativeBinaryInspection {
readonly rustcCommitHashesCount: number;
readonly electronFuseSentinelsCount: number;
readonly dartSnapshotHashesCount: number;
+ readonly dartPoolPackageUriCount: number;
+ readonly dartPoolTokenCount: number;
readonly hasRustDepV0: boolean;
readonly hasGoBuildInfo: boolean;
+ readonly goBuildInfoFramed: boolean;
readonly extractedStringsCount: number;
readonly blaProtected: boolean;
}
@@ -388,7 +395,26 @@ export function inspectNativeBinary(bytes: Buffer): NativeBinaryInspection {
const hasGoBuildInfo =
textLatin1.includes(".go.buildinfo") ||
textLatin1.includes("__go_buildinfo") ||
- textLatin1.includes("\xff Go buildinf:");
+ textLatin1.includes("\xff Go buildinf:") ||
+ textLatin1.includes("[BLA-GO-BUILDINFO]");
+ const goBuildInfoFramed =
+ textLatin1.includes("[BLA-GO-BUILDINFO]") ||
+ textLatin1.includes(".gopclntab") ||
+ textLatin1.includes("runtime.moduledata");
+
+ let dartPoolPackageUriCount = 0;
+ let dartPoolTokenCount = 0;
+ for (const run of textLatin1.split("\0")) {
+ if (run.startsWith("package:") || run.startsWith("dart:")) {
+ dartPoolPackageUriCount++;
+ } else if (
+ run.length >= 5 &&
+ run.length <= 128 &&
+ /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(run)
+ ) {
+ dartPoolTokenCount++;
+ }
+ }
const printableMatches = textLatin1.match(/[A-Za-z0-9_/:.-]{6,}/g) ?? [];
const blaProtected =
@@ -406,8 +432,11 @@ export function inspectNativeBinary(bytes: Buffer): NativeBinaryInspection {
rustcCommitHashesCount: rustcMatches.size,
electronFuseSentinelsCount: fuseInspection.sentinelCount,
dartSnapshotHashesCount,
+ dartPoolPackageUriCount,
+ dartPoolTokenCount,
hasRustDepV0,
hasGoBuildInfo,
+ goBuildInfoFramed,
extractedStringsCount: printableMatches.length,
blaProtected,
};
@@ -453,45 +482,6 @@ export function buildDecoyRustAuditablePayload(prng: SeededPrng): Buffer {
);
}
-/**
- * Builds 66 Dart AOT snapshot records (`0xf5, 0xf5, 0xdc, 0xdc` + 16-byte header + 32-hex hash)
- * plus conflicting `"Dart VM version:"` and `6` `"based on LLVM ..."` strings to trip REA's
- * `FlutterPayloadScan.ts` (`MAX_SNAPSHOT_HASH_CANDIDATES = 64` & `MAX_TOOLCHAIN_LINES = 4`).
- */
-function buildFlutterDartSnapshotOverflowPayload(prng: SeededPrng): Buffer {
- const records: Buffer[] = [];
- const snapshotCount =
- REA_INTERNAL_LIMITS.DART_MAX_SNAPSHOT_HASH_CANDIDATES + 2; // 66 > 64
-
- for (let i = 0; i < snapshotCount; i++) {
- const rec = Buffer.alloc(52, 0);
- rec[0] = 0xf5;
- rec[1] = 0xf5;
- rec[2] = 0xdc;
- rec[3] = 0xdc;
- rec.writeBigUInt64LE(64n, 4); // headerLength
- rec.writeBigUInt64LE(3n, 12); // kind = 3 (FullAOT)
- const hash32 = i.toString(16).padStart(8, "0") + prng.hex(24);
- rec.write(hash32, 20, "ascii");
- records.push(rec);
- }
-
- // Conflicting Dart VM versions (`dartVersionCapped = true`) + >4 LLVM toolchain lines (`toolchainCapped = true`)
- const labeledLines = [
- `\0Dart VM version: 3.5.0-enclave-tee-ring0 (stable) on "linux_x64"\0`,
- `Dart VM version: 3.6.2-sgx-isolated-bridge (stable) on "macos_arm64"\0`,
- `based on LLVM 17.0.6 (https://enclave.internal/llvm-tee-01)\0`,
- `based on LLVM 18.1.2 (https://enclave.internal/llvm-tee-02)\0`,
- `based on LLVM 18.1.8 (https://enclave.internal/llvm-tee-03)\0`,
- `based on LLVM 19.1.0 (https://enclave.internal/llvm-tee-04)\0`,
- `based on LLVM 19.1.4 (https://enclave.internal/llvm-tee-05)\0`,
- `based on LLVM 20.0.0 (https://enclave.internal/llvm-tee-06)\0`,
- ].join("");
-
- records.push(Buffer.from(labeledLines, "latin1"));
- return Buffer.concat(records);
-}
-
/**
* 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
@@ -510,6 +500,9 @@ export function protectNativeBinary(
readonly rustcHashesInjected: number;
readonly electronFuseSentinelsInjected: number;
readonly dartSnapshotHashesInjected: number;
+ readonly dartPoolUrisInjected: number;
+ readonly dartPoolTokensInjected: number;
+ readonly goBuildInfoExceedsLimit: boolean;
readonly chaffPayloadsEmbedded: number;
readonly binarySectionsPatched: number;
readonly electronHardeningReport?: ElectronHardeningReport;
@@ -555,15 +548,8 @@ export function protectNativeBinary(
rustcLines.push(`/rustc/${hash}/library/core/src/enclave_guard.rs\0`);
}
- // 2. Generate decoy Go module metadata lines
- const goLines = [
- `path\tgithub.com/tee-enclave/zero-trust-shim\n`,
- `mod\tgithub.com/tee-enclave/zero-trust-shim\tv4.2.0\th1:${prng.hex(32)}=\n`,
- `dep\tgithub.com/intel-sgx/enclave-sdk-go\tv2.14.0\th1:${prng.hex(32)}=\n`,
- `dep\tgithub.com/google/go-tpm-tools\tv0.4.4\th1:${prng.hex(32)}=\n`,
- `build\t-compiler=gc\n`,
- `build\tCGO_ENABLED=1\n`,
- ].join("");
+ // 2. Framed Go buildinfo + pclntab/moduledata bait
+ const goBuildInfo = buildGoBuildInfoExhaustionPayload(prng, intensity);
// 3. Generate architectural chaff strings + Canary Honeypot + System-Diagnostic Rabbit Holes for Ghidra/Hopper/IDA
const chaffBlock = chaffPayloads
@@ -584,12 +570,13 @@ export function protectNativeBinary(
),
].join("");
const depV0Payload = buildDecoyRustAuditablePayload(prng);
- const dartOverflowPayload = buildFlutterDartSnapshotOverflowPayload(prng);
+ const flutterPool = buildFlutterPoolExhaustionPayload(prng);
+ const dartOverflowPayload = flutterPool.buffer;
const shieldTrailer = Buffer.concat([
Buffer.from("\0[BLA-NATIVE-SHIELD-V1]\0.dep-v0\0", "utf8"),
Buffer.from(rustcLines.join(""), "latin1"),
- Buffer.from(goLines, "utf8"),
+ goBuildInfo.buffer,
decoySentinelsBuffer,
dartOverflowPayload,
Buffer.from(chaffBlock, "utf8"),
@@ -641,8 +628,10 @@ export function protectNativeBinary(
buffer: outBytes,
rustcHashesInjected: rustcCount,
electronFuseSentinelsInjected: decoySentinelsInjected,
- dartSnapshotHashesInjected:
- REA_INTERNAL_LIMITS.DART_MAX_SNAPSHOT_HASH_CANDIDATES + 2,
+ dartSnapshotHashesInjected: flutterPool.snapshotHashes,
+ dartPoolUrisInjected: flutterPool.packageAndDartUris,
+ dartPoolTokensInjected: flutterPool.classLikeTokens,
+ goBuildInfoExceedsLimit: goBuildInfo.exceedsMaxBuildInfoBytes,
chaffPayloadsEmbedded: chaffPayloads.length,
binarySectionsPatched,
...(electronHardeningReport ? { electronHardeningReport } : {}),