diff --git a/.github/workflows/shell-syntax.yml b/.github/workflows/shell-syntax.yml index 2c8636e..53cef34 100644 --- a/.github/workflows/shell-syntax.yml +++ b/.github/workflows/shell-syntax.yml @@ -1,4 +1,4 @@ -name: Validate shell scripts +name: Validate audit tooling on: push: @@ -24,3 +24,34 @@ jobs: printf 'Checking %s\n' "$script" bash -n "$script" done < <(find scripts -type f -name '*.sh' -print0) + + - name: Smoke-test network evidence collector + shell: bash + run: | + set -Eeuo pipefail + temporary_directory="$(mktemp -d)" + trap 'rm -rf -- "$temporary_directory"' EXIT + output_directory="$temporary_directory/evidence" + bash scripts/collect-evidence/collect-network-security-evidence.sh "$output_directory" + text_file_count="$(find "$output_directory" -maxdepth 1 -type f -name '*.txt' | wc -l)" + test "$text_file_count" -eq 31 + test -f "$output_directory/SHA256SUMS" + (cd "$output_directory" && sha256sum --check SHA256SUMS) + + python-validation: + name: Python syntax and anonymizer tests + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + + - name: Validate Python syntax + run: python -m py_compile scripts/collect-evidence/anonymize-audit-evidence.py + + - name: Test anonymizer + run: python -m unittest discover -s scripts/collect-evidence -p 'test_*.py' -v diff --git a/README.md b/README.md index f9f0827..f1e9020 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ See [the build reference](references/BUILD-REFERENCE.md) and [build environment | [06 — Kernel and bootloader](screenshots/06-kernel-and-bootloader/README.md) | Kernel configuration, modules, boot files and GRUB | | [07 — Testing and validation](screenshots/07-testing-and-validation/README.md) | Existing test-log inventory and validation limitations | | [08 — Final system](screenshots/08-final-system/README.md) | GRUB menu, first boot and final system state | +| [09 — Networking and security baseline audit](screenshots/09-networking-and-system-audit/README.md) | 30 anonymized network/security command captures and audit report | The `screenshots/` directory retains its historical name, but includes text captures, scripts and archives as well as images. @@ -57,6 +58,7 @@ The `screenshots/` directory retains its historical name, but includes text capt - [Boot process: firmware, GRUB, kernel and systemd](docs/boot-process.md) - [ELF binaries and dynamic linking](docs/elf-and-dynamic-linking.md) - [Testing and validation methodology](docs/testing-and-validation.md) +- [Networking and security baseline audit](docs/networking-and-security-audit.md) - [Troubleshooting](troubleshooting/README.md) - [Project sources](references/sources.md) @@ -69,6 +71,7 @@ The `screenshots/` directory retains its historical name, but includes text capt - Linux kernel configuration and modules - GRUB bootloader and system initialization with systemd - Test-log interpretation and troubleshooting +- Networking, name resolution, service state and security-baseline evidence ## Evidence policy @@ -76,6 +79,7 @@ The `screenshots/` directory retains its historical name, but includes text capt - A command-presence check is not proof that a package test suite passed. - A compiler's native target is not automatically the LFS target triplet. - Test failures, skips and incomplete records must not be relabeled as successful results. +- The networking/security audit is read-only; it is not a penetration test or security certification. - The LFS book itself is not included; use the official [LFS 13.1-systemd book](https://www.linuxfromscratch.org/lfs/view/13.1-systemd/). ## License diff --git a/docs/README.md b/docs/README.md index f15d064..528f78b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -7,6 +7,7 @@ Project-authored explanations that complement the captured evidence. These docum - [ELF and dynamic linking](elf-and-dynamic-linking.md) — executable formats, shared libraries and inspection commands. - [Testing and validation](testing-and-validation.md) — interpreting logs and separating presence checks from test results. - [Test archive audit](test-archive-audit.md) — findings and limitations from the archived LFS test summaries. +- [Networking and security baseline audit](networking-and-security-audit.md) — read-only review of network configuration, resolver state, services, accounts, firewall visibility and selected kernel parameters. ## Documentation rules diff --git a/docs/networking-and-security-audit.md b/docs/networking-and-security-audit.md new file mode 100644 index 0000000..5147ace --- /dev/null +++ b/docs/networking-and-security-audit.md @@ -0,0 +1,217 @@ +# Networking and Security Baseline Audit + +## 1. Overview + +This document records a read-only networking and security baseline review of the Linux From Scratch (LFS) 13.1-systemd system built for this project. The captured system identifies itself as Linux From Scratch, runs on x86_64, and reported kernel `7.1.8`. The virtual machine uses KVM/QEMU. + +The purpose is to document the system as built, not to apply custom hardening. No firewall, resolver, account, kernel, or systemd service settings were changed during this audit. + +This is a configuration and evidence review. It is not a penetration test, vulnerability scan, security certification, or production-readiness assessment. + +## 2. Scope and methodology + +The audit uses 30 command-output captures collected in two phases: + +- **Phase 2 (14 captures):** interfaces, IP addressing, routing, DNS lookup, listening sockets, running and failed services, accounts, groups, account-file metadata, SSH unit lookup, kernel, OS release, and hostname. +- **Phase 3 (16 captures):** resolver status and service, networkd service, resolver files, network configuration file inventory, enabled unit files, systemd sandboxing scores, firewall command availability, forwarding settings, selected network sysctls, login definitions, shell umask, and interactive-shell account listing. + +The evidence describes the state at collection time (2026-11-15). It is not a guarantee of the system's current state after later boots or configuration changes. Original command output has been retained in individual text files, with identifying values anonymized where appropriate. + +### Evidence labels + +- **Verified from captured output:** directly shown by one or more supplied command outputs. +- **Observed:** a recorded runtime/configuration value that is not automatically a defect. +- **Not verified:** the available commands or output do not establish the claim. +- **Out of scope:** deliberately not tested or modified. + +## 3. Network configuration + +**Verified from captured output:** + +- Interface `enp1s0` was up. +- IPv4 address: `192.168.122.54/24`, obtained through DHCP. +- Default gateway: `192.168.122.1`. +- Connected network: `192.168.122.0/24`. +- The loopback interface was present. + +The `getent hosts example.com` test returned two IPv6 address records. This verifies that this particular name lookup succeeded at collection time. It does not independently establish general Internet reachability, connectivity to arbitrary destinations, or DNS reliability. + +## 4. DNS and name resolution + +**Verified from captured output:** + +- `systemd-resolved.service` was enabled and active (running). +- `/etc/resolv.conf` was a symbolic link to `../run/systemd/resolve/stub-resolv.conf`. +- The stub resolver file pointed local clients to `127.0.0.53`. +- `resolvectl status` reported global current DNS server `1.1.1.1` and the per-link DNS server `192.168.122.1` for `enp1s0`. +- The output listed fallback servers from Cloudflare, Google, and Quad9. + +**Observed runtime protocol state:** + +- Global LLMNR: enabled. +- Global mDNS: enabled. +- On `enp1s0`: LLMNR enabled and mDNS disabled. +- DNS-over-TLS: disabled in the reported status. +- DNSSEC: reported as `no/unsupported`. + +The captured `/etc/systemd/resolved.conf` showed the relevant directives commented out. This means the file does not show explicit local values for those settings. The audit does not infer that the runtime state was manually configured, nor does it establish whether drop-in configuration exists outside the captured file. Runtime observations are taken from `resolvectl status`. + +## 5. Network and systemd services + +**Verified from captured output:** + +- Phase 2 listed 11 loaded service units in the running state. +- `systemctl --failed` listed zero loaded failed units at collection time. +- `systemd-networkd.service` and `systemd-resolved.service` were enabled and active. +- Phase 3 listed 32 enabled unit files. + +The 32 enabled unit files are not 32 running services. The list includes services, sockets, and targets; enabled state describes unit enablement, not necessarily current activity. + +The networkd journal included: + +`Could not set hostname: Access denied` + +The available evidence does not establish the cause, whether the message was transient, or whether it had an operational impact. It is recorded as an observation, not diagnosed as a failure. + +The command `systemctl is-enabled sshd` returned `not-found` (exit status 4). This only means the queried systemd unit name was not found. It does not prove that no SSH client, differently named unit, or other SSH server implementation exists. + +## 6. Listening sockets + +The `ss -tulpn` capture showed: + +- DNS stub sockets on loopback addresses `127.0.0.53:53` and `127.0.0.54:53`. +- UDP sockets on wildcard addresses at port 5353. +- UDP and TCP sockets on wildcard addresses at port 5355. + +Ports 5353 and 5355 are commonly associated with mDNS and LLMNR. The resolver status is consistent with LLMNR being active on the captured link and mDNS being disabled on that link, despite global mDNS being enabled. + +A wildcard-bound socket is a listening-socket observation. It does not by itself prove reachability from an untrusted network, successful remote access, exploitability, or a vulnerability. Network topology and packet-filtering state were not established by these captures. + +## 7. Accounts and account-file permissions + +The captured account listing showed `root` as the only account whose shell did not end in `false` or `nologin`. The separate shell-filter command returned: + +`root:/bin/bash` + +This is a statement about the captured `getent passwd` data and the exact filter used; it is not a complete authentication or authorization audit. + +The captured metadata for account files was: + +| File | Mode | Owner | +|---|---:|---| +| `/etc/passwd` | `0644` | `root:root` | +| `/etc/group` | `0644` | `root:root` | +| `/etc/shadow` | `0400` | `root:root` | + +Only file metadata was collected for `/etc/shadow`; its contents were not included. + +## 8. Kernel network parameters + +The following values were captured: + +| Parameter | Observed value | +|---|---:| +| `net.ipv4.ip_forward` | `0` | +| `net.ipv6.conf.all.forwarding` | `0` | +| `net.ipv4.conf.all.rp_filter` | `0` | +| `net.ipv4.conf.all.accept_redirects` | `1` | +| `net.ipv4.conf.all.send_redirects` | `1` | +| `net.ipv4.conf.all.accept_source_route` | `0` | +| `net.ipv6.conf.all.accept_redirects` | `1` | + +These are reported as observed values. They are not automatically classified as defects, and this report does not claim they are universal defaults for every LFS installation. + +## 9. Firewall inspection + +The two captured commands reported: + +- `nft list ruleset`: `Command unavailable: nft` +- `iptables-save`: `Command unavailable: iptables-save` + +**Firewall state: Not verified.** + +The absence of these command-line utilities does not prove that packet filtering is disabled or that no firewall rules exist in the kernel or elsewhere. The evidence is insufficient to claim that a firewall is enabled or disabled. + +## 10. systemd service sandboxing analysis + +`systemd-analyze security --no-pager` returned exposure scores and labels including `UNSAFE`, `EXPOSED`, `MEDIUM`, and `OK`. + +These are systemd's service-sandboxing exposure heuristics. They are not vulnerability scan findings, exploitability assessments, or evidence that a service is compromised. A score must be interpreted in the context of each unit's purpose and required privileges. No sandbox settings were changed. + +## 11. Login definitions and umask + +The captured `/etc/login.defs` included, among other values: + +- `UMASK 022` +- `ENCRYPT_METHOD YESCRYPT` +- `PASS_MIN_LEN 5` +- `PASS_ALWAYS_WARN yes` +- `LOGIN_RETRIES 5` +- `LOGIN_TIMEOUT 60` +- `PASS_CHANGE_TRIES 5` +- `SU_WHEEL_ONLY no` +- `PREVENT_NO_AUTH superuser` +- UID/GID allocation ranges and subordinate-ID ranges as shown in the raw capture. + +The separate Bash umask probe returned `0022`. + +These are configuration values as printed by the system. The presence of `ENCRYPT_METHOD YESCRYPT` in `login.defs` does not prove that existing password hashes use yescrypt; the shadow-file contents and actual password-change path were not audited. Likewise, `PASS_MIN_LEN` is recorded as a setting, not proof that a particular PAM or password-change path enforces that minimum. + +## 12. Findings and evidence classification + +### Verified from captured output + +- The system identified itself as Linux From Scratch and reported kernel `7.1.8`. +- `enp1s0` was up with the captured DHCP IPv4 address and default route. +- The tested lookup for `example.com` returned IPv6 records. +- `systemd-networkd` and `systemd-resolved` were enabled and active. +- The running-service query listed 11 units; the failed-unit query listed zero. +- The account-file metadata and selected kernel network parameters were captured. +- IPv4 and IPv6 forwarding were both reported as disabled. + +### Observed, not automatically classified as defects + +- LLMNR and mDNS runtime state. +- DNSSEC and DNS-over-TLS status. +- Wildcard-bound sockets on ports 5353 and 5355. +- Selected network sysctl values. +- Login defaults and Bash umask. +- systemd sandboxing exposure scores. +- The networkd hostname access-denied journal message. + +### Not verified + +- Effective firewall ruleset and packet-filtering state. +- General Internet reachability or DNS reliability beyond the single lookup. +- Availability of every possible SSH server implementation. +- Cause and impact of the networkd hostname message. +- Actual password-hash algorithms for existing accounts. +- Overall resistance to attack or production security posture. + +### Out of scope + +- Penetration testing and vulnerability scanning. +- Custom kernel hardening. +- Firewall installation or policy changes. +- Resolver or DNS policy changes. +- Account/authentication policy changes. +- systemd service sandbox modifications. +- Production security certification. + +## 13. Collection limitations + +The Phase 3 collector had an exit-status reporting defect: the helper could print the status of a subsequent `echo` rather than the command being tested. Consequently, the Phase 3 `Exit status` annotations are not authoritative. The command output itself, including explicit errors and unavailable-command messages, remains the evidence to interpret. + +The Phase 2 `systemctl is-enabled sshd` output explicitly reported `not-found` and exit status 4. Do not generalize that result beyond the queried unit. + +## 14. Conclusion + +This review documents the observed networking and security baseline of the captured LFS 13.1-systemd build. It intentionally preserves the system as built and does not prescribe or apply custom hardening. + +The evidence supports specific statements about the captured interfaces, resolver, service state, account metadata, and selected kernel parameters. It does not support a blanket claim that the system is secure, insecure, firewall-protected, or production-ready. + +## 15. Evidence and reproducibility + +The accompanying [evidence directory](../screenshots/09-networking-and-system-audit/README.md) contains the 30 individual Phase 2 and Phase 3 text captures. Identifying MAC/UUID values and the MAC-derived IPv6 link-local interface identifier are replaced with explicit placeholders; technical configuration values and command output are retained. + +The [read-only collector](../scripts/collect-evidence/collect-network-security-evidence.sh) is available in the repository. It writes fresh raw output to a separate directory. Review and anonymize that output before publishing; do not overwrite the existing evidence. diff --git a/screenshots/09-networking-and-system-audit/01-network-interfaces.txt b/screenshots/09-networking-and-system-audit/01-network-interfaces.txt new file mode 100644 index 0000000..e55c71a --- /dev/null +++ b/screenshots/09-networking-and-system-audit/01-network-interfaces.txt @@ -0,0 +1,6 @@ +Command: ip -br link + +lo UNKNOWN 00:00:00:00:00:00 +enp1s0 UP + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/02-ip-addresses.txt b/screenshots/09-networking-and-system-audit/02-ip-addresses.txt new file mode 100644 index 0000000..e822364 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/02-ip-addresses.txt @@ -0,0 +1,6 @@ +Command: ip -br address + +lo UNKNOWN 127.0.0.1/8 ::1/128 +enp1s0 UP 192.168.122.54/24 metric 1024 fe80::[ANONYMIZED_INTERFACE_ID]/64 + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/03-routing-table.txt b/screenshots/09-networking-and-system-audit/03-routing-table.txt new file mode 100644 index 0000000..24877b8 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/03-routing-table.txt @@ -0,0 +1,7 @@ +Command: ip route show + +default via 192.168.122.1 dev enp1s0 proto dhcp src 192.168.122.54 metric 1024 +192.168.122.0/24 dev enp1s0 proto kernel scope link src 192.168.122.54 metric 1024 +192.168.122.1 dev enp1s0 proto dhcp scope link src 192.168.122.54 metric 1024 + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/04-dns-resolution.txt b/screenshots/09-networking-and-system-audit/04-dns-resolution.txt new file mode 100644 index 0000000..25826c0 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/04-dns-resolution.txt @@ -0,0 +1,6 @@ +Command: getent hosts example.com + +2a06:98c1:3122:: example.com +2a06:98c1:3123:: example.com + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/05-listening-sockets.txt b/screenshots/09-networking-and-system-audit/05-listening-sockets.txt new file mode 100644 index 0000000..44aef54 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/05-listening-sockets.txt @@ -0,0 +1,15 @@ +Command: ss -tulpn + +Netid State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess +udp UNCONN 0 0 0.0.0.0:5353 0.0.0.0:* users:(("systemd-resolve",pid=183,fd=17)) +udp UNCONN 0 0 0.0.0.0:5355 0.0.0.0:* users:(("systemd-resolve",pid=183,fd=13)) +udp UNCONN 0 0 127.0.0.54:53 0.0.0.0:* users:(("systemd-resolve",pid=183,fd=24)) +udp UNCONN 0 0 127.0.0.53:53 0.0.0.0:* users:(("systemd-resolve",pid=183,fd=22)) +udp UNCONN 0 0 *:5353 *:* users:(("systemd-resolve",pid=183,fd=18)) +udp UNCONN 0 0 *:5355 *:* users:(("systemd-resolve",pid=183,fd=15)) +tcp LISTEN 0 0 127.0.0.54:53 0.0.0.0:* users:(("systemd-resolve",pid=183,fd=25)) +tcp LISTEN 0 0 127.0.0.53:53 0.0.0.0:* users:(("systemd-resolve",pid=183,fd=23)) +tcp LISTEN 0 0 0.0.0.0:5355 0.0.0.0:* users:(("systemd-resolve",pid=183,fd=14)) +tcp LISTEN 0 0 *:5355 *:* users:(("systemd-resolve",pid=183,fd=16)) + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/06-running-services.txt b/screenshots/09-networking-and-system-audit/06-running-services.txt new file mode 100644 index 0000000..a37b420 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/06-running-services.txt @@ -0,0 +1,22 @@ +Command: systemctl list-units --type=service --state=running --no-pager + + UNIT LOAD ACTIVE SUB DESCRIPTION + dbus.service loaded active running D-Bus System Message Bus + getty@tty1.service loaded active running Getty on tty1 + systemd-journald.service loaded active running Journal Service + systemd-logind.service loaded active running User Login Management + systemd-networkd.service loaded active running Network Management + systemd-nsresourced.service loaded active running Namespace Resource Manager + systemd-oomd.service loaded active running Userspace Out-Of-Memory (OOM) Killer + systemd-resolved.service loaded active running Network Name Resolution + systemd-timesyncd.service loaded active running Network Time Synchronization + systemd-udevd.service loaded active running Rule-based Manager for Device Events and Files + systemd-userdbd.service loaded active running User Database Manager + +Legend: LOAD → Reflects whether the unit definition was properly loaded. + ACTIVE → The high-level unit activation state, i.e. generalization of SUB. + SUB → The low-level unit activation state, values depend on unit type. + +11 loaded units listed. + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/07-failed-services.txt b/screenshots/09-networking-and-system-audit/07-failed-services.txt new file mode 100644 index 0000000..9da2e83 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/07-failed-services.txt @@ -0,0 +1,7 @@ +Command: systemctl --failed --no-pager + + UNIT LOAD ACTIVE SUB DESCRIPTION + +0 loaded units listed. + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/08-user-accounts.txt b/screenshots/09-networking-and-system-audit/08-user-accounts.txt new file mode 100644 index 0000000..e5a48f8 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/08-user-accounts.txt @@ -0,0 +1,18 @@ +Command: getent passwd + +root:x:0:0:root:/root:/bin/bash +bin:x:1:1:bin:/dev/null:/usr/bin/false +daemon:x:6:6:Daemon User:/dev/null:/usr/bin/false +messagebus:x:18:18:D-Bus Message Daemon User:/run/dbus:/usr/bin/false +systemd-journal-gateway:x:73:73:systemd Journal Gateway:/:/usr/bin/false +systemd-journal-remote:x:74:74:systemd Journal Remote:/:/usr/bin/false +systemd-journal-upload:x:75:75:systemd Journal Upload:/:/usr/bin/false +systemd-network:x:76:76:systemd Network Management:/:/usr/bin/false +systemd-resolve:x:77:77:systemd Resolver:/:/usr/bin/false +systemd-timesync:x:78:78:systemd Time Synchronization:/:/usr/bin/false +systemd-coredump:x:79:79:systemd Core Dumper:/:/usr/bin/false +uuidd:x:80:80:UUID Generation Daemon User:/dev/null:/usr/bin/false +systemd-oom:x:81:81:systemd Out Of Memory Daemon:/:/usr/bin/false +nobody:x:65534:65534:Unprivileged User:/dev/null:/usr/bin/false + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/09-groups.txt b/screenshots/09-networking-and-system-audit/09-groups.txt new file mode 100644 index 0000000..88b417d --- /dev/null +++ b/screenshots/09-networking-and-system-audit/09-groups.txt @@ -0,0 +1,37 @@ +Command: getent group + +root:x:0: +bin:x:1:daemon +sys:x:2: +kmem:x:3: +tape:x:4: +tty:x:5: +daemon:x:6: +floppy:x:7: +disk:x:8: +lp:x:9: +dialout:x:10: +audio:x:11: +video:x:12: +utmp:x:13: +clock:x:14: +cdrom:x:15: +adm:x:16: +messagebus:x:18: +systemd-journal:x:23: +input:x:24: +mail:x:34: +kvm:x:61: +systemd-journal-gateway:x:73: +systemd-journal-remote:x:74: +systemd-journal-upload:x:75: +systemd-resolve:x:76: +systemd-timesync:x:78: +systemd-coredump:x:79: +uuidd:x:80: +systemd-oom:x:81: +wheel:x:97: +users:x:999: +nogroup:x:65534: + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/10-account-file-permissions.txt b/screenshots/09-networking-and-system-audit/10-account-file-permissions.txt new file mode 100644 index 0000000..13db02c --- /dev/null +++ b/screenshots/09-networking-and-system-audit/10-account-file-permissions.txt @@ -0,0 +1,28 @@ +Command: stat /etc/passwd /etc/group /etc/shadow + + File: /etc/passwd + Size: 862 Blocks: 8 IO Block: 4096 regular file +Device: 253,17 Inode: 2359323 Links: 1 +Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) +Access: 2026-11-14 20:38:22.537262524 +0330 +Modify: 2026-11-03 22:23:07.700287849 +0330 +Change: 2026-11-03 22:23:07.702696060 +0330 + Birth: 2026-11-03 22:23:07.699696048 +0330 + File: /etc/group + Size: 488 Blocks: 8 IO Block: 4096 regular file +Device: 253,17 Inode: 2359345 Links: 1 +Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) +Access: 2026-11-14 20:38:22.537262524 +0330 +Modify: 2026-11-03 22:23:07.712044393 +0330 +Change: 2026-11-03 22:23:07.715696115 +0330 + Birth: 2026-11-03 22:23:07.711696098 +0330 + File: /etc/shadow + Size: 456 Blocks: 8 IO Block: 4096 regular file +Device: 253,17 Inode: 2359330 Links: 1 +Access: (0400/-r--------) Uid: ( 0/ root) Gid: ( 0/ root) +Access: 2026-11-14 20:39:10.216262524 +0330 +Modify: 2026-11-03 22:23:07.706079053 +0330 +Change: 2026-11-03 22:23:07.708696085 +0330 + Birth: 2026-11-03 22:23:07.705696073 +0330 + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/11-sshd-enabled-state.txt b/screenshots/09-networking-and-system-audit/11-sshd-enabled-state.txt new file mode 100644 index 0000000..4e27106 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/11-sshd-enabled-state.txt @@ -0,0 +1,5 @@ +Command: systemctl is-enabled sshd + +not-found + +Exit status: 4 diff --git a/screenshots/09-networking-and-system-audit/12-kernel-information.txt b/screenshots/09-networking-and-system-audit/12-kernel-information.txt new file mode 100644 index 0000000..0bbb83d --- /dev/null +++ b/screenshots/09-networking-and-system-audit/12-kernel-information.txt @@ -0,0 +1,5 @@ +Command: uname -a + +Linux lfs 7.1.8 #1 SMP PREEMPT_DYNAMIC Wed Nov 4 17:56:56 +0330 2026 x86_64 GNU/Linux + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/13-os-release.txt b/screenshots/09-networking-and-system-audit/13-os-release.txt new file mode 100644 index 0000000..12738bf --- /dev/null +++ b/screenshots/09-networking-and-system-audit/13-os-release.txt @@ -0,0 +1,5 @@ +Command: cat /etc/os-release + +NAME="Linux From Scratch" + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/14-hostname.txt b/screenshots/09-networking-and-system-audit/14-hostname.txt new file mode 100644 index 0000000..8c8dbc8 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/14-hostname.txt @@ -0,0 +1,20 @@ +Command: hostnamectl status + + Static hostname: lfs + Icon name: computer-vm + Chassis: vm 💽 + Machine ID: + Boot ID: + Product UUID: + Virtualization: kvm +Operating System: Linux From Scratch + Kernel: Linux 7.1.8 + Architecture: x86-64 + Hardware Vendor: QEMU + Hardware Model: Standard PC _Q35 + ICH9, 2009_ +Hardware Version: pc-q35-10.2 +Firmware Version: edk2-20260812-8.fc44 + Firmware Date: Wed 2026-08-12 + Firmware Age: 3month 3d + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/15-resolvectl-status.txt b/screenshots/09-networking-and-system-audit/15-resolvectl-status.txt new file mode 100644 index 0000000..bd5dc3e --- /dev/null +++ b/screenshots/09-networking-and-system-audit/15-resolvectl-status.txt @@ -0,0 +1,22 @@ +Command: resolvectl status + +Global + Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported + resolv.conf mode: stub + Current DNS Server: 1.1.1.1#one.one.one.one +Fallback DNS Servers: 1.1.1.1#one.one.one.one 8.8.8.8#dns.google + 9.9.9.9#dns.quad9.net 1.0.0.1#one.one.one.one + 8.8.4.4#dns.google 149.112.112.112#dns.quad9.net + 2606:4700:4700::1111#one.one.one.one + 2001:4860:4860::8888#dns.google 2620:fe::fe#dns.quad9.net + 2606:4700:4700::1001#one.one.one.one + 2001:4860:4860::8844#dns.google 2620:fe::9#dns.quad9.net + +Link 2 (enp1s0) + Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6 + Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported +Current DNS Server: 192.168.122.1 + DNS Servers: 192.168.122.1 + Default Route: yes + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/16-resolved-service.txt b/screenshots/09-networking-and-system-audit/16-resolved-service.txt new file mode 100644 index 0000000..630da4e --- /dev/null +++ b/screenshots/09-networking-and-system-audit/16-resolved-service.txt @@ -0,0 +1,29 @@ +Command: systemctl status systemd-resolved --no-pager + +● systemd-resolved.service - Network Name Resolution + Loaded: loaded (/usr/lib/systemd/system/systemd-resolved.service; enabled; preset: enabled) + Active: active (running) since Sun 2026-11-15 00:57:14 +0330; 41s ago + Invocation: +TriggeredBy: ● systemd-resolved-varlink.socket + ● systemd-resolved-monitor.socket + Docs: man:systemd-resolved.service(8) + man:org.freedesktop.resolve1(5) + https://systemd.io/WRITING_NETWORK_CONFIGURATION_MANAGERS + https://systemd.io/WRITING_RESOLVER_CLIENTS + Main PID: 178 (systemd-resolve) + Status: "Processing requests..." + Tasks: 1 (limit: 14274) + Memory: 4.5M (peak: 4.6M) + CPU: 25ms + CGroup: /system.slice/systemd-resolved.service + └─178 /usr/lib/systemd/systemd-resolved + +Nov 15 00:57:14 lfs systemd-resolved[178]: Positive Trust Anchors: +Nov 15 00:57:14 lfs systemd-resolved[178]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d +Nov 15 00:57:14 lfs systemd-resolved[178]: . IN DS 38696 8 2 683d2d0acb8c9b712a1948b27f741219298d0a450d612c483af444a4c0fb2b16 +Nov 15 00:57:14 lfs systemd-resolved[178]: Negative trust anchors: home.arpa 10.in-addr.arpa 16.172.in-addr.arpa 17.172.in-addr.arpa 18.172.in-addr.arpa 19.172.in-addr.arpa 20.172.in-addr.arpa 21.172.in-addr.arpa 22.172.in-addr.arpa 23.172.in-addr.arpa 24.172.in-addr.arpa 25.172.in-addr.arpa 26.172.in-addr.arpa 27.172.in-addr.arpa 28.172.in-addr.arpa 29.172.in-addr.arpa 30.172.in-addr.arpa 31.172.in-addr.arpa 170.0.0.192.in-addr.arpa 171.0.0.192.in-addr.arpa 168.192.in-addr.arpa d.f.ip6.arpa ipv4only.arpa resolver.arpa corp home internal intranet lan local private test +Nov 15 00:57:14 lfs systemd-resolved[178]: Using system hostname 'lfs'. +Nov 15 00:57:14 lfs systemd[1]: Started Network Name Resolution. +Nov 15 00:57:14 lfs systemd-resolved[178]: Switching to fallback DNS server 1.1.1.1#one.one.one.one. + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/17-networkd-service.txt b/screenshots/09-networking-and-system-audit/17-networkd-service.txt new file mode 100644 index 0000000..c188599 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/17-networkd-service.txt @@ -0,0 +1,33 @@ +Command: systemctl status systemd-networkd --no-pager + +● systemd-networkd.service - Network Management + Loaded: loaded (/usr/lib/systemd/system/systemd-networkd.service; enabled; preset: enabled) + Active: active (running) since Sun 2026-11-15 00:57:14 +0330; 40s ago + Invocation: +TriggeredBy: ● systemd-networkd-varlink-metrics.socket + ● systemd-networkd-varlink.socket + ● systemd-networkd-resolve-hook.socket + ● systemd-networkd.socket + Docs: man:systemd-networkd.service(8) + man:org.freedesktop.network1(5) + Main PID: 244 (systemd-network) + Status: "Processing requests..." + Tasks: 1 (limit: 14274) + FD Store: 0 (limit: 512) + Memory: 3.8M (peak: 4.1M) + CPU: 23ms + CGroup: /system.slice/systemd-networkd.service + └─244 /usr/lib/systemd/systemd-networkd + +Nov 15 00:57:14 lfs systemd-networkd[244]: lo: Link UP +Nov 15 00:57:14 lfs systemd-networkd[244]: lo: Gained carrier +Nov 15 00:57:14 lfs systemd[1]: Started Network Management. +Nov 15 00:57:14 lfs systemd-networkd[244]: eth0: Interface name change detected, renamed to enp1s0. +Nov 15 00:57:14 lfs systemd-networkd[244]: enp1s0: Configuring with /etc/systemd/network/10-ethernet-dhcp.network. +Nov 15 00:57:14 lfs systemd-networkd[244]: enp1s0: Link UP +Nov 15 00:57:14 lfs systemd-networkd[244]: enp1s0: Gained carrier +Nov 15 00:57:16 lfs systemd-networkd[244]: enp1s0: Gained IPv6LL +Nov 15 00:57:17 lfs systemd-networkd[244]: enp1s0: DHCPv4 address 192.168.122.54/24, gateway 192.168.122.1 acquired from 192.168.122.1 +Nov 15 00:57:17 lfs systemd-networkd[244]: Could not set hostname: Access denied + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/18-resolv-conf.txt b/screenshots/09-networking-and-system-audit/18-resolv-conf.txt new file mode 100644 index 0000000..0fd016c --- /dev/null +++ b/screenshots/09-networking-and-system-audit/18-resolv-conf.txt @@ -0,0 +1,27 @@ +resolv.conf symlink: +../run/systemd/resolve/stub-resolv.conf + +resolv.conf contents: +# This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8). +# Do not edit. +# +# This file might be symlinked as /etc/resolv.conf. If you're looking at +# /etc/resolv.conf and seeing this text, you have followed the symlink. +# +# This is a dynamic resolv.conf file for connecting local clients to the +# internal DNS stub resolver of systemd-resolved. This file lists all +# configured search domains. +# +# Run "resolvectl status" to see details about the uplink DNS servers +# currently in use. +# +# Third party programs should typically not access this file directly, but only +# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a +# different way, replace this symlink by a static file or a different symlink. +# +# See man:systemd-resolved.service(8) for details about the supported modes of +# operation for /etc/resolv.conf. + +nameserver 127.0.0.53 +options edns0 trust-ad +search . diff --git a/screenshots/09-networking-and-system-audit/19-resolved-conf.txt b/screenshots/09-networking-and-system-audit/19-resolved-conf.txt new file mode 100644 index 0000000..6853b08 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/19-resolved-conf.txt @@ -0,0 +1,48 @@ +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; either version 2.1 of the License, or (at your option) +# any later version. +# +# Entries in this file show the compile time defaults. Local configuration +# should be created by either modifying this file (or a copy of it placed in +# /etc/ if the original file is shipped in /usr/), or by creating "drop-ins" in +# the /etc/systemd/resolved.conf.d/ directory. The latter is generally +# recommended. Defaults can be restored by simply deleting the main +# configuration file and all drop-ins located in /etc/. +# +# Use 'systemd-analyze cat-config systemd/resolved.conf' to display the full config. +# +# See resolved.conf(5) for details. + +[Resolve] +# Some examples of DNS servers which may be used for DNS= and FallbackDNS=: +# Cloudflare: 1.1.1.1#one.one.one.one 1.0.0.1#one.one.one.one 2606:4700:4700::1111#one.one.one.one 2606:4700:4700::1001#one.one.one.one +# Google: 8.8.8.8#dns.google 8.8.4.4#dns.google 2001:4860:4860::8888#dns.google 2001:4860:4860::8844#dns.google +# Quad9: 9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net +# +# Using DNS= configures global DNS servers and does not suppress link-specific +# configuration. Parallel requests will be sent to per-link DNS servers +# configured automatically by systemd-networkd.service(8), NetworkManager(8), or +# similar management services, or configured manually via resolvectl(1). See +# resolved.conf(5) and systemd-resolved(8) for more details. +#DNS= +#FallbackDNS=1.1.1.1#one.one.one.one 8.8.8.8#dns.google 9.9.9.9#dns.quad9.net 1.0.0.1#one.one.one.one 8.8.4.4#dns.google 149.112.112.112#dns.quad9.net 2606:4700:4700::1111#one.one.one.one 2001:4860:4860::8888#dns.google 2620:fe::fe#dns.quad9.net 2606:4700:4700::1001#one.one.one.one 2001:4860:4860::8844#dns.google 2620:fe::9#dns.quad9.net +#Domains= +#DNSSEC=no +#DNSOverTLS=no +#MulticastDNS=yes +#LLMNR=yes +#Cache=yes +#CacheFromLocalhost=no +#DNSCacheSize=4096 +#MulticastDNSCacheSize=4096 +#LLMNRCacheSize=4096 +#DNSStubListener=yes +#DNSStubListenerExtra= +#ReadEtcHosts=yes +#ReadStaticRecords=yes +#ResolveUnicastSingleLabel=no +#StaleRetentionSec=0 +#RefuseRecordTypes= diff --git a/screenshots/09-networking-and-system-audit/20-network-config-file-list.txt b/screenshots/09-networking-and-system-audit/20-network-config-file-list.txt new file mode 100644 index 0000000..67371d0 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/20-network-config-file-list.txt @@ -0,0 +1 @@ +/etc/systemd/network/10-ethernet-dhcp.network diff --git a/screenshots/09-networking-and-system-audit/21-enabled-services.txt b/screenshots/09-networking-and-system-audit/21-enabled-services.txt new file mode 100644 index 0000000..33ca6f2 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/21-enabled-services.txt @@ -0,0 +1,39 @@ +Command: systemctl list-unit-files --state=enabled --no-pager + +UNIT FILE STATE PRESET +getty@.service enabled enabled +systemd-confext.service enabled enabled +systemd-network-generator.service enabled enabled +systemd-networkd-wait-online.service enabled enabled +systemd-networkd.service enabled enabled +systemd-oomd.service enabled enabled +systemd-pstore.service enabled enabled +systemd-resolved.service enabled enabled +systemd-sysext.service enabled enabled +systemd-timesyncd.service enabled enabled +systemd-udev-load-credentials.service enabled enabled +systemd-userdb-load-credentials.service enabled enabled +systemd-factory-reset.socket enabled enabled +systemd-journald-audit.socket enabled enabled +systemd-mountfsd.socket enabled enabled +systemd-networkd-resolve-hook.socket enabled enabled +systemd-networkd-varlink-metrics.socket enabled enabled +systemd-networkd-varlink.socket enabled enabled +systemd-networkd.socket enabled enabled +systemd-nsresourced.socket enabled enabled +systemd-oomd.socket enabled enabled +systemd-report-basic.socket enabled enabled +systemd-report-cgroup.socket enabled enabled +systemd-resolved-monitor.socket enabled enabled +systemd-resolved-varlink.socket enabled enabled +systemd-storage-block.socket enabled enabled +systemd-storage-fs.socket enabled enabled +systemd-sysext.socket enabled enabled +systemd-userdbd.socket enabled enabled +machines.target enabled enabled +reboot.target enabled enabled +remote-fs.target enabled enabled + +32 unit files listed. + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/22-systemd-security.txt b/screenshots/09-networking-and-system-audit/22-systemd-security.txt new file mode 100644 index 0000000..d7c44ef --- /dev/null +++ b/screenshots/09-networking-and-system-audit/22-systemd-security.txt @@ -0,0 +1,24 @@ +Command: systemd-analyze security --no-pager + +UNIT EXPOSURE PREDICATE HAPPY +dbus.service 9.1 UNSAFE :-{ +emergency.service 9.4 UNSAFE :-{ +getty@tty1.service 9.5 UNSAFE :-{ +rescue.service 9.4 UNSAFE :-{ +systemd-ask-password-console.service 9.4 UNSAFE :-{ +systemd-ask-password-wall.service 9.5 UNSAFE :-{ +systemd-hostnamed.service 4.1 OK :-) +systemd-journald.service 7.2 MEDIUM :-| +systemd-logind.service 5.2 MEDIUM :-| +systemd-machined.service 7.7 EXPOSED :-( +systemd-mountfsd.service 7.6 EXPOSED :-( +systemd-networkd.service 4.9 OK :-) +systemd-nsresourced.service 6.2 MEDIUM :-| +systemd-oomd.service 4.2 OK :-) +systemd-resolved.service 4.3 OK :-) +systemd-rfkill.service 9.2 UNSAFE :-{ +systemd-timesyncd.service 4.0 OK :-) +systemd-udevd.service 8.7 EXPOSED :-( +systemd-userdbd.service 4.4 OK :-) + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/23-nftables-rules.txt b/screenshots/09-networking-and-system-audit/23-nftables-rules.txt new file mode 100644 index 0000000..0995eca --- /dev/null +++ b/screenshots/09-networking-and-system-audit/23-nftables-rules.txt @@ -0,0 +1,3 @@ +Command: nft list ruleset + +Command unavailable: nft diff --git a/screenshots/09-networking-and-system-audit/24-iptables-rules.txt b/screenshots/09-networking-and-system-audit/24-iptables-rules.txt new file mode 100644 index 0000000..1ab177e --- /dev/null +++ b/screenshots/09-networking-and-system-audit/24-iptables-rules.txt @@ -0,0 +1,3 @@ +Command: iptables-save + +Command unavailable: iptables-save diff --git a/screenshots/09-networking-and-system-audit/25-ipv4-forwarding.txt b/screenshots/09-networking-and-system-audit/25-ipv4-forwarding.txt new file mode 100644 index 0000000..517d4fc --- /dev/null +++ b/screenshots/09-networking-and-system-audit/25-ipv4-forwarding.txt @@ -0,0 +1,5 @@ +Command: sysctl net.ipv4.ip_forward + +net.ipv4.ip_forward = 0 + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/26-ipv6-forwarding.txt b/screenshots/09-networking-and-system-audit/26-ipv6-forwarding.txt new file mode 100644 index 0000000..97c560a --- /dev/null +++ b/screenshots/09-networking-and-system-audit/26-ipv6-forwarding.txt @@ -0,0 +1,5 @@ +Command: sysctl net.ipv6.conf.all.forwarding + +net.ipv6.conf.all.forwarding = 0 + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/27-kernel-network-hardening.txt b/screenshots/09-networking-and-system-audit/27-kernel-network-hardening.txt new file mode 100644 index 0000000..8561e19 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/27-kernel-network-hardening.txt @@ -0,0 +1,9 @@ +Command: sysctl net.ipv4.conf.all.rp_filter net.ipv4.conf.all.accept_redirects net.ipv4.conf.all.send_redirects net.ipv4.conf.all.accept_source_route net.ipv6.conf.all.accept_redirects + +net.ipv4.conf.all.rp_filter = 0 +net.ipv4.conf.all.accept_redirects = 1 +net.ipv4.conf.all.send_redirects = 1 +net.ipv4.conf.all.accept_source_route = 0 +net.ipv6.conf.all.accept_redirects = 1 + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/28-login-definitions.txt b/screenshots/09-networking-and-system-audit/28-login-definitions.txt new file mode 100644 index 0000000..43df566 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/28-login-definitions.txt @@ -0,0 +1,511 @@ +Command: cat /etc/login.defs + +# +# /etc/login.defs - Configuration control definitions for the shadow package. +# +# $Id$ +# + +# +# Delay in seconds before being allowed another attempt after a login failure +# Note: when PAM is used, some modules may enforce a minimum delay (e.g. +# pam_unix(8) enforces a 2s delay) +# +FAIL_DELAY 3 + +# +# Enable logging and display of /var/log/faillog login(1) failure info. +# +FAILLOG_ENAB yes + +# +# Enable display of unknown usernames when login(1) failures are recorded. +# +LOG_UNKFAIL_ENAB no + +# +# Enable logging of successful logins +# +LOG_OK_LOGINS no + +# +# Enable logging and display of /var/log/lastlog login(1) time info. +# +LASTLOG_ENAB yes + +# +# Limit the highest user ID number for which the lastlog entries should +# be updated. +# +# No LASTLOG_UID_MAX means that there is no user ID limit for writing +# lastlog entries. +# +#LASTLOG_UID_MAX + +# +# Enable checking and display of mailbox status upon login. +# +# Disable if the shell startup files already check for mail +# ("mailx -e" or equivalent). +# +MAIL_CHECK_ENAB yes + +# +# Enable additional checks upon password changes. +# +OBSCURE_CHECKS_ENAB yes + +# +# Enable checking of time restrictions specified in /etc/porttime. +# +PORTTIME_CHECKS_ENAB yes + +# +# Enable setting of ulimit, umask, and niceness from passwd(5) gecos field. +# +QUOTAS_ENAB yes + +# +# Enable "syslog" logging of su(1) activity - in addition to sulog file logging. +# SYSLOG_SG_ENAB does the same for newgrp(1) and sg(1). +# +SYSLOG_SU_ENAB yes +SYSLOG_SG_ENAB yes + +# +# If defined, either full pathname of a file containing device names or +# a ":" delimited list of device names. Root logins will be allowed only +# from these devices. +# +CONSOLE /etc/securetty +#CONSOLE console:tty01:tty02:tty03:tty04 + +# +# If defined, all su(1) activity is logged to this file. +# +#SULOG_FILE /var/log/sulog + +# +# If defined, ":" delimited list of "message of the day" files to +# be displayed upon login. +# +MOTD_FILE /etc/motd +#MOTD_FILE /etc/motd:/usr/lib/news/news-motd + +# +# If defined, this file will be output before each login(1) prompt. +# +#ISSUE_FILE /etc/issue + +# +# If defined, file which maps tty line to TERM environment parameter. +# Each line of the file is in a format similar to "vt100 tty01". +# +#TTYTYPE_FILE /etc/ttytype + +# +# If defined, login(1) failures will be logged here in a utmp format. +# last(1), when invoked as lastb(1), will read /var/log/btmp, so... +# +FTMP_FILE /var/log/btmp + +# +# If defined, name of file whose presence will inhibit non-root +# logins. The content of this file should be a message indicating +# why logins are inhibited. +# +NOLOGINS_FILE /etc/nologin + +# +# If defined, the command name to display when running "su -". For +# example, if this is defined as "su" then ps(1) will display the +# command as "-su". If not defined, then ps(1) will display the +# name of the shell actually being run, e.g. something like "-sh". +# +SU_NAME su + +# +# *REQUIRED* +# Directory where mailboxes reside, _or_ name of file, relative to +# the home directory. If you do define both, MAIL_DIR takes precedence. +# +MAIL_DIR /var/mail +#MAIL_FILE .mail + +# +# If defined, file which inhibits all the usual chatter during the login +# sequence. If a full pathname, then hushed mode will be enabled if the +# user's name or shell are found in the file. If not a full pathname, then +# hushed mode will be enabled if the file exists in the user's home directory. +# +HUSHLOGIN_FILE .hushlogin +#HUSHLOGIN_FILE /etc/hushlogins + +# +# If defined, either a TZ environment parameter spec or the +# fully-rooted pathname of a file containing such a spec. +# +#ENV_TZ TZ=CST6CDT +#ENV_TZ /etc/tzname + +# +# If defined, an HZ environment parameter spec. +# +# for Linux/x86 +ENV_HZ HZ=100 +# For Linux/Alpha... +#ENV_HZ HZ=1024 + +# +# *REQUIRED* The default PATH settings, for superuser and normal users. +# +# (they are minimal, add the rest in the shell startup files) +ENV_SUPATH PATH=/usr/sbin:/usr/bin +ENV_PATH PATH=/usr/bin + +# +# Terminal permissions +# +# TTYGROUP Login tty will be assigned this group ownership. +# TTYPERM Login tty will be set to this permission. +# +# If you have a write(1) program which is "setgid" to a special group +# which owns the terminals, define TTYGROUP as the number of such group +# and TTYPERM as 0620. Otherwise leave TTYGROUP commented out and +# set TTYPERM to either 622 or 600. +# +TTYGROUP tty +TTYPERM 0600 + +# +# Login configuration initializations: +# +# ERASECHAR Terminal ERASE character ('\010' = backspace). +# KILLCHAR Terminal KILL character ('\025' = CTRL/U). +# ULIMIT Default "ulimit" value. +# +# The ERASECHAR and KILLCHAR are used only on System V machines. +# The ULIMIT is used only if the system supports it. +# (now it works with setrlimit too; ulimit is in 512-byte units) +# +# Prefix these values with "0" to get octal, "0x" to get hexadecimal. +# +ERASECHAR 0177 +KILLCHAR 025 +#ULIMIT 2097152 + +# Default initial "umask" value used by login(1) on non-PAM enabled systems. +# Default "umask" value for pam_umask(8) on PAM enabled systems. +# UMASK is also used by useradd(8) and newusers(8) to set the mode for new +# home directories if HOME_MODE is not set. +# 022 is the default value, but 027, or even 077, could be considered +# for increased privacy. There is no One True Answer here: each sysadmin +# must make up their mind. +UMASK 022 + +# HOME_MODE is used by useradd(8) and newusers(8) to set the mode for new +# home directories. +# If HOME_MODE is not set, the value of UMASK is used to create the mode. +#HOME_MODE 0700 + +# +# If "yes", the user must be listed as a member of the first gid 0 group +# in /etc/group (called "root" on most Linux systems) to be able to "su" +# to uid 0 accounts. If the group doesn't exist or is empty, no one +# will be able to "su" to uid 0. +# +SU_WHEEL_ONLY no + +# +# Min/max values for automatic uid selection in useradd(8) +# +UID_MIN 1000 +UID_MAX 60000 +# System accounts +SYS_UID_MIN 101 +SYS_UID_MAX 999 +# Extra per user uids +SUB_UID_MIN 100000 +SUB_UID_MAX 600100000 +SUB_UID_COUNT 65536 +# +# If set to yes, subordinate user ID entries in /etc/subuid are stored +# using the numeric user ID rather than the username. +#SUB_UID_STORE_BY_UID no + +# +# Enable deterministic subordinate UID allocation based on the user's UID. +# When set to "yes", subordinate UID ranges are calculated using a +# deterministic formula instead of searching for the next free range: +# +# WARNING: Do not mix deterministic and linear (default) allocation +# on the same system or across systems sharing /etc/subuid. Mixing +# methods will cause subordinate ID range conflicts and overlaps. +# +# Default: no +# +#SUB_UID_DETERMINISTIC no + +# +# Allow deterministic subordinate UID calculation to wrap around using +# modulo arithmetic when a UID would overflow the configured subordinate +# ID space. Only effective when SUB_UID_DETERMINISTIC is "yes". +# +# When disabled (default), any arithmetic overflow is a hard error, +# ensuring non-overlapping monotonic allocation. +# +# WARNING: SECURITY RISK - MAY CAUSE RANGE OVERLAPS AND PRIVILEGE ESCALATION! +# +# When enabled (WRAP MODE), the subordinate UID space is treated as a ring +# buffer. Uses modulo arithmetic to handle overflow. May cause range +# overlaps between users. +# +# Default: no +# +#UNSAFE_SUB_UID_DETERMINISTIC_WRAP no + +# +# Min/max values for automatic gid selection in groupadd(8) +# +GID_MIN 1000 +GID_MAX 60000 +# System accounts +SYS_GID_MIN 101 +SYS_GID_MAX 999 +# Extra per user group ids +SUB_GID_MIN 100000 +SUB_GID_MAX 600100000 +SUB_GID_COUNT 65536 +# +# If set to yes, subordinate group ID entries in /etc/subgid are stored +# using the numeric user ID rather than the username. +#SUB_GID_STORE_BY_UID no + +# +# Enable deterministic subordinate GID allocation based on the user's UID. +# When set to "yes", subordinate GID ranges are calculated using a +# deterministic formula instead of searching for the next free range: +# +# WARNING: Do not mix deterministic and linear (default) allocation +# on the same system or across systems sharing /etc/subgid. Mixing +# methods will cause subordinate ID range conflicts and overlaps. +# +# Default: no +# +#SUB_GID_DETERMINISTIC no + +# +# Allow deterministic subordinate GID calculation to wrap around using +# modulo arithmetic when a UID would overflow the configured subordinate +# ID space. Only effective when SUB_GID_DETERMINISTIC is "yes". +# +# When disabled (default), any arithmetic overflow is a hard error, +# ensuring non-overlapping monotonic allocation. +# +# WARNING: SECURITY RISK - MAY CAUSE RANGE OVERLAPS AND PRIVILEGE ESCALATION! +# +# When enabled (WRAP MODE), the subordinate GID space is treated as a ring +# buffer. Uses modulo arithmetic to handle overflow. May cause range +# overlaps between users. +# +# Default: no +# +#UNSAFE_SUB_GID_DETERMINISTIC_WRAP no + +# +# Max number of login(1) retries if password is bad +# +LOGIN_RETRIES 5 + +# +# Max time in seconds for login(1) +# +LOGIN_TIMEOUT 60 + +# +# Maximum number of attempts to change password if rejected (too easy) +# +PASS_CHANGE_TRIES 5 + +# +# Password strength controls: +# +# Warn about weak passwords (but still allow them) if you are root. +PASS_ALWAYS_WARN yes +# Minimum acceptable password length. +PASS_MIN_LEN 5 + +# +# Require password before chfn(1)/chsh(1) can make any changes. +# +CHFN_AUTH yes + +# +# Which fields may be changed by regular users using chfn(1) - use +# any combination of letters "frwh" (full name, room number, work +# phone, home phone). If not defined, no changes are allowed. +# For backward compatibility, "yes" = "rwh" and "no" = "frwh". +# +CHFN_RESTRICT rwh + +# +# Password prompt (%s will be replaced by user name). +# +# XXX - it doesn't work correctly yet, for now leave it commented out +# to use the default which is just "Password: ". +#LOGIN_STRING "%s's Password: " + +# +# Only works if compiled with ENCRYPTMETHOD_SELECT defined: +# If set to SHA256, SHA256-based algorithm will be used for encrypting password +# If set to SHA512, SHA512-based algorithm will be used for encrypting password +# If set to BCRYPT, BCRYPT-based algorithm will be used for encrypting password +# If set to YESCRYPT, YESCRYPT-based algorithm will be used for encrypting password +# +# Note: if you use PAM, it is recommended to use a value consistent with +# the PAM modules configuration. +# +ENCRYPT_METHOD YESCRYPT + +# +# Only works if ENCRYPT_METHOD is set to SHA256 or SHA512. +# +# Define the number of SHA rounds. +# With a lot of rounds, it is more difficult to brute-force the password. +# However, more CPU resources will be needed to authenticate users if +# this value is increased. +# +# If not specified, the libc will choose the default number of rounds (5000), +# which is orders of magnitude too low for modern hardware. +# The values must be within the 1000-999999999 range. +# If only one of the MIN or MAX values is set, then this value will be used. +# If MIN > MAX, the highest value will be used. +# +#SHA_CRYPT_MIN_ROUNDS 5000 +#SHA_CRYPT_MAX_ROUNDS 5000 + +# +# Only works if ENCRYPT_METHOD is set to BCRYPT. +# +# Define the number of BCRYPT rounds. +# With a lot of rounds, it is more difficult to brute-force the password. +# However, more CPU resources will be needed to authenticate users if +# this value is increased. +# +# If not specified, 13 rounds will be attempted. +# If only one of the MIN or MAX values is set, then this value will be used. +# If MIN > MAX, the highest value will be used. +# +#BCRYPT_MIN_ROUNDS 13 +#BCRYPT_MAX_ROUNDS 13 + +# +# Only works if ENCRYPT_METHOD is set to YESCRYPT. +# +# Define the YESCRYPT cost factor. +# With a higher cost factor, it is more difficult to brute-force the password. +# However, more CPU time and more memory will be needed to authenticate users +# if this value is increased. +# +# If not specified, a cost factor of 5 will be used. +# The value must be within the 1-11 range. +# +#YESCRYPT_COST_FACTOR 5 + +# +# List of groups to add to the user's supplementary group set +# when logging in from the console (as determined by the CONSOLE +# setting). Default is none. +# +# Use with caution - it is possible for users to gain permanent +# access to these groups, even when not logged in from the console. +# How to do it is left as an exercise for the reader... +# +#CONSOLE_GROUPS floppy:audio:cdrom + +# +# Should login be allowed if we can't cd to the home directory? +# Default is no. +# +DEFAULT_HOME yes + +# +# The pwck(8) utility emits a warning for any system account with a home +# directory that does not exist. Some system accounts intentionally do not +# have a home directory. Such accounts may have this string as their home +# directory in /etc/passwd to avoid a spurious warning. +# +NONEXISTENT /nonexistent + +# +# If this file exists and is readable, login environment will be +# read from it. Every line should be in the form name=value. +# +ENVIRON_FILE /etc/environment + +# +# If defined, this command is run when removing a user. +# It should remove any at/cron/print jobs etc. owned by +# the user to be removed (passed as the first argument). +# +#USERDEL_CMD /usr/sbin/userdel_local + +# +# Enable setting of the umask group bits to be the same as owner bits +# (examples: 022 -> 002, 077 -> 007) for non-root users, if the uid is +# the same as gid, and username is the same as the primary group name. +# +# This also enables userdel(8) to remove user groups if no members exist. +# +USERGROUPS_ENAB yes + +# +# If set to a non-zero number, the shadow utilities will make sure that +# groups never have more than this number of users on one line. +# This permits to support split groups (groups split into multiple lines, +# with the same group ID, to avoid limitation of the line length in the +# group file). +# +# 0 is the default value and disables this feature. +# +#MAX_MEMBERS_PER_GROUP 0 + +# +# If useradd(8) should create home directories for users by default (non +# system users only). +# This option is overridden with the -M or -m flags on the useradd(8) +# command-line. +# +#CREATE_HOME yes + +# +# Force use shadow, even if shadow passwd & shadow group files are +# missing. +# +#FORCE_SHADOW yes + +# +# Allow newuidmap and newgidmap when running under an alternative +# primary group. +# +#GRANT_AUX_GROUP_SUBIDS yes + +# +# Prevents an empty password field to be interpreted as "no authentication +# required". +# Set to "yes" to prevent for all accounts +# Set to "superuser" to prevent for UID 0 / root (default) +# Set to "no" to not prevent for any account (dangerous, historical default) +PREVENT_NO_AUTH superuser + +# +# Select the HMAC cryptography algorithm. +# Used in pam_timestamp module to calculate the keyed-hash message +# authentication code. +# +# Note: it is recommended to check hmac(3) to see the possible algorithms +# that are available in your system. +# +#HMAC_CRYPTO_ALGO SHA512 + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/29-shell-umask.txt b/screenshots/09-networking-and-system-audit/29-shell-umask.txt new file mode 100644 index 0000000..0d1f7c0 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/29-shell-umask.txt @@ -0,0 +1,5 @@ +Command: bash -c umask + +0022 + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/30-system-users-shells.txt b/screenshots/09-networking-and-system-audit/30-system-users-shells.txt new file mode 100644 index 0000000..81e2e45 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/30-system-users-shells.txt @@ -0,0 +1,5 @@ +Command: bash -c awk -F: '$7 !~ /(false|nologin)$/ {print $1 ":" $7}' /etc/passwd + +root:/bin/bash + +Exit status: 0 diff --git a/screenshots/09-networking-and-system-audit/README.md b/screenshots/09-networking-and-system-audit/README.md new file mode 100644 index 0000000..d1da9aa --- /dev/null +++ b/screenshots/09-networking-and-system-audit/README.md @@ -0,0 +1,60 @@ +# Networking and System Audit Evidence + +This directory contains 30 individual text captures from the Phase 2 and Phase 3 read-only audit. + +## File map + +### Phase 2 + +1. `01-network-interfaces.txt` +2. `02-ip-addresses.txt` +3. `03-routing-table.txt` +4. `04-dns-resolution.txt` +5. `05-listening-sockets.txt` +6. `06-running-services.txt` +7. `07-failed-services.txt` +8. `08-user-accounts.txt` +9. `09-groups.txt` +10. `10-account-file-permissions.txt` +11. `11-sshd-enabled-state.txt` +12. `12-kernel-information.txt` +13. `13-os-release.txt` +14. `14-hostname.txt` + +### Phase 3 + +15. `15-resolvectl-status.txt` +16. `16-resolved-service.txt` +17. `17-networkd-service.txt` +18. `18-resolv-conf.txt` +19. `19-resolved-conf.txt` +20. `20-network-config-file-list.txt` +21. `21-enabled-services.txt` +22. `22-systemd-security.txt` +23. `23-nftables-rules.txt` +24. `24-iptables-rules.txt` +25. `25-ipv4-forwarding.txt` +26. `26-ipv6-forwarding.txt` +27. `27-kernel-network-hardening.txt` +28. `28-login-definitions.txt` +29. `29-shell-umask.txt` +30. `30-system-users-shells.txt` + +## Anonymization + +The published captures retain technical lines, command output, errors, versions, configuration values, and service names. Identifying values are replaced consistently: + +- Hardware MAC addresses: `` (the standard all-zero loopback value is retained) +- MAC-derived IPv6 link-local interface identifier: `fe80::[ANONYMIZED_INTERFACE_ID]/64` +- Machine ID: `` +- Boot ID: `` +- Product UUID: `` +- systemd invocation IDs: `` + +Private IPv4 addresses, interface names, and the hostname `lfs` are retained because they are needed to understand the captured virtual-network topology. The original system was not modified. + +## Evidence integrity + +The Phase 3 collector's exit-status annotation has a logging defect and must not be treated as authoritative. Preserve the command output and document this limitation. The Phase 2 SSH unit lookup explicitly returned `not-found` with exit status 4. + +See [the audit report](../../docs/networking-and-security-audit.md) for interpretation, limitations, and findings. diff --git a/screenshots/09-networking-and-system-audit/collection-metadata.txt b/screenshots/09-networking-and-system-audit/collection-metadata.txt new file mode 100644 index 0000000..e1a5460 --- /dev/null +++ b/screenshots/09-networking-and-system-audit/collection-metadata.txt @@ -0,0 +1,10 @@ +LFS Phase 3 Security and Network Audit + +Collected: 2026-11-15T00:57:55+03:30 +Hostname: lfs +Kernel: 7.1.8 + +This is a read-only configuration audit. +No firewall, resolver, account, or kernel settings were changed. + +Review output before publishing. diff --git a/screenshots/README.md b/screenshots/README.md index 7aba130..a8c781c 100644 --- a/screenshots/README.md +++ b/screenshots/README.md @@ -14,6 +14,7 @@ This directory contains visual and technical evidence for **Linux From Scratch 1 | `06-kernel-and-bootloader/` | Kernel configuration, modules, boot files and GRUB | | `07-testing-and-validation/` | Existing test-log inventory and validation archive | | `08-final-system/` | GRUB menu, first boot and final system state | +| `09-networking-and-system-audit/` | 30 individual networking/security command captures, anonymized identifiers and audit documentation | ## Build reference @@ -29,3 +30,5 @@ Official book: https://www.linuxfromscratch.org/lfs/view/13.1-systemd/ Captured output describes what was reported at collection time. A command-presence check is not a package test result, and a compiler smoke test is not a full toolchain test suite. The compiler capture reporting `x86_64-pc-linux-gnu` is kept distinct from the LFS target triplet. See [the testing methodology](../docs/testing-and-validation.md). The test archive is retained as collected; its contents should be inspected before drawing package-wide conclusions. + +The networking/security evidence is a read-only baseline snapshot, not a penetration test or a firewall verification. See the [networking and security audit](../docs/networking-and-security-audit.md) for scope and limitations. diff --git a/scripts/collect-evidence/README.md b/scripts/collect-evidence/README.md index f3df075..a714a3e 100644 --- a/scripts/collect-evidence/README.md +++ b/scripts/collect-evidence/README.md @@ -8,11 +8,25 @@ These scripts collect selected information from the system where they are execut | `collect-kernel-bootloader-evidence.sh` | Captures kernel, modules, boot files and GRUB information | | `collect-testing-validation-evidence.sh` | Inventories existing package test logs and extracts recognizable counters | | `collect-final-system-evidence.sh` | Captures final system, kernel, systemd and filesystem state | +| `collect-network-security-evidence.sh` | Read-only collection of 30 networking/security command outputs with correct exit-status capture | +| `anonymize-audit-evidence.py` | Writes anonymized copies of text evidence without modifying originals | -## Execution +## Network/security evidence -The scripts default to output directories under `/root/`. Run them with appropriate privileges inside the LFS system, or provide an alternate output directory as the first argument where supported. +Run the collector with Bash and an optional output directory: -Review each script before execution. Captured reports may contain machine-specific details such as disk names, mount points, hostnames and hardware information. +```bash +bash scripts/collect-evidence/collect-network-security-evidence.sh /path/to/raw-evidence +``` -These are collectors, not installers. They do not modify the bootloader or kernel configuration. The testing collector does not rerun package test suites. +The collector writes raw output and collection metadata. When `sha256sum` is available, it also writes a SHA-256 checksum manifest; otherwise it prints a warning and does not create a misleading manifest. It does not change system configuration. Raw captures may contain machine-specific identifiers; create a separate anonymized copy before publishing: + +```bash +python3 scripts/collect-evidence/anonymize-audit-evidence.py /path/to/raw-evidence /path/to/anonymized-evidence +``` + +Review every anonymized file manually. Do not overwrite the originals. + +## General execution + +Review each script before execution. Captured reports may contain host-specific details such as disk names, mount points, hostnames and hardware information. These scripts are collectors, not installers. diff --git a/scripts/collect-evidence/anonymize-audit-evidence.py b/scripts/collect-evidence/anonymize-audit-evidence.py new file mode 100644 index 0000000..a270112 --- /dev/null +++ b/scripts/collect-evidence/anonymize-audit-evidence.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 +"""Write anonymized copies of LFS audit text evidence; never modify originals.""" + +from __future__ import annotations + +import argparse +import re +from pathlib import Path + +MAC_RE = re.compile(r"(?i)\b(?:[0-9a-f]{2}:){5}[0-9a-f]{2}\b") +IPV6_LL_RE = re.compile(r"(?i)(?P
\bfe80::[0-9a-f:]+)(?P/\d{1,3})?\b") +UUID_FIELD_RE = re.compile( + r"(?im)(?P\b(?:Machine\s+ID|Boot\s+ID|Product\s+UUID|Hardware\s+UUID|Invocation(?:\s+ID)?)\s*:\s*)" + r"(?P[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{32})" +) + + +def anonymize(text: str) -> str: + text = MAC_RE.sub( + lambda match: match.group(0) + if match.group(0) == "00:00:00:00:00:00" + else "", + text, + ) + text = IPV6_LL_RE.sub( + lambda match: "fe80::[ANONYMIZED_INTERFACE_ID]" + (match.group("prefix") or ""), + text, + ) + + def replace_uuid(match: re.Match[str]) -> str: + label = match.group("prefix").lower() + if "machine" in label: + token = "" + elif "boot" in label: + token = "" + elif "product" in label or "hardware" in label: + token = "" + else: + token = "" + return match.group("prefix") + token + + text = UUID_FIELD_RE.sub(replace_uuid, text) + text = re.sub(r"(?im)(\bInvocation:\s*)[0-9a-f]{32}\b", r"\1", text) + return text + + +def main() -> int: + parser = argparse.ArgumentParser() + parser.add_argument("source", type=Path, help="Directory containing original .txt evidence") + parser.add_argument("destination", type=Path, help="Separate directory for anonymized copies") + args = parser.parse_args() + + source = args.source.resolve() + destination = args.destination.resolve() + if not source.is_dir(): + parser.error(f"source directory does not exist: {source}") + if source == destination or source in destination.parents or destination in source.parents: + parser.error("source and destination directories must not overlap") + + files = sorted(source.glob("*.txt")) + if not files: + parser.error(f"no .txt files found in {source}") + + destination.mkdir(parents=True, exist_ok=True) + for original_path in files: + original = original_path.read_text(encoding="utf-8", errors="replace") + (destination / original_path.name).write_text(anonymize(original), encoding="utf-8") + + print(f"Anonymized copies written: {len(files)}") + print(f"Originals unchanged: {source}") + print(f"Anonymized output: {destination}") + print("Review every output manually before publication.") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/scripts/collect-evidence/collect-network-security-evidence.sh b/scripts/collect-evidence/collect-network-security-evidence.sh new file mode 100644 index 0000000..e9c4bc9 --- /dev/null +++ b/scripts/collect-evidence/collect-network-security-evidence.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +# Read-only LFS networking/security evidence collector. +# Writes raw output only to the selected output directory. +set -u + +OUTPUT_DIR="${1:-$PWD/lfs-network-security-evidence-raw}" +mkdir -p -- "$OUTPUT_DIR" || exit 1 +OUTPUT_DIR="$(cd -- "$OUTPUT_DIR" && pwd -P)" || exit 1 + +capture() { + local filename="$1" + shift + local status + { + printf 'Command:' + printf ' %q' "$@" + printf '\n\n' + if "$@" 2>&1; then + status=0 + else + status=$? + fi + printf '\nExit status: %d\n' "$status" + } > "$OUTPUT_DIR/$filename" +} + +capture 01-network-interfaces.txt ip -br link +capture 02-ip-addresses.txt ip -br address +capture 03-routing-table.txt ip route show +capture 04-dns-resolution.txt getent hosts example.com +capture 05-listening-sockets.txt ss -tulpn +capture 06-running-services.txt systemctl list-units --type=service --state=running --no-pager +capture 07-failed-services.txt systemctl --failed --no-pager +capture 08-user-accounts.txt getent passwd +capture 09-groups.txt getent group +capture 10-account-file-permissions.txt stat /etc/passwd /etc/group /etc/shadow +capture 11-sshd-enabled-state.txt systemctl is-enabled sshd +capture 12-kernel-information.txt uname -a +capture 13-os-release.txt cat /etc/os-release +capture 14-hostname.txt hostnamectl status + +capture 15-resolvectl-status.txt resolvectl status +capture 16-resolved-service.txt systemctl status systemd-resolved --no-pager +capture 17-networkd-service.txt systemctl status systemd-networkd --no-pager +capture 18-resolv-conf.txt bash -c 'printf "resolv.conf symlink:\n"; readlink /etc/resolv.conf; printf "\nresolv.conf contents:\n"; cat /etc/resolv.conf' +capture 19-resolved-conf.txt cat /etc/systemd/resolved.conf +capture 20-network-config-file-list.txt find /etc/systemd/network -maxdepth 1 -type f -print +capture 21-enabled-services.txt systemctl list-unit-files --state=enabled --no-pager +capture 22-systemd-security.txt systemd-analyze security --no-pager +capture 23-nftables-rules.txt nft list ruleset +capture 24-iptables-rules.txt iptables-save +capture 25-ipv4-forwarding.txt sysctl net.ipv4.ip_forward +capture 26-ipv6-forwarding.txt sysctl net.ipv6.conf.all.forwarding +capture 27-kernel-network-hardening.txt sysctl net.ipv4.conf.all.rp_filter net.ipv4.conf.all.accept_redirects net.ipv4.conf.all.send_redirects net.ipv4.conf.all.accept_source_route net.ipv6.conf.all.accept_redirects +capture 28-login-definitions.txt cat /etc/login.defs +capture 29-shell-umask.txt bash -c umask +capture 30-system-users-shells.txt awk -F: '$7 !~ /(false|nologin)$/ {print $1 ":" $7}' /etc/passwd + +{ + printf 'LFS Networking and Security Evidence Collection\n\n' + printf 'Collected: ' + date --iso-8601=seconds + printf 'Hostname: ' + hostname + printf 'Kernel: ' + uname -r + printf '\nRead-only collection; no system configuration was changed.\n' +} > "$OUTPUT_DIR/collection-metadata.txt" + +if command -v sha256sum >/dev/null 2>&1; then + if ! (cd -- "$OUTPUT_DIR" && sha256sum -- *.txt > SHA256SUMS); then + rm -f -- "$OUTPUT_DIR/SHA256SUMS" + printf 'Warning: checksum generation failed.\n' >&2 + fi +else + printf 'Warning: sha256sum unavailable; no checksum manifest generated.\n' >&2 +fi + +printf 'Raw evidence written to: %s\n' "$OUTPUT_DIR" +printf 'Review and anonymize the output before publishing.\n' diff --git a/scripts/collect-evidence/test_anonymize_audit_evidence.py b/scripts/collect-evidence/test_anonymize_audit_evidence.py new file mode 100644 index 0000000..e81d71f --- /dev/null +++ b/scripts/collect-evidence/test_anonymize_audit_evidence.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python3 +"""Unit tests for anonymize-audit-evidence.py.""" + +from __future__ import annotations + +import importlib.util +import subprocess +import sys +import tempfile +import unittest +from pathlib import Path + +SCRIPT = Path(__file__).with_name("anonymize-audit-evidence.py") +SPEC = importlib.util.spec_from_file_location("anonymize_audit_evidence", SCRIPT) +assert SPEC is not None and SPEC.loader is not None +MODULE = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(MODULE) + + +class AnonymizeTests(unittest.TestCase): + def test_replaces_mac_and_preserves_other_values(self) -> None: + source = "MAC=52:54:00:73:b0:78 IP=192.168.122.54" + result = MODULE.anonymize(source) + self.assertEqual(result, "MAC= IP=192.168.122.54") + + def test_zero_loopback_mac_is_preserved(self) -> None: + self.assertEqual( + MODULE.anonymize("lo 00:00:00:00:00:00"), + "lo 00:00:00:00:00:00", + ) + + def test_link_local_prefix_is_preserved_when_present(self) -> None: + self.assertEqual( + MODULE.anonymize("fe80::5054:ff:fe73:b078/64"), + "fe80::[ANONYMIZED_INTERFACE_ID]/64", + ) + + def test_link_local_without_prefix_does_not_gain_one(self) -> None: + self.assertEqual( + MODULE.anonymize("fe80::5054:ff:fe73:b078"), + "fe80::[ANONYMIZED_INTERFACE_ID]", + ) + + def test_uuid_fields_are_replaced(self) -> None: + source = ( + "Machine ID: 0123456789abcdef0123456789abcdef\n" + "Boot ID: 01234567-89ab-cdef-0123-456789abcdef\n" + "Product UUID: 01234567-89ab-cdef-0123-456789abcdef\n" + "Invocation: 0123456789abcdef0123456789abcdef" + ) + result = MODULE.anonymize(source) + self.assertIn("Machine ID: ", result) + self.assertIn("Boot ID: ", result) + self.assertIn("Product UUID: ", result) + self.assertIn("Invocation: ", result) + + def test_cli_writes_separate_copy_and_preserves_original(self) -> None: + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + source = root / "source" + destination = root / "destination" + source.mkdir() + original = source / "capture.txt" + original.write_text("52:54:00:73:b0:78\n", encoding="utf-8") + + result = subprocess.run( + [sys.executable, str(SCRIPT), str(source), str(destination)], + check=False, + capture_output=True, + text=True, + ) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(original.read_text(encoding="utf-8"), "52:54:00:73:b0:78\n") + self.assertEqual( + (destination / "capture.txt").read_text(encoding="utf-8"), + "\n", + ) + + def test_cli_rejects_overlapping_directories(self) -> None: + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + source = root / "source" + source.mkdir() + nested = source / "nested" + result = subprocess.run( + [sys.executable, str(SCRIPT), str(source), str(nested)], + check=False, + capture_output=True, + text=True, + ) + self.assertNotEqual(result.returncode, 0) + self.assertIn("must not overlap", result.stderr) + + def test_cli_rejects_destination_that_contains_source(self) -> None: + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + source = root / "parent" / "source" + source.mkdir(parents=True) + destination = source.parent + result = subprocess.run( + [sys.executable, str(SCRIPT), str(source), str(destination)], + check=False, + capture_output=True, + text=True, + ) + self.assertNotEqual(result.returncode, 0) + self.assertIn("must not overlap", result.stderr) + + +if __name__ == "__main__": + unittest.main()