« Webserver/Apache/Modules/Security » : différence entre les versions

De TartareFR
Aller à la navigation Aller à la recherche
Aucun résumé des modifications
Ligne 66 : Ligne 66 :
</IfModule>
</IfModule>
</syntaxhighlight>
</syntaxhighlight>
== test du module ==
* Saisir '''<code>OR 1=1</code>''' dans un champ de recherche
* Ajouter '''<code><script>xss</script></code>''' à la fin de l'url
* Ajouter '''<code>/../../etc/passwd</code>''' à la fin de l'url


== Désactivation pour un site particulier ==
== Désactivation pour un site particulier ==

Version du 12 mai 2014 à 12:13

LogoApache.svgmod_security

Le module apache mod_security est un un pare-feu applicatif qui se présente sous la forme d’un module pour le serveur Web Apache.

Son rôle est de détecter et de protéger le serveur contre des attaques en tout genre : injections SQL, cross-site scripting (XSS)...

ApacheModuleSecurity.png

Installation

yum install mod_security mod_security_crs

Le fichier de configuration principal est <path>/etc/httpd/conf.d/mod_security.conf</path>

<IfModule mod_security2.c>
    # ModSecurity Core Rules Set configuration
        IncludeOptional modsecurity.d/*.conf
        IncludeOptional modsecurity.d/activated_rules/*.conf
    
    # Default recommended configuration
    SecRuleEngine On
    SecRequestBodyAccess On
    SecRule REQUEST_HEADERS:Content-Type "text/xml" \
         "id:'200000',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=XML"
    SecRequestBodyLimit 13107200
    SecRequestBodyNoFilesLimit 131072
    SecRequestBodyInMemoryLimit 131072
    SecRequestBodyLimitAction Reject
    SecRule REQBODY_ERROR "!@eq 0" \
    "id:'200001', phase:2,t:none,log,deny,status:400,msg:'Failed to parse request body.',logdata:'%{reqbody_error_msg}',severity:2"
    SecRule MULTIPART_STRICT_ERROR "!@eq 0" \
    "id:'200002',phase:2,t:none,log,deny,status:44,msg:'Multipart request body \
    failed strict validation: \
    PE %{REQBODY_PROCESSOR_ERROR}, \
    BQ %{MULTIPART_BOUNDARY_QUOTED}, \
    BW %{MULTIPART_BOUNDARY_WHITESPACE}, \
    DB %{MULTIPART_DATA_BEFORE}, \
    DA %{MULTIPART_DATA_AFTER}, \
    HF %{MULTIPART_HEADER_FOLDING}, \
    LF %{MULTIPART_LF_LINE}, \
    SM %{MULTIPART_MISSING_SEMICOLON}, \
    IQ %{MULTIPART_INVALID_QUOTING}, \
    IP %{MULTIPART_INVALID_PART}, \
    IH %{MULTIPART_INVALID_HEADER_FOLDING}, \
    FL %{MULTIPART_FILE_LIMIT_EXCEEDED}'"

    SecRule MULTIPART_UNMATCHED_BOUNDARY "!@eq 0" \
    "id:'200003',phase:2,t:none,log,deny,status:44,msg:'Multipart parser detected a possible unmatched boundary.'"

    SecPcreMatchLimit 1000
    SecPcreMatchLimitRecursion 1000

    SecRule TX:/^MSC_/ "!@streq 0" \
            "id:'200004',phase:2,t:none,deny,msg:'ModSecurity internal error flagged: %{MATCHED_VAR_NAME}'"

    SecResponseBodyAccess Off
    SecDebugLog /var/log/httpd/modsec_debug.log
    SecDebugLogLevel 0
    SecAuditEngine RelevantOnly
    SecAuditLogRelevantStatus "^(?:5|4(?!04))"
    SecAuditLogParts ABIJDEFHZ
    SecAuditLogType Serial
    SecAuditLog /var/log/httpd/modsec_audit.log
    SecArgumentSeparator &
    SecCookieFormat 0
    SecTmpDir /var/lib/mod_security
    SecDataDir /var/lib/mod_security
</IfModule>

test du module

  • Saisir OR 1=1 dans un champ de recherche
  • Ajouter <script>xss</script> à la fin de l'url
  • Ajouter /../../etc/passwd à la fin de l'url

Désactivation pour un site particulier

On peut soit désactiver un ou plusieurs rôles avec la ligne SecRuleRemoveById ou l'intégralité des règles avec la ligne SecRuleEngine Off

<LocationMatch "/wiki/.*">
        <IfModule mod_security2.c>
                #SecRuleRemoveById 981173
                SecRuleEngine Off
        </IfModule>
</LocationMatch>
Warning.png
Mediawiki
Le module mod_security est connu pour posé problème à <package>mediawiki</package>. Il doit donc être désactivé pour cet alias ou hôte virtuel.

On peut lire les lignres suivantes dans <path>/var/log/httpd/modsec_audit.log</path>

Message: Access denied with code 403 (phase 2). Pattern match "([\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\-\\+\\=\\{\\}\\[\\
]\\|\\:\\;\"\\'\\\xc2\xb4\\\xe2\x80\x99\\\xe2\x80\x98\\`\\<\\>].*?){4,}" at ARGS:modules. [file "/etc/httpd/modsecurit
y.d/activated_rules/modsecurity_crs_41_sql_injection_attacks.conf"] [line "159"] [id "981173"] [rev "2"] [msg "Restric
ted SQL Character Anomaly Detection Alert - Total # of special characters exceeded"] [data "Matched Data: | found with
in ARGS:modules: ext.cite|jquery.autoEllipsis,checkboxShiftClick,hidpi,highlightText,makeCollapsible,mw-jump,placehold
er,suggestions,tabIndex|mediawiki.action.view.postEdit|mediawiki.api,cldr,hidpi,jqueryMsg,language,searchSuggest,user|
mediawiki.language.data,init|mediawiki.libs.pluralruleparser|mediawiki.page.ready|skins.vector.collapsibleNav"] [ver "
OWASP_CRS/2.2.8"] [maturity "9"] [accuracy "8"] [tag "OWASP_CRS/WEB_ATTACK/SQL_INJECTION"]
Action: Intercepted (phase 2)
Apache-Handler: application/x-httpd-php
Stopwatch: 1399885271656634 13313 (- - -)
Stopwatch2: 1399885271656634 13313; combined=11418, p1=604, p2=10716, p3=0, p4=0, p5=93, sr=170, sw=5, l=0, gc=0
Response-Body-Transformed: Dechunked
Producer: ModSecurity for Apache/2.7.5 (http://www.modsecurity.org/); OWASP_CRS/2.2.8.
Server: Apache/2.4.9 (Fedora) OpenSSL/1.0.1e-fips mod_perl/2.0.9-dev Perl/v5.18.2
Engine-Mode: "ENABLED"