sed "/iframe/d" yourfilename
Main Topics
Browse All TopicsHi,
I need to remove an iframe from dozens of files on a linux system (a trojan got onto a computer with FTP details and spread iframes far and wide) and would like to do it in one hit if possible.
Could someone suggest the best way to do this with a shell script?
Cheers,
W1B
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Ozo's solution is the only one that deletes the contents of the iframe - which I believe the original was after. The other solutions just remove the string "iframe" from all the files, which will leave you with a bunch of broken HTML files.
Back up your files before you try any of these solutions! (Although Ozo's solution actually does this as well - he's very good).
Hi All,
Thanks for the quick responses. Below is some more information on what i've found. Some may not be relevant but I thought it best to give too much detail than too little.
@Ozo; Could you break your suggestion down for me? I can't replace all instances of 'iframe' as there are legitimate implementations on the sites. I really need to target only the specific frame.
@Jack; I can't really change the file names, or at least I need to change them all back after removing the offending frame. (Already changed the FTP details and isolated the affected systems, thanks for being thorough!).
In HTML files it places the frame immediately after the <body> tag. I think it searches for the string 'body' however as i've seen one case where it inserted the frame after a class with 'body' in it. In PHP files it places the iframe at the end of the file.
The frame is always iserted after the tag on a single line:
<body><iframe src="http://someattacksite
I've also found various cases where it seems to have created it's own 'default.html' and 'index.html' files in various subdirectories. These files contain the following:
No Access
<iframe src="http://someattacksite
I'm guessing the script used just creates these files once it hits a dead end.
As far as I can tell looks for 'default.*' and 'index.*' files, however I've also found one case where 'home.php' was affected so i'd guess it looks for files of that name also.
I've been able to find the infected files (with a pretty good certainty, some of the affected sites were small enough to manually check) by using grep:
grep -R ":8080" *
and
grep -R ".cn:8080"
Thanks for your help!
Thanks nemws1, I was writing at the same time as you I think.
Creating backups would be great... If Ozo could elaborate a little I'd happily go with his suggestion. I've got absolutely no idea wrt perl, but no objections to learning either.
It might be asking too much but and ideal solution would be a generic script along the lines of;
1. Find files with [some string] in [some path]
2. Print a list of files to be changed, request confirmation
3. Backup said files in a neutral format, in their own directories same directory (so that the malicious link isn't a threat and the backup is in a logical place)
4. Remove [some string]
5. Save or email a log file of changes, with full paths.
I'll bump up the points if i can get the whole enchilada...
if the iframe is always exactly the same
perl -i.bak -pe 's#<iframe src="http://someattacksite
Thanks Ozo, this is working in my tests within the same directory but I'm having difficulty getting it to work on the files found using grep (if theres another way to get it to recurse, please let me know).
for files in 'grep -R -l ".cn:8080" *'; do
perl -i.bak -pe 's#\<iframe src="http://someattacksite
done
Any suggestions appreciated.
Cheers,
W1B
find . -name '*.html' -o '*.php' | xargs perl -i.bak -pe 's#<iframe src="http://someattacksite
grep -R -l ".cn:8080" . | xargs perl -i.bak -pe 's#<iframe src="http://someattacksite
Business Accounts
Answer for Membership
by: ozoPosted on 2009-08-09 at 19:49:26ID: 25056894
something like ' *
perl -i.bak -0ne 's#<iframe[^>]*>.*?</iframe>#gs