| Server IP : 3.111.61.48 / Your IP : 216.73.216.67 Web Server : Apache System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64 User : ubuntu ( 1000) PHP Version : 8.2.31 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /etc/script/ |
Upload File : |
import smtplib
import os
from datetime import datetime
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# Configuration
MONITOR_DIR = "/var/www/vhost" # Directory to monitor
SCRIPT_DIR = "/etc/script" # Directory for script and logs
LOG_FILE = os.path.join(SCRIPT_DIR, "monitored_default_Store-files.log") # Log file for stored file paths
EMAIL_LOG_FILE = os.path.join(SCRIPT_DIR, "email_alerts.log") # Log file for email alerts
# File extensions to monitor
MONITORED_EXTENSIONS = ('.php', '.exe', '.sh', '.js', '.htaccess', '.html', '.ini', '.bash', '.webp','.txt', '.png','.jpeg', '.py', '.xml')
# Email Configuration
sender_email = os.getenv("SENDER_EMAIL", "uptime@arukustech.com")
receiver_email = os.getenv("RECEIVER_EMAIL", "hosting@arukustech.com")
aws_smtp_server = os.getenv("AWS_SMTP_SERVER", "email-smtp.ap-south-1.amazonaws.com")
aws_smtp_port = int(os.getenv("AWS_SMTP_PORT", 587))
aws_smtp_username = os.getenv("AWS_SMTP_USERNAME", "AKIAYOTEITKZPI26TMDM")
aws_smtp_password = os.getenv("AWS_SMTP_PASSWORD", "BLFjkzAixZKQPoRz3owT9eVITObkYtODYxE7z/sU/M5K")
# Function to load the previously stored file paths from the log
def load_existing_files():
if os.path.exists(LOG_FILE):
with open(LOG_FILE, 'r') as log_file:
return set(log_file.read().splitlines())
else:
return set()
# Function to get the current list of files in the monitored directory with specific extensions
def get_current_files():
files = set()
for root, dirs, filenames in os.walk(MONITOR_DIR):
for filename in filenames:
if filename.endswith(MONITORED_EXTENSIONS): # Filter by extensions
file_path = os.path.join(root, filename)
files.add(file_path)
return files
# Function to log new file paths
def log_file_paths(file_paths):
try:
with open(LOG_FILE, 'a') as log:
for file_path in file_paths:
log.write(f"{file_path}\n")
print(f"Logged new files: {file_paths}")
except Exception as e:
print(f"Failed to log files: {e}")
# Function to send email alerts with new file paths
def send_email_alert(new_files):
if not new_files:
return # No new files to report
subject = "Alert: Arukus WP SRV Suspicious Files Detected"
body = "<html><body><h2 style='color: red;'>New Suspicious Files Detected</h2><ul>"
for file in new_files:
body += f"<li>{file}</li>"
body += "</ul><p><strong>Action Required:</strong> Please review the files listed above.</p>"
body += "<p><strong>Best regards,</strong><br>Arukus Tech Support</p></body></html>"
msg = MIMEMultipart()
msg['From'] = sender_email
msg['To'] = receiver_email
msg['Subject'] = subject
msg.attach(MIMEText(body, 'html'))
try:
print("Attempting to send email...")
with smtplib.SMTP(aws_smtp_server, aws_smtp_port) as server:
server.starttls()
server.login(aws_smtp_username, aws_smtp_password)
server.sendmail(sender_email, receiver_email, msg.as_string())
print("Email sent successfully.")
# Log email alert
with open(EMAIL_LOG_FILE, 'a') as email_log:
email_log.write(f"{datetime.now()} - Email Sent for Files: {', '.join(new_files)}\n")
except Exception as e:
print(f"Failed to send email: {e}")
with open(EMAIL_LOG_FILE, 'a') as email_log:
email_log.write(f"{datetime.now()} - Failed to Send Email - Error: {e}\n")
# Main function to compare file paths and send email
def main():
# Load the previously logged file paths
existing_files = load_existing_files()
# Get the current file paths in the monitored directory
current_files = get_current_files()
# Find the new files by comparing the current files with the existing ones
new_files = current_files - existing_files
if new_files:
print(f"New files detected: {new_files}")
# Send email alert for new files
send_email_alert(new_files)
# Log the new file paths into the monitored log file
log_file_paths(new_files)
else:
print("No new files detected.")
if __name__ == "__main__":
main()