# Handle an alert on a device

> See an alert from one of your devices, look into it in the security log, block what's attacking it for a set time, and cut the device off if it's the device itself you can't trust.

The realm's overview shows a burst of failed SSH sign-ins on one of your servers, all from one address. You want to know
what happened, block that address on the server for the next hour while you look into it, and, if the server turns
out to be compromised, cut it off from the realm. You do all of it from the realm, without signing in to the server.

## Before you start

- You are an administrator of the realm, in a group holding `RealmOwner`, with your session in `$CVYUH_SESSION` for
  the API calls ([Call the API](../../../develop/api/)).
- The server is an enrolled Linux device (see
  [Get started with Endpoint Management](../../../endpoint-management/get-started/)): its security sensor reports to
  the realm from the moment it enrolls.

## Handle it

<Steps>

1. **See the alert.** Read the overview, devices by status and the alerts over the range by level, then the last
   hour's alerts (see [Security events](../../security-log/events/)):

   ```sh
   curl "https://foobar.cvyuh.com/api/v0/endpoint/dar/v1/overview?from=<RFC 3339 time>&to=<RFC 3339 time>" \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"

   curl "https://foobar.cvyuh.com/api/v0/endpoint/dar/v1/events?from=<RFC 3339 time>&to=<RFC 3339 time>" \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{"page": 1, "pageSize": 20, "qbe": {"text": "sshd"}}'
   ```

   Each alert shows the device it came from, the rule that raised it, its level, and the ATT&CK techniques it's
   evidence of (see [Threat mapping](../../detection/threat-mapping/)). Note the source address (`data.srcip`) and the
   device's sensor id (`agent.id`).

2. **Look into it in the security log.** The device's [device view](../../security-log/device-view/) shows the same
   device from every side, each part with its call: its events; its file integrity, for system files changed around
   the same time; its inventory, for open ports, processes and local users; and its configuration assessment, for
   settings that left it exposed. A failed sign-in burst with nothing changed on the device is an attack to block; a
   changed binary or a new local account means the device itself may be compromised.

3. **Block the address** with an [active response](../../response/active-response/), for an hour:

   ```sh
   curl https://foobar.cvyuh.com/api/v0/endpoint/dar/v1/agents/respond \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{"agents": ["<sensor id>"], "response": "blockIp", "argument": "203.0.113.24", "timeout": 3600}'
   ```

   The answer lists the sensors the response was sent to under `done`, and any it wasn't under `failed`, with why.
   `done` means sent: to confirm it ran, check a connection from the address now gets no answer (see
   [Confirm it ran](../../response/active-response/#confirm-it-ran)). A device that's offline is in `failed`, and
   nothing waits for it: send the response again once it's back.

4. **Cut the device off, if it can't be trusted.** If step 2 showed the device itself compromised, revoke it, so it
   can reach nothing in the realm. Find its device id in the realm's device list, by the device's name (or by its
   sensor id, as the [API reference](../../api/) describes).

   ```sh
   curl https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1 \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"

   curl -X PUT https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/<device id>/revocation \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{"reason": "Compromised: alert on maya-laptop"}'
   ```

   Every stream the device holds closes at once, its sensor's included. See
   [Cut off a lost device](../../../endpoint-management/guides/cut-off-a-lost-device/) for restoring or removing it
   later.

</Steps>

## Check it worked

Reading the device's events again, with the range moved on past the moment you responded, the failed sign-ins from the address stop
on that device. If you revoked the device, its `connected` answers `{ "connected": false }`:

```sh
curl https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/<device id>/connected \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
```

<Aside type="tip" title="Not sure how long you need?">
  Start short. When the time is up the device lifts the block itself; send the response again to extend it.
</Aside>

## Undo it

- **The block:** wait for its time to run out, and the device lifts it by itself. There is no call to lift a response
  early, and no record of it in the realm's audit trail: note what you sent.
- **The revocation:** a `DELETE` on the device's `/revocation`, and the device reconnects (see
  [Device revocation](../../../endpoint-management/revoke-and-remove/revocation/)).

## Related

- [Security events](../../security-log/events/): every alert, and how to search them.
- [Active response](../../response/active-response/): every response, argument and timeout.
- [Device revocation](../../../endpoint-management/revoke-and-remove/revocation/): how the cut reaches every server.
- [Detection](../../detection/): what the sensors watch for.
