Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ssh command for searching inside files

Tags:

grep

search

ssh

Some weeks ago 2 of my sites have been exploited probably from an ftp bruteforce attack corrupting lots of my websites files. I found out that they usually insert the following code in js or php files:

[Trojan code removed as irrelevant to this question.]

I want to login via ssh and run a grep command searching all files and giving output only for the ones that have this code included.

Any help?

like image 960
makmour Avatar asked Nov 30 '22 08:11

makmour


2 Answers

I use this command to find all files that contain a specified string:

find /path/ -name "*.ext" -exec grep -l "sting" {} \;
like image 86
Bdwey Avatar answered Dec 04 '22 03:12

Bdwey


After you log in, just run:

find /path/to/fies -type f -name "*.js" -exec grep -il 'string' {}\; > output.txt

replacing "/path/to/files" and 'string' as appropriate, of course.

like image 44
Dmitri Avatar answered Dec 04 '22 03:12

Dmitri