WAF nginx反向代理和透明代理

下面看一下实例:反向代理(10.0.13.222)和透明代理(10.0.1.66)站点。

反向代理:

Nginx自带反向代理功能,只需在Linux系统上开启相应的端口。

反向代理规则链移植:

iptables -t filter -N waf_proxy
iptables -t filter -A INPUT -j waf_proxy
iptables -A waf_proxy -p tcp -m multiport --ports 8001 -j ACCEPT

透明代理:

数据包从网卡上来,原本经过二层的broute表转发数据包。ebtable命令让其在二层的转发包Drop掉,直接上三层。在broute表添加规则,如下:

数据包上至三层后,首先经过PREROUTING阶段,在该阶段,要给数据包打上MARK标志。如下:

并且调用iptables的TPROXY模块。tproxy功能主要:

  1. 重定向一部分经过路由选择的流量到本地路由进程(类似NAT中的REDIRECT)。

  2. 使用非本地IP作为源IP初始化连接。

  3. 无需iptables参与,在非本地IP上起监听。

tproxy使得打标记的数据包走本地策略路由表3000,如下:

然后在filter的INPUT链上规则,放开本地监听代理端口。如下:

透明代理规则链移植:

ebtables添加链规则:
ebtables -t broute -A waf_redirect -p ipv4 --ip-proto tcp --ip-src 10.0.1.66 --ip-sport 80 -j redirect --redirect-target DROP >/dev/null 2>&1
ebtables -t broute -A waf_redirect -p ipv4 --ip-proto tcp --ip-dst 10.0.1.66 --ip-dport 80 -j redirect --redirect-target DROP >/dev/null 2>&1 

mangle添加链规则:(WAF之前的链waf_redirect在jump_pos链下绑着)
iptables -t mangle -N waf_redirect
iptables -t mangle -A proxy_pos -j waf_redirect

数据包重定向操作:
iptables -t mangle -A waf_redirect -d 10.0.1.66 -p tcp --dport 80 -j TPROXY --tproxy-mark 0x1234 --on-port 8001  >/dev/null 2>&1

mangle添加链添加:(WAF之前的链waf_socket_match在jump_pos链下绑着)
iptables -t mangle -N waf_socket_match
iptables -t mangle -A proxy_pos -j waf_socket_match
        
iptables -t mangle -N DIVERT
iptables -t mangle -A DIVERT -j MARK --set-mark 0x1234
iptables -t mangle -A DIVERT -j ACCEPT

服务端包到本地:
iptables -t mangle -A waf_socket_match -p tcp -s 10.0.1.66 --sport 80 -m socket -j DIVERT >/dev/null 2>&1

filter添加链规则:(iptables接收透明代理回应到本地的数据包)
iptables -A waf_proxy -s 10.0.1.66 -p tcp --sport 80 -j ACCEPT >/dev/null 2>&1(不必须)
iptables -A waf_proxy -d 10.0.1.66 -p tcp --dport 80 -j ACCEPT >/dev/null 2>&1    

其它相关配置:

filter添加链规则:(jiaoxt added forward rst pkt for testlink site died)
iptables -t filter -N waf_forward_rst
iptables -t filter -I FORWARD -j waf_forward_rst
        
iptables -A waf_forward_rst -s 10.0.1.66 -p tcp --sport 80 -j REJECT --reject-with tcp-reset >/dev/null 2>&1

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值