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
How to replace specific text line out of multiple occurance madhusmita Shell Programming and Scripting 5 06-17-2008 01:03 PM
Replace text in multiple files on9west Shell Programming and Scripting 1 05-20-2008 01:35 AM
Replace text in multiple files Tonka52 Shell Programming and Scripting 10 03-24-2008 08:11 AM
How do you delete multiple text from a comma delimited file dolo21taf Shell Programming and Scripting 1 02-20-2008 05:12 AM
Need to search and replace in multiple files in directory hierarchy umen Shell Programming and Scripting 3 12-24-2007 04:56 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #15 (permalink)  
Old 06-05-2009
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
Quote:
Originally Posted by Nejc View Post
OK. Obviously this script doesn't do, what I would like, since it purged all my files. No harm done anyway, I did it on purpose on a testing website which was also spamed.

Before I ran the script, I also tested only with sed using this code:

Code:
sed "s:<?php echo '<script language='JavaScript'>function e590206b977().*<\/script>'; ?>::" index.php > index.temp

Surely it won't do anything, since you removed two crucial backslashes before the closing tag \/script>. It won't work without them:

Code:
sed "s:<?php echo '<script language='JavaScript'>function e590206b977().*<\\\/script>'; ?>::" index.php > index.temp

Quote:
I can say, that the above command of sed, just copies the file index.php to index.temp. Nothing else.
There is one thing for sure, every single character counts, if you miss one the whole code will fail. Please copy/paste when testing.

I tested with your spam sample, and it worked fine; obviously, if you have another spam string, different from the one above, the code needs again modifications.

The only important point about sed's pattern is the greedy regex .* , it'll match the whole portion of the string from the end of ...>function e590206b977() pattern up to the beginning of <\/script> spam's closing tag.
  #16 (permalink)  
Old 06-05-2009
Nejc Nejc is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 5
It still won't go. I have a normal index.php file added at the end of the file:

Code:
...
JDEBUG ? $_PROFILER->mark('afterRender') : null;
$mainframe->triggerEvent('onAfterRender');

/**
 * RETURN THE RESPONSE
 */
echo JResponse::toString($mainframe->getCfg('gzip'));
<?php echo '<script language='JavaScript'>function e590206b977() jozejsadf</script>'; ?>
In shell I do, for now even without that function part:

Code:
sed "s:<?php echo '<script language='JavaScript'>.*<\\\/script>'; ?>::" index.php > index.temp
Nothing happens. index.temp gets created with the same content as index.php.

Below is a copy/paste of the command:

Code:
demo@soncek:~/demo2$ sed "s:<?php echo '<script language='JavaScript'>.*<\\\/script>'; ?>::" index.php > index.temp

Last edited by Nejc; 06-05-2009 at 10:42 AM.. Reason: Pasted the command
  #17 (permalink)  
Old 06-05-2009
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
Quote:
Originally Posted by Nejc View Post
...
Nothing happens. index.temp gets created with the same content as index.php.

Below is a copy/paste of the command:

Code:
demo@soncek:~/demo2$ sed "s:<?php echo '<script language='JavaScript'>.*<\\\/script>'; ?>::" index.php > index.temp
I see ..., the previous code ( 3 backslashes ) worked fine in your previous sample, the code will work with the current sample if you remove only one \ .
Anyway to have predictable results, you'd be better off of getting rid of the <\/ pattern from the closing tag.

I get the desired output for all samples with the following code ( note the differences ):

Code:
sed "s:<?php echo '<script language='JavaScript'>.*script>'; ?>::" filename
Tested OK in Solaris and Cygwin (GNU sed).
Sponsored Links
Reply

Bookmarks

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 05:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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