{"id":1479,"date":"2013-06-14T12:41:53","date_gmt":"2013-06-14T16:41:53","guid":{"rendered":"http:\/\/mossiso.com\/?p=1479"},"modified":"2014-09-22T14:36:14","modified_gmt":"2014-09-22T18:36:14","slug":"ossec-suhosin-and-wordpress","status":"publish","type":"post","link":"https:\/\/mossiso.com\/2013\/06\/14\/ossec-suhosin-and-wordpress\/","title":{"rendered":"OSSEC, Suhosin, and WordPress"},"content":{"rendered":"<p>I had a problem show up on some of our servers. Visiting sites would work fine, but as soon as you log in to a WordPress site, then your IP was blocked at the firewall level. It took a bit of hunting around the OSSEC logs to figure out the cause, and then finally <a href=\"https:\/\/www.atomicorp.com\/forum\/viewtopic.php?f=3&amp;t=5612\" target=\"_blank\">tipped off<\/a> to a local rule to combat the blockage. I outline the process of figuring out what was wrong, and how to fix it below.<\/p>\n<h2>DENIED!<\/h2>\n<p><a href=\"http:\/\/mossiso.com\/wp-content\/uploads\/2013\/06\/gareth-davies-logo3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1493 alignright\" src=\"http:\/\/mossiso.com\/wp-content\/uploads\/2013\/06\/gareth-davies-logo3-300x62.png\" alt=\"gareth-davies-logo3\" width=\"300\" height=\"62\" srcset=\"https:\/\/mossiso.com\/wp-content\/uploads\/2013\/06\/gareth-davies-logo3-300x62.png 300w, https:\/\/mossiso.com\/wp-content\/uploads\/2013\/06\/gareth-davies-logo3-250x52.png 250w, https:\/\/mossiso.com\/wp-content\/uploads\/2013\/06\/gareth-davies-logo3-150x31.png 150w, https:\/\/mossiso.com\/wp-content\/uploads\/2013\/06\/gareth-davies-logo3.png 430w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>So initially, this was quite confusing. All of a sudden people would have their IP blocked. I checked the different sites, and seemed to have no problem. Then when I logged in to the back end, BAM, blocked as well. We have <a href=\"http:\/\/shorewall.net\">Shorewall<\/a> running, so doing:<\/p>\n<pre class=\"lang:sh decode:true\">shorewall show dynamic<\/pre>\n<p>Showed all of the IPs that Shorewall had blocked. This could also be done by using iptables<\/p>\n<pre class=\"lang:sh decode:true\">iptables -nL --line-numbers<\/pre>\n<p>Sure enough, my IP had been blocked. I unblocked my IP with:<\/p>\n<pre class=\"lang:sh decode:true\">shorewall allow ip.ad.dr.es<\/pre>\n<p>Or could also do<\/p>\n<pre class=\"lang:sh decode:true\">iptables -D INPUT 2<\/pre>\n<p>where INPUT is the position or section of the firewall chain, and &#8220;2&#8221; is the line number containing my IP address.<\/p>\n<p>Then I checked with other web applications on that server. Where they also causing an issue? I logged in to an Omeka install. No problems.<\/p>\n<h2>FOUND IT!<\/h2>\n<p><a href=\"http:\/\/mossiso.com\/wp-content\/uploads\/2013\/06\/ossec_logo.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-1494\" src=\"http:\/\/mossiso.com\/wp-content\/uploads\/2013\/06\/ossec_logo.png\" alt=\"ossec_logo\" width=\"191\" height=\"67\" srcset=\"https:\/\/mossiso.com\/wp-content\/uploads\/2013\/06\/ossec_logo.png 191w, https:\/\/mossiso.com\/wp-content\/uploads\/2013\/06\/ossec_logo-150x52.png 150w\" sizes=\"(max-width: 191px) 100vw, 191px\" \/><\/a>OK. I know <a href=\"http:\/\/ossec.net\">OSSEC<\/a> is to blame some how. It&#8217;s an awesome HIDS (Host Intrusion Detection Software) that actively responds to issues on the server based on scanning through the system logs and various rules.<\/p>\n<p>OSSEC keeps itself chroot&#8217;ed to \/var\/ossec\/, so all of the ossec logs are located in \/var\/ossec\/logs\/.<\/p>\n<p>I first looked in the \/var\/ossec\/logs\/active-responses.log. Sure enough, a couple of lines like this show my IP being completely blocked to the server.<\/p>\n<pre class=\"lang:vim decode:true\">Fri Jun 14 06:50:47 EDT 2013 \/var\/ossec\/active-response\/bin\/host-deny.sh add - XXX.XX.XX.XX 1371207047.5913585 20101\r\nFri Jun 14 06:50:47 EDT 2013 \/var\/ossec\/active-response\/bin\/firewall-drop.sh add - XXX.XX.XX.XX 1371207047.5913585 20101\r\n<\/pre>\n<p><span style=\"line-height: 1.714285714; font-size: 1rem;\">So, there we are. OSSEC blocking the IP for some reason. Now why is it blocking the IP?<\/span><\/p>\n<p>Taking a look in the \/var\/ossec\/logs\/alerts\/alerts.log file to see why it thinks it needs to block the IP&#8230;<\/p>\n<pre class=\"lang:sh decode:true\">** Alert 1371206381.5698606: - ids,\r\n2013 Jun 14 06:39:41 (server1) 127.0.0.1-&gt;\/var\/log\/messages\r\nRule: 20101 (level 6) -&gt; 'IDS event.'\r\nSrc IP: XXX.XX.XX.XX\r\nJun 14 06:39:40 server1 suhosin[18563]: ALERT - script tried to increase memory_limit to 268435456 bytes which is above the allowed value (attacker 'XXX.XX.XX.XX', file '\/var\/html\/wp-admin\/admin.php', line 109)<\/pre>\n<p>There were other lines in there with my IP, but nothing would\/should have caused blocking, like a WordPress login event, or an SSH login event. Also, the error above is categorized as an IDS event with level 6, which by default OSSEC rules means it gets blocked.<\/p>\n<h2>HOW TO FIX IT!<\/h2>\n<p>As a quick fix, I changed the &#8220;suhosin.memory_limit&#8221; option in \/etc\/php.d\/suhosin.ini to 256M, and the &#8220;memory_limit&#8221; in \/etc\/php.ini to 256M so that no error would be generated.<\/p>\n<p>Now came the hard part of finding out how to fix it for real. OSSEC is a pretty big beast to tackle, so I turned to my friendly web search engine to help out.<\/p>\n<p>To fix the issue, I would need to write a decoder or new rule to ignore the suhosin rule causing the problem. OSSEC has descent documentation to get you started, but fortunately the blog linked above had the solution already. <a href=\"https:\/\/www.atomicorp.com\/forum\/viewtopic.php?f=3&amp;t=5612\">https:\/\/www.atomicorp.com\/forum\/viewtopic.php?f=3&amp;t=5612<\/a><\/p>\n<p>From user &#8216;faris&#8217; in the forum linked above:<\/p>\n<p>Add the following lines the the \/var\/ossec\/etc\/rules.d\/local_rules.xml file.<br \/>\n<b><\/b><\/p>\n<pre class=\"lang:xhtml decode:true \">&lt;group name=\"local,ids,\"&gt;\r\n  &lt;!-- First Time Suhosin event rule --&gt;\r\n  &lt;rule id=\"101006\" level=\"14\"&gt;\r\n    &lt;if_sid&gt;20100&lt;\/if_sid&gt;\r\n    &lt;decoded_as&gt;suhosin&lt;\/decoded_as&gt;\r\n    &lt;description&gt;First Time Suhosin Event&lt;\/description&gt;\r\n  &lt;\/rule&gt;\r\n  &lt;!-- Generic Suhosin event rule --&gt;\r\n  &lt;rule id=\"101007\" level=\"12\"&gt;\r\n    &lt;if_sid&gt;20101&lt;\/if_sid&gt;\r\n    &lt;decoded_as&gt;suhosin&lt;\/decoded_as&gt;\r\n    &lt;description&gt;Suhosin Event&lt;\/description&gt;\r\n  &lt;\/rule&gt;\r\n  &lt;!-- Specific Suhosin event rule --&gt;\r\n  &lt;rule id=\"101008\" level=\"5\"&gt;\r\n    &lt;if_sid&gt;101006,101007&lt;\/if_sid&gt;\r\n    &lt;match&gt;script tried to increase memory&lt;\/match&gt;\r\n    &lt;description&gt;Suhosin Memory Increase Event&lt;\/description&gt;\r\n  &lt;\/rule&gt;\r\n&lt;\/group&gt;\r\n<\/pre>\n<p><span style=\"line-height: 1.714285714; font-size: 1rem;\">What these new rules do is change the level of the default rules that were tagged\/decoded as being suhosin errors. In the first rule, if the default error is 20100, and is decoded (or tagged, or matches) as suhosin, then set the level to 14 instead of the default 8.<\/span><\/p>\n<p>The second rule detects if the default error 20101 is decoded as coming from suhosin and sets the level to 12 instead of the default 6.<\/p>\n<p>The third new rule looks at any error tagged as suhosin and if the error has the matching text in it, then it sets the error level to 5 (below the limit for firing an active response).<\/p>\n<p>So, just add that group of rules to the local_rules.xml file and restart the OSSEC service. BA-DA-BING! no more blocking the IP when logging in to WordPress.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had a problem show up on some of our servers. Visiting sites would work fine, but as soon as you log in to a WordPress site, then your IP was blocked at the firewall level. It took a bit of hunting around the OSSEC logs to figure out the cause, and then finally tipped &hellip; <a href=\"https:\/\/mossiso.com\/2013\/06\/14\/ossec-suhosin-and-wordpress\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">OSSEC, Suhosin, and WordPress<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1498,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[259,167,10],"tags":[262,263,260,261,223,278],"class_list":["post-1479","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-systems-administration-technical","category-technical","category-wordpress","tag-firewall","tag-iptables","tag-ossec","tag-shorewall","tag-systems-administration","tag-wordpress"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/mossiso.com\/wp-content\/uploads\/2013\/06\/Access_Denied_-_geograph.org_.uk_-_1197284.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9wosP-nR","_links":{"self":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/1479"}],"collection":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/comments?post=1479"}],"version-history":[{"count":24,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/1479\/revisions"}],"predecessor-version":[{"id":1653,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/1479\/revisions\/1653"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/media\/1498"}],"wp:attachment":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/media?parent=1479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/categories?post=1479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/tags?post=1479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}