LawlietRequest demo ↗

16. Agent security

This guide describes Lawliet 1.6.3.b (the current release, a beta: earlier releases are beta. The first stable release will be 2.0.0). Screens, commands and procedures may change in later versions; the usage guide is updated with each release. Check the version your server runs under Settings > Platform or with ./lawliet version, and see the Releases page for what changed.

This chapter covers the controls that protect the agents themselves: self-protection, uninstall codes, the recovery key, agent tokens and the enrolment secret, and how agents follow a change of the server certificate.

16.1 How agents are protected by default#

Without any setting:

  • The agent talks only to the server, over HTTPS, and checks the server certificate.
  • Every command from the server is signed with the agent's own token. The agent refuses unsigned, altered, replayed, too old (over 10 minutes) or future-dated (over 60 seconds) commands.
  • An upgrade is installed only if the vendor's signature and the file's SHA-256 verify. An older release cannot be pushed to weaken a host.
  • The agent's token and settings are readable by root (Linux) or SYSTEM and Administrators (Windows) only.
  • The watchdog keeps the agent running.

When the server runs HTTPS but some agents still talk to it over plain HTTP, Environment > Hosts shows a red banner: their tokens crossed the network unencrypted, and the token also signs the commands they run. Reinstall those hosts over HTTPS (Show the HTTPS install command) and remove the old enrolment.

16.2 Self-protection#

When self-protection is on for a host:

  • the agent reports the hashes of its own program files every heartbeat; a file the server never released reads as tampering and raises a critical review item, with an Isolate this host action (four-eyes);
  • the watchdog and the agent keep each other running and restore the program from the local known-good copy if it is deleted or changed;
  • uninstalling needs a code issued in the console after a second signature (16.3), or the recovery key (16.4);
  • a protected agent that stops reporting for 5 minutes raises a critical "stopped reporting" alert. The server cannot tell why: the host may be off or rebooting, its network down, or the agent stopped or removed. An agent stopped with a stop code raises it when the stop window ends and the agent has not come back. For 5 minutes after the Lawliet server itself starts, no agent is marked offline, so a server restart does not raise these alerts for every host.

A host's own administrator can still remove any software. Self-protection makes it hard, repairs itself and alerts you; it is not a kernel driver.

Since 1.5.16.b every newly enrolled agent is protected from the start. Hosts enrolled before keep their setting until you turn protection on, one by one or all at once (below). A host that is still unprotected also raises a per-host "stopped reporting" item and notification when it goes silent, at high severity rather than critical. Expect these after upgrading to 1.5.16.b for hosts that are switched off, asleep or offline.

Procedure: turn self-protection on for all hosts#

Required permission: Manage agents (administrators). Four-eyes: no (it only adds protection, as turning it on for one host does). It is audited as one entry naming every host, and every administrator is notified.

  1. Environment > Hosts, click Protect all hosts at the top of the list.
  2. Read the dialog and click Turn on for all unprotected hosts.
  3. What you see: "Protection turned on for N hosts. Each shows On once its agent next checks in and confirms it."

Turning protection off stays per host and always needs a second signature.

Procedure: turn self-protection on#

Required permission: Manage agents. Four-eyes: no (it only adds protection).

  1. Environment > Hosts, click the host.
  2. In the drawer, under Self-protection, click Turn on.
  3. What you see: "Saved. It takes effect when the agent next checks in and confirms it." The state shows Turning on - waiting for the agent to confirm, then On once the agent has saved it (normally within one heartbeat, 15 seconds).

If it stays "Turning on": the host is offline, or its agent is older than 1.5.9 and never reports protection. Check the host's status and version.

Tamper state in the drawer is ok, tampered or unknown (not protected or never checked). With protection on and tampering found, the panel shows "Tampering detected on this host. The agent repairs itself; investigate."

Procedure: turn self-protection off#

Required permission: Manage agents. Four-eyes: yes (critical action "Delete an agent"), because once off reaches the host, the agent can be removed with no code.

  1. In the host's drawer, Self-protection > Turn off.
  2. "Sent for approval. Turning protection off needs a second signature." Have it approved and execute it from Approvals > My requests > Execute now.
  3. The state shows Turning off - waiting for the agent to confirm, then Off.

Risk: the host can then be uninstalled by any local administrator without a code. Rollback: Turn on again.

16.3 Uninstall codes#

A code authorises removing one protected agent. It is signed by the server, bound to that host, valid for one hour, and checked by the agent with no network.

Required permission: Delete agents. Four-eyes: yes.

  1. In the host's drawer, under Self-protection (shown when protection is on), click Issue uninstall code.

  2. "Sent for approval. Once someone else signs it, issue the code from Approvals." Have it approved; then Approvals > My requests > Execute now.

  3. The code is shown once: "Code to uninstall this host (valid 1 hour, this host only)". Copy it.

  4. Use it on the host within the hour:

    PlatformCommand (as root / Administrator)
    Linuxsudo bash install_linux.sh --uninstall --code <code>
    macOSsudo bash install_macos.sh --uninstall --code <code>
    Windows (script install)powershell -NoProfile -ExecutionPolicy Bypass -File .\install_windows.ps1 -Uninstall -Code '<code>'
    Windows (MSI install)put the code in a file and use msiexec /x {<product code>} LAWLIET_UNINSTALL_CODE_FILE=<file> /qn (chapter 12.7)
  5. Remove the host in the console (chapter 10.7).

If it fails: "a valid host authorization code is required" - the code expired, is for another host, or was mistyped. Issue a new one. A host whose address changed since it last reported may not match the code: let it report once, then issue the code.

Command lines can be recorded by process auditing (Windows event 4688, Sysmon, Linux audit). Issue the code just before use; it expires after an hour. On Windows MSI installs, prefer the code file.

Stopping a protected agent with a stop code#

For maintenance or troubleshooting, without turning protection off:

  1. Agents > the host > Self-protection: set Stop for N min (default 60, at most 1440), then Issue stop code (Delete agents permission, four-eyes). The code is valid for one hour (five minutes of host clock skew allowed), for this host only, works once, and covers a stop of up to N minutes.
  2. On the host, as root / Administrator, from the agent's install directory:
    PlatformCommand
    Linuxcd /opt/lawliet-agent && sudo ./lawliet-agent --stop --code <code> --minutes <N>
    macOScd /usr/local/lawliet-agent && sudo -H ./lawliet-agent --stop --code <code> --minutes <N>
    Windowscd 'C:\Program Files\Lawliet Agent'; .\lawliet-agent.exe --stop --code '<code>' --minutes <N> (PowerShell as Administrator)

    On a Python-fallback install run agent.py with the agent's own Python and the same flags.

  3. The command checks the code offline, waits up to 90 seconds for the agent to report the stop to the server, then stops the agent. The server checks the report against the code it issued: it marks the code used, holds the silence alarm off for at most N minutes and writes an "agent_stopped_with_code" audit entry. A report it cannot match (a code it did not issue for this agent, or one already used) gets no quiet window, an "agent_stop_report_rejected" audit entry and a critical review item Unverified agent stop.
  4. The agent stays stopped for --minutes (1 to 1440, default 60) or until the host restarts, whichever comes first; the watchdog then starts it again. The stop is tied to the boot it was started in, and an ended stop no longer keeps its code on disk. Against someone with root / Administrator who kept the code, a restart ends the stop only once the code has expired (codes are valid one hour): within that hour they can write a stop for the new boot with the spent code. The server still refuses that replay - it takes each code once - and raises the Unverified agent stop review item or, if the agent stays silent, the silence alert. A stop longer than N minutes is not covered: after N minutes the server raises the silence alert as for any protected agent that stops reporting.

Messages: "this stop code was already used" (issue a new one); "not a valid stop code for this host" (expired, another host, an uninstall code, or another server); "the agent did not report the stop" (it was not running or the server was unreachable: it is stopped anyway, and the server may raise a silence alert). Every attempt is a line in stop-log.jsonl next to the agent's config (/etc/lawliet, /var/root/Library/Application Support/Lawliet, C:\ProgramData\Lawliet).

16.4 The recovery key#

Each installation has one recovery key. It authorises removing any agent of this server, for example when the server is gone. It can be shown once; after that only its hash remains.

An administrator reveals it once, right after installation, and stores it offline (a safe, a sealed envelope):

  1. Agents > Recovery key (top right; shown to administrators only).
  2. Read the note, have the offline store ready, click Reveal it now. Since 1.5.16.b you confirm it is you (15.1), and with an approver pair the reveal is sent for approval (critical action "Delete an agent"): have it approved and execute it from Approvals. Every administrator is told when the key is revealed.
  3. The key is shown once. Copy it or write it down, then I have stored it - the only way to close the dialog while the key is shown (a click outside it or Escape does nothing, so the key cannot be lost by accident). Closing drops it from the page; it is not logged.

Opened again, it answers "The recovery key was already revealed. It cannot be shown again." The same is available to scripts as POST /api/v1/agents/protection/recovery-key/reveal (administrator session).

Never put it into a transform, a GPO or a script.

Procedure: remove a protected agent with the recovery key#

Use this only when an uninstall code cannot be issued (for example the server is gone). Risk: the key authorises removing any agent of this installation; anyone who sees it can. Rollback: reinstall the agent.

  1. Fetch the key from where it is stored offline.

  2. On the host, as root or Administrator, run the uninstall with the key:

    PlatformCommand
    Linuxsudo bash install_linux.sh --uninstall --recovery-key <key>
    macOSsudo bash install_macos.sh --uninstall --recovery-key <key>
    Windowspowershell -NoProfile -ExecutionPolicy Bypass -File .\install_windows.ps1 -Uninstall -RecoveryKey '<key>'
  3. What you see: the installer removes the services and files, as in an ordinary uninstall (11.6, 12.9).

  4. Clear the shell history on the host, and return the key to safe storage. If it may have been seen, treat it as exposed and tell support.

16.5 Agent tokens#

Each agent has its own token, issued at enrolment. It is not the enrolment secret.

SituationActionWhere
A token may be leaked; keep the agent and its historyKeep the records: revoke its tokenEnvironment > Hosts > the host > Remove agent, then choose it
Replace a token and hand the new one to the agent yourselfRotate the tokenAPI: POST /api/v1/agents/{agent_id}/rotate-token (permissions Manage agents and Delete an agent; a recent re-authentication; a second signature when an approver pair exists); returns the new token once, and every administrator is told
Cut a host off completelyRevoke its token and rotate the enrolment secret (16.6), or delete the agent

After a revoke, a running agent that still knows the enrolment secret enrols again as the same agent once the server has refused its heartbeats for 30 minutes (five refusals in a row over at least 30 minutes; from 1.5.14.s - one refusal is not proof the record is gone, and the agent keeps its enrolment until then). Without the secret in memory it never forgets its enrolment and keeps trying. From 1.5.15.s agents the secret leaves the agent's memory as soon as the server has accepted a heartbeat (16.6), so an enrolled agent whose record is revoked or deleted keeps trying with its old token and does not enrol itself again: enrol it again with a fresh install command or enrolment code. Either way, once the refusal is sustained the agent takes down the audit settings it switched on for audit steps, as --teardown-audit does. A host enrolled from an offline package cannot re-enrol as that agent with its code, but could enrol as a new agent while the code is valid: also revoke the code.

16.6 The enrolment secret and enrolment codes#

The enrolment secret lets any host with the copy-paste command enrol.

sudo ./lawliet token            # show the secret and the install commands
sudo ./lawliet token --rotate   # replace the secret (asks first, restarts the backend)

Rotating does not affect enrolled agents; they use their own tokens. Only new installs need the new value. Rotate it after a rollout, and whenever it may have leaked - in particular when a host that was installed with it is compromised: an administrator of that host could have read it while it was on disk, and it enrols any number of agents until rotated.

The secret does not stay on the hosts. From 1.5.14.s the installers remove it from config.env (and on macOS from the LaunchDaemon) as soon as the agent has enrolled, whichever secret or code was used, and the agent removes it itself after enrolling and after its first heartbeat the server accepts - which also clears it on hosts reinstalled over an existing enrolment and on hosts first enrolled by an older agent, once they run agent 2.1.10.s. Until 1.5.14.s the running agent kept it in memory, so an agent whose record was deleted while it ran enrolled again (after 30 minutes of refused heartbeats, 16.5). From the 1.5.15.s agent build the secret also leaves the agent's memory at that first accepted heartbeat, and if config.env cannot be read or written the agent tries again at the next heartbeat instead of giving up until a restart. An agent whose record is deleted (or lost in a database restore, see chapter 5) stays unenrolled, also after a restart: it needs a reinstall with a fresh install command or enrolment code (--reset-token / remove the agent first). A restart alone does not: an enrolled agent keeps its own token on disk. The change is in the agent, so it applies to agents built after 1.5.14.s (the agent version is raised when they ship), not to the server version. On macOS the LaunchDaemon job keeps the value in launchd's loaded environment until the next load of the job; the plist on disk is already empty.

Enrolment codes (offline packages and Group Policy rollouts) expire (at most 30 days) and enrol at most the chosen number of hosts. Every code made, downloaded, used and revoked is in the audit trail under enrolment_code.

Procedure: revoke an enrolment code#

Permission: Deploy agents remotely. Four-eyes: no (revoking takes risk away). Risk: none to enrolled hosts. Rollback: none; make a new package if more hosts must enrol.

  1. Open Environment > Hosts > Install agent > Offline package.
  2. Under Enrolment codes, find the code by its label, target, uses (for example 12/50), expiry and status.
  3. Press Revoke and confirm "Revoke "<label>"? No further host can enrol with it, and its package is removed from the server. Hosts already enrolled are not affected."
  4. What you see: the status becomes revoked.

Codes are never deleted; expired, exhausted and revoked codes stay in the list as a record.

16.7 When the server certificate changes#

An agent trusts exactly the certificate it was installed with. When the server certificate is replaced (./lawliet tls, ./lawliet tls repair, ./lawliet tls on), agents 2.1.9.s follow it without a step on the host:

  1. The new certificate is staged: every heartbeat reply announces it, signed with this installation's trust key. The agent checks the signature and adds the certificate to its trusted file (the old one stays).

  2. The command waits until the enrolled agents hold it, then the server switches:

    OptionMeaning
    --ack PSwitch when P percent of agents hold it (default 100)
    --timeout SWait at most S seconds (default 600), with progress every 10 seconds
    --forceSwitch now, even if not every agent holds it
  3. After the switch each agent checks the new certificate alone and removes the old one.

If not every agent holds it in time, nothing switches. The command lists the hosts that do not have it and offers: run it again to keep waiting, add --force, or withdraw it with sudo ./lawliet tls cancel.

Risk: agents that do not hold the new certificate stop reporting after the switch. Rollback: before the switch, sudo ./lawliet tls cancel; after it, refresh those hosts by hand (below).

By hand (agents older than 2.1.9.s, agents offline the whole time, macOS):

  1. On the server: sudo ./lawliet tls --export. Copy lawliet-server.pem to the host.
  2. On the host:
    PlatformCommand
    Linuxsudo bash install.sh --refresh-ca --ca-cert /path/to/lawliet-server.pem
    Windowspowershell -ExecutionPolicy Bypass -File install.ps1 -RefreshCa -CaCert C:\path\to\lawliet-server.pem
    macOScopy the file over /etc/lawliet/server-ca.pem, then sudo launchctl kickstart -k system/com.lawliet.agent

The refresh first checks the server with the new certificate and changes nothing if that fails. The agent keeps its identity; nothing is re-enrolled.

Upgrade agents to 2.1.9.s before replacing the certificate. The certificate commands are in chapter 6.

16.8 Removing every agent at the end of an engagement#

For an engagement licence, Settings > Platform shows Decommission all agents.

Required permission: Delete agents. Four-eyes: yes.

  1. Export the evidence bundles and reports you need first.
  2. Click Decommission all agents, enter a Reason, for the audit trail, and click Remove the agents.
  3. After approval and execution: "Sent to N agents. Each removes itself at its next check-in."

Each agent stops, deletes itself from its host and is revoked. The records stay. It cannot be undone: a host would need reinstalling to report again.

16.9 Reporting a security problem#

Report a suspected vulnerability in the agent or the server as described on the security disclosure page. For any other help, contact [email protected].

More detail: agents reference, command security and upgrade channel.