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.0

Where 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#

OptionHelp textDefault
--config CONFIGpath of swarmlabre.toml (default: $SWARMLABRE_CONFIG, ./swarmlabre.toml, ~/.config/swarmlabre/)none; the search order applies
--versionshow program's version number and exitnone
usage
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#

CodeMeaning
0done
1the work failed
2bad usage or input
3needs a model and none is configured
130run 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#

CommandHelp text
reportbuild the report files of a stored run
demowrite a harmless demo sample and the script of a mock model that analyses it
corpuswrite the benign generated samples (ELF, PE, APK, script, hostile strings) into a folder
runanalyse a sample with the agent swarm
replayrebuild a recorded run offline and compare every output with its manifest
exportpack a sealed run into a folder that replay can rebuild elsewhere
servestart 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
usage: swarmlabre report [-h] [--out OUT] run
ArgumentHelp textDefault
runa run folder or a run id (sXXXXXXXX)none
--out OUTalso copy the report files into this foldernone
$ 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
usage: swarmlabre demo [-h] [--variant {one,two}] dir
ArgumentHelp textDefault
dirfolder to write the demo sample and mock-script intonone
--variant {one,two}two = a second sample with a UTF-16 string, a dispute and a round-2 planone
$ 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:

NameFileKind
elf-benigndemo.elfelf
elf-widedemo2.elfelf
pe-benigndemo.exepe
apk-benigndemo.apkapk
elf-hostilehostile.elfelf
script-shdemo.shscript

A name that is not in the table exits 2 with the line no such sample 'NAME' (have: ...), and nothing is written.

usage
usage: swarmlabre corpus [-h] dir [names ...]
ArgumentHelp textDefault
dirno help textnone
nameswhich samples (default: all)all six
$ python3 -m swarmlabre corpus corpus/ elf-benign pe-benign

run#

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
usage: swarmlabre run [-h] [--brief BRIEF] [--replay RUN] [--mock SCRIPT]
                      [--roles ROLES] [--tlp TLP] [--out OUT] [--quiet]
                      sample
ArgumentHelp textDefault
samplean ELF, PE or APK filenone
--brief BRIEFthe 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 RUNanswer from the recorded model replies of an earlier run (containers still run; the agents get the exact recorded answers)none
--mock SCRIPTanswer from a scripted mock model (a JSON file) instead of [model] base_urlnone
--roles ROLEScomma-separated roles (triage and reporter always run); default all sixall six
--tlp TLPreport marking: CLEAR, GREEN, AMBER, AMBER+STRICT, REDthe tlp key of [swarm]
--out OUTalso copy the report files into this foldernone
--quietno progress linesoff
$ 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
usage: swarmlabre replay [-h] [--out OUT] [--no-sample] run
ArgumentHelp textDefault
runa run folder or a run idnone
--out OUTalso write the rebuilt files into this foldernone
--no-sampledo 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
usage: swarmlabre export [-h] [--with-sample] run dest
ArgumentHelp textDefault
runa run folder or a run idnone
destfolder to create <run id>/ innone
--with-sampleinclude 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
usage: swarmlabre serve [-h] [--host HOST] [--port PORT] [--replay RUN]
                        [--speed SPEED] [--paused]
ArgumentHelp textDefault
--host HOSTaddress to listen on (default 127.0.0.1, this machine only)the host key of [serve]
--port PORTport (default 8810; 0 = any free port)the port key of [serve]
--replay RUNplay a sealed run folder or an exported bundle through the UI: no model, no Dockernone
--speed SPEEDreplay speed: 'real' (default) or a number, 8 = eight times fasterreal
--pausedreplay: start pausedoff
$ python3 -m swarmlabre serve --replay demo/sfaef16e6 --speed 8
SwarmLabRE alpha 0.1.0Edit this page on GitHub