{"id":1542,"date":"2012-10-02T12:31:23","date_gmt":"2012-10-02T04:31:23","guid":{"rendered":"http:\/\/rmohan.com\/?p=1542"},"modified":"2012-10-02T12:34:25","modified_gmt":"2012-10-02T04:34:25","slug":"disabling-mod_security","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=1542","title":{"rendered":"Disabling Mod_Security"},"content":{"rendered":"<p>\u00a0\u00a0\u00a0 1 Disabling Mod_Security Globally<br \/>\u00a0\u00a0\u00a0 2 Disabling Mod_security per domain<br \/>\u00a0\u00a0\u00a0 3 Disabling Mod_security per domain for an IP address<br \/>\u00a0\u00a0\u00a0 4 Disable Mod_security on a global URL<br \/>\u00a0\u00a0\u00a0 5 Disable Mod_security for an IP address<br \/>\u00a0\u00a0\u00a0 6 Whitelist an IP<br \/>\u00a0\u00a0\u00a0 7 Disable a rule for a single domain<br \/>\u00a0\u00a0\u00a0 8 Disable Mod_security rule for a specific application in a single domain<br \/>\u00a0\u00a0\u00a0 9 Disable Mod_security rule for all domains<br \/>\u00a0\u00a0\u00a0 10 Disable Mod_security rules globally for a specific application<br \/>\u00a0\u00a0\u00a0 11 Disable Mod_security rules by domain, for a specific application, for a list of IPs<br \/>\u00a0\u00a0\u00a0 12 Customizing a rule<br \/>\u00a0\u00a0\u00a0 13 Configuring and Setting up mod_security<\/p>\n<p>[edit] Disabling Mod_Security Globally<\/p>\n<p>Step 1) Disable config file<\/p>\n<p>mv \/etc\/httpd\/conf.d\/00_mod_security.conf \/etc\/httpd\/conf.d\/00_mod_security.conf.disabled<\/p>\n<p>Step 2) Restart Apache<\/p>\n<p>service httpd restart<\/p>\n<p>[edit] Disabling Mod_security per domain<\/p>\n<p>For Plesk and similar systems you can also disable modsecurity in the Apache configuration.<\/p>\n<p>Step 1) Edit the vhost\/vhost_ssl.conf for the domain<\/p>\n<p>\u00a0vim \/var\/www\/vhosts\/&lt;DOMAINNAME&gt;\/conf\/vhost.conf<\/p>\n<p>Step 2) Add the following<\/p>\n<p>&lt;IfModule mod_security2.c&gt;<br \/>\u00a0 SecRuleEngine Off<br \/>&lt;\/IfModule&gt;<\/p>\n<p>Then restart apache, if you are using Plesk then you will also need follow steps 3 and 4.<\/p>\n<p>Step 3) Add vhost.conf to domain config<\/p>\n<p>\/usr\/local\/psa\/admin\/bin\/websrvmng -a<\/p>\n<p>Step 4) Restart Apache<\/p>\n<p>service httpd restart<\/p>\n<p>[edit] Disabling Mod_security per domain for an IP address<\/p>\n<p>For Plesk and similar systems you can also disable modsecurity in the Apache configuration.<\/p>\n<p>Step 1) Edit the vhost\/vhost_ssl.conf for the domain<\/p>\n<p>\u00a0vim \/var\/www\/vhosts\/&lt;DOMAINNAME&gt;\/conf\/vhost.conf<\/p>\n<p>Step 2) Add the following<\/p>\n<p>&lt;IfModule mod_security2.c&gt;<br \/>\u00a0SecRule REMOTE_ADDR &#8220;^1.2.3.4$ &#8220;phase:1,t:none,nolog,allow,ctl:ruleEngine=Off,ctl:auditEngine=Off&#8221;<br \/>&lt;\/IfModule&gt;<\/p>\n<p>Then restart apache, if you are using Plesk then you will also need follow steps 3 and 4.<\/p>\n<p>Step 3) Add vhost.conf to domain config<\/p>\n<p>\/usr\/local\/psa\/admin\/bin\/websrvmng -a<\/p>\n<p>Step 4) Restart Apache<\/p>\n<p>service httpd restart<\/p>\n<p>[edit] Disable Mod_security on a global URL<\/p>\n<p>Step 1) Create a global exclude file<\/p>\n<p>vim \/etc\/httpd\/modsecurity.d\/00_custom_exclude.conf<\/p>\n<p>Step 2) Add the LocationMatch for the url to exclude. Example: \/server.php<\/p>\n<p>&lt;LocationMatch \/server.php&gt;<br \/>\u00a0 &lt;IfModule mod_security2.c&gt;<br \/>\u00a0\u00a0\u00a0 SecRuleEngine Off <br \/>\u00a0 &lt;\/IfModule&gt;<br \/>&lt;\/LocationMatch&gt;<\/p>\n<p>Step 3) Restart apache<\/p>\n<p>service httpd restart<\/p>\n<p>[edit] Disable Mod_security for an IP address<\/p>\n<p>In ASL, just click the &#8220;Whitelist&#8221; button.<\/p>\n<p>If you are not using ASL, simply add your IP address to the file:<\/p>\n<p>\/etc\/asl\/whitelist<\/p>\n<p>And restart Apache.<\/p>\n<p>Note: For this rule to work, in ASL you must have the MODSEC_00_WHITELIST ruleset enabled.<\/p>\n<p>If you are not using ASL, then you must have the 00_asl_whitelist.conf ruleset loaded.<\/p>\n<p>[edit] Whitelist an IP<\/p>\n<p>See above, &#8220;Disable Mod_security for an IP address&#8221;<br \/>[edit] Disable a rule for a single domain<\/p>\n<p>If you have ASL installed:<\/p>\n<p>Method 1:<\/p>\n<p>Log into the ASL GUI, and click on the &#8220;Configuration&#8221; tab. Then click &#8220;Rule Management&#8221;, then click the &#8220;Rules&#8221; tab, then click the &#8220;WAF&#8221; tab. Type in the rule ID and the rule manager will pull up the rule. Click on the green down error which will pull up the options for this rule.<\/p>\n<p>Type in the vhost name into the Text box on the left side of the options, then click &#8220;add&#8221;.<\/p>\n<p>Keep in mind this is literal, so if you have a vhost with the name &#8220;example.com&#8221; that serves content for &#8220;ftp.example.com&#8221; and &#8220;www.example.com&#8221; you will need to add those FQDNs as well.<\/p>\n<p>Method 2: Run this command as root:<\/p>\n<p>\u00a0asl -dr RULE_ID &#8211;vhost www.example.com<\/p>\n<p>Replace RULE_ID with the ID of the rule you want to disable for the vhost. Keep in mind this is literal, so if you have a vhost with the name &#8220;example.com&#8221; that serves content for &#8220;ftp.example.com&#8221; and &#8220;www.example.com&#8221; you will need to add those as well. For example:<\/p>\n<p>\u00a0asl -dr RULE_ID &#8211;vhost www.example.com<\/p>\n<p>\u00a0asl -dr RULE_ID &#8211;vhost ftp.example.com<\/p>\n<p>\u00a0asl -dr RULE_ID &#8211;vhost example.com<\/p>\n<p>If you do not have ASL installed you will have to do this manually:<\/p>\n<p>Step 1) Edit the vhost\/vhost_ssl.conf for the domain<\/p>\n<p>vim \/var\/www\/vhosts\/&lt;DOMAINNAME&gt;\/conf\/vhost.conf<\/p>\n<p>Step 2) Add the LocationMatch for the rule to exclude. Example, ruleid 950005<\/p>\n<p>&lt;LocationMatch .*&gt;<br \/>\u00a0 &lt;IfModule mod_security2.c&gt;<br \/>\u00a0\u00a0\u00a0 SecRuleRemoveById 950005<br \/>\u00a0 &lt;\/IfModule&gt;<br \/>&lt;\/LocationMatch&gt;<\/p>\n<p>If you want to disable multiple rules:<\/p>\n<p>Step 2) Add the LocationMatch for the rule to exclude. Example, ruleids 950005 and 950006<\/p>\n<p>&lt;LocationMatch .*&gt;<br \/>\u00a0 &lt;IfModule mod_security2.c&gt;<br \/>\u00a0\u00a0\u00a0 SecRuleRemoveById 950005<br \/>\u00a0\u00a0\u00a0 SecRuleRemoveById 950006<br \/>\u00a0 &lt;\/IfModule&gt;<br \/>&lt;\/LocationMatch&gt;<\/p>\n<p>[edit] Disable Mod_security rule for a specific application in a single domain<\/p>\n<p>Step 1) Edit the vhost\/vhost_ssl.conf for the domain<\/p>\n<p>vim \/var\/www\/vhosts\/&lt;DOMAINNAME&gt;\/conf\/vhost.conf<\/p>\n<p>Step 2) Add the LocationMatch for the rule to exclude. Example, ruleid 950005<\/p>\n<p>&lt;LocationMatch \/URL\/path\/to\/application.php&gt;<br \/>\u00a0 &lt;IfModule mod_security2.c&gt;<br \/>\u00a0\u00a0\u00a0 SecRuleRemoveById 950005<br \/>\u00a0 &lt;\/IfModule&gt;<br \/>&lt;\/LocationMatch&gt;<\/p>\n<p>[edit] Disable Mod_security rule for all domains<\/p>\n<p>Method 1:<\/p>\n<p>Log into the ASL GUI, and click on the &#8220;Configuration&#8221; tab. Then click &#8220;Rule Management&#8221;, then click the &#8220;Rules&#8221; tab, then click the &#8220;WAF&#8221; tab. Type in the rule ID and the rule manager will pull up the rule. Click on the green down error which will pull up the options for this rule.<\/p>\n<p>Set &#8220;disabled&#8221; to yes and click update.<\/p>\n<p>Method 2:<\/p>\n<p>Use ASL utility to disable rule by ID. Example: 950005<\/p>\n<p>asl &#8211;disable-rule 950005<\/p>\n<p>Note: This requires that Atomic Secured Linux be installed. If you do not have Atomic Secured Linux installed you can disable a rule globally manually by adding a rule to your own custom rules files that contains a line similar to this:<\/p>\n<p>&lt;LocationMatch .*&gt;<br \/>\u00a0 &lt;IfModule mod_security2.c&gt;<br \/>\u00a0\u00a0\u00a0 SecRuleRemoveById 340000<br \/>\u00a0 &lt;\/IfModule&gt;<br \/>&lt;\/LocationMatch&gt;<\/p>\n<p>Custom rules should be loaded after atomicorp rules. A good place to add this, again only if you do not have ASL installed, is in the 999_user_exclude.conf file. If you don&#8217;t have this file, just create it. Then make sure your modsecurity configuration is setup to load this file.<br \/>[edit] Disable Mod_security rules globally for a specific application<\/p>\n<p>Add this to either you vhost.conf file, or if your want to make this global make sure this exclusion is loaded after your rules are loaded. A good place to add this in the 999_user_exclude.conf file. If you don&#8217;t have this file, just create it. Then make sure your modsecurity configuration is setup to load this file.<\/p>\n<p>&lt;LocationMatch \/url\/to\/your\/application&gt;<br \/>\u00a0 &lt;IfModule mod_security2.c&gt;<br \/>\u00a0\u00a0\u00a0 SecRuleRemoveById 1234567<br \/>\u00a0\u00a0\u00a0 SecRuleRemoveById 9999999<br \/>\u00a0 &lt;\/IfModule&gt;<br \/>&lt;\/LocationMatch&gt;<\/p>\n<p>Whats important to remember is that the LocationMatch variable must match the URL, not the path on the system.<br \/>[edit] Disable Mod_security rules by domain, for a specific application, for a list of IPs<\/p>\n<p>Step 1) Edit the vhost\/vhost_ssl.conf for the domain<\/p>\n<p>vim \/var\/www\/vhosts\/&lt;DOMAINNAME&gt;\/conf\/vhost.conf<\/p>\n<p>Step 2) Add the LocationMatch for the rule to exclude.<\/p>\n<p>&lt;LocationMatch \/foo\/bar.php&gt;<br \/>\u00a0 &lt;IfModule mod_security2.c&gt;<br \/>\u00a0\u00a0\u00a0 SecRule REMOTE_ADDR &#8220;@pmFromFile \/etc\/asl\/whitelist&#8221; &#8220;nolog,phase:1,allow&#8221;<br \/>\u00a0 &lt;\/IfModule&gt;<br \/>&lt;\/LocationMatch&gt;<\/p>\n<p>Step 3) Add IP to \/etc\/asl\/whitelist<\/p>\n<p>echo &#8220;10.11.12.13&#8221; &gt;&gt; \/etc\/asl\/whitelist<\/p>\n<p>Or:<\/p>\n<p>If you want to create a special whitelist for just that application:<\/p>\n<p>Step 1) Edit the vhost\/vhost_ssl.conf for the domain<\/p>\n<p>vim \/var\/www\/vhosts\/&lt;DOMAINNAME&gt;\/conf\/vhost.conf<\/p>\n<p>Step 2) Add the LocationMatch for the rule to exclude.<\/p>\n<p>&lt;LocationMatch \/foo\/bar.php&gt;<br \/>\u00a0 &lt;IfModule mod_security2.c&gt;<br \/>\u00a0\u00a0\u00a0 SecRule REMOTE_ADDR &#8220;@pmFromFile \/path\/to\/your\/custom\/whitelist_for_this_application&#8221; &#8220;nolog,phase:1,allow&#8221;<br \/>\u00a0 &lt;\/IfModule&gt;<br \/>&lt;\/LocationMatch&gt;<\/p>\n<p>Step 3) Create your custom whitelist and add IP to \/etc\/asl\/whitelist<\/p>\n<p>echo &#8220;10.11.12.13&#8221; &gt;&gt; \/path\/to\/your\/custom\/whitelist_for_this_application<\/p>\n<p>Keep in mind these custom lists are *not* managed by ASL, so if you want to add IPs to these lists you will need to do it from the command line.<br \/>[edit] Customizing a rule<\/p>\n<p>If you need to customize a rule do not change the asl*conf files. These files will be overwritten by updates. If you need to change a rule because it is incorrectly blocking something we recommend you report it to use as a False Postive, using the Reporting_False_Positives procedure. If you simply want to modify a rule to perform different actions, then copy the entire rule into your own rule file, and make sure you tell mod_security not to enable the original ASL rule. You can do that by using the mod_security action SecRuleRemoveById. Here is a simple example:<\/p>\n<p>If you had an original rule like this:<\/p>\n<p>\u00a0SecRule REQUEST_URI &#8220;\/foo&#8221; &#8220;t:normalisePath,id:9000000,rev:1,severity:2,msg:&#8217;Atomicorp.com WAF Rules: Block \/foo'&#8221;<\/p>\n<p>And you want it to block &#8220;bar&#8221; instead of &#8220;foo&#8221;, then you would copy the entire rule into your own custom rule file. If you are using our rules we recommend you use the filename 99_asl_zzz_custom.confm and change the id: field to an unused ID.<\/p>\n<p>\u00a0SecRuleRemoveById 9000000<br \/>\u00a0SecRule REQUEST_URI &#8220;\/bar&#8221; &#8220;t:normalisePath,id:9999999,rev:1,severity:2,msg:&#8217;Atomicorp.com WAF Rules: Block \/foo'&#8221;<\/p>\n<p>These are the reserved ranges:<\/p>\n<p>\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0 1-99,999; reserved for local (internal) use. Use as you see fit but do not use this range for rules that are distributed to others.<br \/>\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0 100,000-199,999; reserved for internal use of the engine, to assign to rules that do not have explicit IDs.<br \/>\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0 200,000-299,999; reserved for rules published at modsecurity.org.<br \/>\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0 300,000-399,999; reserved for rules published at gotroot.com.<br \/>\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0 400,000-419,999; unused (available for reservation).<br \/>\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0 420,000-429,999; reserved for ScallyWhack.<br \/>\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0 430,000-699,999; unused (available for reservation).<br \/>\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0 700,000-799,999; reserved for Ivan Ristic.<br \/>\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0 900,000-999,999; reserved for the Core Rules project.<br \/>\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0 1,000,000 and above; unused (available for reservation).<\/p>\n<p>&nbsp;<\/p>\n<p>Apache ModSecurity &#8211; IP Whitelist<br \/>Add this rule to ModSecurity rules:<\/p>\n<p>SecRule REMOTE_ADDR &#8220;^192\\.168\\.2\\.15$&#8221; phase:1,nolog,allow,ctl:ruleEngine=off<\/p>\n<p>It means the IP 192.168.2.15 will be ignored by ModSecurity.<\/p>\n<p>Don&#8217;t forget to restart Apache after adding new rule.<\/p>\n","protected":false},"excerpt":{"rendered":"<p> 1 Disabling Mod_Security Globally 2 Disabling Mod_security per domain 3 Disabling Mod_security per domain for an IP address 4 Disable Mod_security on a global URL 5 Disable Mod_security for an IP address 6 Whitelist an IP 7 Disable a rule for a single domain 8 Disable Mod_security rule for a specific application in a [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1542"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1542"}],"version-history":[{"count":4,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1542\/revisions"}],"predecessor-version":[{"id":1545,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1542\/revisions\/1545"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}