system: set_hostname writes /etc/hosts through a fixed /tmp file as root #66

Closed
opened 2026-11-12 21:31:57 +00:00 by christianmanivong · 0 comments
Owner

Prio: P3

Found in netOrk's security sweep of 2026-11-12 (NetOrk/netork#2446).

system_mixin.set_hostname() rewrites /etc/hosts as root with echo <b64> | base64 -d > /tmp/_netork_hosts && mv /tmp/_netork_hosts /etc/hosts && chmod 644 /etc/hosts. The name in /tmp is fixed and world-writable territory: a local user can create /tmp/_netork_hosts (or a symlink there) beforehand. The redirection then writes into the user's file, and mv puts a file the user owns at /etc/hosts, which the user can rewrite afterwards (or the symlink sends root's write elsewhere).

Fix: write into a mktemp file created next to the target (/etc/.hosts.XXXXXX, root-only directory, same filesystem), chmod 644, then mv over /etc/hosts; remove the temporary file if a step fails.

Prio: P3 Found in netOrk's security sweep of 2026-11-12 (NetOrk/netork#2446). `system_mixin.set_hostname()` rewrites `/etc/hosts` as root with `echo <b64> | base64 -d > /tmp/_netork_hosts && mv /tmp/_netork_hosts /etc/hosts && chmod 644 /etc/hosts`. The name in `/tmp` is fixed and world-writable territory: a local user can create `/tmp/_netork_hosts` (or a symlink there) beforehand. The redirection then writes into the user's file, and `mv` puts a file the user owns at `/etc/hosts`, which the user can rewrite afterwards (or the symlink sends root's write elsewhere). **Fix:** write into a `mktemp` file created next to the target (`/etc/.hosts.XXXXXX`, root-only directory, same filesystem), `chmod 644`, then `mv` over `/etc/hosts`; remove the temporary file if a step fails.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NAPALM/napalm-proxmox#66