#!/bin/bash
# Colors
ESC_SEQ="\x1b["
COL_RESET=$ESC_SEQ"39;49;00m"
COL_RED=$ESC_SEQ"31;01m"
COL_GREEN=$ESC_SEQ"32;01m"
COL_YELLOW=$ESC_SEQ"33;01m"
COL_BLUE=$ESC_SEQ"34;01m"
COL_MAGENTA=$ESC_SEQ"35;01m"
COL_CYAN=$ESC_SEQ"36;01m"
COL_LCYAN=$ESC_SEQ"37;01m"


xx=`cat suspicious | wc -l`
c=`cat suspicious | awk -F ':' {'print $1'}`
for i in $c;do
i=`echo $i | awk -F ':' {'print $1'}`
z=`cat "$i" | grep 'die("Access Denied")'`
if [[ "$z" != "" ]];then
echo "Skipping due to die"
x=$(($x+1))
i="dfsdf"
fi

if [ -f "$i" ];then
x=$(($x+1))
h=`head $i`
len=${#h}
echo "=========================================== ($x of $xx) $i ==============================="
echo -e "$COL_BLUE First 5 lines"
if [ "$len" -gt "500" ];then
echo -e "$COL_RED"
fi

head $i -n 5
echo ""
echo -e "$COL_RESET"
echo ". . . . . . . . . ."
echo ""
echo -e "$COL_BLUE Last 5 lines"
hhh=`tail $i`
tail $i -n 5
echo -e "$COL_RESET"
if [ "$len" -gt "500" ];then
echo "Found big header, will try to resolve..."
echo "<?php" > swap
sed '1d' $i >> swap
sz=`cat swap | grep -v '<?' | wc -l`
echo "---------------------------------Modified file------------------------"
hh=`head swap`
echo -e "$COL_LCYAN"
head swap
echo -e "$COL_RESET"
echo "----------------------------------------------------------------------"
                        fi

# echo $h
echo ""
echo "Virus ? (y/d/s $sz)"

if [[ "$h" = "$hhhh" ]];then
echo "d, DELETING is recommended, file is malware only"
fi

if [[ "$sz" = "0" ]];then
echo "d, DELETING is recommended, because corrected file have just 1 line"
fi

if [[ "$h" != "$hh" ]];then
echo "s, SAVING is recommended, seems file was cleaned"
fi





read a
if [[ "$a" == "y" ]];then
cp $i /infected/
echo $i >> infect_list
vim.tiny $i
                     fi

if [[ "$a" == "d" ]];then
cp $i /infected/
echo $i >> infect_list
rm -f $i
                     fi

if [[ "$a" == "s" ]];then
cp $i /infected/
cat swap > $i
echo $i >> infect_list
                     fi



echo "$x OK"
                fi
done
