server-audit.sh: a UFW rule to the server's own address counts as firewalled

Aperta
#162 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
bash
Ambito
security

Direzione di ricerca

Start in server-audit.sh at ufw_rule_fields and ufw_port_access, where a UFW To column is parsed and matched only against a port, a profile or Anywhere. Run tests/audit-ufw-ports.sh first; its cases "whole protocol to one destination address" and "rule with an IPv6 destination address" currently expect none. Done when a rule to one of the server's own addresses counts as exposed for the sockets listening there, a rule to an unowned address still counts as none, and the tests reflect this.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

agent-ready area: audit bug claude priority: medium size: S

Milestone Next patch release · Priority medium · Size S · Depends on nothing · Agent-ready: an agent can pick it up


What happens

The audit's "Exposed TCP ports" check (ufw_port_access in server-audit.sh) matches a UFW rule only when its To column is a port, a profile or Anywhere. A rule with a destination address, such as

sudo ufw allow to 203.0.113.10 port 80 proto tcp

shows 203.0.113.10 80/tcp in To. That matches no port, so port 80 is listed as firewalled, even when 203.0.113.10 is the server's own public address and the port is open to the internet. The same happens for a whole protocol to one address (192.168.1.50/tcp) and for an IPv6 destination (2001:db8::1 2222/tcp).

Expected

A rule to one of the server's own addresses counts like a rule to Anywhere for the sockets that listen on that address (or on all addresses). A rule to an address the server does not have opens nothing, as today.

Where

  • server-audit.sh: ufw_rule_fields and ufw_port_access.
  • tests/audit-ufw-ports.sh: the cases "whole protocol to one destination address" and "rule with an IPv6 destination address" expect none today, and should change with the fix.

Found during the review of #161 (issue #78). It is not a regression: main behaves the same. Servers set up only by server-prep are not affected, since its firewall step adds rules without a destination address.

Fix

  • ufw_rule_fields: split a To value that starts with a destination address (203.0.113.10 80/tcp, 192.168.1.50/tcp, 2001:db8::1 2222/tcp) into the address and the port spec, so the port spec is matched as today.
  • Read the server's own addresses once, in the main shell (ip -o addr show), like ufw_cache_apps does for profiles, because ufw_port_access runs in $(...).
  • ufw_port_access: take the socket's listening address as an extra argument. A rule to one of the server's own addresses matches like Anywhere when the socket listens on that address or on all addresses (0.0.0.0, ::, *). A rule to an address the server does not have still matches nothing. The source and interface rules stay as they are (any / restricted).
  • tests/audit-ufw-ports.sh: change the two cases that record today's behaviour ("whole protocol to one destination address", "rule with an IPv6 destination address (issue #162)"), and add cases for a rule to an address the server does not have (none) and a rule to the server's address from one source (restricted).
  • CHANGELOG.md line under ### Fixed.

How to verify

bash -n server-audit.sh && shellcheck -S warning server-audit.sh
bash tests/audit-ufw-ports.sh
bash tests/exit-status.sh
# test server only: a port open to the server's own public address
sudo ufw allow to <server-public-ip> port 8080 proto tcp
python3 -m http.server 8080 &
sudo ./server-audit.sh --json a.json   # 8080 is listed under internet-exposed, not firewalled

🤖 Automated by Claude Code (review-fixer routine). A maintainer reviews before anything is merged.

Lingua principale
Shell
Stelle
2
Fork
3
Merge medio
2g 14m
PR unite (30g)
47

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di exceev-consulting/server-prep

Tutte le issue di exceev-consulting/server-prep

Issue simili

Altre issue su Shell/Bash

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.