Docs / Reference / Command line
Command line
SwarmLabRE has seven commands. Each one prints its result as JSON on standard output and its messages on standard error, and ends with an exit code.
How to call it#
Run a command as python3 -m swarmlabre COMMAND from the folder of the repository. Options that belong to no command, --config and --version, go before the command name; a command does not take them.
$ python3 -m swarmlabre --version
swarmlabre 0.1.0Where a command takes a run, it takes a folder or a run id. An argument that is not a folder is looked up as runs/<id> in the state folder, which is [paths] state in the configuration. A run id is s and eight hexadecimal digits.
Options before the command#
| Option | Help text | Default |
|---|---|---|
--config CONFIG | path of swarmlabre.toml (default: $SWARMLABRE_CONFIG, ./swarmlabre.toml, ~/.config/swarmlabre/) | none; the search order applies |
--version | show program's version number and exit | none |
usage: swarmlabre [-h] [--config CONFIG] [--version]
{report,demo,corpus,run,replay,export,serve} ...Every command also takes -h and --help, which print its help and exit.
Exit codes#
| Code | Meaning |
|---|---|
0 | done |
1 | the work failed |
2 | bad usage or input |
3 | needs a model and none is configured |
130 | run was stopped with Ctrl-C; the run ends and keeps what the board holds |
The first four are the codes of swarmlabre/cli.py. A usage or input error prints its message to standard error. A configuration file that is named with --config but does not exist, or that is not valid TOML, ends the command with 2 and the line config: ....
The commands#
| Command | Help text |
|---|---|
report | build the report files of a stored run |
demo | write a harmless demo sample and the script of a mock model that analyses it |
corpus | write the benign generated samples (ELF, PE, APK, script, hostile strings) into a folder |
run | analyse a sample with the agent swarm |
replay | rebuild a recorded run offline and compare every output with its manifest |
export | pack a sealed run into a folder that replay can rebuild elsewhere |
serve | start the web UI (live, or --replay RUN for a recorded run) |
report#
Builds every report file of a stored run again, in place, into the out/ folder of the run, and prints the run id, the folder and the files it wrote as JSON. It needs no model and no Docker. With --out the files are also copied to another folder.
It exits 0 when report.json was written, 1 when it was not, and 2 when the argument is not a run folder (it has no swarm.json) or the run record cannot be read.
usage: swarmlabre report [-h] [--out OUT] run
| Argument | Help text | Default |
|---|---|---|
run | a run folder or a run id (sXXXXXXXX) | none |
--out OUT | also copy the report files into this folder | none |
$ python3 -m swarmlabre report demo/sfaef16e6 --out reports/demo#
Writes a harmless demo sample and the script of a mock model that analyses it into dir: demo.elf and mock-script.json, or with --variant two demo2.elf and mock-script2.json. It prints their paths as JSON and, on standard error, a hint with the run command that analyses them.
It exits 0. The mock model describes the script format.
usage: swarmlabre demo [-h] [--variant {one,two}] dir| Argument | Help text | Default |
|---|---|---|
dir | folder to write the demo sample and mock-script into | none |
--variant {one,two} | two = a second sample with a UTF-16 string, a dispute and a round-2 plan | one |
$ python3 -m swarmlabre demo out-demo/ $ python3 -m swarmlabre demo out-demo2/ --variant two
corpus#
Writes the benign generated samples into dir and prints a JSON object from each sample name to the file it wrote. Without names it writes all six:
| Name | File | Kind |
|---|---|---|
elf-benign | demo.elf | elf |
elf-wide | demo2.elf | elf |
pe-benign | demo.exe | pe |
apk-benign | demo.apk | apk |
elf-hostile | hostile.elf | elf |
script-sh | demo.sh | script |
A name that is not in the table exits 2 with the line no such sample 'NAME' (have: ...), and nothing is written.
usage: swarmlabre corpus [-h] dir [names ...]
| Argument | Help text | Default |
|---|---|---|
dir | no help text | none |
names | which samples (default: all) | all six |
$ python3 -m swarmlabre corpus corpus/ elf-benign pe-benignrun#
Analyses one sample: it stages the file, starts the run, waits for it and prints where the report is. It needs Docker and the two images, also with --mock. While it waits it prints one progress line to standard error whenever the phase or the number of finished tasks changes, unless --quiet is given. When the run ends it prints one JSON object with the run id, the status, the reason, the run folder, the files written and the counts, and with --replay also replay_diverged, the number of requests that had no recorded reply.
It exits 0 when the run status is done and 1 for any other status. It exits 2 when the sample is refused or the model settings are wrong, and 3 when no model is configured. Ctrl-C stops the run and exits 130. Analyse a file follows a run from start to finish, and Use a real model sets up the endpoint.
usage: swarmlabre run [-h] [--brief BRIEF] [--replay RUN] [--mock SCRIPT]
[--roles ROLES] [--tlp TLP] [--out OUT] [--quiet]
sample| Argument | Help text | Default |
|---|---|---|
sample | an ELF, PE or APK file | none |
--brief BRIEF | the question the agents answer (default: what does it do, name its main functions) | What does this sample do? Name its most important functions and say what each one is for. |
--replay RUN | answer from the recorded model replies of an earlier run (containers still run; the agents get the exact recorded answers) | none |
--mock SCRIPT | answer from a scripted mock model (a JSON file) instead of [model] base_url | none |
--roles ROLES | comma-separated roles (triage and reporter always run); default all six | all six |
--tlp TLP | report marking: CLEAR, GREEN, AMBER, AMBER+STRICT, RED | the tlp key of [swarm] |
--out OUT | also copy the report files into this folder | none |
--quiet | no progress lines | off |
$ python3 -m swarmlabre run out-demo/demo.elf --mock out-demo/mock-script.json --out out/replay#
Rebuilds a recorded run offline and compares every output with its manifest. It prints the checks as JSON.
It exits 0 when everything is identical, 1 when something differs and 2 when the folder cannot be replayed. Replay and export a run describes the levels and the checks.
usage: swarmlabre replay [-h] [--out OUT] [--no-sample] run
| Argument | Help text | Default |
|---|---|---|
run | a run folder or a run id | none |
--out OUT | also write the rebuilt files into this folder | none |
--no-sample | do not use the kept sample: re-run only the report building (the downstream level) | off |
$ python3 -m swarmlabre replay demo/sfaef16e6 $ python3 -m swarmlabre replay demo/sfaef16e6 --no-sample
export#
Packs a sealed run into dest/<run id>/, which replay can rebuild anywhere, and prints the folder and whether the sample is in it as JSON.
It exits 0, or 2 when the run is not sealed or dest/<run id> already exists.
usage: swarmlabre export [-h] [--with-sample] run dest
| Argument | Help text | Default |
|---|---|---|
run | a run folder or a run id | none |
dest | folder to create <run id>/ in | none |
--with-sample | include the sample (the bundle then replays at the full level) | off |
$ python3 -m swarmlabre export demo/sfaef16e6 bundles/serve#
Starts the web UI and prints its address, with the bearer token in the fragment, at every start. Live, it runs the real pipeline and needs Docker and a model. With --replay it plays a recorded run through the same page, with no model and no Docker.
It runs until Ctrl-C or SIGTERM and then exits 0. It exits 1 when it cannot listen on the address and 2 when --replay or --speed is wrong. A host that is not loopback prints a warning. The web UI covers the three modes and the token.
usage: swarmlabre serve [-h] [--host HOST] [--port PORT] [--replay RUN]
[--speed SPEED] [--paused]| Argument | Help text | Default |
|---|---|---|
--host HOST | address to listen on (default 127.0.0.1, this machine only) | the host key of [serve] |
--port PORT | port (default 8810; 0 = any free port) | the port key of [serve] |
--replay RUN | play a sealed run folder or an exported bundle through the UI: no model, no Docker | none |
--speed SPEED | replay speed: 'real' (default) or a number, 8 = eight times faster | real |
--paused | replay: start paused | off |
$ python3 -m swarmlabre serve --replay demo/sfaef16e6 --speed 8