2017-04-26 18 views
0

mod-security2では、の一部を無効にしたい特定の ルールID-(既定のルールから最も頻繁に誤検出される)。modsecurity 2 - 特定のルールIDのログを無効にしますか?

異常スコアリングのためにルールを有効にしておきたいが、一部のルールのログをオフにするだけだ。

どうすればよいですか?

答えて

1

これを実現するには、SecRuleUpdateActionByIdを使用できます。例えば

あなたはこれを持っている場合:

SecRule ARGS attack "phase:2,id:12345,log,pass" 
SecRuleUpdateActionById 12345 "pass" 

は、その後、あなたがログを削除します。これはルールのアクション部分(フェーズとIDを除く)を完全に置き換えるので、すべてを元のルールのアクションをSecRuleUpdateActionByIdにコピーする必要があります。ルールが新しいバージョンに更新されたかのように、これが長期的にどのくらい持続可能であるかわからない場合は、アクションが変更されていないことを確認する必要があります。

騒々しいログは、私が異常スコアリングメソッドが気に入らない主な理由の1つです。ルールが優先され、標準のブロッキングモードが使用され、これらのノイズのあるルールを完全に無効にするだけです彼らはしばしば偽陽性をもたらす。

+0

ヒントありがとうございます。私はデフォルトルールを "更新"するのではなく、コピーして新しいバージョンで "上書き"する方が簡単かもしれないと考えました。しかし、私は同じidで新しいルールを定義することはできません - まあ、論理的です。しかし、最初にSecRuleRemoveByIdを実行しても同じIDで更新されたルールを定義しても、「同じIDを持つ別のルールが見つかりました」という結果が得られます。 – Rop

+0

私は次のようにします:SecRuleRemoveById古いルールに123456を加え、SecRule ... 'id:9123456'のような新しい一意のIDを持つ新規の修正済みアイテムを追加します---これはモードセキュリティが一番簡単ではないようです、私が働いている最もよく設計された製品は、この「*いくつかのルールのログをオフにする」という簡単なタスクが複雑になるときです。 – Rop

+0

私の修正はうまくいくようですが、ここに:) ---- http://stackoverflow.com/questions/43663373/modsecurity-execution-phases-can-only-be-specified-by-chain-starter-rules – Rop

0

この問題を解決するために、特定のルールIDのロギングを無効にするために少しのutil-scriptをノックアップしてしまい、ログファイルをあまりにも煩雑にしていました。

これは私のニーズにはうまくいきますが、これを自分の責任で使用してください - これは理由のためにオープンソースです! :)

#!/bin/bash 

# Filename: suppress_logging.sh 

# From your mod-secure base_rules/ directory, do: mkdir -p ../tools/ 
# Put this script in that tools/ directory, and run it to turn off logging for specific rules (frequent false alerts) 
# 
# For example, rule-id 123456 will be "overridden" with a new rule-id 9123456 that does exactly the same thing, but without logging anything (nolog). 
# 
# For rules defined in a single line, use the function: suppressLoggingForSinglelineRule below. 
# 
# For rules spanning over multiple lines (including chained-rules), use the function: suppressLoggingForMultilineRule below. 

# This script was developed and used for mod-security version: 2.1.9. 

cd ../base_rules/ 

cat /dev/null > z_logging_suppress.TMP 
cat /dev/null > z_logging_suppress_multiline.TMP 

function suppressLoggingForSinglelineRule(){ 
    ruleId=$1 
    echo Processing suppressLoggingForSinglelineRule $ruleId 
    echo SecRuleRemoveById $ruleId >> z_logging_suppress.TMP 
    cat modsecurity_*.conf | grep $ruleId >> z_logging_suppress.TMP 
} 

function suppressLoggingForMultilineRule(){ 
    ruleId=$1 
    before=$2 
    after=$3 
    echo Processing suppressLoggingForMultilineRule $ruleId 
    echo SecRuleRemoveById $ruleId        >> z_logging_suppress_multiline.TMP 
    cat modsecurity_*.conf | grep -B"${before}" -A"${after}" $ruleId >> z_logging_suppress_multiline.TMP 
} 

suppressLoggingForSinglelineRule 960032 
suppressLoggingForSinglelineRule 960034 
# ... here add your own annoying rule-ids from the log-files ... 
# ... 

suppressLoggingForMultilineRule 960010 0 2 # This means the rule spans 0 lines BEFORE the rule-id, and 2 lines AFTER, in the modsecurity_*.conf file, etc. 
suppressLoggingForMultilineRule 960011 3 16 # 
# ... here add your own annoying rule-ids from the log-files ... 
# ... 

# If the rule contains: ,block, 
# change it to: ,block,nolog, (this is true for most rules) 
# If the rule contains: ,log, 
# change it to ,nolog,   (a few rules) 
# BUT BEWARE -- there are a few rules in the modsecurity_* scripts that contains neither -- this won't work for those. 

cat z_logging_suppress.TMP   | sed '1,$s/,block,/,block,nolog,/' | sed '1,$s/ block,/ block,nolog,/' | sed '1,$s/,log,/,nolog,/' > z_logging_suppress.TMP2 
cat z_logging_suppress_multiline.TMP | sed '1,$s/,block,/,block,nolog,/' | sed '1,$s/ block,/ block,nolog,/' | sed '1,$s/,log,/,nolog,/' > z_logging_suppress_multiline.TMP2 

cat z_logging_suppress.TMP2   | sed '1,$s/,id:'"'"'/,id:'"'"'9/' | sed '1,$s/"id:'"'"'/"id:'"'"'9/' | sed '1,$s/ id:'"'"'/ id:'"'"'9/' > z_logging_suppress.conf 
cat z_logging_suppress_multiline.TMP2 | sed '1,$s/,id:'"'"'/,id:'"'"'9/' | sed '1,$s/"id:'"'"'/"id:'"'"'9/' | sed '1,$s/ id:'"'"'/ id:'"'"'9/' > z_logging_suppress_multiline.conf 

echo SANITY CHECK -- The following counts should give identical numbers: 
grep -c '^SecRule ' z_logging_suppress.conf 
grep -c ',nolog,' z_logging_suppress.conf 
if [ "$(grep -c '^SecRule ' z_logging_suppress.conf)" != "$(grep -c ',nolog,' z_logging_suppress.conf)" ]; then 
    echo ' *** WARNING -- Sanity check FAILED ***' 
fi 

echo SANITY CHECK -- The following counts should give identical numbers: 
grep -c '^SecRule ' z_logging_suppress_multiline.conf 
grep -c ',nolog,' z_logging_suppress_multiline.conf 
if [ "$(grep -c '^SecRule ' z_logging_suppress_multiline.conf)" != "$(grep -c ',nolog,' z_logging_suppress_multiline.conf)" ]; then 
    echo ' *** WARNING -- Sanity check FAILED ***' 
fi 

# You may comment-out the following line while debugging/maintaining this script, 
# so you can diff what the final sed-commands do. 
# Activate it when you are done, to remove the *.TMP* files: 
# rm *.TMP *.TMP2 
関連する問題