{"id":50,"date":"2009-12-02T13:02:16","date_gmt":"2009-12-02T12:02:16","guid":{"rendered":"http:\/\/blog.pi3.com.pl\/?p=50"},"modified":"2009-12-02T21:48:01","modified_gmt":"2009-12-02T20:48:01","slug":"yum-mod_security-update","status":"publish","type":"post","link":"https:\/\/blog.pi3.com.pl\/?p=50","title":{"rendered":"yum + mod_security + update = &#8230;"},"content":{"rendered":"<p>OK. I haven&#8217;t written long time on blog. Today I want to show you what sometimes<br \/>\nyum can do without your knowledge. Few days ago I was upgrading one of system using yum.<br \/>\nEverything looked fine. I was happy that sometimes yum is useful. After work I went sleep<br \/>\nand next day I received messages that smth is fu** up with www&#8230;<\/p>\n<p><!--more--><br \/>\n&#8230; yep and the real history is starting now \ud83d\ude42 After update nobody can log into wordpress. When you go to site you saw only text and all design was not loaded. In logs I saw message 403 &#8211; Access Denied. Hm&#8230; but yesterday everything was working good. WTF? Someone compromised my box? Change the permission? Hm&#8230; let&#8217;s look&#8230; Hm&#8230; permission is good so why I have 403 message? Let&#8217;s look for rootkits \ud83d\ude42 After few hours I was almost\u00a0 sure that box was clean!<br \/>\nLet&#8217;s check another test. I was creating directory &#8216;wp-content&#8217; on random site and put some random file. When I send request for this file i received\u00a0 403 message once again. When I moved file to upper directory &#8211; everything worked fine \ud83d\ude42 Strange \ud83d\ude42 Let&#8217;s look for logs once again&#8230; What I saw? Look:<\/p>\n<p>&#8211;c28ca12d-B&#8211;<br \/>\nGET \/wp-content\/themes\/gods-and-monsters\/style.css HTTP\/1.1<br \/>\n&#8230;<br \/>\n&#8230;<br \/>\n&#8211;c28ca12d-F&#8211;<br \/>\nHTTP\/1.1 403 Forbidden<br \/>\nContent-Length: 311<br \/>\nConnection: close<br \/>\nContent-Type: text\/html; charset=iso-8859-1<\/p>\n<p>&#8211;c28ca12d-H&#8211;<br \/>\nMessage: Pattern match &#8220;([^*:\\s\\w,.\\\/?+-]\\s*)?(?&lt;![a-z]\\s)(?&lt;![a-z_@&gt;\\|])(\\s*return\\s*)?(?:globalstorage|sessionstorage|postmessage|callee|constructor|content|domain|prototype|try|catch|top|call|apply|url|function|object|array|string|math|if|elseif|case|switch|regex|boolean|l &#8230;&#8221; at REQUEST_URI_RAW. [file &#8220;\/etc\/httpd\/modsecurity.d\/base_rules\/modsecurity_crs_41_phpids_filters.conf&#8221;] [line &#8220;67&#8221;] [id &#8220;phpids-20&#8221;] [msg &#8220;Detects JavaScript language constructs&#8221;] [data &#8220;content\/&#8221;] [severity &#8220;CRITICAL&#8221;] [tag &#8220;WEB_ATTACK&#8221;]<br \/>\n&#8230;<br \/>\n&#8230;<\/p>\n<p>WTF? &#8220;Detects JavaScript language constructs&#8221; ? &#8220;CRITICAL&#8221; ? LOL Let&#8217;s look for this strange filter:<\/p>\n<p>-rw-r&#8211;r&#8211; 1 root root\u00a0 xxK 11-29 xx:xx modsecurity_crs_41_phpids_filters.conf<br \/>\n-rw-r&#8211;r&#8211; 1 root root\u00a0 xxK 11-29 xx:xx modsecurity_crs_40_generic_attacks.conf<\/p>\n<p>Hm this files was modified when i was upgrading system \ud83d\ude42 Line 67 looks like:<\/p>\n<p>SecRule REQUEST_BODY|REQUEST_URI_RAW|XML:\/* &#8220;([^*:\\s\\w,.\\\/?+-]\\s*)?(?&lt;![a-z]\\s)(?&lt;![a-z_@&gt;\\|])(\\s*return\\s*)?(?:globalstorage|sessionstorage|postmessage|cal<br \/>\nlee|constructor|content|domain|prototype|try|catch|top|call|apply|url|function|object|array|string|math|if|elseif|case|switch|regex|boolean|location|settimeo<br \/>\nut|setinterval|void|setexpression|namespace|while)(?(1)[^\\w%\\&#8221;]|(?:\\s*[^@\\s\\w%\\&#8221;,.+\\-]))&#8221; &#8220;phase:2,capture,t:none,t:urlDecodeUni,t:htmlEntityDecode,t:replace<br \/>\nComments,t:compressWhiteSpace,t:lowercase,ctl:auditLogParts=+E,block,nolog,auditlog,msg:&#8217;Detects JavaScript language constructs&#8217;,id:&#8217;phpids-20&#8242;,tag:&#8217;WEB_ATTA<br \/>\nCK&#8217;,logdata:&#8217;%{TX.0}&#8217;,severity:&#8217;2&#8242;,setvar:&#8217;tx.msg=%{rule.msg}&#8217;,setvar:tx.anomaly_score=+20,setvar:tx.%{rule.id}-WEB_ATTACK-%{matched_var_name}=%{matched_var}<br \/>\n&#8221;<\/p>\n<p>heh \ud83d\ude42 So everything which was in wp-content was blocked by mod_security \ud83d\ude42 I removed this line and some other strange (bad access wasn&#8217;t causes\u00a0 only by this line) and everything back to normal \ud83d\ude42<\/p>\n<p>Conclusion:<br \/>\n*) I always have been compiling by hand and modifying\u00a0 by hand everything so I always know what I do. When you are using automatic tools you can be surprised\u00a0 \ud83d\ude42<br \/>\n*) I didn&#8217;t believe that mod_security could causes this problem so I ignored this logs on first reading &#8211; and it causes longer time to discover real\u00a0 problem \ud83d\ude42<br \/>\n*) Automatic tool = faster but you should always check everything before you &#8220;Accept&#8221; his job \ud83d\ude42<\/p>\n<p>Best regards,<br \/>\nAdam Zabrocki<\/p>\n","protected":false},"excerpt":{"rendered":"<p>OK. I haven&#8217;t written long time on blog. Today I want to show you what sometimes yum can do without your knowledge. Few days ago I was upgrading one of system using yum. Everything looked fine. I was happy that sometimes yum is useful. After work I went sleep and next day I received messages [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6,1],"tags":[],"class_list":["post-50","post","type-post","status-publish","format-standard","hentry","category-ideas","category-o-wszystkim-i-o-niczym"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=\/wp\/v2\/posts\/50","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=50"}],"version-history":[{"count":4,"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=\/wp\/v2\/posts\/50\/revisions"}],"predecessor-version":[{"id":54,"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=\/wp\/v2\/posts\/50\/revisions\/54"}],"wp:attachment":[{"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=50"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=50"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}