Docs / Guides / Analyse a file
Analyse a file
Analysing a new file needs Docker, two images and a model. With the scripted mock model it needs no GPU, no key and no network, and that is how the first run below works.
What you need#
You need Python 3.12, Docker and about ten minutes for the one-time image build. The tools image compiles Ghidra's decompiler for arm64, so analysing a file runs on arm64 Linux only today. Replaying a recorded run, the web UI, the static demo and the tests do not use Docker.
The sample must be an ELF, PE or APK file. ELF and PE files up to 4 MB and APK files up to 16 MB are accepted; max_sample_native_mb and max_sample_apk_mb set the limits. Any other file is refused with "Only ELF, PE and APK files are supported." and exit code 2.
A run starts when the memory for both containers is free. The tools container gets 4 GiB for an APK, 6 GiB for a native file up to 1 MB and 12 GiB for a larger one. The agents container gets 0.5 GiB plus 0.15 GiB per agent, at least 1 GiB. tools_memory_gb and agent_memory_gb override both. memory_reserve_gb (4 by default) keeps memory free for the host. While memory is short the run waits for up to 30 minutes (wait_minutes) and then fails.
Build the two images#
$ docker build -t swarmlabre-agent sandbox/ $ docker build -f sandbox/Dockerfile.re -t swarmlabre-tools sandbox/
Build the agent image first, because the tools image starts from it. Both are built from the Dockerfiles in sandbox/.
| Image | Starts from | Holds |
|---|---|---|
swarmlabre-agent | node:22-slim | The pi coding agent 1.1.0, ripgrep, jq, Python 3 and the other basic tools the agents use. |
swarmlabre-tools | swarmlabre-agent | REA 6.4.0, Ghidra 12.1.4 (headless, with its decompiler built for arm64), JDK 21, jadx, Apktool 3.0.3, Binwalk 3.1.0, mitmdump 12.2.3 and the usual archive extractors. |
The tool versions in the table are pinned. The Debian packages are not, and node:22-slim is pinned to its tag only. The Ghidra, Binwalk, jadx, Apktool and mitmproxy downloads are checked against a SHA-256 while the image is built, and nothing is downloaded when a run starts, because the containers have no network.
Run the demo sample#
$ python3 -m swarmlabre demo out-demo/ $ python3 -m swarmlabre run out-demo/demo.elf --mock out-demo/mock-script.json --out out/
demo writes demo.elf, a harmless generated program that only exits, and mock-script.json, the script of the scripted model that analyses it. The mock model describes the script. With --mock the run needs no GPU, no key and no network, and takes about a minute.
run stages the file, starts the two containers and waits for the run. Whenever the phase or the number of finished tasks changes, it writes a line such as s1a2b3c4d: prepare, 0 tasks done to stderr; --quiet turns those lines off. At the end it prints one JSON line to stdout with the run id, the status, the reason, the folder of the run, the report files and the counts of findings. --out copies the report files into a folder.
The run is kept in runs/<run id> under the state folder, ~/.local/state/swarmlabre unless [paths] state says otherwise. The newest 20 runs are kept (keep_runs). A finished run holds report.html, report.md, report.json, board.json, the three indicator files and, when the file has enough strings, detection.yar. Reports describes them and Reports and exports shows how to use the indicator files and the rules.
Choose the roles, the marking and the question#
| Option | Value | Default | What it does |
|---|---|---|---|
--brief TEXT | 1 to 4096 bytes | see below | The question the agents answer. It goes into every agent's prompt. |
--roles a,b | role ids, comma-separated | all six | The roles that run. Triage and the Reporter always run, so --roles ioc runs three agents. |
--tlp X | CLEAR, GREEN, AMBER, AMBER+STRICT or RED | AMBER | The marking on the report files. [swarm] tlp sets the default. |
The role ids are triage, static, ioc, crypto, behaviour and reporter; The six roles says what each does. An unknown id stops the command with "Unknown agent role." and exit code 2. A marking that is not in the list stops it with "TLP must be one of CLEAR, GREEN, AMBER, AMBER+STRICT, RED." and exit code 2. The default brief is:
What does this sample do? Name its most important functions and say what each one is for.
A run with one role, a marking and its own question:
$ python3 -m swarmlabre run out-demo/demo.elf --mock out-demo/mock-script.json --roles ioc --tlp GREEN --brief "List the network indicators."What happens to the file#
- The host reads the file itself, then starts the tools container with the sample mounted read-only.
- Ghidra, jadx, Apktool and rea write the prepared files: strings, imports, functions and decompiled code. The host reads them out as a tar stream, without extracting it, and caps the size and the number of files.
- The host starts the agents container with the prepared files mounted read-only.
- An agent sends a model request to a loopback address inside its container. A forwarder passes it to the gate's Unix socket on the host.
- The gate pins the sampling, adds the key and sends the request to the model.
- The model answers.
- The gate passes the reply to the agent and records it.
- An agent calls a tool through the locked socket of the tools container. The tool server answers one call at a time for the whole swarm.
- The tool server returns the result.
- An agent posts a finding by running
swarm-post. The host reads the agent's session output and takes a finding only from a line that carries that task's own nonce. - The board checks the post against the bytes of the file and the run's tool log. The reports are built from the board.
After the run#
| Exit code | Meaning |
|---|---|
| 0 | the run is done |
| 1 | the work failed |
| 2 | bad usage or input |
| 3 | a model is needed and none is configured |
| 130 | stopped with Ctrl-C |
Ctrl-C stops the run, keeps what the board holds and writes the reports from it. python3 -m swarmlabre report RUN rebuilds every report file from a stored run folder or a run id. Replay and export a run covers replay and export.
When a run does not start#
Before it starts a container, run checks the model, the memory, the disk, the images and the network of a throwaway container. A check that fails prints Cannot start: and the reason, and the command exits with code 1.
| Reason | What to check |
|---|---|
| no model is reachable | The endpoint in [model] base_url does not answer, or the model named in model is not one it lists. With no [model] section and no --mock the command exits with code 3 before this check. |
| there is not enough free memory | The run waits for the memory instead of stopping, as described above. |
| the disk is nearly full | A run needs 512 MiB plus four times the size of the sample free in the state folder. |
| a sandbox image is missing | Build the two images. |
| the sandbox check failed | A throwaway container with no network showed an interface or reached the internet, or the check gave no answer. The sandbox describes the check. |