原文链接:基于docker的网络安全靶场搭建(建议收藏 -实战靶场)
背景介绍 在学习网络安全技术过程中,我们往往需要有一个自己的操作机与多个用来搭建环境的靶机,使用VM虚拟机模拟资源占用较大,成本高、局限性大且使用十分不便。 这时我们可以使用一台安装好Docker环境的linux虚拟机来完成桌面版操作机与WEB靶机的搭建与实验操作。 Docker 包括三个基本概念: ● 镜像(Image) ● 容器(Container) ● 仓库(Repository) 操作机与靶机制作: ● kali操作机:kali-top10、xfce、xrdp ● web靶机:tomcat、mysql、ssh ~不用纠结 操作机肯定是有图形化桌面,简单易懂安装步骤与复制粘贴的操作命令。 事先准备一台linux主机,并且已安装好docker环境。centos安装docker环境如下: - <p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"><font face="宋体">查询可安装版本:</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"><font face="Calibri">yum list docker-ce --showduplicates | sort -r</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"><font face="宋体">安装</font><font face="Calibri">docker-ce</font><font face="宋体">:</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"><font face="Calibri">yum install docker-ce-20.10.6 docker-ce-cli-20.10.6 containerd.io</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"><font face="宋体">查看是否安装成功:</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"><font face="Calibri">docker version</font><font face="宋体">或者</font><font face="Calibri">docker info</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"><font face="宋体">安装启动</font><font face="Calibri">docker: </font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"><font face="Calibri">systemctl start docker</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"><font face="宋体">开机自启:</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"><font face="Calibri">systemctl enable docker</font></span></p>
复制代码
#2 操作机制作 一、操作机基础工具安装 操作机:拉取kali基础镜像,安装基础工具包、GUI,配置XRDP进行远程控制。 1、搜索kali基础镜像: docker search kali 图中kalilinux/kali-rolling、kalilinux/kali镜像都可使用。 2、拉取基础镜像: docker pull kalilinux/kali-rolling 3、查看拉取镜像: docker images 4、启动容器: docker run -itd -p 3399:3389 kalilinux/kali-rolling /bin/bash 输出容器ID表示启动成功。 5、查看容器信息: docker ps 6、进入容器: docker attach ID 7、安装基础环境包: - <p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"><font face="Calibri">apt-get -y update && apt-get -y upgrade && \</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"> <font face="Calibri">DEBIAN_FRONTEND=noninteractive apt-get install -y \</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"> <font face="Calibri">kali-tools-top10 \</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"> <font face="Calibri">pciutils \</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"> <font face="Calibri">vim \</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"> <font face="Calibri">iputils-ping \</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"> <font face="Calibri">bash-completion && \</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"> <font face="Calibri">apt-get autoremove -y && \</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"> <font face="Calibri">apt-get clean</font></span></p>
复制代码
●kali-tools-top10:最常用的工具,推荐其他kali-Metapackages kali-linux-default:“默认”桌面 (amd64/i386) 图像包括这些工具、kali-linux-large:我们以前用于 amd64/i386 图像的默认工具、kali-linux-everything:这里列出的每个元包和工具(选择安装自己需要的软件包)。 ● pciutils:lspci工具 ● bash-completion :命令自动补全 ● vim :文本编辑器 ● iputils: iputils软件包是linux环境下一些实用的网络工具的集合 等待安装完成...... 8、生成镜像: docker commit ID kali-2021 在容器内安装需要的基础工具与命令后,将容器重新打包成新的镜像。 二、远程桌面环境安装 1、使用新镜像生成容器并进入容器: docker run -itd -p 3399:3389 kali-2021 这次运行容器需映射xrdp的端口,不带bash因与xfce存在冲突。 2、进入容器: docker exec -it ID /bin/bash 临时开启bash, 如果从这个容器退出,容器不会停止。 3、更换Kali源: - <p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"><font face="Calibri">vi /etc/apt/source.list</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"> </span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"><font face="Calibri">deb http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"><font face="Calibri">deb-src http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib</font></span><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"></span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"> </span></p><p class="MsoNormal"><span style="mso-spacerun:'yes';font-family:宋体;mso-ascii-font-family:Calibri;
- mso-hansi-font-family:Calibri;mso-bidi-font-family:'Times New Roman';font-size:10.5000pt;
- mso-font-kerning:1.0000pt;"><font face="Calibri">apt-get update</font></span></p>
复制代码
4、安装桌面环境相关服务: apt-get -y install kali-desktop-xfce xorg xrdp ● kali-desktop-xfce :安装远程桌面环境 ● xrdp :远程桌面服务 ● xorg:xorg是x11的一个实现,xorg提供X server 访问 Kali GUI 的一种简单方法是安装 Xfce 并设置 XRDP。 5、配置xrdp实现远程连接图形界面: sed -i 's/port=3399/port=3389/g' /etc/xrdp/xrdp.ini service xrdp restart 6、打开远程桌面进行登录:
这时就可以打开远程桌面连接对docker版kali操作机的XRDP进行连接。第一次连接一般会出现登录错误,需修改容器的root用户密码。 7、修改root用户密码: passwd root 修改成功。 8、再次登录XRDP: 输入修改账号密码。 访问成功,开始使用吧。 #3 WEB靶机制作 WEB靶机 :mysql数据库、tomcat服务、搭建JAVAWEB应用。 1、拉取基础镜像: docker run -d --name="tomcat-mysql-run" -e MYSQL_PASSWORD=root -p 1306:3306 -p 1080:8080 aallam/tomcat-mysql 数据密码为root,映射端口 1306 、1080 。 2、进入已运行容器: docker exec –it ID /bin/bash
3、进入容器修改mysql配置信息: ● 新建文件夹:mkdir -p /data/mysql ● 修改MYSQL数据库配置文件:vi /etc/mysql/my.cnf ● datadir =/data/mysql 因容器对数据库的数据存放文件路径进行本地映射,不存放在的容器里,如不修改数据存放文件,容器关闭时数据也将丢失。 4、连接mysql数据库:
输入主机、端口(1306)、用户名、密码,连接成功。 5、导入数据库,运行.sql文件:
6、访问主机的1080 端口: 7、进入tomcat的管理界面,上传WAR包文件:
8、点击访问上传的war网站:
访问成功,开始测试吧。 #4 文章总结 文章主要讲述docker实验环境搭建,从无到有定制化自己的操作机与靶机,无docker命令基础也可以按照文章一步步搭建环境,以制作环境为目的而不是单纯的命令使用。主要掌握在制作过程中使用到的docker命令。 作者:Ezreal,转载于国科漏斗社区 如侵权,私信删除。
|