Sample Header Ad - 728x90

Find recursively all files whose content match a specific regular expression

2 votes
1 answer
7520 views
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: 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.
Asked by TAPIO (23 rep)
Feb 2, 2021, 05:46 AM
Last activity: Feb 5, 2021, 02:41 PM