The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk find and replace in multiple files jdhahbi Shell Programming and Scripting 7 07-22-2009 10:03 AM
Opening Mulitple files using For loop in Perl Raynon Shell Programming and Scripting 4 05-06-2009 08:18 PM
Need help on Mulitple files mutliple actions saariko Shell Programming and Scripting 1 01-16-2009 03:35 AM
Find Strings in Files thepurple Shell Programming and Scripting 3 10-04-2008 06:23 AM
how find and replace into different files ran UNIX for Dummies Questions & Answers 1 03-18-2005 03:18 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-28-2009
zzlegs zzlegs is offline
Registered User
  
 

Join Date: May 2009
Posts: 1
Help with Find/Replace Javascript Injected Strings in mulitple files

Hi, guys, I'm not a high-end programmer, but I've been trying to write a script to remove all of the b.rtbn2.cn (and b.adserv.cn and any future variation) injected script tags on the server. (Still working on security fixes to prevent it in the future, just need to clean up now.)

My approach is 2 parted. First, make a file listing all of the filenames of infected files. Second, feed that file to a find/replace script. I want this to be a script file I can just run in the future with no modifications.

In March I figured out how to make a file listing all of the infected files and it worked fine, but when I ran it again this month after another malicious script injection, it's only finding the infected files in some of the directories instead of all of them. (If I change the directory to search a specific directory in /home/infecteddirectory then it finds it, but if I run it to search /home it doesn't find any in the above directory at all and I don't understand why. (It found some of the files in sub directories, but not in other sub directories.)

First part: Find all infected files in /home. The first one is the original line from March (worked then but not now) and the second on is the one modified to hopefully find all variations in May:

Code:
find /home -exec egrep -q "b.rtbn2.cn|b.adserv.cn" '{}' \; -print 2>/dev/null >infected_files_march2009 &

find /home -exec egrep -q "b\.([0-9]|[A-Z]|[a-z])+\.cn" '{}' \; -print 2>/dev/null >infected_files_may2009 &
Either one seems to be finding /home/infecteddirectory1 but then skipping /home/infecteddirectory2. Not sure why it's not listing all files in all subdirectories that are infected, please let me know if you see any scripting errors in the above code. It's like it's only doing a partial recursive and randomly stopping in the middle and saying it's done.

Second Part: I need help getting the sed/while do part to work. It currently doesn't work, but I can't quite figure out why. This first version is only looking for b.rtbn2.cn and not the any variety of b.something.cn. I wanted to get this working and then try to add the variable part, but I'm lost. I would like it just to leave the <script></script> part and take out the src="http://b.rtbn2.cn" part. (I found out if you leave the script tags in then the hacking program doesn't put them back in if it hits again.

Code:
cat infected_files_may2009|while read line ; do sed -i"s#<script src='http:\/\/b\.rtbn2\.cn\/E\/J\.JS'>##g" $line ;
Any help getting this to work would be greatly appreciated. I did search the boards, but didn't find an example close enough for me to follow.

Thanks!

Last edited by zzlegs; 05-28-2009 at 01:48 PM..
  #2 (permalink)  
Old 05-28-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,513
Quote:
Originally Posted by zzlegs View Post
Code:
cat infected_files_may2009|while read line ; do sed -i"s#<script src='http:\/\/b\.rtbn2\.cn\/E\/J\.JS'>##g" $line ;
the cat and while loop are useless. just use sed.
Code:
sed -i "s#.....................#" infected_files
Reply

Bookmarks

Tags
b.rtbn2.cn, find, hacked, multiple files, replace

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0