Reputation: 421
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
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
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
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).*<\/script>//
Upvotes: 2