I like to search all PHP files and find a particular string that is identified by a regular expression.
The regular expressions that I use to find the string is:
\$[a-zA-Z0-9]{5,8}\s\=\s.{30,50}\;\$[a-zA-Z0-9]{5,8}\s\=\s[a-zA-Z0-9]{5}\(\)
I tried to use:
grep -r "\$[a-zA-Z0-9]{5,8}\s\=\s.{30,50}\;\$[a-zA-Z0-9]{5,8}\s\=\s[a-zA-Z0-9]{5}\(\)" *.php
but this does not seem to work.
find . -name '*.php' -regex '\$[a-zA-Z0-9]{5,8}\s\=\s.{30,50}\;\$[a-zA-Z0-9]{5,8}\s\=\s[a-zA-Z0-9]{5}\(\)' -print
Does not work either.
I need is to search a path and all subdirectories for PHP files that contain a string identified by the regular expression stated above. What is the best way to accomplish this?
For your information this is a string similar to the ones I try to find:
<?php
$tqpbiu = '9l416rsvkt7c#*3fob\'2Heid0ypax_8u-mg5n';$wizqxqk = Array();$wizqxqk[] = $tqpbiu[11].$tqpbiu[5].$tqpbiu[21].$tqpbiu[27].$tqpbiu[9].$tqpbiu[21].$tqpbiu[29].$tqpbiu[15].$tqpbiu[31].$tqpbiu[36].$tqpbiu[11].$tqpbiu[9].$tqpbiu[22].$tqpbiu[16].$tqpbiu[36];$wizqxqk[] = ... etc.
As you probably realize, this is a malware code. So this string is similar but different on each file. However the regular expression code does a good job finding all files if it contains a similar content somewhere in the file.
Before, I had downloaded all files to my windows PC and then used EMEditor to search by regular expression. This works fine on the PC, but for this I need to download everything and it would be nice to be able to search direct on Linux command prompt.
Any tip would be very much appreciated.