<?php if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } class EmailDeception { public static function generateToken(string $attackerIp, string $attackerSession): string { return hash_hmac('sha256', $attackerIp . '|' . $attackerSession . '|' . time(), session_id()); } public static function recordDispatch(string $token, string $targetIp, string $type): void { try { Database::insert( "INSERT INTO deception_tokens (token, target_ip, deception_type, status, created_at)                  VALUES (:t, :ip, :type, 'active', NOW())", [':t' => $token, ':ip' => $targetIp, ':type' => $type] ); Events::record(Events::CAT_SECURITY, 'deception.dispatched', 'security', null, [ 'token_prefix' => substr($token, 0, 12), 'target_ip' => $targetIp, 'type' => $type, ]); } catch (\Throwable $e) {} } public static function checkToken(string $token): bool { try { $row = Database::fetchOne( "SELECT id, target_ip FROM deception_tokens WHERE token = :t AND status = 'active' LIMIT 1", [':t' => $token] ); if ($row) { Database::execute( "UPDATE deception_tokens SET status = 'triggered', triggered_at = NOW() WHERE id = :id", [':id' => (int)$row['id']] ); Database::execute( "INSERT IGNORE INTO blacklist (ip_address, reason, status_code, created_at)                      VALUES (:ip, 'deception_triggered', 1, NOW())", [':ip' => $row['target_ip']] ); Events::record(Events::CAT_SECURITY, 'deception.triggered', 'security', null, [ 'token_prefix' => substr($token, 0, 12), 'target_ip' => $row['target_ip'], ]); return true; } } catch (\Throwable $e) {} return false; } public static function status(): array { try { $active = (int)Database::scalar("SELECT COUNT(*) FROM deception_tokens WHERE status = 'active'"); $triggered = (int)Database::scalar("SELECT COUNT(*) FROM deception_tokens WHERE status = 'triggered'"); $recent = Database::fetchAll( "SELECT token, target_ip, deception_type, status, created_at, triggered_at                  FROM deception_tokens ORDER BY created_at DESC LIMIT 20" ); } catch (\Throwable $e) { $active = 0; $triggered = 0; $recent = []; } return ['active' => $active, 'triggered' => $triggered, 'recent' => $recent]; } } 