Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 38 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ committed, so they can be read without the 7 GB download.
and a known port held by an unexpected process is flagged on its term.
Sources are `ANY` unless a profile, `heuristics.py` in your definitions,
says who may reach what; `def/heuristics.py` is a commented template.
4. **Tighten.** `firru tighten` narrows `ANY` sources to the peers seen in
traffic. Its proposals are written beside the reviewed policy, never into it.
5. **Validate.** `firru diff` shows what a proposal changes and, given flows,
which of them it would block. `aerleon-to-bpf` compiles a policy into one
4. **Propose.** `firru propose` narrows `ANY` sources to the peers seen in
traffic and denies, logged, the listeners nothing reached. It prints each
edit as a firru command ending in its reason, so what to apply is a grep,
and writes the proposals beside the reviewed policy, never into it.
5. **Validate.** `firru check` shows what a policy refuses of the traffic,
and which of that the host answered, which is what would break. `firru
diff` shows what a proposal changes and, given flows, which of them it
would block. `aerleon-to-bpf` compiles a policy into one
BPF filter per term, so a single matching packet flags a violation.

A person reviews and commits every change. `firru diff -o sh` writes the change
Expand Down Expand Up @@ -90,12 +94,9 @@ firru synth --input loot/*.json --defs def --output policies/staged/
# review policies/staged/, commit what you accept to policies/pol/; flows from
# the collector's conntrack snapshot, or from Zeek or Arkime (below), then
loot-conntrack hosts/web1/loot-host/conntrack > flows.jsonl
firru tighten --policy policies/pol/*.yml --defs def \
--flows-file flows.jsonl --outdir policies/tightened/
firru diff policies/pol/web1.yml policies/tightened/web1.yml \
--defs def --flows flows.jsonl
firru diff policies/pol/web1.yml policies/tightened/web1.yml \
--defs def -o sh | grep narrowed | sh
firru propose policies/pol/*.yml --defs def --flows-file flows.jsonl \
--outdir policies/tightened/ | grep observed | sh
firru check policies/pol/web1.yml --defs def --flows-file flows.jsonl

# compile what is committed
aclgen --base_directory policies --definitions_directory def --output_directory out/
Expand All @@ -109,6 +110,25 @@ Firewall; it reads every directory named `pol` below `--base_directory`, so
point it at `policies/`, not `policies/pol/`, or it finds nothing and says so
only in its log.

## A project

A directory with a `firru.toml` is a project, found the way git finds a
repository: from anywhere below it, or by `$FIRRU_PROJECT`. `firru.toml`
names the flow store and the time windows (`--window night`), so commands
run inside it need neither `--flows-file` nor `--since`. `examples/lspr24`
is one.

Beside it, `site/` holds what the site knows and firru cannot derive. A file
there is used without a flag, and a flag still names another for one run.
A missing one is said once per run, with what its absence costs; an empty
one is the site saying "none".

| file | what | without it |
|---|---|---|
| `site/heuristics.py` | who may reach what, as code; start from firru's `def/heuristics.py` (`firru/site_profile.py` documents each name) | firru's shipped defaults: SSDP denied, mDNS and LLMNR link-local, everything else ANY |
| `site/policy.py` | what the site decides rather than guesses: who may administer a host (`MGMT_SERVICES`, `management_sources`, read before `heuristics.py`), and the ports that must stay open (`scored(host, metadata)`, read from wherever the site keeps them) | nothing decided |
| `site/host_metadata.json` | hosts to zones, OS and roles | synthesis knows no zones |

## Drift and conformance

- `firru diff POLICY nft.json` compares a committed policy with the nftables
Expand Down Expand Up @@ -145,11 +165,10 @@ synth warns when the installed Aerleon would compile them unscoped.

Each takes `--help`.

- `firru apply POL --from NEW`: merge a generated policy's changes onto the
reviewed one, three-way with `--base OLD`; narrowings with `--narrow`,
removals with `--prune`, widenings never.
- `firru set-source`, `firru set-dest`, `firru rm`: one edit to one term, the
commands `firru diff -o sh` writes. `firru mass` runs a stream of them in one
- `firru remove-source`, `firru add-source`, `firru set-source`, `firru
set-action`, `firru add-term`, `firru rm` (and `-dest` for egress): one
edit to one term, the commands `firru propose` and `firru diff -o sh`
write. `firru mass` runs a stream of them in one
process.
- `firru merge-zones`: per-host policies into per-zone policy;
`aerleon-to-nftables` renders zones as nftables chain fragments.
Expand All @@ -165,15 +184,16 @@ Each takes `--help`.
the case study's inputs (`examples/lspr24/`).
- `scripts/conn-audit.sh`, `scripts/conn-audit.ps1`: which process connected
where, collected beside `loot-host/`. Nothing in firru 1.0 reads it yet;
`firru tighten` builds egress terms from flows.
`firru propose` builds egress terms from flows.

## Status

The paper evaluates the five stages with Arkime traffic, on Linux and Windows
hosts. Implemented since, but not yet evaluated: collection of running
nftables and Windows Firewall rule sets, conformance over Zeek and conntrack
flows, an enforcement probe (`policy-to-nmap`), the process-mismatch flag, and
comparison against stock operating system baselines.
flows, an enforcement probe (`policy-to-nmap`), the process-mismatch flag,
comparison against stock operating system baselines, and `propose` and `check`,
which replace the paper's `tighten`.

## Install

Expand Down
2 changes: 1 addition & 1 deletion def/base-networks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ANY, ANY_V4, ANY_V6 every address (a term firru could not narrow)
# LOOPBACK the host itself
# MDNS_SOURCES_*, LLMNR_SOURCES_* where link-local name resolution comes
# from: firru.src_heuristics scopes mDNS and LLMNR
# from: firru.site_profile scopes mDNS and LLMNR
# terms to these instead of ANY
networks:
ANY_V4:
Expand Down
26 changes: 21 additions & 5 deletions def/heuristics.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
# Source policy: who may reach each synthesized service.
#
# firru synth reads heuristics.py from the definitions directory. This one
# sets nothing, so every service gets ANY except link-local discovery (mDNS,
# LLMNR) and SSDP (denied). Copy it into your project's def/ and uncomment
# what your inventory supports; firru/src_heuristics.py documents each name.
# firru's defaults, used as they are by a project without its own
# site/heuristics.py, and the template for one: copy this file into site/
# and edit it. A site's file is all of its configuration; nothing from this
# one is layered underneath, so keep what you want of the settings below.
# What the site decides rather than guesses (who may administer a host)
# goes in site/policy.py. firru/site_profile.py documents each name.
# This file is code, and firru runs it.

# Management services take their sources from management_sources().
# Denied before the drop-ANY rather than given a term.
DENY_SERVICES = {
"SSDP": "udp", # UPnP discovery, udp/1900: no legitimate inbound use on servers
}

# Their multicast groups are link-local (224.0.0.251, 224.0.0.252, ff02::fb,
# ff02::1:3): a router will not forward them, so neither should a source rule.
LINK_LOCAL_TOKENS = {
"MDNS": ("MDNS_SOURCES_V4", "MDNS_SOURCES_V6"),
"LLMNR": ("LLMNR_SOURCES_V4", "LLMNR_SOURCES_V6"),
}

# Management services take their sources from management_sources(). Who
# may administer a host is a decision, so these belong in site/policy.py;
# here they still work for a site that has not moved them.
# MGMT_SERVICES = ["SSH", "RDP", "WINRM-HTTP", "WINRM-HTTPS"]
#
# def management_sources(metadata):
Expand Down
20 changes: 10 additions & 10 deletions docs/comment-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ a leading tag; an untagged line is owned by nobody and is inviolable.
| tag | regenerated from | who writes it |
|------------|-------------------------|--------------------------|
| `[auto]` | loot / flow store | any generator |
| `[score]` | `scoring.yml` | the scoring pass |
| `[score]` | the site's scoring | the site, or a tool of its own; `rm`, `set-action` and `propose` leave its term alone |
| *(none)* | nobody — authored | a human, in `$EDITOR` |

History is **not** a tag. "was: ANY" is the pre-change value, which is exactly
Expand All @@ -52,9 +52,9 @@ not write a `[hist]` line; lean on the repo.
> the term list) are changed only by an explicit, named operation.

This is **not** a feature of one tool. It binds every tool that round-trips a
human file: `firru synth`, `firru tighten`, and the edit commands (`firru
set-source`, `firru apply`, `firru rm`) alike. A
generator that rewrites a term's whole comment block — as `tighten` once did,
human file: `firru synth`, `firru propose`, and the edit commands (`firru
set-source`, `firru remove-source`, `firru set-action`, `firru add-term`, `firru rm`) alike. A
generator that rewrites a term's whole comment block — as `tighten` (now `propose`) once did,
with an unconditional `yaml_set_start_comment` — violates it and silently eats
intent. The `firru.comments` helper is the shared implementation: it recovers
each term's non-`[auto]` lines before a rebuild and re-attaches them, hiding
Expand Down Expand Up @@ -99,9 +99,9 @@ A diff over two generated policies classifies each port as:

| class | example | default action |
|-----------------------|----------------------------------|-----------------------------------|
| added (known svc) | new listener on a defined port | apply — copy the term verbatim |
| added (known svc) | new listener on a defined port | `add-term` — copy the term verbatim |
| added (unknown port) | rogue / undefined port | **alert**, never auto-allow |
| removed | postgres → loopback-only | annotate; `--prune` opt-in; **scoring vetoes** |
| removed | postgres → loopback-only | annotate; `rm` by name; **scoring vetoes** |
| modified, enforcement | source ANY → DOCKER_INTERNAL | advisory — preview old vs new |
| modified, cosmetic | token renamed, process changed | auto — refresh the `[auto]` line |
| unchanged | — | nothing |
Expand Down Expand Up @@ -142,10 +142,10 @@ regenerate the `[auto]` block, copy a verbatim addition term, pull one named
tightened field. The moment an edit needs a *choice* (keep ANY? is
DOCKER_INTERNAL right? allow this rogue port?) there is no flag for it: the
tool tells you where to open `$EDITOR`, not a switch that decides for you.
Looking and writing are separate: `firru diff` only reports (or prints the
commands), `firru apply --dry-run` previews a merge, every write is a command
that names what it changes, and destructive actions take their own flag
(`firru apply --prune`, `firru rm --force` for a term with a scoring note).
Looking and writing are separate: `firru diff` and `firru propose` only
report (or print the commands), every write is a command that names what it
changes, and overriding a scoring note takes its own flag (`firru rm --force`,
`firru set-action --force`).

If a proposed flag seems to want an argument that encodes a judgment, that is
the signal to stop and let the editor win.
Expand Down
2 changes: 1 addition & 1 deletion docs/fleet-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ explain is short, and that short list is what a person has to look at.
2. **Diff the fleet against its baselines**, one baseline per role:

```
firru diff --baseline baselines/ loot/ -o sh \
firru loot-diff --baseline baselines/ loot/ -o sh \
--assign 'dc*=win2022-dc' --assign 'mail*=win2022-exchange' \
--assign 'ws*=win11' --assign '*=win2022' > review.sh
```
Expand Down
14 changes: 7 additions & 7 deletions docs/fleet.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ A stock install of the same OS and role explains most of what a host listens
on. Compare each host with one, and read only the difference:

```sh
firru diff --baseline baselines/ loot/ \
firru loot-diff --baseline baselines/ loot/ \
--assign 'dc*=win2022-std-desktop-dc-g2' \
--assign 'win*=win2022-std-desktop-public-g2' \
--assign '*=ubuntu-24.04.5-server-g1'
Expand Down Expand Up @@ -135,13 +135,13 @@ domain at work: win1 and the admin workstations using dc1's DNS, Kerberos,
LDAP, SMB, RPC and time.

```sh
firru tighten --policy policies/pol/*.yml --defs def --flows-file flows.jsonl --outdir policies/tightened
firru propose policies/pol/*.yml --defs def --flows-file flows.jsonl -o yaml --outdir policies/tightened
firru diff policies/pol/mon1.yml policies/tightened/mon1.yml --defs def --flows flows.jsonl
```

```
mon1:
narrowed (1) — fewer peers, safe to apply (--narrow):
narrowed (1) — fewer peers, safe to apply:
> allow-tcp-MUNIN tcp/4949 source ANY -> MONITORING observed (288 flows)
address family (1) — coverage changed:
# allow-tcp-MUNIN tcp/4949 v4+v6 -> v4
Expand All @@ -164,7 +164,7 @@ Before a policy is deployed, the question is what it would break now: check
it against the latest traffic, not the window it was tightened on.

```sh
firru tighten --policy policies/pol/dc1.yml --defs def --flows-file flows.jsonl --check --since -30min
firru check policies/pol/dc1.yml --defs def --flows-file flows.jsonl --since -30min
```

It lists, per source, the flows the policy would refuse: to a port no term
Expand Down Expand Up @@ -284,14 +284,14 @@ services nobody used.
## 11. Had day 2 been the learning window

```sh
firru tighten --policy policies/staged/*.yml --defs def --flows-file flows-day2.jsonl \
--outdir policies/learned-day2
firru propose policies/staged/*.yml --defs def --flows-file flows-day2.jsonl \
-o yaml --outdir policies/learned-day2
firru diff policies/staged/mon1.yml policies/learned-day2/mon1.yml --defs def
```

```
mon1:
narrowed (1) — fewer peers, safe to apply (--narrow):
narrowed (1) — fewer peers, safe to apply:
> allow-tcp-MUNIN tcp/4949 source ANY -> [MONITORING, web1]
```

Expand Down
26 changes: 13 additions & 13 deletions examples/fleet-zones/expected/transcript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,60 +68,60 @@ Reading flows from flows.jsonl (single pass, 12 hosts) …
Host: db1 IPs: ['10.20.2.13', '2001:db8:20:2::d']
ingress: 507 flows across 2 service buckets
egress: 0 flows across 0 service buckets
Written: policies/tightened/db1.yml (2 changed, 1 log-drop candidate)
Host: dc1 IPs: ['10.20.2.10', '2001:db8:20:2::a']
ingress: 392 flows across 5 service buckets
egress: 0 flows across 0 service buckets
Written: policies/tightened/dc1.yml (4 changed, 19 log-drop candidates)
Host: files1 IPs: ['10.20.2.11', '2001:db8:20:2::b']
ingress: 92 flows across 2 service buckets
egress: 0 flows across 0 service buckets
Written: policies/tightened/files1.yml (1 changed, 9 log-drop candidates)
Host: jump1 IPs: ['10.20.9.10', '2001:db8:20:9::a']
ingress: 0 flows across 0 service buckets
egress: 24 flows across 2 service buckets
Written: policies/tightened/jump1.yml (0 changed, 2 log-drop candidates)
Host: mail1 IPs: ['10.20.1.11', '2001:db8:20:1::b']
ingress: 47 flows across 2 service buckets
egress: 0 flows across 0 service buckets
Written: policies/tightened/mail1.yml (1 changed, 5 log-drop candidates)
Host: ns1 IPs: ['10.20.1.12', '2001:db8:20:1::c']
ingress: 187 flows across 2 service buckets
egress: 0 flows across 0 service buckets
Written: policies/tightened/ns1.yml (1 changed, 1 log-drop candidate)
Host: print1 IPs: ['10.20.2.12', '2001:db8:20:2::c']
ingress: 0 flows across 0 service buckets
egress: 0 flows across 0 service buckets
Written: policies/tightened/print1.yml (0 changed, 10 log-drop candidates)
Host: smb1 IPs: ['10.20.2.14', '2001:db8:20:2::e']
ingress: 4 flows across 1 service buckets
egress: 0 flows across 0 service buckets
Written: policies/tightened/smb1.yml (1 changed, 1 log-drop candidate)
Host: web1 IPs: ['10.20.1.10', '2001:db8:20:1::a']
ingress: 408 flows across 3 service buckets
egress: 500 flows across 1 service buckets
Written: policies/tightened/web1.yml (1 changed, 1 log-drop candidate)
Host: ws1 IPs: ['10.20.3.21', '2001:db8:20:3::15']
ingress: 0 flows across 0 service buckets
egress: 160 flows across 4 service buckets
Written: policies/tightened/ws1.yml (0 changed, 8 log-drop candidates)
Host: ws2 IPs: ['10.20.3.22', '2001:db8:20:3::16']
ingress: 0 flows across 0 service buckets
egress: 163 flows across 5 service buckets
Written: policies/tightened/ws2.yml (0 changed, 1 log-drop candidate)
Host: ws3 IPs: ['10.20.3.23', '2001:db8:20:3::17']
ingress: 0 flows across 0 service buckets
egress: 160 flows across 4 service buckets
Written: policies/tightened/db1.yml (2 changed, 1 log-drop candidate)
Written: policies/tightened/dc1.yml (4 changed, 19 log-drop candidates)
Written: policies/tightened/files1.yml (1 changed, 9 log-drop candidates)
Written: policies/tightened/jump1.yml (0 changed, 2 log-drop candidates)
Written: policies/tightened/mail1.yml (1 changed, 5 log-drop candidates)
Written: policies/tightened/ns1.yml (1 changed, 1 log-drop candidate)
Written: policies/tightened/print1.yml (0 changed, 10 log-drop candidates)
Written: policies/tightened/smb1.yml (1 changed, 1 log-drop candidate)
Written: policies/tightened/web1.yml (1 changed, 1 log-drop candidate)
Written: policies/tightened/ws1.yml (0 changed, 8 log-drop candidates)
Written: policies/tightened/ws2.yml (0 changed, 1 log-drop candidate)
Written: policies/tightened/ws3.yml (0 changed, 3 log-drop candidates)
dc1:
narrowed (4) — fewer peers, safe to apply (--narrow):
narrowed (4) — fewer peers, safe to apply:
> allow-tcp-KERBEROS-TCP tcp/88 source ANY -> CLIENTS_HOSTS observed (120 flows)
> allow-tcp-LDAP-TCP tcp/389 source ANY -> CLIENTS_HOSTS observed (180 flows)
> allow-tcp-WINDOWS-RPC-ENDPOINT-MAPPER tcp/135 source ANY -> CLIENTS_HOSTS observed (30 flows)
> allow-tcp-WINDOWS-SMB tcp/445 source ANY -> CLIENTS_HOSTS observed (60 flows)
postures: review-then-deploy takes `observed` only; block-early also takes `unexercised` and drops zero-evidence listeners (no data == can deny, log-drop as the net). CONTRADICTED and widenings are never runnable.
db1:
narrowed (1) — fewer peers, safe to apply (--narrow):
narrowed (1) — fewer peers, safe to apply:
> allow-tcp-POSTGRES tcp/5432 source ANY -> [web1, ws2] observed (503 flows)
postures: review-then-deploy takes `observed` only; block-early also takes `unexercised` and drops zero-evidence listeners (no data == can deny, log-drop as the net). CONTRADICTED and widenings are never runnable.
web1:
Expand Down
12 changes: 11 additions & 1 deletion examples/fleet-zones/heuristics.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# Source policy for the zoned fleet (firru.src_heuristics reads this file
# Source policy for the zoned fleet (firru.site_profile reads this file
# from the definitions directory; see its header for the contract).
#
# Administration comes from the jump host and nowhere else, whatever the
# zone. NetBIOS and the discovery protocols stay inside the host's zone: they
# are not routed, so the zone's hosts are their only clients by definition.

# Kept from firru's shipped heuristics.py: a site's file is all of its
# configuration. SSDP (UPnP discovery, udp/1900) has no legitimate inbound
# use on a server, and mDNS and LLMNR are link-local: a router will not
# forward them, so neither should a source rule.
DENY_SERVICES = {"SSDP": "udp"}
LINK_LOCAL_TOKENS = {
"MDNS": ("MDNS_SOURCES_V4", "MDNS_SOURCES_V6"),
"LLMNR": ("LLMNR_SOURCES_V4", "LLMNR_SOURCES_V6"),
}

MGMT_SERVICES = ["SSH", "RDP", "WINRM-HTTP", "WINRM-HTTPS"]


Expand Down
2 changes: 1 addition & 1 deletion examples/fleet-zones/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ cp -r policies/staged policies/pol # the review: here, accept all

step "5. traffic, and what tighten makes of it"
python3 "$EX/make-flows.py" > flows.jsonl
firru tighten --policy policies/pol/*.yml --defs def --flows-file flows.jsonl --outdir policies/tightened
firru propose policies/pol/*.yml --defs def --flows-file flows.jsonl -o yaml --outdir policies/tightened
for h in dc1 db1 web1; do
firru diff policies/pol/$h.yml policies/tightened/$h.yml --defs def --flows flows.jsonl || true
done
Expand Down
Loading