Listing files with certain text

Reply

Join Date: Jul 2009
Posts: 1
Reputation: daprezjer is an unknown quantity at this point 
Solved Threads: 0
daprezjer daprezjer is offline Offline
Newbie Poster

Listing files with certain text

 
0
  #1
Jul 8th, 2009
Pretty new at shell scripting. My server was hacked and instances of links for viagra were placed in it. I have lots of sites, so I need to search for all instances of "viagra" and list the files, so I can go remove the intrusions. Can this be done using shell?

Thanks.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,208
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is online now Online
.NET Enthusiast

Re: Listing files with certain text

 
0
  #2
Jul 9th, 2009
I'm going out on a limb and assuming you are using linux. If that is the case you can use grep to find the word:
  1. sk@svn:/tmp$ ls
  2. sk@svn:/tmp$ mkdir -p ./some/junk/dir
  3. sk@svn:/tmp$ echo "viagra" >> ./some/junk/dir/somefile.txt
  4. sk@svn:/tmp$ grep -l -r -i viagra .
  5. ./some/junk/dir/somefile.txt

For grep --
-l: list files, not the lines
-r: recursive
-i: case insensitive
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 2
Reputation: parul1234 is an unknown quantity at this point 
Solved Threads: 0
parul1234 parul1234 is offline Offline
Newbie Poster

Re: Listing files with certain text

 
0
  #3
Jul 10th, 2009
Are you using wordpress it happened with me few days back ... the reason was the old version of wordpress
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: Listing files with certain text

 
0
  #4
Jul 10th, 2009
Originally Posted by daprezjer View Post
Pretty new at shell scripting. My server was hacked and instances of links for viagra were placed in it. I have lots of sites, so I need to search for all instances of "viagra" and list the files, so I can go remove the intrusions. Can this be done using shell?

Thanks.
Yes, it can. A simplistic way to find all affected files, leaving you to do the rest of the work:
Shell Scripting Syntax (Toggle Plain Text)
  1. find / -type f -exec grep -li viagra {} \;

Or, assuming you are on a reasonably POSIX-ish system, a more complex way to find and edit all affected files, minimizing the effort you must exert:
Shell Scripting Syntax (Toggle Plain Text)
  1. find / -type f -exec grep -li viagra {} \; | while read a; do
  2. echo -n "Press <ENTER> to edit "
  3. tput smso
  4. echo -n "$a"
  5. tput rmso
  6. echo " or <CTRL/C> to quit"
  7. read b </dev/tty
  8. vi "$a" </dev/tty
  9. done

The tput() commands assist clarity, but aren't vital; delete them if your system doesn't speak terminfo. This is re-entrant. You don't have to remember where you were when you took a break or erred; once the noxious content has been removed, find() won't find it again.

This works on Debian Linux.
Last edited by Fest3er; Jul 10th, 2009 at 2:05 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC