本次测试的虚拟机

CentOS 7

卸载旧版本

旧版本的 Docker 称为 docker 或者 docker-engine,如之前有安装,需使用以下命令卸载旧版本:

docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

开始安装

使用 yum 安装

执行以下命令安装依赖包:

yum install -y yum-utils

鉴于国内网络问题,强烈建议使用国内源,官方源请在注释中查看。

执行下面的命令添加 yum 软件源:

--add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo

# 官方源
# yum-config-manager \
#     --add-repo \
#     https://download.docker.com/linux/centos/docker-ce.repo
安装 Docker

更新 yum 软件源缓存,并安装 docker-ce

yum install docker-ce docker-ce-cli containerd.io

启动 Docker

建立 docker 用户组

默认情况下,docker 命令会使用 Unix socket 与 Docker 引擎通讯。而只有 root 用户和 docker 组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑,一般 Linux 系统上不会直接使用 root 用户。因此,更好地做法是将需要使用 docker 的用户加入 docker 用户组。

建立 docker 组:

groupadd docker

将当前用户加入 docker 组:

usermod -aG docker $USER
退出当前终端并重新登录,进行如下测试。

验证 Docker 是否安装成功

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
若能正常输出以上信息,则说明安装成功。

镜像加速器

如果发现后续下载镜像速度非常慢,可配置国内的镜像加速器,下面是配置加速

打开阿里云官网

搜索容器镜像服务

 

cent os7下docker安装halo和雷池WAF后测试防护_docker

点击管理控制台

cent os7下docker安装halo和雷池WAF后测试防护_服务器_02

进入后点击镜像工具

,再点击镜像加速器

cent os7下docker安装halo和雷池WAF后测试防护_docker_03

选择cent os

根据给的代码粘贴到虚拟机中

然后可以重新运行docker run --rm hello-world

#看看速度是否变快

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

 

安装halo

因为是体验所以直接运行

docker run -it -d --name halo -p 8090:8090 -v ~/.halo2:/root/.halo2 registry.fit2cloud.com/halo/halo:2.16

然后访问<ip>:8090

就可以进行网站初始化

 

安装雷池WAF

最低配置需求

  • 操作系统:Linux
  • 指令架构:x86_64
  • 软件依赖:Docker 20.10.14 版本以上
  • 软件依赖:Docker Compose 2.0.0 版本以上
  • 最小化环境:1 核 CPU / 1 GB 内存 / 5 GB 磁盘

可以逐行执行以下命令来确认服务器配置

uname -m                                  # 查看指令架构
docker version                             # 查看 Docker 版本
docker compose version                     # 查看 Docker Compose 版本
docker-compose version                     # 老版本查看Compose 版本
cat /proc/cpuinfo| grep "processor"        # 查看 CPU 信息
free -h                                    # 查看内存信息
df -h                                      # 查看磁盘信息
lscpu | grep ssse3                         # 确认CPU是否支持 ssse3 指令集

在线安装

如果服务器可以访问互联网环境,推荐使用该方式

复制以下命令执行,即可完成安装

bash -c "$(curl -fsSLk https://waf-ce.chaitin.cn/release/latest/setup.sh)"

如果需要使用华为云加速,可使用

CDN=1 bash -c "$(curl -fsSLk https://waf-ce.chaitin.cn/release/latest/setup.sh)"

如果需要安装最新版本流式检测模式,可使用

STREAM=1 bash -c "$(curl -fsSLk https://waf-ce.chaitin.cn/release/latest/setup.sh)"

离线安装

如果服务器不可以访问互联网环境,推荐使用该方式

离线安装前需完成环境检测,默认已完成 docker 环境准备

  1. 下载 雷池社区版镜像包 并传输到需要安装雷池的服务器上,执行以下命令加载镜像
cat image.tar.gz | gzip -d | docker load
  1. 执行以下命令创建并进入雷池安装目录
mkdir -p safeline && cd safeline # 创建 safeline 目录并且进入
  1. 下载 编排脚本 并传输到 safeline 目录中
  2. 复制执行以下命令,生成雷池运行所需的相关环境变量
cat >> .env <<EOF
SAFELINE_DIR=$(pwd)
IMAGE_TAG=latest
MGT_PORT=9443
POSTGRES_PASSWORD=$(LC_ALL=C tr -dc A-Za-z0-9 </dev/urandom | head -c 32)
SUBNET_PREFIX=172.22.222
IMAGE_PREFIX=chaitin
EOF

注意:不要一行一行复制,一次性复制全部命令后执行,如图

cent os7下docker安装halo和雷池WAF后测试防护_docker_04

  1. 执行以下命令启动雷池
     
docker compose up -d

登录雷池

登录流程

1.浏览器打开后台管理页面 https://<waf-ip>:9443

2.输入初始的admin密码

完成安装后在shell会自动输出密码。

cent os7下docker安装halo和雷池WAF后测试防护_Docker_05

若忘记查看,需手动执行重置命令获得初始密码

docker exec safeline-mgt resetadmin

配置站点

点击站点管理

点击添加站点

因为是测试所以域名填空

端口默认为80

上游服务器填写http://<ip>:8090

点击添加

 

测试防护

确认网站可以正常访问

根据雷池 WAF 配置的网站参数访问你的网站。

打开浏览器访问 http://<IP或域名>:<端口>/

尝试手动模拟攻击

访问以下地址模拟出对应的攻击:

  • 模拟 SQL 注入,请访问 http://<IP或域名>/?id=1%20AND%201=1
  • 模拟 XSS,请访问 http://<IP或域名>/?html=<script>alert(1)</script>

通过浏览器,你将会看到雷池已经发现并阻断了攻击请求。 

cent os7下docker安装halo和雷池WAF后测试防护_Docker_06

然后就结束了,下面是雷池简介

雷池简介

什么是雷池

雷池(SafeLine)是长亭科技耗时近 10 年倾情打造的 WAF,核心检测能力由智能语义分析算法驱动。

Slogan: 不让黑客越雷池一步。

什么是 WAF

WAF 是 Web Application Firewall 的缩写,也被称为 Web 应用防火墙。

区别于传统防火墙,WAF 工作在应用层,对基于 HTTP/HTTPS 协议的 Web 系统有着更好的防护效果,使其免于受到黑客的攻击。

为什么是雷池

便捷性

采用容器化部署,一条命令即可完成安装,0 成本上手

安全配置开箱即用,无需人工维护,可实现安全躺平式管理

安全性

首创业内领先的智能语义分析算法,精准检测、低误报、难绕过

语义分析算法无规则,面对未知特征的 0day 攻击不再手足无措

高性能

无规则引擎,线性安全检测算法,平均请求检测延迟在 1 毫秒级别

并发能力强,单核轻松检测 2000+ TPS,只要硬件足够强,可支撑的流量规模无上限

高可用

流量处理引擎基于 Nginx 开发,性能与稳定性均可得到保障

内置完善的健康检查机制,服务可用性高达 99.99%

WAF 部署架构

下图是一个简单的网站流量拓扑,外部用户发出请求,经过网络最终传递到网站服务器。

此时,若外部用户中存在恶意用户,那么由恶意用户发出的攻击请求也会经过网络最终传递到网站服务器。

cent os7下docker安装halo和雷池WAF后测试防护_服务器_07

社区版雷池以反向代理方式接入,优先于网站服务器接收流量,对流量中的攻击行为进行检测和清洗,将清洗过后的流量转发给网站服务器。

通过以上行为,最终确保外部攻击流量无法触达网站服务器。

cent os7下docker安装halo和雷池WAF后测试防护_docker_08

雷池WAF的更多使用技巧需要读者们自行研究