#!/bin/sh # Comstop 0.1, Scot Hacker, shacker@birdhouse.org # Latest version at http://birhouse.org/blog/software/comstop.txt # A quick-n-dirty script to quickly rename all comment & trackback # scripts on a site currently undergoing a comment spam attack. # The goal is crude -- to simply pull the comment scripts out # from under the spammer so they'll be returned quick 404s instead. # Of course this disables ALL commenting until the script is run in reverse! # If run for multiple users, we assume it's being run as root. # This script could be amended in future versions # to also stop apache and kill lingering threads. # Install: Rename to "comstop" or "comstop.sh" and place in your path. # Change the SUFFIX variable and edit the SCRIPTFILE array to suit. # chmod 700 comstop -- nobody else should be able to read or run this script! # Run as "comstop do" (to rename files) or "comstop undo" (to un-rename) ############################ # Edit variables in this section # A made-up string to append to the end of comment script names # Change this to prevent educated guesses SUFFIX=pqrs # List paths to all files you want to rename. # This list can be as long or as short as you like. # TAKE CARE TO INCREMENT THE ARRAY NUMBERS! SCRIPTFILE[1]=/var/www/cgi-bin/mt/mt-comments.cgi SCRIPTFILE[2]=/var/www/cgi-bin/mt/mt-trackback.cgi SCRIPTFILE[3]=/home/joe/cgi-bin/mt/talking-87.cgi SCRIPTFILE[4]=/home/joe/cgi-bin/mt/tb-87.cgi SCRIPTFILE[5]=/home/jane/cgi-bin/mt/talking-22.cgi SCRIPTFILE[6]=/home/jane/cgi-bin/mt/tback.cgi SCRIPTFILE[7]=/home/fuzzy/cgi-bin/mt/talking-97.cgi SCRIPTFILE[8]=/home/fuzzy/cgi-bin/mt/track-17.cgi # Do not edit below this point ################################ # Make sure we got an argument. if [ ! $1 ]; then echo "comstop must be run with do or undo as an argument" exit else action="$1" fi # Should actually test here to make sure it's a *valid* argument, but whatevah. # OK, we need to rename or un-rename. Which is it? #################### # Rename files if [ "$action" == "do" ]; then echo "Renaming files with made-up suffixes" echo # Get the number of items in the array, for the counter NUMFILES=${#SCRIPTFILE[@]} # Add 1 to $NUMFILES for the counter let NUMFILES+=1 counter=1 while [ "$counter" != $NUMFILES ] do mv ${SCRIPTFILE[$counter]} ${SCRIPTFILE[$counter]}-$SUFFIX echo "$counter: Renamed ${SCRIPTFILE[$counter]} to ${SCRIPTFILE[$counter]}-$SUFFIX" echo let counter+=1 done fi #################### # Un-rename files if [ "$action" == "undo" ]; then echo "Restoring original filenames" echo # Get the number of items in the array, for the counter NUMFILES=${#SCRIPTFILE[@]} # Add 1 to $NUMFILES for the counter let NUMFILES+=1 counter=1 while [ "$counter" != $NUMFILES ] do mv ${SCRIPTFILE[$counter]}-$SUFFIX ${SCRIPTFILE[$counter]} echo "$counter: Restored ${SCRIPTFILE[$counter]}-$SUFFIX to ${SCRIPTFILE[$counter]}" echo let counter+=1 done fi