Getting started with the CLI
Installation
To install M&NTIS CLI in a virtualenv, use the following commands:
$ mkdir venv
$ virtualenv venv/
$ source venv/bin/activate
(venv) $ pip install mantis_api_client
(...)Authentication
In order to authenticate the CLI with M&NTIS Platform, use the user login command:
$ mantis user login
A web browser should have been opened for 'mantis-platform.io'
Waiting callback for 60s
Access grantedYou can see that you are correctly logged with:
$ mantis user self
[+] Current user information:
[+] ID: 3f2c1a9e-5b7d-4e8f-9a0b-1c2d3e4f5a6b
[+] Name: John Doe
[+] Email: john.doe@example.com
[+] Creation date: 2024-03-21T10:44:53.037000Machines without a web browser
At the end of the browser step, the instance sends the browser to http://localhost:9876/callback, where mantis user login waits for it: the browser has to reach port 9876 of the machine that runs the CLI. When the CLI runs on a server you reach over SSH, forward that port from your workstation and use the workstation's browser:
# On your workstation
$ ssh -L 9876:127.0.0.1:9876 user@server
# In that SSH session, on the server
$ mantis user login --domain mantis.example.org
Open this URL in a web browser in order to create an access token for M&NTIS:
https://id.mantis.example.org/realms/mantis/protocol/openid-connect/auth?...
Waiting callback for 60sOpen the URL in the workstation's browser and log in: the browser's redirection to localhost:9876 goes through the tunnel to the CLI, which prints Access granted. The login is stored on the server, in ~/.config/mantis.
- The workstation must resolve
id.<domain>(through DNS or its/etc/hosts) and its browser must accept the instance's certificate. - Port 9876 must be free on the workstation, and only one login can wait through the tunnel at a time.
- The CLI waits 60 seconds. Give it more time with
OIDC_REDIRECT_URL_TIMEOUT=300 mantis user login .... - Through a bastion, add it to the same command:
ssh -J user@bastion -L 9876:127.0.0.1:9876 user@server.
Instances with their own certificate
An instance whose certificate is not signed by a public authority (a dev or on-prem instance) is trusted per instance, on the first user login:
$ mantis user login --domain mantis.example.org
id.mantis.example.org presents a self-signed certificate:
Host: id.mantis.example.org
Subject: CN=mantis.example.org
Issuer: CN=mantis.example.org
Names: app.mantis.example.org, id.mantis.example.org
SHA-256: E2:88:97:E7:...:2C:EB
Valid until: 2036-11-07 16:47 UTC
Check the fingerprint with the instance's administrator. Trust this certificate for mantis.example.org? [y/n] (n):- Check the SHA-256 fingerprint with the instance's administrator before answering
y: it is the only proof that the certificate is the instance's. - The certificate is saved in
~/.config/mantis/certs/<domain>.pemand used for that instance only, by the CLI and by AI agents (mantis-mcp). Whenid.andapp.present the same certificate, you are asked once. - If the certificate is signed by your organization's own authority, the CLI names that authority instead of asking. Get its certificate (PEM) and pass it with
mantis user login --domain <domain> --ca-cert <file>. - If an instance's certificate changes, every command to it fails with the new fingerprint until you run
mantis user login --domain <domain>again to review it. A new certificate is never trusted silently. mantis user logoutremoves the saved certificate with the instance's last login.- A login without a terminal (a script) refuses an unknown certificate and prints its fingerprint.
CR_CA_CERTstill applies to the instances that have no saved certificate.
Several instances and accounts
Each login is stored as a profile. After the browser step, mantis user login asks for the profile's name, offering <username>@<domain>; --profile <name> gives it directly. A name is 1 to 64 letters, digits and . _ @ + -. Logging in again under a stored name replaces that profile; under a new name, the other profiles stay, so an administrator account and a regular one can be logged into the same instance side by side:
$ mantis user login --profile adminWhen the instance already has a profile, the browser would log its account in again, whatever you type. The CLI then prints the login URL instead of opening it: open it in a private window to log in to another account.
List the profiles, and see which one your commands go to:
$ mantis user profiles
[+] M&NTIS profiles (3):
* john john.doe mantis-platform.io workspace 034d4346-f8ff-4ccf-b8d0-54b6060faac5 (active)
admin john.doe-admin mantis-platform.io workspace 034d4346-f8ff-4ccf-b8d0-54b6060faac5
example john.doe mantis.example.org workspace 04d0c886-5c0e-4a48-80f9-7d635cb48063Switch to another one without logging in again:
$ mantis user use admin
[+] Now using admin on mantis-platform.io (workspace 034d4346-f8ff-4ccf-b8d0-54b6060faac5)The switch is local: it works even when the instance is unreachable, and an expired login shows on the next command. A profile stored before profiles had names is named after its domain, and its account shows as unknown until its next login.
Accessing the threat catalogs
Two threat catalogs are available:
- Attacks (TTPs)
- Scenarios (killchains)
You can list the attack catalog contents with:
$ mantis attack list
[+] Available attacks (90):
[+] NAME - DESCRIPTION
[+] wordpress_tatsubuilder_rce - RCE on Wordpress with Tatsu Builder (T1190)
[+] mimikatz_logonpasswords - Dump Credentials from Memory with Mimikatz (T1003.001)
[+] list_local_process - Discover Local Processes (T1518)
(...)And for listing the available scenarios:
$ mantis scenario list
[+] Available scenarios (6):
[+] aetheris: Starts with a Log4shell attack on a server, then ARP poisoning (...)Launching a lab
If you want to launch an attack in a lab, for example the attack list_local_process, use the attack run command:
$ mantis attack run list_local_process
[+] Going to execute attack: list_local_process
Needed argument --scenario_profile, in order to choose the scenario to run
Available scenarios:
[+] windows10
[+] linuxYou should receive a message telling you that you need to select one of the available scenarios, here either windows10 or linux. You can do it with the command:
$ mantis attack run list_local_process --scenario_profile linuxHere is a complete log of an attack execution. This log displays each scenario step executed (provisioning steps, user activity steps, attack steps, etc.), and also returns the lab ID which can be used afterwards to interact with the lab.
$ mantis attack run list_local_process --scenario_profile linux
[+] Going to execute attack: list_local_process
[+] Scenario lab ID: 2f603ea7-98aa-40dd-8f21-e2ee299a02e9
[+] Notifications:
⚡ 2024-07-25 20:34:27 - Initialization
⚡ 2024-07-25 20:34:27 - Reserve Cyber Range instance
⚡ 2024-07-25 20:34:38 - Start Cyber Range
⚡ 2024-07-25 20:36:09 - Initialize Cyber Range
⚡ 2024-07-25 20:38:18 - Create simulation from topology '/cyber-range-catalog/redteam_topologies/ubuntu'
⚡ 2024-07-25 20:38:18 - Fetch required baseboxes
⚡ 2024-07-25 20:38:37 - Simulation started. You can use the Interactive view.
⚡ 2024-07-25 20:38:38 - Deploying 'os_set_hostname' playbook on 'TARGET'
⚡ 2024-07-25 20:39:31 - Playing 'operating_system/open_session' activity on 'TARGET'
⚡ 2024-07-25 20:40:29 - Begin attack 'Deploy an nginx web server'
⚡ 2024-07-25 20:40:31 - Finished attack 'Deploy an nginx web server'
⚡ 2024-07-25 20:40:32 - Begin attack 'Deploys a C&C'
⚡ 2024-07-25 20:40:36 - Finished attack 'Deploys a C&C'
⚡ 2024-07-25 20:40:48 - Playing 'operating_system/activate_payload_linux' activity on 'TARGET'
⚡ 2024-07-25 20:41:53 - Begin attack 'Discover Local Processes'
(...)
[========================================] in 7:41.1
[+] Scenario endedSeveral kind of content can be launched in a lab. Here are the available contents:
- See attack reference documentation.
- See scenario reference documentation.
- See basebox reference documentation.
- See topology reference documentation.
Configuring a lab
When launching a lab, you can configure it with the option --lab_config which expects a YAML configuration file as parameter.
See lab_config reference documentation.
The CLI usage when passing a lab_config YAML file is as follow:
$ mantis attack run list_local_process --scenario_profile linux --lab_config config.yaml
(...)In the next subchapters, we illustrate the use of the lab_config data structure to control scenario execution, and to configure defense.
Configuring scenario execution
There are three ways of managing scenario execution:
automatic: the various attack steps are executed one after the other without pause (default behavior).step_by_step: a pause occurs between each attack step.custom: a list of attack steps for which a pause is required as defined in thestep_waiting_listattribute.
A paused scenario can either require a user action to resume (default behavior), or wait for a random duration chosen between two values (random_waiting_minutes). Pauses are performed before and after the attack step.
In order to resume a scenario execution, the resume command should be entered:
$ mantis lab 2f603ea7-98aa-40dd-8f21-e2ee299a02e9 resumeThe following example runs a step-by-step scenario, stopping before and after each step:
$ cat config.yaml
---
scenario_execution_mode: "step_by_step"This example pauses on a scenario's "api_control" attack step:
$ cat config.yaml
---
scenario_execution_mode: "custom"
step_waiting_list: ["api_control"]Thie next example waits between 1 and 3 minutes before and after each attack rather than waiting for a user to resume the scenario:
$ cat config.yaml
---
random_waiting_minutes: [1, 3]Configuring defense
Defense log collection can be configured through the log_collectors attribute of the lab_config data structure.
The following extract illustratres a lab_config data structure used to configure the log collection chain Winlogbeat that emits logs towards a logstash log aggregator. Logs are then stored in a Elasticsearch database, and are then accessible through an analyst machine connecting to a Kibana instance.
$ cat config_collect.yaml
---
config_name: "config_collect_auditbeat"
log_collectors:
- instance_name: auditbeat
collector_name: auditbeat
collector_type: agent
location:
- location_type: system_type
value: linux
output:
- instance_name: logstash
collector_name: logstash
collector_type: aggregator
- instance_name: logstash
collector_name: logstash
collector_type: aggregator
location:
- location_type: new_node
value: logstash
output:
- instance_name: elasticsearch
collector_name: elasticsearch
collector_type: aggregator
- instance_name: elasticsearch
collector_name: elasticsearch
collector_type: aggregator
location:
- location_type: new_node
value: elasticsearch
- instance_name: kibana
collector_name: kibana
collector_type: visualization
location:
- location_type: new_node
value: kibana
- instance_name: analyst_machine
collector_name: analyst_machine
collector_type: visualization
location:
- location_type: new_node
value: analyst_machine
user_config:
nb_machines: 1Accessing lab information
Several lab commands are available with the CLI, as shown by the --help message:
$ mantis lab 2f603ea7-98aa-40dd-8f21-e2ee299a02e9 --help
(...)
info Get information about a lab
api Get API URLs to directly access the lab
topology Get scenario topology on current lab
nodes Get scenario nodes on current lab
assets Get scenario assets on current lab
attack-report Get scenario attack report on current lab
attack-infras Get scenario attack infras on current lab
attack-sessions Get scenario attack sessions on current lab
attack-knowledge Get scenario attack knowledge on current lab
notifications Get scenario notifications on current lab
scenario-run-config Get scenario run config on current lab
get-remote-access Get info for remote access to lab VMs
(...)Lab metadata
In order to retrieve lab metadata, the info command is available:
$ mantis lab 2f603ea7-98aa-40dd-8f21-e2ee299a02e9 info
[+] Lab information:
[+] Id: 2f603ea7-98aa-40dd-8f21-e2ee299a02e9
[+] Name: list_local_process
[+] Type: ATTACK
[+] Status: RUNNING
[+] Start time: 2024-07-29 07:29:13
[+] Elapsed time (minutes): 8.01
[+] Created by: jdeSee lab info reference documentation.
Lab nodes
To fetch the nodes metadata, use the nodes subcommand.
$ mantis lab 2f603ea7-98aa-40dd-8f21-e2ee299a02e9 nodesThis subcommand allows to display nodes information as JSON with the --json option. This option is usefull when looking for a specific piece of information with the tool jq:
$ mantis lab 2f603ea7-98aa-40dd-8f21-e2ee299a02e9 nodes --json | jq
[
{
"simulation_id": 1,
"basebox_id": "AMOSSYS/linux/ubuntu_20.04_gnome_chrome_firefox_fr",
"id": 1,
"name": "TARGET",
"node_start_time": "2024-07-29T07:33:07",
"status": "RUNNING",
"nb_proc": 2,
"memory_size": 4096,
"type": "virtual_machine",
"username": "alex",
"password": "123456;!",
"admin_username": "root",
"admin_password": "Beezh35;",
"vnc_port": 5901,
"spice_port": 6901,
"remote_password": "sXi-KRj8wjXtLucCMtPi6zenm8Ph7Y4U",
"active": true,
"roles": [
"client"
],
"network_interfaces": [
{
"mac_address": "00:21:1b:96:1b:14",
"ip_address_runtime": "192.168.33.11",
(...)
}
],
},
(...)For example, to list all the node names, you can use this command:
$ mantis lab cbf18e0c-f870-4048-9e42-413167bcd789 nodes|jq '.[] | .name'
"TARGET"
"SwitchGateway"
"RouterGateway"
"SwitchExt"
"DHCPServerExt"
"SwitchInternet"
"DHCPServerInternet"
"RouterFwExt"
"SwitchDMZ"
"DHCPServerDMZ"
"RouterFwInt"
"SwitchUsers"
"DHCPServerUsers"
"SwitchMonitoring"
"DHCPServerMonitoring"
"PhysicalGateway"
"DNSPublic"
"DNSDMZ"
"internetproxy"
"provAgentSimu1"
"logstash"
"nginxserver"
"apicontrol"See lab nodes reference documentation.
Accessing attack report
Once a scenario is finished (or during scenario execution), you can fetch information related to the attack execution:
$ mantis lab 2f603ea7-98aa-40dd-8f21-e2ee299a02e9 mantis attack-report
(...)
{
"id": 24,
"source_id": 10,
"worker": {
"id": "1518_000_001",
"name": "list_local_process",
"title": "Discover Local Processes",
"title_fr": "Liste les processus locaux",
"description": "Lists all running processes on the local workstation.",
"version": "1.1",
"cve": [],
"stability": "CRASH_SAFE",
"reliability": null,
"side_effect": "",
"killchain_step": "DISCOVERY",
"topics": "attack_session",
"repeatable": true,
"mitre_data": {
"technique": {
"id": "T1518",
"name": "Software Discovery"
},
"subtechnique": {},
"tactics": [
{
"id": "TA0007",
"name": "Discovery"
}
]
},
"attack_mode": "INDIRECT"
},
"status": "success",
"started_date": "2024-07-29T11:25:23Z",
"last_update": "2024-07-29T11:25:29Z",
"target_nodes": [
{
"node_type": "ATTACK_SESSION",
"node_info": {
"ip": "192.168.33.11",
"type_session": "sh",
"privilege_level": "user",
"session_id": "2101d27b-9870-4af8-b999-dcb642181dbd",
"username": "adurand"
},
"attack_process_graph": [
{
"sh": {
"encoded_command": "cABzACAAYQB4AGMAbwAgAGMAbwBtAG0AYQBuAGQA",
"decoded_command": "ps axco command"
}
}
]
}
],
},
(...)See attack-report reference documentation.

