# File integrity

> Changes to each device's system files and binaries, reported with what changed, and searchable across the realm.

A changed system binary or configuration file is one of the clearest signs of an intruder, and of a change no one
recorded. The sensor watches the device's system folders and reports every file added, changed or removed, with its
checksums, owner and permissions before and after.

## Before you begin

- **Who:** an administrator of the realm, in a group holding `RealmOwner` or `RealmViewer` on the realm or a realm
  above it (see [Delegated administration](../../../platform/realms/delegated-administration/)). Reading needs no
  more than `RealmViewer`; adding folders is a [group configuration](../../sensors/group-configuration/) change.
- **Where:** the API.
- **First:** an enrolled device. Watching starts when it enrolls.

## How it works

Out of the box the sensor watches these folders, and everything below them:

| System | Folders watched |
|---|---|
| Linux | `/etc`, `/usr/bin`, `/usr/sbin`, `/bin`, `/sbin`, `/boot` |
| macOS | `/etc`, `/usr/bin`, `/usr/sbin`, `/bin`, `/sbin` |

It records each file's checksums (MD5, SHA-1, SHA-256), owner, group, permissions, size and time, and compares them at
each scan. A scan runs when the sensor starts and on a schedule, every 12 hours by default.

**When a change shows up depends on the folder:**

- **The default folders** are compared at each scan, so a change there shows up at the next scan, up to 12 hours
  later.
- **Folders you add with `realtime="yes"`** report a change as it happens, usually within seconds (see
  [Watch another folder on your devices](../../guides/watch-another-folder/)).

To hear about changes in a default folder sooner, add it again as real-time, or shorten the scan schedule, in the
[group configuration](../../sensors/group-configuration/).

Each change becomes an alert, with what changed: which attributes, the size and checksums before and after, and,
for folders set to report changes, what changed in a text file's content. The alert says who owns the file now; it
doesn't say which user or process made the change.

## Set it up

Nothing to turn on. Through the API ([Call the API](../../../develop/api/)), read the realm's changes over a range (by
kind, and the paths and devices that change most), then one device's monitored files by its sensor id, with when its
last scan ran:

```sh
curl "https://foobar.cvyuh.com/api/v0/endpoint/dar/v1/fim/summary?from=<RFC 3339 time>&to=<RFC 3339 time>" \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
  -H "Content-Type: application/json" \
  -d '{}'

curl "https://foobar.cvyuh.com/api/v0/endpoint/dar/v1/fim/files?agent=<sensor id>" \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
  -H "Content-Type: application/json" \
  -d '{"page": 1, "pageSize": 50}'
```

`GET https://foobar.cvyuh.com/api/v0/endpoint/dar/v1/fim/files/scan?agent=<sensor id>` says when that device's last scan
started and ended. The change alerts themselves are [Security events](../../security-log/events/) with `preset=fim`,
filterable by `path` and `change`.

## Limits and defaults

| Limit | Default | Can you change it? |
|---|---|---|
| Folders watched | The system folders above | Add folders in the [group configuration](../../sensors/group-configuration/) |
| Scan schedule | When the sensor starts, then every 12 hours | Yes, `<frequency>` in the [configuration reference](../../sensors/configuration-reference/#file-integrity-syscheck) |
| Real-time reporting | Off for the default folders | Yes, per folder you add |
| Content changes in alerts | Off | Yes, per folder you add (`report_changes`) |
| Coverage | Local disks | Network shares and container images aren't covered |

## Good to know

- **Noise left out.** Files that change by design, such as logs, are left out.
- **Gentle on the device.** The sensor runs at low priority and paces its reports, so it doesn't load the device.
- **Folders and schedule** are part of the realm's [group configuration](../../sensors/group-configuration/).

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| A change in `/etc` hasn't shown up | Default folders report at the next scan | Wait for the scan, or add the folder as real-time |
| A folder you added reports only at scans | It didn't exist on the device when the sensor started | Create it, then restart the sensor ([Sensor actions](../../sensors/sensor-actions/)) |
| A device's last scan is old | The device is offline | Check its status in its [device view](../../security-log/device-view/) |

## Audit record

The changes are themselves alerts in the [security log](../../security-log/events/); reading them writes no audit
record.

## Related

- [Watch another folder on your devices](../../guides/watch-another-folder/): add a real-time folder.
- [Security events](../../security-log/events/): every alert, file changes included.
- [Configuration assessment](../configuration-assessment/): settings, rather than files.
