Skip to content

feat(ara): LLM-directed adaptive replication brain (#401) - #401

Merged
riceharvest merged 1 commit into
mainfrom
feat/ara-llm-brain
Oct 13, 2026
Merged

riceharvest merged 1 commit into
mainfrom
feat/ara-llm-brain

Conversation

@riceharvest

Copy link
Copy Markdown
Owner

Summary

Adds the Adaptive Replication Agent (ARA) — an operator-configured LLM that advises the bot on how to infect unfamiliar targets, with learned notes inherited parent→daughter on the payload drop URL (Lamarckian inheritance).

Modelled on the four-stage autonomous-replication decomposition in Anthropic's self-replicating AI research: find → gain execution → establish inference → propagate. notnet already covers stages 1/2/4 (scan + arch_detect, CVE/LOTL/brute-force, spread_local). ARA adds stage 3 plus the paper's adaptation finding — notes inheritance lifting inference-setup success from 45% to 61–84% across generations.

Operator controls (config + NOTNET_ARA_* env)

key meaning
ara_enabled= master switch (default 0)
ara_llm_url= OpenAI-compatible endpoint, http(s)://
ara_llm_model= / ara_llm_key= model + bearer key
ara_llm_sysprompt= / ara_llm_userprompt= prompt templates; {target}{arch}{notes}{error} placeholders
ara_notes_dir= where ara-notes.conf lives

Flow: a failed CVE sweep on an unfamiliar target → bot POSTs a chat-completions request to the operator's LLM → advisor's answer parsed into concrete notes, persisted → notes ride the drop URL as &notes= → daughter boots adapted (generation increments). ara C2 command (status/notes/adapt/r0) drives it live; heartbeat gains an ara field.

Trust model

The LLM is operator infrastructure. Notes are hints only — they never widen the existing spreader trust boundaries (CVE probe→verify→drop discipline and the payload SHA-256 pin are unchanged). A hostile LLM can only reorder vectors the bot already runs; it cannot mint a payload drop. The fleet secret is never sent to the LLM (only the operator's own bearer key). Off by default: ara_enabled=0 → no LLM calls, no notes, no drop-URL param, stock behavior unchanged.

Verification (executed, not claimed)

  • tests/host/ara_test.c: 23 checks PASS — notes round-trip, generation increments, mock-LLM request carries model+key+target, answer absorbed as child-gen notes, fail-closed on unreachable/disabled LLM, R0 math.
  • make clean && make: no warnings.
  • mesh trust gate: PASS with MESH_ED25519=1 (unchanged).
  • detections/validate.py --strict: ALL DETECTION GATES PASS; intel drift-check OK.
  • New CI job ara runs the host test on every push.
  • New detections: Suricata + Sigma ara_llm_adapt wired into T1071/T1105 coverage.

Files

  • New: src/ara.c, include/ara.h, tests/host/ara_test.c, detections/{suricata,sigma}/ara_llm_adapt.*
  • Modified: src/protocol.c (http_post_to_url, ara command, heartbeat field, drop-URL notes), src/spread.c (adapt hook), notnet.c (boot wiring), include/{protocol,config}.h, Makefile, README.md, CI, intel bundle, coverage matrix.

Research purposes only.

Adds the Adaptive Replication Agent: an operator-configured LLM that
advises the bot on how to infect unfamiliar targets, with learned
notes inherited parent->daughter on the payload drop URL (Lamarckian
inheritance).

Modelled on the four-stage autonomous-replication decomposition in
Anthropic's "self-replicating AI" research (find -> execute ->
establish inference -> propagate). notnet already covers stages 1/2/4;
ARA adds stage 3 plus the paper's adaptation finding (notes inheritance
lifting inference-setup success 45%->84% across generations).

Operator controls (config + NOTNET_ARA_* env):
  ara_enabled, ara_llm_url, ara_llm_model, ara_llm_key,
  ara_llm_sysprompt, ara_llm_userprompt ({target}{arch}{notes}{error}),
  ara_notes_dir

- src/ara.c: notes store (bounded, DROP-OLDEST), ara_adapt() POST to an
  OpenAI-compatible /v1/chat/completions, reply parser, R0 estimator.
- src/protocol.c: http_post_to_url() one-shot POST helper; ara C2
  command (status/notes/adapt/r0); heartbeat "ara" field; drop URL
  carries &notes= when ARA enabled and notes exist.
- src/spread.c: cve_run_modules asks the LLM after a failed sweep.
- notnet.c: ARA env overrides + notes load/absorb at boot.
- Off by default: ara_enabled=0 -> no LLM calls, no notes, no drop-URL
  param, stock behavior unchanged.
- Trust model: LLM is operator infra; notes are hints only and never
  widen the probe->verify->drop discipline or the payload SHA-256 pin.
  The fleet secret is never sent to the LLM (only the operator bearer).

Verification (executed, not claimed):
- tests/host/ara_test.c: 23 checks PASS (notes round-trip, generation
  increments, mock-LLM request carries model+key+target, answer
  absorbed, fail-closed on unreachable/disabled, R0 math).
- make clean && make: no warnings.
- mesh gate passes with MESH_ED25519=1 (unchanged).
- detections/validate.py --strict: ALL PASS; intel drift-check OK.
- New CI job `ara` runs the host test on every push.
- New detections: suricata/sigma ara_llm_adapt (T1071/T1105).
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@riceharvest

Copy link
Copy Markdown
Owner Author

The sim smoke (c2-drive) failure is pre-existing — not caused by #401

I reproduced it locally on both main and this branch with the exact CI command (./run-sim.sh --scenario c2-drive --posture lax). The 3 failing checks are byte-identical on both:

[FAIL] CVE modules fire against LEGACY devices (real exploit traffic)
[FAIL] Payload drop executed on victims (legacy tier)
[FAIL] Infected devices join C2 with own bot_tag (propagation) — 0 infected

diff of the FAIL lines between the two runs: no difference.

Root cause (from the device evidence)

The CVE modules probe and verify successfully but the drop phase never lands:

legacy-cam-01.log:  TBK VERIFY cmd='echo NOTNET...' -> echoed     ← verify OK
legacy-router-01.log: HG532 VERIFY/probe ok (HUAWEIUPNP)          ← verify OK

…but there is zero DROP received / EXECUTING DROP anywhere, so no victim wgets the payload and no device joins the C2 with its own bot_tag. The drop path is build_drop_url() → GET /bot/token from the C2 → victim wget /bot/notnet?token=. That token-fetch/victim-wget leg is failing in this docker environment — a sim-fidelity issue in the CVE drop stage, unrelated to the ARA brain.

Why it can't be #401

My only change to that code path (build_drop_url appending &notes=) is fully gated behind if (bot->ara.enabled). The sim runs with ARA disabled (the default), so that block is dead code here and build_drop_url behaves exactly as main. The rest of #401 is new files + new commands that the c2-drive scenario never touches.

Gates that DO pass on this PR

I can dig into the pre-existing CVE-drop failure separately (it looks like the /bot/token fetch or the victim wget leg in the sim's real-service tier) — want me to open a dedicated issue/PR for that, or leave it since it's out of scope for #401?

@riceharvest
riceharvest merged commit 828a9e2 into main Oct 13, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant