欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Apache下ModSecurity的安裝啟用與配置

 更新時(shí)間:2018年10月18日 17:42:04   投稿:mdxy-dxy  
這篇文章主要介紹了Apache下ModSecurity的安裝啟用與配置,需要的朋友可以參考下

ModSecurity 是一個(gè)強(qiáng)大的包過(guò)濾工具,將檢查每一個(gè)進(jìn)入web服務(wù)器的包。它將根據(jù)內(nèi)部規(guī)則,比較每一個(gè)包,并且確定是否需要禁止這個(gè)包或繼續(xù)發(fā)送給web服務(wù)器。

1、下載

modsecurity-apache: http://sourceforge.net/projects/mod-security/files/modsecurity-apache/
modsecurity-crs: http://sourceforge.net/projects/mod-security/files/modsecurity-crs/0-CURRENT/

2、安裝

1)啟用 mod_unique_id 模塊
2)驗(yàn)證服務(wù)器安裝了最新版本libxml2函數(shù)庫(kù)
3)停止Apache httpd

4)解壓

gzip -d modsecurity-apache_2.6.3.tag.gz
tar xvzf modsecurity-apache_2.6.3.tar
gzip -d modsecurity-core-rules_2.6.tar.gz
tar xvzf modsecurity-core-rules_2.6.tar.gz

5)配置

./configure

6)編譯并測(cè)試ModSecurity

make
make test

7)安裝

make install

修改 http.conf,啟用ModSecurity,在httpd.conf文件添加:

LoadFile /usr/lib/libxml2.so
LoadModule security2_module modules/mod_security2.so

8)重啟apache

到這里已經(jīng)安裝了ModSecurity,你可以查看配置指令文檔:http://sourceforge.net/apps/mediawiki/mod-security/index.php?title=Reference_Manual

ubuntu上安裝Apache2+ModSecurity及自定義WAF規(guī)則

雖然VPS使用了云WAF功能,但還是有點(diǎn)小擔(dān)心,為了雙重保險(xiǎn),決定使用modsecurity來(lái)定制規(guī)則,以下介紹如何為apache服務(wù)器配置ModSecurity防護(hù)罩(modsecurity目前也支持Nginx,IIS) 。

本次選擇使用包管理器來(lái)安裝,因?yàn)槊看问褂迷创a包的安裝方式,都會(huì)被詭異的庫(kù)依賴錯(cuò)誤弄得發(fā)型都抓亂。

安裝環(huán)境:

OS:Ubuntu 14.04.1 LTS
Apache: Apache/2.4.7 (Ubuntu)

第一步:安裝apache

我建議安裝Apache最好用apt-get安裝,這樣就可以少很多的庫(kù)支持?。。。∪绻幌勇闊┑脑捒梢杂迷创a安裝

輸入apt-get install apache2

如果提示沒(méi)有這個(gè)軟件包就更新一下軟件包 apt-get install update

這步安裝好了以后apache就可以提供服務(wù)了,輸入127.0.0.1就可以訪問(wèn)本地網(wǎng)站了

第二步:安裝modsecurity

這個(gè)也和上邊的一樣,使用

apt-get install libxml2 libxml2-dev libxml2-utils libaprutil1 libaprutil1-dev libapache2-modsecurity

安裝好了以后就可以查看你的modsecurity的版本號(hào)是多少,使用

dpkg -s libapache2-modsecurity | grep Version

第三步 配置modsecurity

service apache2 reload

該命令生效后,會(huì)在/var/log/apache2/目錄下生成modsecurity的日志文件modsec_audit.log

使用modsecurity核心規(guī)則集

將我們想起用的規(guī)則集放置在以下目錄下

cd /usr/share/modsecurity-crs/activated_rules/

選擇啟用base規(guī)則集

for f in $(ls ../base_rules/); do ln -s ../base_rules/$f; done

修改apache模塊配置,啟用規(guī)則集

注意:modsecurity 2.7版本與2.6版本的配置文件有些區(qū)別

(1)2.7版本

vim /etc/apache2/mods-available/security2.conf
修改

<IfModule security2_module>
# Default Debian dir for modsecurity's persistent data
SecDataDir /var/cache/modsecurity
# Include all the *.conf files in /etc/modsecurity.
# Keeping your local configuration in that directory
# will allow for an easy upgrade of THIS file and
# make your life easier
IncludeOptional /etc/modsecurity/*.conf
IncludeOptional /usr/share/modsecurity-crs/*.conf
IncludeOptional /usr/share/modsecurity-crs/activated_rules/*.conf
</IfModule>

(2)2.6版本

‍‍vim /etc/apache2/mods-available/mod-security.conf‍‍
修改

Include /etc/modsecurity/*.conf
Include /usr/share/modsecurity-crs/*.conf
Include /usr/share/modsecurity-crs/activated_rules/*.conf

第四步:?jiǎn)⒂胢odsecurity模塊

a2enmod headersa2enmod security2 (版本2.6: a2enmod mod-security)service apache2 restart

第五步:測(cè)試真實(shí)的攻擊payload

看是否能攔截

http://www.tanjiti.com/?case=archive&act=orders&aid[typeid`%3D1%20and%20ord(mid((select/**/concat(username,0x3a,password)%20from%20cmseasy_user),1,1))%3C49%23]=1
我們發(fā)現(xiàn)請(qǐng)求包被403攔截了,

可以查看modsecurity日志文件看具體的攔截情況

tail /var/log/apache2/modsec_audit.log
message: Access denied with code 403 (phase 2). Pattern match "(/\\*!?|\\*/|[&#039;;]--|--[\\s\\r\\n\\v\\f]|(?:--[^-]*?-)|([^\\-&])#.*?[\\s\\r\\n\\v\\f]|;?\\x00)" at ARGS_NAMES:aid[typeid`=1 and ord(mid((select/**/concat(username,0x3a,password) from cmseasy_user),1,1))
<49#].
[file "/usr/share/modsecurity-crs/activated_rules/modsecurity_crs_41_sql_injection_attacks.conf"] [line "49"] [id "981231"] [rev "2"] [msg "SQL Comment Sequence Detected."] [data "Matched Data: /* found within ARGS_NAMES:aid[typeid`=1 and ord(mid((select/**/concat(username,0x3a,password) from cmseasy_user),1,1))<49#]: aid[typeid`=1 and ord(mid((select/**/concat(username,0x3a,password) from cmseasy_user),1,1))<49#]"] [severity "CRITICAL"] [ver "OWASP_CRS/2.2.8"] [maturity "8"] [accuracy "8"] [tag "OWASP_CRS/WEB_ATTACK/SQL_INJECTION"] [tag "WASCTC/WASC-19"] [tag "OWASP_TOP_10/A1"] [tag "OWASP_AppSensor/CIE1"] [tag "PCI/6.5.2"]

可以看到是被base規(guī)則集的modsecurity_crs_41_sql_injection_attacks.conf文件的規(guī)則981231攔截,命中了SQL注釋語(yǔ)句。
對(duì)于網(wǎng)站結(jié)構(gòu)比較了解的站長(zhǎng)們,完全可以自定義規(guī)則,特別是白名單規(guī)則來(lái)防護(hù)我們的網(wǎng)站。

第六步:自定義WAF規(guī)則

規(guī)則語(yǔ)法快速入門參考 ModSecurity SecRule cheatsheets

WAF規(guī)則實(shí)例1:上傳文件名白名單,只允許上傳圖片文件

vim /usr/share/modsecurity-crs/activated_rules/MY.conf
添加規(guī)則

SecRule FILES "!\\.(?i:jpe?g|gif|png|bmp)$" "deny,tag:'WEB_ATTACK/FILEUPLOAD',msg:'upload no-picture file',id:0000001,phase:2"
測(cè)試,上傳php文件

(http的使用參照HTTP發(fā)包工具 -HTTPie)
http www.tanjiti.com filename@a.php
我們可以看到請(qǐng)求包被攔截,查看modsecurity日志

more /var/log/apache2/modsec_audit.log
可以看到命中了規(guī)則0000001

Message: Access denied with code 403 (phase 2). Match of "rx \\.(?i:jpe?g|gif|png|bmp)$" against "FILES:filename" required. [file "/usr/share/modsecurity-crs/activated_rules/MY.conf"] [line "1"] [id "0000001"] [msg "upload no-picture file"] [tag "WEB_ATTACK/FILEUPLOAD"]
WAF規(guī)則實(shí)例2: 上傳文件名中包含%00進(jìn)行阻斷

vim /usr/share/modsecurity-crs/activated_rules/MY.conf
添加規(guī)則

SecRule FILES "@contains %00" "deny,tag:&#039;WEB_ATTACK/FILEUPLOAD',msg:'filename has null character',id:0000002,phase:2"
測(cè)試,上傳文件名包含%00的文件

http www.tanjiti.com filename@a.php%00.jpeg
我們可以看到請(qǐng)求包被攔截,查看modsecurity日志

more /var/log/apache2/modsec_audit.log
可以看到命中了規(guī)則0000002

Message: Access denied with code 403 (phase 2). String match "%00" at FILES:filename. [file "/usr/share/modsecurity-crs/activated_rules/MY.conf"] [line "2"] [id "0000002"] [msg "filename has null character"] [tag "WEB_ATTACK/FILEUPLOAD"]
非常簡(jiǎn)單吧,下一步,計(jì)劃介紹一下nginx服務(wù)器的防護(hù)。

注意?。。。。。。。。。。。。。?br /> 一旦這樣修改了以后,使用IP地址就顯示403錯(cuò)誤!?。。。。榱诉@個(gè)錯(cuò)誤,搞了一天,在網(wǎng)上搜各種403錯(cuò)誤就是不行,為什么呢????
查看errol.log 就可以發(fā)現(xiàn),是modsecurity里面禁止了使用IP訪問(wèn)?。。。。。∈褂胠ocalhost就可以正常訪問(wèn)了。。。
所以,看日志是一個(gè)很重要的事兒

相關(guān)文章

  • Linux 查看遠(yuǎn)程服務(wù)器文件狀態(tài)的方法

    Linux 查看遠(yuǎn)程服務(wù)器文件狀態(tài)的方法

    今天小編就為大家分享一篇Linux 查看遠(yuǎn)程服務(wù)器文件狀態(tài)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-07-07
  • Linux之刪除帶有空格的文件(不是目錄)

    Linux之刪除帶有空格的文件(不是目錄)

    這篇文章主要介紹了Linux之刪除帶有空格的文件(不是目錄),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • Linux中執(zhí)行Shell腳本的三種實(shí)現(xiàn)方式

    Linux中執(zhí)行Shell腳本的三種實(shí)現(xiàn)方式

    這篇文章主要介紹了Linux中執(zhí)行Shell腳本的三種實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • Linux  ProFTPd安裝與卸載詳細(xì)介紹

    Linux ProFTPd安裝與卸載詳細(xì)介紹

    這篇文章主要介紹了Linux ProFTPd安裝與卸載詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下
    2016-10-10
  • Linux 解決Deepin無(wú)法在root用戶啟動(dòng)Google Chrome瀏覽器的問(wèn)題

    Linux 解決Deepin無(wú)法在root用戶啟動(dòng)Google Chrome瀏覽器的問(wèn)題

    這篇文章主要介紹了Linux 解決Deepin無(wú)法在root用戶啟動(dòng)Google Chrome瀏覽器的問(wèn)題,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-07-07
  • Linux中文件描述符fd與文件指針FILE*互相轉(zhuǎn)換實(shí)例解析

    Linux中文件描述符fd與文件指針FILE*互相轉(zhuǎn)換實(shí)例解析

    這篇文章主要介紹了Linux中文件描述符fd與文件指針FILE*互相轉(zhuǎn)換實(shí)例解析,小編覺(jué)得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下
    2018-01-01
  • Linux使用fdisk實(shí)現(xiàn)磁盤分區(qū)過(guò)程圖解

    Linux使用fdisk實(shí)現(xiàn)磁盤分區(qū)過(guò)程圖解

    這篇文章主要介紹了Linux使用fdisk實(shí)現(xiàn)磁盤分區(qū)過(guò)程圖解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • Linux添加swap分區(qū)的方法

    Linux添加swap分區(qū)的方法

    這篇文章主要介紹了Linux添加swap分區(qū)的方法,首先需要我們建立一個(gè)普通的linux 分區(qū),具體實(shí)例代碼,大家跟隨腳本之家小編一起看看吧
    2018-08-08
  • CentOS設(shè)置精準(zhǔn)時(shí)間的方法

    CentOS設(shè)置精準(zhǔn)時(shí)間的方法

    下面小編就為大家分享一篇CentOS設(shè)置精準(zhǔn)時(shí)間的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-02-02
  • Ubuntu系統(tǒng)下安裝ImageMagick出錯(cuò)的解決過(guò)程

    Ubuntu系統(tǒng)下安裝ImageMagick出錯(cuò)的解決過(guò)程

    由于項(xiàng)目需要, 所以要在Ubuntu下面安裝ImageMagick,但在安裝過(guò)程中遇到了些問(wèn)題,通過(guò)查找相關(guān)的資料最終得以解決了,所以下面這篇文章主要給大家介紹了關(guān)于Ubuntu系統(tǒng)下安裝ImageMagick出錯(cuò)的解決過(guò)程,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-07-07

最新評(píng)論