Файловый менеджер - Редактировать - /home/digitalm/phpscanner1.py
Назад
import os import re import sys import argparse import pandas as pd from concurrent.futures import ThreadPoolExecutor, as_completed def scan_file(file_path, patterns): """ Scans a single file (PHP or .htaccess) for suspicious patterns. """ try: with open(file_path, 'r', encoding='utf-8', errors='ignore') as f: content = f.read() except Exception as e: return file_path, None, f"Error reading file: {e}" matches = {} for desc, regex in patterns.items(): found = regex.findall(content) if found: matches[desc] = f"[{desc}] Matches: {', '.join(set(found))}" return file_path, matches, None def scan_directory(root_path, patterns): """ Recursively scans a directory for PHP and .htaccess files. """ results = [] files_to_scan = [os.path.join(dp, f) for dp, _, filenames in os.walk(root_path) for f in filenames if f.endswith('.php') or f == '.htaccess'] with ThreadPoolExecutor() as executor: future_to_file = {executor.submit(scan_file, file, patterns): file for file in files_to_scan} for future in as_completed(future_to_file): file_path, matches, error = future.result() if error: print(f"[!] {file_path}: {error}") continue if matches: results.append({ "File Name": os.path.basename(file_path), "File Path": file_path, "Suspicious Signatures": " | ".join(matches.values()), # Merge signatures "Vulnerability Score": sum(len(v.split(',')) * 10 for v in matches.values()) # Sum scores }) return results def save_to_excel(results, output_file): """ Saves the scan results to an Excel file. """ df = pd.DataFrame(results) df.index += 1 df.index.name = "Number" try: df.to_excel(output_file, index=True, engine='openpyxl') print(f"\nResults saved to: {output_file}") except Exception as e: print(f"[!] Error saving results: {e}") def main(): parser = argparse.ArgumentParser(description="Scan PHP and .htaccess files for suspicious code.") parser.add_argument("path", help="Path to the website folder to scan") parser.add_argument("--output", default="suspicious_scan_results.xlsx", help="Path to output Excel file (default: suspicious_scan_results.xlsx)") args = parser.parse_args() root_path = args.path output_path = args.output if not os.path.isdir(root_path): print(f"Error: '{root_path}' is not a valid directory.") sys.exit(1) # Define suspicious regex patterns suspicious_patterns = { # PHP patterns "goto_statement": re.compile(r'\bgoto\s+\w+\s*;', re.IGNORECASE), "error_reporting_0": re.compile(r'\berror_reporting\s*\(\s*0\s*\)', re.IGNORECASE), "eval_function": re.compile(r'\beval\s*\(', re.IGNORECASE), "base64_decode": re.compile(r'\bbase64_decode\s*\(', re.IGNORECASE), "str_rot13": re.compile(r'\bstr_rot13\s*\(', re.IGNORECASE), "hex_escapes": re.compile(r'(\\x[0-9a-fA-F]{2}){5,}'), "curl_init": re.compile(r'\bcurl_init\s*\(', re.IGNORECASE), "file_get_contents": re.compile(r'\bfile_get_contents\s*\(', re.IGNORECASE), "include_statement": re.compile(r'@?\s*include\s*\(', re.IGNORECASE), # .htaccess suspicious rules "deny_php_execution": re.compile(r'<FilesMatch\s*"\.\(py\|exe\|php\)\$">\s*Order\s+allow,deny\s*Deny\s+from\s+all', re.IGNORECASE), "allow_suspicious_php": re.compile(r'<FilesMatch\s*"[^"]*\.php">\s*Order\s+allow,deny\s*Allow\s+from\s+all', re.IGNORECASE), "mod_rewrite_redirect": re.compile(r'RewriteRule\s+\.\s+/index\.php\s+\[L\]', re.IGNORECASE) } print(f"Scanning directory: {root_path}...") results = scan_directory(root_path, suspicious_patterns) if results: save_to_excel(results, output_path) else: print("No suspicious files detected.") if __name__ == "__main__": main()
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Генерация страницы: 0.03 |
proxy
|
phpinfo
|
Настройка