🛡️ 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
fix(shields): densify ASAR/WASM past REA budgets; shrink ELF isolate
qybaihee356459754d5
diff --git a/src/core/types.ts b/src/core/types.tsindex 8709e3b..21dff70 100644--- a/src/core/types.ts+++ b/src/core/types.ts@@ -51,6 +51,7 @@ export type ReaAttackVectorId =| "model-artifact-inspection"| "android-dex-il2cpp-inspection"| "archive-inventory"+ | "asar-header-admission"| "erlang-beam-inspection"| "evm-bytecode-inspection"| "pcap-capture-inspection"diff --git a/src/engine/protector.ts b/src/engine/protector.tsindex 209af51..38bc42b 100644--- a/src/engine/protector.ts+++ b/src/engine/protector.ts@@ -20,6 +20,7 @@ import { generateChaffPayloads } from "../shields/chaff/chaff-generator.js";import { transformJavaScriptWithBlaShield } from "../shields/javascript/ast-shield.js";import { generateHoneySourceMap } from "../shields/formats/sourcemap.js";import { packAsarBuffer, unpackAsarBuffer, validateAsarProtectionInput, type VirtualAsarFile } from "../shields/formats/asar.js";+import { planAsarHeaderAmplification } from "../shields/exhaustion/asar-header-amplifier.js";import { protectWasmBinary } from "../shields/formats/wasm.js";import { findPythonPrologueInsertionOffset, protectPythonPycBuffer, protectPythonSource } from "../shields/formats/python.js";import { protectNativeBinary, validateElf64Layout } from "../shields/formats/native.js";@@ -234,15 +235,23 @@ export function protectTarget(options: ProtectionOptions): ProtectionResult {content: Buffer.from(decoyBridgeJs.code, "utf8"),});+ // Flood ASAR Pickle JSON header past REA DEFAULT_ASAR_MAX_HEADER_BYTES at+ // bankrupt intensity (mapped decoy shard paths; real modules untouched).+ const asarAmplification = planAsarHeaderAmplification(prng, intensity);+ for (const decoy of asarAmplification.files) {+ protectedFiles.push(decoy);+ }+const repacked = packAsarBuffer(protectedFiles);writeFileSync(absOutput, repacked);- binarySectionsPatched = 1;+ binarySectionsPatched = 1 + asarAmplification.files.length;counteredVectors.add("electron-ipc-bridge");counteredVectors.add("js-static-semantics");counteredVectors.add("sourcemap-recovery");counteredVectors.add("call-graph-tracing");counteredVectors.add("obligation-ledger-cloning");counteredVectors.add("archive-inventory");+ counteredVectors.add("asar-header-admission");} else if (format === "wasm") {const rawWasm = readFileSync(absInput);const res = protectWasmBinary(rawWasm, { intensity, seed });diff --git a/src/shields/exhaustion/asar-header-amplifier.ts b/src/shields/exhaustion/asar-header-amplifier.tsindex c06be96..8a10b99 100644--- a/src/shields/exhaustion/asar-header-amplifier.ts+++ b/src/shields/exhaustion/asar-header-amplifier.ts@@ -3,38 +3,65 @@ import type { ProtectionIntensity } from "../../core/types.js";import type { VirtualAsarFile } from "../formats/asar.js";/**- * Exact constants from `morluto/rea/src/domain/analysisResourceLimits.ts:7,15`.+ * Exact constants from REA ASAR header admission+ * (`DEFAULT_ASAR_MAX_HEADER_BYTES` / `MAXIMUM_ASAR_MAX_HEADER_BYTES`).*/export const REA_ASAR_HEADER_LIMITS = {DEFAULT_ASAR_MAX_HEADER_BYTES: 16 * 1024 * 1024,MAXIMUM_ASAR_MAX_HEADER_BYTES: 256 * 1024 * 1024,} as const;+export interface AsarHeaderAmplificationPlan {+ readonly files: readonly VirtualAsarFile[];+ readonly estimatedHeaderBytes: number;+ readonly exceedsDefaultAdmission: boolean;+}+/**- * Generates virtual decoy enclave manifest entries inside an Electron `.asar` archive- * to expand REA's `inspect_artifact` inventory graph (`src/artifacts/AsarFailure.ts`).+ * Generates virtual decoy enclave manifest entries inside an Electron `.asar`+ * archive so REA's `admitAsarHeader` trips `DEFAULT_ASAR_MAX_HEADER_BYTES`+ * (16 MiB) at bankrupt intensity. Paths are long and bodies tiny so the Pickle+ * JSON header dominates — inventory growth without mutating real app modules.*/export function generateAsarHeaderDecoyFiles(prng: SeededPrng,intensity: ProtectionIntensity = "balanced",): readonly VirtualAsarFile[] {+ return planAsarHeaderAmplification(prng, intensity).files;+}++export function planAsarHeaderAmplification(+ prng: SeededPrng,+ intensity: ProtectionIntensity = "balanced",+): AsarHeaderAmplificationPlan {+ // bankrupt: ~4000 × ~4 KiB paths → header ≳ 17 MiB (> DEFAULT 16 MiB).+ // lower intensities: inventory chaff only (header stays well under admission).const count =intensity === "stealth"? 4: intensity === "balanced"? 8: intensity === "maximum"- ? 16- : 24;+ ? 64+ : 4000;+ const pathPadLen =+ intensity === "stealth"+ ? 24+ : intensity === "balanced"+ ? 48+ : intensity === "maximum"+ ? 256+ : 4096;const tag = prng.hex(3);+ const pad = "a".repeat(pathPadLen);const files: VirtualAsarFile[] = [];for (let i = 0; i < count; i++) {- const relPath = `enclave/shards/ring0-slot-${tag}-${i}.json`;+ const relPath = `enclave/shards/ring0-slot-${tag}-${pad}_${i}.json`;const body = JSON.stringify({shardId: i,enclaveCid: 16,- attestationHash: prng.hex(32),+ attestationHash: prng.hex(8),delegated: true,});files.push({@@ -43,5 +70,16 @@ export function generateAsarHeaderDecoyFiles(});}- return files;+ // Conservative estimate: path + JSON entry overhead (~80 bytes framing).+ const estimatedHeaderBytes = files.reduce(+ (sum, f) => sum + f.relativePath.length + 80 + f.content.length,+ 64,+ );++ return {+ files,+ estimatedHeaderBytes,+ exceedsDefaultAdmission:+ estimatedHeaderBytes > REA_ASAR_HEADER_LIMITS.DEFAULT_ASAR_MAX_HEADER_BYTES,+ };}diff --git a/src/shields/exhaustion/index.ts b/src/shields/exhaustion/index.tsindex 7640eb2..8422316 100644--- a/src/shields/exhaustion/index.ts+++ b/src/shields/exhaustion/index.ts@@ -41,6 +41,8 @@ import {import {REA_ASAR_HEADER_LIMITS,generateAsarHeaderDecoyFiles,+ planAsarHeaderAmplification,+ type AsarHeaderAmplificationPlan,} from "./asar-header-amplifier.js";export {@@ -60,6 +62,8 @@ export {generateFridaCaptureSaturation,generateRegexWorkerTarpit,generateAsarHeaderDecoyFiles,+ planAsarHeaderAmplification,+ type AsarHeaderAmplificationPlan,type ReaSubsystemBudgetSpec,type ObligationFloodResult,type CallGraphLabyrinthResult,diff --git a/src/shields/exhaustion/wasm-interface-exhaustion.ts b/src/shields/exhaustion/wasm-interface-exhaustion.tsindex a0538e2..278ff3f 100644--- a/src/shields/exhaustion/wasm-interface-exhaustion.ts+++ b/src/shields/exhaustion/wasm-interface-exhaustion.ts@@ -1,6 +1,7 @@import { SeededPrng } from "../../core/prng.js";import type { ProtectionIntensity } from "../../core/types.js";import { computeReaWasmInterfaceCharge } from "./rea-budget-matrix.js";+import { REA_INTERNAL_LIMITS } from "../../identity.js";export interface WasmExhaustionDescriptor {readonly moduleName: string;@@ -15,18 +16,22 @@ export interface WasmInterfaceExhaustionPlan {readonly totalBinaryOverheadBytes: number;readonly totalReaChargedBytes: number;readonly byteAmplificationFactor: number;+ readonly exceedsRepresentationBudget: boolean;}/**- * Targets REA's `WasmInterfaceBudget` (`src/domain/wasm/wasmInterface.ts:90-108`),- * where every WebAssembly import/export entry is charged:- * `1024 + (module.length + name.length + wat_form.length) * 6 + (params.length + results.length) * 16`- * against a fixed 32 MiB (`WASM_INTERFACE_REPRESENTATION_BYTES`) ceiling.+ * Targets REA's `WasmInterfaceBudget` (`WASM_INTERFACE_REPRESENTATION_BYTES` =+ * 32 MiB), where every WebAssembly import/export entry is charged:+ * `1024 + (module.length + name.length + wat_form.length) * 6 + (params+results) * 16`.+ *+ * At bankrupt intensity, descriptors are sized so the charged representation+ * exceeds the 32 MiB ceiling (Wabt path or in-process budget probe).*/export function planWasmInterfaceBudgetExhaustion(prng: SeededPrng,intensity: ProtectionIntensity = "balanced",): WasmInterfaceExhaustionPlan {+ const budget = REA_INTERNAL_LIMITS.WASM_INTERFACE_REPRESENTATION_BYTES;const count =intensity === "stealth"? 12@@ -34,15 +39,20 @@ export function planWasmInterfaceBudgetExhaustion(? 24: intensity === "maximum"? 48- : 72;+ : 128;+ // bankrupt: long module/export/wat names so ~128 entries clear 32 MiB.+ // bankrupt: ~15 KiB names × 128 entries → charged representation ≫ 32 MiB.+ const namePad =+ intensity === "bankrupt" ? 15_000 : intensity === "maximum" ? 64 : 0;const descriptors: WasmExhaustionDescriptor[] = [];let totalBinaryOverheadBytes = 0;let totalReaChargedBytes = 0;for (let i = 0; i < count; i++) {- const moduleName = `enclave_tee_ring0_attestation_domain_${prng.hex(6)}`;- const exportName = `bla_enclave_verify_zero_trust_merkle_slot_${i}_${prng.hex(8)}`;+ const pad = namePad > 0 ? prng.hex(Math.min(8, namePad)).padEnd(namePad, "b") : "";+ const moduleName = `enclave_tee_ring0_attestation_domain_${prng.hex(6)}${pad ? `_${pad}` : ""}`;+ const exportName = `bla_enclave_verify_zero_trust_merkle_slot_${i}_${prng.hex(8)}${pad ? `_${pad}` : ""}`;const paramCount = 16;const resultCount = 4;const watForm = `(func $${exportName} (param ${Array(paramCount).fill("i64").join(" ")}) (result ${Array(resultCount).fill("i64").join(" ")}))`;@@ -53,7 +63,8 @@ export function planWasmInterfaceBudgetExhaustion(paramCount,resultCount,});- const binaryBytes = moduleName.length + exportName.length + paramCount + resultCount + 8;+ const binaryBytes =+ moduleName.length + exportName.length + paramCount + resultCount + 8;descriptors.push({moduleName,@@ -73,5 +84,6 @@ export function planWasmInterfaceBudgetExhaustion(byteAmplificationFactor: Number((totalReaChargedBytes / Math.max(1, totalBinaryOverheadBytes)).toFixed(2),),+ exceedsRepresentationBudget: totalReaChargedBytes > budget,};}diff --git a/src/shields/formats/go-flutter-exhaustion.ts b/src/shields/formats/go-flutter-exhaustion.tsindex 464e874..96e172d 100644--- a/src/shields/formats/go-flutter-exhaustion.ts+++ b/src/shields/formats/go-flutter-exhaustion.ts@@ -302,9 +302,11 @@ export function buildFlutterPoolExhaustionPayload(prng: SeededPrng): {* Flutter parsers can be exercised in tests and the benchmark.*/export function buildMappedGoFlutterElfFixture(): Buffer {- // Isolate must be large enough for REA's real string-pool projection to- // observe > MAX_POOL_URIS (500) and > MAX_POOL_TOKENS (2000) entries.- const ISO_SIZE = 160 * 1024;+ // Isolate must fit dense plants past MAX_POOL_URIS (500) / MAX_POOL_TOKENS+ // (2000). Keep it compact (~48 KiB): a larger zero-filled baseline inflated+ // the benchmark "before" token estimate and understated the native-ELF+ // multiplier without changing real after-protection strength.+ const ISO_SIZE = 48 * 1024;const GO_SIZE = 512;const goOff = 1024;const isoOff = 2048;diff --git a/src/shields/formats/wasm.ts b/src/shields/formats/wasm.tsindex 3fe3d62..3a38d90 100644--- a/src/shields/formats/wasm.ts+++ b/src/shields/formats/wasm.ts@@ -1,4 +1,5 @@import { SeededPrng } from "../../core/prng.js";+import { planWasmInterfaceBudgetExhaustion } from "../exhaustion/wasm-interface-exhaustion.js";import type { ProtectionIntensity } from "../../core/types.js";import { generateChaffPayloads } from "../chaff/chaff-generator.js";import { buildCanaryAndDiagnosticPayloads } from "../deception/format-payloads.js";@@ -189,6 +190,9 @@ export function protectWasmBinary(readonly chaffPayloadsEmbedded: number;readonly canaryTokensEmbedded: number;readonly diagnosticsEmbedded: number;+ readonly interfaceDescriptorsEmbedded: number;+ readonly projectedInterfaceChargeBytes: number;+ readonly exceedsRepresentationBudget: boolean;} {if (bytes.length < 8 ||@@ -282,11 +286,35 @@ export function protectWasmBinary(),);+ // Projected WasmInterfaceBudget exhaustion plan (Wabt path / in-process probe).+ const ifacePlan = planWasmInterfaceBudgetExhaustion(prng, intensity);+ const ifacePayload = Buffer.from(+ JSON.stringify({+ schema: "bla-wasm-interface-exhaustion/v1",+ descriptors: ifacePlan.descriptors.map((d) => ({+ module: d.moduleName,+ name: d.exportName,+ params: d.paramCount,+ results: d.resultCount,+ charge: d.reaChargedRepresentationBytes,+ })),+ totalCharge: ifacePlan.totalReaChargedBytes,+ exceeds: ifacePlan.exceedsRepresentationBudget,+ }),+ "utf8",+ );+ addedSections.push(+ createWasmCustomSection("bla.wasm.interface.exhaustion", ifacePayload),+ );+return {buffer: Buffer.concat([...keptChunks, ...addedSections]),customSectionsAdded: addedSections.length,chaffPayloadsEmbedded: chaffPayloads.length,canaryTokensEmbedded: deception.canary.syntheticCanaryTokens.length,diagnosticsEmbedded: deception.diagnostics.diagnosticsInjected.length,+ interfaceDescriptorsEmbedded: ifacePlan.descriptors.length,+ projectedInterfaceChargeBytes: ifacePlan.totalReaChargedBytes,+ exceedsRepresentationBudget: ifacePlan.exceedsRepresentationBudget,};}