LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 01-23-2010, 12:45 PM   #1
motiongrafika
LQ Newbie
 
Registered: Jan 2010
Location: India
Distribution: Ubuntu 9.10
Posts: 6

Rep: Reputation: 0
Using sed to remove a line from all files in a directory


A Javascript has crept into all my hmtl, php files in my shared hosting account. I have SSH access.

How can I use sed to remove that line from all files in a directory recursively ?
sed doesnt change the original file.
And I need to specify *.php and *.html

Thanx
 
Old 01-23-2010, 12:53 PM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by motiongrafika View Post
A Javascript has crept into all my hmtl, php files in my shared hosting account. I have SSH access.

How can I use sed to remove that line from all files in a directory recursively ?
sed doesnt change the original file.
And I need to specify *.php and *.html
You don't seem to be too concerned about how this got on there in the first place (please correct me if I'm wrong), which is weird considering you've posted in Security. Are you sure the JavaScript isn't placed there by your hosting provider? If it is, then removing it could be a violation of the terms and conditions.

Last edited by win32sux; 01-23-2010 at 12:56 PM.
 
1 members found this post helpful.
Old 01-24-2010, 01:35 AM   #3
motiongrafika
LQ Newbie
 
Registered: Jan 2010
Location: India
Distribution: Ubuntu 9.10
Posts: 6

Original Poster
Rep: Reputation: 0
Its a Virus / Phishing Script that has got injected.
This has happened previously on our previous hosting company. So definitely not by the host. We are still investigating the roots of this injection.

But for now I need to remove this in all my html & php files
Code:
<script>/*LGPL*/ try{ window.onload = function(){Gf7msvj9kxh8z [MODERATED] catch(Dv3z1tirm73hc81l1fz ) {}</script>

Last edited by unSpawn; 01-24-2010 at 02:25 AM. Reason: //Defused javascript
 
Old 01-24-2010, 02:23 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599
Quote:
Originally Posted by motiongrafika View Post
I need to remove this in all my html & php files
See this simple example for backing up and removing code and make your sed line look like something like 'sed -i "s|<script.*LGPL.*catch(Dv3z1tirm73hc81l1fz.).{}</script>|<\!-- REMOVED0 -->|g" -i "s|<\!--d7090973ec8e254afa1b87186938b792-->|<\!-- REMOVED1 -->|g" "${FILE}"'.


Quote:
Originally Posted by motiongrafika View Post
for now (..) We are still investigating the roots of this injection.
Leaving it at changing files will seem carefree and easy but you'll find the "infection" will also spread again and as easy. Best combat the cause first.
 
Old 01-28-2010, 12:32 AM   #5
motiongrafika
LQ Newbie
 
Registered: Jan 2010
Location: India
Distribution: Ubuntu 9.10
Posts: 6

Original Poster
Rep: Reputation: 0
The value of catch keeps changing.
Any method to remove all lines after </html> ?

Quote:
Leaving it at changing files will seem carefree and easy but you'll find the "infection" will also spread again and as easy. Best combat the cause first.
You are right - we removed it manually and re-uploaded and its back today.

But this script is not seen on pages which another guy located elsewhere uploads to. This seems to happen only when we upload in office.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sed or awk help - need to remove text on each line before a regular expression kmkocot Linux - Newbie 15 10-30-2009 03:20 AM
using sed to remove line in a comma-delimited file seefor Programming 4 03-10-2009 03:35 PM
Trying to use sed to remove last line if it contains a certain string. slaxative Linux - Software 1 03-18-2008 02:13 AM
[SOLVED] sed: How to remove the end of a line? angel115 Programming 2 10-01-2007 10:29 AM
sed question: remove decoration from each line Hivemind Linux - Software 1 01-18-2006 07:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 03:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration