Skip to content

cf-execd: Rejected runagent socket requests injecting cf-runagent args - #6506

Open
Dhanu-dynamic wants to merge 1 commit into
cfengine:masterfrom
Dhanu-dynamic:execd-runagent-socket-arg-injection
Open

Dhanu-dynamic wants to merge 1 commit into
cfengine:masterfrom
Dhanu-dynamic:execd-runagent-socket-arg-injection

Conversation

@Dhanu-dynamic

Copy link
Copy Markdown
Contributor

HandleRunagentRequest() reads one line from runagent.socket, the host to
hail, and for a non-localhost request builds the command

<bindir>/cf-runagent -b -H <request>

which cf_popen() runs as root after ArgSplitCommand() splits it into argv
on whitespace, treating quotes as delimiters. The request was used
verbatim, so one containing a space, tab or quote appends further
arguments to cf-runagent. A caller allowed on the socket through
runagent_socket_allow_users (cfapache on an Enterprise hub) is only meant
to pick a host, but a request like "host -f /tmp/evil.cf" makes
cf-runagent load another policy as root, and injected "-D", "-s" or
"--remote-bundles" reach the remote agents, which the socket interface is
documented not to allow. There is no shell, so this is argument injection,
not command injection.

Refuse any request containing whitespace or a quote character before
building the command, which no host name, IP, host:port or comma-separated
host list contains. The same JSON error reply as the other failure paths
is sent.

HandleRunagentRequest() reads one line from runagent.socket, the host to
hail, and for a non-localhost request builds the command

    <bindir>/cf-runagent -b -H <request>

which cf_popen() runs as root after ArgSplitCommand() splits it into argv
on whitespace, treating quotes as delimiters. The request was used
verbatim, so one containing a space, tab or quote appends further
arguments to cf-runagent. A caller allowed on the socket through
runagent_socket_allow_users (cfapache on an Enterprise hub) is only meant
to pick a host, but a request like "host -f /tmp/evil.cf" makes
cf-runagent load another policy as root, and injected "-D", "-s" or
"--remote-bundles" reach the remote agents, which the socket interface is
documented not to allow. There is no shell, so this is argument injection,
not command injection.

Refuse any request containing whitespace or a quote character before
building the command, which no host name, IP, host:port or comma-separated
host list contains. The same JSON error reply as the other failure paths
is sent.

Changelog: Title
Signed-off-by: Dhanraj E <dhanraj@labs.digiscrypt.com>
@cf-bottom

Copy link
Copy Markdown

Thank you for submitting a PR! Maybe @craigcomstock can review this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants