# Get started with Detection & Response

> Raise an alert on one of your enrolled Linux devices, find it in your realm's security log, and block the address behind it on the device for an hour.

In this guide you see an alert from one of your devices and act on it. A burst of failed SSH sign-ins against
`maya-laptop` raises alerts in your realm's security log; you find them, read where they came from, and block that
address on the laptop for an hour, all from the realm. It takes about fifteen minutes.

## Before you begin

- **An enrolled device** running Linux with an SSH server, here `maya-laptop`. If you have none yet,
  [Get started with Endpoint Management](../../endpoint-management/get-started/) enrolls one. Its security sensor
  reports to the realm from the moment it enrolls.
- **A realm administrator's session** in `$CVYUH_SESSION`: a user in a group holding `RealmOwner` on the realm.
  [Call the API](../../develop/api/) shows how to get one.
- **Another machine** that can reach the device over SSH, to make the failed sign-ins.

## See an alert and act on it

<Steps>

1. **Find the device's sensor id.** Calls about a device's security name it by its sensor's id. Ask the sensors list
   for the laptop:

   ```sh
   curl https://foobar.cvyuh.com/api/v0/endpoint/dar/v1/agents \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{"page": 1, "pageSize": 20, "qbe": {"filter": {"field": "name", "op": "=", "value": "maya-laptop"}}}'
   ```

   Its `id` is the sensor id, and its `status` should be `active`.

2. **Raise an alert.** From the other machine, try to sign in to the laptop over SSH a few times as a user that
   doesn't exist, and give up at each password prompt:

   ```sh
   ssh no-such-user@<device address>
   ```

   The laptop's authentication log records each attempt, the sensor sends the lines to your realm, and the realm's
   ruleset raises an alert for each.

3. **See the alerts.** Ask for the laptop's alerts over the last hour, newest first:

   ```sh
   curl "https://foobar.cvyuh.com/api/v0/endpoint/dar/v1/events?agent=<sensor id>&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}'
   ```

   Each alert names the device, the rule that raised it, its [level](../security-log/events/#alert-levels), and the
   ATT&CK techniques it's evidence of. The address the attempts came from is in `data.srcip`:

   ```json
   {
     "data": [
       {
         "id": "<alert id>",
         "time": "<RFC 3339 time>",
         "agent": { "id": "<sensor id>", "name": "maya-laptop" },
         "rule": {
           "id": "<rule id>",
           "level": 5,
           "description": "<a failed SSH sign-in for a user that doesn't exist>",
           "mitre": { "ids": ["T1110.001"], "tactics": ["Credential Access"] }
         },
         "data": { "srcip": "203.0.113.24", "srcuser": "no-such-user" }
       }
     ],
     "totalPages": 1,
     "totalCount": 4
   }
   ```

4. **Block the address on the laptop for an hour.** Send an active response to the laptop's sensor:

   ```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.
   The laptop drops the address's traffic at its firewall, and lifts the block itself after an hour.

</Steps>

## Check it worked

Try SSH from the other machine again: the connection gets no answer. Asking for the laptop's alerts again with the
range moved past the moment you responded shows no new failed sign-ins from that address.

<Aside type="tip" title="Not sure how long you need?">
  Start short. A response runs for one of six fixed times, from a minute to a day, and can't be lifted early; send it
  again to extend it.
</Aside>

## Next steps

<CardGrid>
  <LinkCard title="Handle an alert on a device" description="Look into an alert from every side, and cut the device off if it's compromised." href="../guides/handle-an-alert/" />
  <LinkCard title="Detection" description="Everything the sensor watches for, and where you see it." href="../detection/" />
  <LinkCard title="Active response" description="Every response, its argument and its timeouts." href="../response/active-response/" />
</CardGrid>
