> ## Documentation Index
> Fetch the complete documentation index at: https://docs.infrawatch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Writing rules

> Turn scan observations into repeatable detections

Rules evaluate typed scan observations as they arrive. Use them to identify
exposed services, suspicious infrastructure, software, and protocol-specific
behaviour.

<img src="https://mintcdn.com/infrawatch/hFIgmGIh7O3VGQHG/images/sections/rules.svg?fit=max&auto=format&n=hFIgmGIh7O3VGQHG&q=85&s=a5abbe784181ad63af956c1145487ce8" alt="A rule being evaluated into classified results" className="rounded-2xl" width="640" height="320" data-path="images/sections/rules.svg" />

## Rule anatomy

Each source contains one YARA rule. Conditions read fields from the
`infrawatch` module.

```yara theme={null}
import "infrawatch"

rule Exposed_Redis_Without_Authentication {
  meta:
    description = "Redis accepted a probe without requiring authentication"

  condition:
    defined infrawatch.scan.redis.authentication_required and
    infrawatch.scan.port == 6379 and
    not infrawatch.scan.redis.authentication_required
}
```

<Note>
  The rule editor validates and formats source before a rule can be enabled.
</Note>

## Detection metadata

Keep detection logic in the source. Set its meaning separately:

| Setting        | Purpose                                    |
| -------------- | ------------------------------------------ |
| Classification | `benign`, `suspicious`, or `malicious`     |
| Categories     | Slash-delimited paths such as `malware/c2` |
| Tags           | The labels applied when the rule matches   |
| Input          | Scan results or certificate events         |

See the [intelligence taxonomy](/platform/taxonomy) for the canonical category
paths and classification model.

## Write reliable conditions

* Prefer typed protocol fields over banner text.
* Check that an optional field is `defined` before using it.
* Combine independent signals to reduce false positives.
* Put reusable text or byte patterns in the `strings` section.
* Explain the detection intent in `meta.description`.

<CardGroup cols={2}>
  <Card title="Copy working examples" icon="https://mintcdn.com/infrawatch/gCEz_Bv1hOrMPG8n/images/products/examples.svg?fit=max&auto=format&n=gCEz_Bv1hOrMPG8n&q=85&s=6510d5e047da1ba98e9da12cde1997ae" href="/scanning/rules/examples" width="32" height="32" data-path="images/products/examples.svg">
    Start with compiled Redis, MQTT, and HTTP detections.
  </Card>

  <Card title="Browse protocol fields" icon="https://mintcdn.com/infrawatch/gCEz_Bv1hOrMPG8n/images/products/fields.svg?fit=max&auto=format&n=gCEz_Bv1hOrMPG8n&q=85&s=a6d87a2fa8964f596ca22c157b395f01" href="/scanning/rules/protocols" width="32" height="32" data-path="images/products/fields.svg">
    Find the exact path and type emitted by each scanner.
  </Card>
</CardGroup>
