{"id":562,"date":"2010-07-26T10:13:51","date_gmt":"2010-07-26T15:13:51","guid":{"rendered":"http:\/\/it.thelibrarie.com\/weblog\/?p=562"},"modified":"2010-12-06T15:30:48","modified_gmt":"2010-12-06T20:30:48","slug":"decode-eval-gzinflate-base64_decode","status":"publish","type":"post","link":"https:\/\/it.thelibrarie.com\/weblog\/2010\/07\/decode-eval-gzinflate-base64_decode\/","title":{"rendered":"Decode eval gzinflate base64_decode"},"content":{"rendered":"<p>I had to install a wordpress theme for a customer.  I&#8217;m not a web developer by any means, so lucky for me wordpress is pretty straight forward.  The theme they wanted to use was &#8220;free&#8221;, but had a footer with links to the theme&#8217;s developer site.  Unfortunately the developer&#8217;s site was no longer functioning.  A brief search for their company yielded similar results &#8211; all landing website pages or 404 error sites.<\/p>\n<p>The terms and conditions for the theme stated that you could remove the footer only if you paid $29.95 to the company.  As there was no company to pay, a &#8220;gray area&#8221; was presented.  Should I just remove the footer and be done with my day?  The customer requested that I adhere to the terms and conditions but make sure that the links would not go to unknown websites for fear that a malicious link could be used.  They also requested that an RSS feed link be removed from the footer.<\/p>\n<p>I go to edit the footer and notice the following PHP code:<br \/>\n<code>gzinflate(base64_decode('bVJRa9swEH4P5D9cTTrZEKdjG3tYbIeydexlfUhgMMYQtnWxRWTJk+RkWcl\/n2S7bUirB+t8p\/u+u+9ulSWM76EUuTFp8FUpizrIphNw52Uk5lI+x89PkkOtcZsGyaqtWyiE+qrjcqpBoY97RTgsSLWGVBY94zh3bvIp5qWQAlluBabDe$<\/code><br \/>\nWell how do I know this obfuscated PHP script isn&#8217;t going to send customers to malicious sites?  I need to see the decoded PHP!<\/p>\n<p>Scripting to the rescue!<\/p>\n<p>Easiest way is to have a linux server laying around.  I have a fully patched 10.04LTS Ubuntu server just for this purpose (VMWare Server).<\/p>\n<p>Make the following PHP file:<\/p>\n<blockquote><p>\n<code>< ? php\n\/*\nTaken from http:\/\/www.php.net\/manual\/de\/function.eval.php#59862\nDirections:\n1. Save this snippet as decrypt.php\n2. Save encoded PHP code in coded.txt\n3. Create a blank file called decoded.txt (from shell do CHMOD 0666 decoded.txt)\n4. Execute this script (visit decrypt.php in a web browser or do php decrypt.php in the shell)\n5. Open decoded.txt, the PHP should be decrypted\n*\/\necho \"\\nDECODE nested eval(gzinflate()) by DEBO Jurgen <jurgen@person.be>\\n\\n\";<br \/>\necho \"1. Reading coded.txt\\n\";<br \/>\n$fp1 = fopen (\"coded.txt\", \"r\");<br \/>\n$contents = fread ($fp1, filesize (\"coded.txt\"));<br \/>\nfclose($fp1);<br \/>\necho \"2. Decoding\\n\";<br \/>\nwhile (preg_match(\"\/eval\\(gzinflate\/\",$contents)) {<br \/>\n    $contents=preg_replace(\"\/< \\?|\\?>\/\", \"\", $contents); eval(preg_replace(\"\/eval\/\", \"\\$contents=\", $contents)); } echo \"3. Writing decoded.txt\\n\"; $fp2 = fopen(\"decoded.txt\",\"w\"); fwrite($fp2, trim($contents)); fclose($fp2);<br \/>\n?><\/code><\/p><\/blockquote>\n<p>Then follow the directions in the script.  Or, if you&#8217;re like me, just create the following:<br \/>\ncoded.txt (this file will have the ENTIRE PHP portion &#8211; everything from &#8220;eval(gzinflate&#8221; to the last &#8220;);&#8221;)<br \/>\ndecoded.txt (make sure it&#8217;s writeable &#8211; either 0666 or 0777)<br \/>\nRun the script<br \/>\nOpen the decoded.txt file<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had to install a wordpress theme for a customer. I&#8217;m not a web developer by any means, so lucky for me wordpress is pretty straight forward. The theme they wanted to use was &#8220;free&#8221;, but had a footer with links to the theme&#8217;s developer site. Unfortunately the developer&#8217;s site was no longer functioning. A &hellip; <a href=\"https:\/\/it.thelibrarie.com\/weblog\/2010\/07\/decode-eval-gzinflate-base64_decode\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Decode eval gzinflate base64_decode<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,1],"tags":[],"class_list":["post-562","post","type-post","status-publish","format-standard","hentry","category-linux","category-miscellaneous"],"_links":{"self":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/562","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/comments?post=562"}],"version-history":[{"count":6,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/562\/revisions"}],"predecessor-version":[{"id":642,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/562\/revisions\/642"}],"wp:attachment":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/media?parent=562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/categories?post=562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/tags?post=562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}