#!/bin/bash
# ===============================
# Script quét tìm file nghi ngờ (PHP shell, file quyền sai, file mới tạo)
# ===============================

WEB_PATH="/home/username/public_html"  # <--- Thay đường dẫn web của bạn
LOG_FILE="scan_result_$(date +%F_%H-%M-%S).log"

echo "===== BẮT ĐẦU QUÉT WEBSITE =====" | tee -a $LOG_FILE
echo "Thời gian: $(date)" | tee -a $LOG_FILE
echo "Thư mục web: $WEB_PATH" | tee -a $LOG_FILE
echo "----------------------------------------" | tee -a $LOG_FILE

# 1. Tìm file chứa hàm nguy hiểm
echo "[1] File chứa hàm nguy hiểm:" | tee -a $LOG_FILE
grep -rilE "shell_exec|system\(|passthru|proc_open|base64_decode\(|eval\(" "$WEB_PATH" 2>/dev/null | tee -a $LOG_FILE
echo "----------------------------------------" | tee -a $LOG_FILE

# 2. Tìm file có quyền ghi 777
echo "[2] File có quyền ghi 777:" | tee -a $LOG_FILE
find "$WEB_PATH" -type f -perm 0777 2>/dev/null | tee -a $LOG_FILE
echo "----------------------------------------" | tee -a $LOG_FILE

# 3. Tìm file sửa đổi trong 7 ngày qua
echo "[3] File sửa đổi trong 7 ngày qua:" | tee -a $LOG_FILE
find "$WEB_PATH" -type f -mtime -7 2>/dev/null | tee -a $LOG_FILE
echo "----------------------------------------" | tee -a $LOG_FILE

# 4. Tìm file PHP nhỏ nhưng tên lạ
echo "[4] File PHP nhỏ (<200KB) tên lạ:" | tee -a $LOG_FILE
find "$WEB_PATH" -type f -name "*.php" ! -name "index.php" ! -name "wp-*.php" ! -name "functions.php" -size -200k 2>/dev/null | tee -a 
$LOG_FILE
echo "----------------------------------------" | tee -a $LOG_FILE

echo "===== QUÉT HOÀN TẤT =====" | tee -a $LOG_FILE
echo "Kết quả lưu tại: $LOG_FILE"
