前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >自己动手,DIY一台硬件WAF!

自己动手,DIY一台硬件WAF!

作者头像
FB客服
发布2019-11-08 09:57:59
1.8K0
发布2019-11-08 09:57:59
举报
文章被收录于专栏:FreeBufFreeBuf

硬件WAF,好像是很高端,很神秘的样子,而且很贵。今天向大家展示如何自己动手,DIY一台硬件WAF!

一、软硬件需求

a、服务器一台 b、系统:Linux CentOS c、软件:ShareWAF d、硬件需求:Bypass网卡

简单说明:

a、使用linux系统,是为了在系统中搭建网桥,有了网桥,就可以实现硬件WAF的透明代理效果。 b、软件用ShareWAF,ShareWAF是一款WAF软件,可以在云端部署,也支持灌装硬件(这一点很重要)。而且,防护功能不错,目前最大支持同时保护256个网站。 c、Bypass网卡,主要是实现断电、系统故障等情况下自动将硬件“变”成为网线,实现Bypass效果,达到各种问题下都不中断业务功能,也就是实现高可用。

如果没有Bypass网卡,或者不是很需要高可用,那么灌装出来的硬件是一台透明代理硬件WAF,只是不具备bypass功能。(一般情况下,除了银行之类,别的单位很少能用着这种级别的高可用设备,因为还可以多机热备嘛,所以,其实没有bypass网卡也没太大关系)。

二、准备工作

ETH1网口连通外网,并给其设置IP;

ETH2,ETH3为一双Bypass网口,为做网桥使用;

ETH3口连接内网web服务器。

三、系统配置,实现透明代理

(完整详细步骤,如果熟悉linux网络操作命令的话,其中有些环节可以跳过)

关闭centos 7自带防火墙

systemctl stop firewalld.service
systemctl disable firewalld.service

安装iptables

yum -y install iptables
yum -y install iptables-services

开启iptables

service iptables start

清除Iptables自带规则

iptables -F

安装ifconfig

yum -y install net-tools.x86_64

安装网桥

yum -y install bridge-utils

设置网桥

/sbin/modprobe bridge
/usr/sbin/brctl addbr br0(设置网桥名为br0)
/sbin/ifup enp4s0 (要加入网桥的网卡,通过ifconfig查看)
/sbin/ifup enp5s0 (要加入网桥的网卡)

注:执行以上两步之前最好将能通的网线插在网口上,否则执行时间会稍长,会显示激活失败。

如果以上步骤报错:

无法创建 NMClient 对象GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: Method "GetManagedObjects" with signature "" on interface "org.freedesktop.DBus.ObjectManager" doesn't exist

这时,执行如下命令:

chkconfig NetworkManager offchkconfig network onservice NetworkManager stopservice network start/usr/sbin/brctl addif br0 enp4s0/usr/sbin/brctl addif br0 enp5s0

设置网桥IP (例:192.168.1.73 设置一个在内网网段的IP)

ifconfig br0 192.168.1.73 netmask 255.255.255.0

开启网桥

/sbin/ip link set br0 up

查看

sudo brctl show

关闭

ifconfig br0 down

删除 (删除前先将网桥关闭)

sudo brctl delbr br0

在/etc/sysctl.conf下添加内容

vi /etc/sysctl.conf

将光标移至文字最后一行按o,右键选择粘贴

net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1
net.ipv4.ip_forward = 1
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.br0.rp_filter = 0

1.按esc 2.输入 : 3.然后输入 wq 回车

执行使生效

sysctl -p

如果报错:

sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-ip6tables: 没有那个文件或目录
sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-iptables: 没有那个文件或目录
sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-arptables: 没有那个文件或目录
执行 modprobe br_netfilter
再次执行sysctl -p

添加路由

/sbin/ip -f inet rule add fwmark 1 lookup 100
/sbin/ip -f inet route add local default dev lo table 100

添加规则前,首先查内是否有其他规则

iptables -t 表名 -L

如果有其他规则,将其删除

iptables -t 表名 -D 链名 第几条规则

添加规则

iptables -t nat -A PREROUTING -d 192.168.1.20 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.73:80

说明:

192.168.1.20 web服务器IP 80 web服务端口 192.168.1.73 网桥IP 8080 ShareWAF端口

保存规则

service iptables save

以上,系统透明模式需要的设置已完成。为实现断电或异常时Bypass功能,需向Bypass网卡或硬件厂家咨询、索取其Bypass网卡相关程序、资料,如:“喂狗程序”、脚本等。

透明网桥配成功后。

四、安装NodeJS

(ShareWAF运行依赖的环境)

yum -y install wget
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
wget https://nodejs.org/dist/v8.11.1/node-v8.11.1-linux-x64.tar.xz --no-check-certificate
tar -xvf node-v8.11.1-linux-x64.tar.xz
mv node-v8.11.1-linux-x64 node-v8.11.1
ln -s /root/node-v8.11.1/bin/node /usr/local/bin/node
ln -s /root/node-v8.11.1/bin/npm /usr/local/bin/npm

也可以从nodejs官网直接下载。

也可以用以下的方法:

 sudo apt-get install nodejs-legacy
 sudo apt-get install npm
 sudo npm install -g n
 sudo n stable
从ShareWAF官网,获取ShareWAF程序包后,在其目录下执行:

ShareWAF启动成功

到这里,基本就完成了,然后,就是进入ShareWAF后台配置网站就可以了。

这样一个硬件WAF,就完工了。

*本文作者:w2sfoot,转载请注明来自FreeBuf.COM

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-11-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 FreeBuf 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、软硬件需求
  • 二、准备工作
  • 三、系统配置,实现透明代理
  • 四、安装NodeJS
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档