离线安装App Protect
2020-06-23 13:55:35
晏顺
一、 App Protect介绍
NGINX App Protect是一种新的应用安全解决方案,它将先进的F5 WAF技术的功效与NGINX Plus的敏捷性和性能相结合。该解决方案在NGINX Plus上本地运行,可解决现代DevOps环境面临的一些最困难的挑战:
· 将安全控制直接集成到开发自动化管道中
· 为现代和分布式应用程序环境(例如容器和微服务)应用和管理安全性
· 提供适当级别的安全控制,而不会影响发布和上市速度
· 符合安全和法规要求
二、 需求描述
在Nginx官网链接https://docs.nginx.com/nginx-app-protect/admin-guide/ 中描述了在线的安装方式。然而在生产场景中为了确保安全性,通常不会允许主机直接连接互联网进行软件的安装和升级。因此,在现实环境中存在大量的离线安装Nginx,App Protect以及更新App Protect signature的需求。
三、 离线安装步骤
通过一台可以连接互联网的机器(以Centos7为例)下载所需的安装包
3.1 创建/etc/ssl/nginx目录
sudo mkdir -p /etc/ssl/nginx
3.2 将以下文件上传至步骤3.1创建的目录
nginx-repo.key
nginx-repo.crt
3.3 安装需要的软件包
sudo yum install ca-certificates epel-release wget
3.4 将nginx-plus-7.repo加入到/etc/yum.repos.d
sudo wget -P /etc/yum.repos.d https://cs.nginx.com/static/files/nginx-plus-7.repo
3.5 通过以下命令下载app-protec所有依赖的软件包
sudo yum install --downloadonly --downloaddir=/root/app app-protect
3.6 查看/root/app目录,确认nginx-plus的rpm是否存在,如不存在也需手动下载。
ls -l /root/app
total 38196
-rw-r--r--. 1 root root 19776 Jun 8 11:36 app-protect-22+2.52.5-1.el7.ngx.x86_64.rpm
-rw-r--r--. 1 root root 13562604 May 12 23:49 app-protect-compiler-3.22.6-1.el7.ngx.x86_64.rpm
-rw-r--r--. 1 root root 11886248 May 13 16:51 app-protect-engine-3.22.6-1.el7.ngx.x86_64.rpm
-rw-r--r--. 1 root root 19896 Jun 8 11:36 app-protect-plugin-2.52.5-1.el7.ngx.x86_64.rpm
-rw-r--r--. 1 root root 36256 Apr 27 13:51 boost-atomic-1.53.0-28.el7.x86_64.rpm
-rw-r--r--. 1 root root 44844 Apr 27 13:51 boost-chrono-1.53.0-28.el7.x86_64.rpm
-rw-r--r--. 1 root root 53176 Apr 27 13:51 boost-date-time-1.53.0-28.el7.x86_64.rpm
-rw-r--r--. 1 root root 302624 Apr 27 13:51 boost-regex-1.53.0-28.el7.x86_64.rpm
-rw-r--r--. 1 root root 40732 Apr 27 13:51 boost-system-1.53.0-28.el7.x86_64.rpm
-rw-r--r--. 1 root root 58924 Apr 27 13:51 boost-thread-1.53.0-28.el7.x86_64.rpm
-rw-r--r--. 1 root root 31264 Jan 10 15:39 mailcap-2.1.41-2.el7.noarch.rpm
-rw-r--r--. 1 root root 3562640 Jun 5 15:09 nginx-plus-22-1.el7.ngx.x86_64.rpm
-rw-r--r--. 1 root root 51316 Jun 8 11:36 nginx-plus-module-appprotect-22+2.52.5-1.el7.ngx.x86_64.rpm
-rw-r--r--. 1 root root 169236 Jan 10 15:39 perl-Bit-Vector-7.3-3.el7.x86_64.rpm
sudo yum install --downloadonly --downloaddir=/root/nginx nginx-plus
3.7 增加app protect signature相关的repo,下载对应的rpm包
sudo wget -P /etc/yum.repos.d https://cs.nginx.com/static/files/app-protect-signatures-7.repo
sudo yum install --downloadonly --downloaddir=/root/app-sig app-protect-attack-signatures
3.8 通过ftp/sftp上传上述步骤中下载的rpm包到需要离线安装的主机。通过以下命令安装
cd /root/app
sudo yum --disablerepo=* localinstall *.rpm
3.9 nginx配置中打开app protect相关功能。在nginx.conf中增加:
load_module modules/ngx_http_app_protect_module.so;
more /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
load_module modules/ngx_http_app_protect_module.so;
error_log /var/log/nginx/error.log debug;
pid /var/run/nginx.pid;
3.10 在http/server/location 部分增加
app_protect_enable on;
more default.conf
server {
listen 80 default_server;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
app_protect_enable on;
root /usr/share/nginx/html;
index index.html index.htm;
}
3.11 设置SELinux
sudo setenforce 0
3.12 启动nginx服务,并查看/var/log/nginx/error.log,确认app protect处于connected状态
2020/06/22 02:31:42 [notice] 5405#5405: APP_PROTECT { "event": "waf_connected", "enforcer_thread_id": 0, "worker_pid": 5405, "mode": "operational", "mode_changed": false}
2020/06/22 02:31:42 [notice] 5406#5406: APP_PROTECT { "event": "waf_connected", "enforcer_thread_id": 1, "worker_pid": 5406, "mode": "operational", "mode_changed": false}
3.13 进行简单测试
curl http://localhost <<<<< 正常访问
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
curl http://localhost/?a=\<script\> <<<<<<模拟攻击访问,查看拦截状态
<html>
<head>
<title>Request Rejected</title>
</head>
<body>
The requested URL was rejected. Please consult with your administrator.<br><br>Your support ID is: 13266279912517115499<br><br><a href='javascript:history.back();'>[Go Back]</a>
</body>
</html>
发布评论 加入社群
相关文章

F5 Python SDK简介
Will Tang
2021-07-29 11:55:36 650

自动化的崛起:如何管理当今世界中的BOT
Vanessa.WANG?
2020-11-24 16:40:01 827

iRules 101-#02-if和表达式
CUNHUI
2020-11-09 18:40:29 2207

回复评论
发布评论