forked from idrisawad/Webshell-Detect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebshell_detection.sh
57 lines (50 loc) · 1.79 KB
/
webshell_detection.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Step 1: Clone the repository
git clone https://github.com/rick001/Webshell-Detect.git
cd Webshell-Detect
# Step 2: Check if python3 is installed
if ! command -v python3 &> /dev/null; then
# Step 3: Install python3 if it's not installed
sudo apt update
sudo apt install -y python3
fi
# Step 4: Run the python script
python3 webshell_detect.py
# Step 5: Read the generated csv file and print the detected files
csv_file="webshell_detection_results.csv"
if [ -f "$csv_file" ]; then
echo "Detected Webshells:"
# Read the CSV file line by line and prompt the user for each file
tail -n +2 "$csv_file" | cut -d',' -f1 | while IFS= read -r file; do
if [[ -z "${file// }" ]]; then
continue
fi
echo "Found file: $file"
echo "Do you want to delete and kill processes for this file? (y/n)"
read -r response < /dev/tty
if [[ $response =~ ^[Yy]$ ]]; then
if [ -f "$file" ]; then
# Delete the file if it exists
rm "$file"
echo "Deleted: $file"
fi
# Check if a process with the same name is running and terminate it
process_name=$(basename "$file")
pids=$(pgrep -f "$process_name")
if [ -n "$pids" ]; then
echo "Processes running for $file:"
ps -p $pids
echo "Do you want to terminate these processes? (y/n)"
read -r kill_response < /dev/tty
if [[ $kill_response =~ ^[Yy]$ ]]; then
kill $pids
echo "Terminated processes for $file"
fi
else
echo "No running processes found for $file"
fi
fi
done
else
echo "No Webshell detected."
fi