反向代理和客戶端 IP 背後的 mod_security

反向代理和客戶端 IP 背後的 mod_security
client -> haproxy -> mod_security boxes -> backends

問題:mod_security 方塊使用 mod_rpaf 和「RPAFproxy_ips」中的 haproxy ip。 Apache 日誌記錄顯示客戶端真實 IP,但 mod_security 仍會報告 haproxys IP,如下所示。

在 mod_sec 方塊的 apache 日誌中找到客戶端 IP

x.93.129.90 - - [14/Oct/2015:08:35:56 +0200] "GET /MYTEST HTTP/1.1" 301 524 "-" "curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5"

Mod_security 報告代理程式 IP(客戶端 x.21.107.165)

 ==> /var/log/apache2/site.se_error.log <==
[Wed Oct 14 08:36:12.584500 2015] [:error] [pid 10264:tid 139895758558976]  [client x.21.107.165] ModSecurity: Access denied with code 403 (phase 2). 
Pattern match "\\\\balert\\\\b[^a-zA-Z0-9_]{0,}?\\\\(" at ARGS_NAMES:
<script>alert(1)</script>. [file "/usr/share/cwaf/rules/07_XSS_XSS.conf"] <etc>..

網路上的人似乎用 mod_sec 運行 rpaf,我做錯了什麼嗎?

有人知道另一種好方法嗎?我已經看到一些 mod_sec 規則基本上使用標頭中的值(如果存在),否則回退到remote_addr,但我沒有讓它們工作。

答案1

mod_rpaf 只適用於 apache < 2.4,mod_remoteip 適用於 2.4,mod_security 現在會報告客戶端 IP,而不是負載平衡器/代理的 IP

在 ubuntu 14.04 上

a2enmod remoteip
echo "RemoteIPHeader X-Client-Ip" > /etc/apache2/mods-enabled/remoteip.conf
service apache2 restart

相關內容