JJ15
JJ15

Reputation: 421

Remove string/script from all files (recursive)

One of my websites has been hacked, all the index.html and index.php files have been infected with a certain Javascript. I would like to have a unix command to remove this script from all files.

Script is here: http://pastie.org/private/6osrvd5zhphe372gblrc6w

I am trying to figure this out with sed but no luck so far

Thanks!

Upvotes: 1

Views: 2291

Answers (3)

DonCallisto
DonCallisto

Reputation: 29932

sed -i 's/<script>.*<\/script>//' fileName

will remove the tag script and all its content.

This works if you only have one <script> tag.

If you haven't only one, extend it with try keyword in the following way

sed -i 's/<script>try.*<\/script>//' fileName

Edit

If you want to do it on all files in a recursive way, you can use a find command like this:

find . -name "index.html" -print | xargs sed -i 's/<script>try.*<\/script>//' fileName

where . is the current directory

Upvotes: 3

Vijay
Vijay

Reputation: 67291

perl -pi -e 's/<script>.*<\/script>//g' index.html

Upvotes: 0

Mirage
Mirage

Reputation: 31568

You can try this

find src/ -name "index.html" -print | xargs sed -i 's/<script>try{document.body++}catch(dgsgsdg){zxc=12;ww=window;}if(zxc).*<\/scri‌​pt>//

Upvotes: 2

Related Questions