Skip to content

Sending command to agent

import requests
import base64
import json

# Configuration
baseUrl = "https://localhost:8443"
username = "---USERNAME---"
password = "---PASSWORD---"
agentGUID = "---AGENT-GUID---"

# Login & get JWT token
headers = {
    "Authorization":
        "Basic " +
        base64
        .b64encode(
            (username + ":" + password)
            .encode('utf-8')
        )
        .decode('utf-8')
}
response = requests.request("POST", "%s/api/v1/auth/login" % baseUrl, headers=headers, verify=False)
if response.status_code != 200:
    print("Login failed")
    exit()

authToken = response.text
headers = {"Authorization": "Bearer " + authToken}

# Send command "cmd /c whoami" to agent
conf = {
    "template": "cmd",
    "configuration":
        {
            "command": "whoami"
        }
}

response = requests.post("%s/api/v1/agents/%s/commands" % (baseUrl, agentGUID), headers=headers, json=conf, verify=False)
if response.status_code != 200:
    print("Creating command failed")
    print(response.text)
    exit()

data = json.loads(response.text)
print("Command sent and got id %s" % data["id"])
print(response.text)