<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bot Defense Platform | Security Operations</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--bg-primary: #0a0e17;
--bg-secondary: #111827;
--bg-tertiary: #1a2235;
--accent-cyan: #00d4ff;
--accent-green: #00ff88;
--accent-red: #ff4757;
--accent-orange: #ffa502;
--accent-purple: #a855f7;
--text-primary: #e8eaed;
--text-secondary: #9ca3af;
--border-color: #2a3441;
}
body {
font-family: 'Segoe UI', system-ui, sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
min-height: 100vh;
overflow-x: hidden;
}
#canvas-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 0;
pointer-events: none;
}
.main-container {
position: relative;
z-index: 1;
padding: 20px;
max-width: 1600px;
margin: 0 auto;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px 30px;
background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
border-radius: 16px;
border: 1px solid var(--border-color);
margin-bottom: 20px;
}
.logo {
display: flex;
align-items: center;
gap: 15px;
}
.logo-icon {
width: 50px;
height: 50px;
background: linear-gradient(135deg, var(--accent-cyan), var(--accent-green));
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
font-weight: bold;
color: var(--bg-primary);
}
.logo h1 {
font-size: 24px;
font-weight: 600;
background: linear-gradient(90deg, var(--accent-cyan), var(--accent-green));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.logo span {
font-size: 12px;
color: var(--text-secondary);
display: block;
}
.status-badge {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 20px;
background: rgba(0, 212, 255, 0.1);
border: 1px solid var(--accent-cyan);
border-radius: 30px;
}
.status-dot {
width: 10px;
height: 10px;
background: var(--accent-green);
border-radius: 50%;
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { box-shadow: 0 0 0 0 rgba(0, 255, 136, 0.4); }
50% { box-shadow: 0 0 0 10px rgba(0, 255, 136, 0); }
}
.dashboard-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20px;
}
.panel {
background: var(--bg-secondary);
border-radius: 16px;
border: 1px solid var(--border-color);
overflow: hidden;
transition: transform 0.3s, box-shadow 0.3s;
}
.panel:hover {
transform: translateY(-2px);
box-shadow: 0 10px 40px rgba(0, 212, 255, 0.1);
}
.panel-header {
padding: 20px;
background: var(--bg-tertiary);
border-bottom: 1px solid var(--border-color);
display: flex;
justify-content: space-between;
align-items: center;
}
.panel-title {
font-size: 16px;
font-weight: 600;
display: flex;
align-items: center;
gap: 10px;
}
.panel-icon {
width: 32px;
height: 32px;
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
font-size: 16px;
}
.panel-content {
padding: 20px;
}
.col-span-2 { grid-column: span 2; }
.row-span-2 { grid-row: span 2; }
/* Risk Score Display */
.risk-display {
text-align: center;
padding: 30px;
}
.risk-circle {
width: 180px;
height: 180px;
margin: 0 auto 20px;
position: relative;
}
.risk-circle svg {
transform: rotate(-90deg);
}
.risk-bg {
fill: none;
stroke: var(--bg-tertiary);
stroke-width: 12;
}
.risk-progress {
fill: none;
stroke-width: 12;
stroke-linecap: round;
transition: stroke-dashoffset 1s ease, stroke 0.5s ease;
}
.risk-value {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 48px;
font-weight: 700;
}
.risk-label {
font-size: 14px;
color: var(--text-secondary);
margin-top: 10px;
}
.verdict {
padding: 12px 30px;
border-radius: 30px;
font-weight: 600;
font-size: 14px;
text-transform: uppercase;
letter-spacing: 1px;
margin-top: 15px;
display: inline-block;
}
.verdict.human {
background: rgba(0, 255, 136, 0.15);
color: var(--accent-green);
border: 1px solid var(--accent-green);
}
.verdict.suspicious {
background: rgba(255, 165, 2, 0.15);
color: var(--accent-orange);
border: 1px solid var(--accent-orange);
}
.verdict.bot {
background: rgba(255, 71, 87, 0.15);
color: var(--accent-red);
border: 1px solid var(--accent-red);
}
/* Behavioral Canvas */
.behavior-canvas-container {
position: relative;
height: 200px;
background: var(--bg-primary);
border-radius: 12px;
overflow: hidden;
cursor: crosshair;
}
#behaviorCanvas {
width: 100%;
height: 100%;
}
.behavior-stats {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 10px;
margin-top: 15px;
}
.stat-item {
background: var(--bg-tertiary);
padding: 12px;
border-radius: 8px;
text-align: center;
}
.stat-value {
font-size: 20px;
font-weight: 600;
color: var(--accent-cyan);
}
.stat-label {
font-size: 11px;
color: var(--text-secondary);
margin-top: 4px;
}
/* Fingerprint Panel */
.fingerprint-list {
max-height: 300px;
overflow-y: auto;
}
.fingerprint-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px 15px;
background: var(--bg-tertiary);
border-radius: 8px;
margin-bottom: 8px;
transition: background 0.3s;
}
.fingerprint-item:hover {
background: rgba(0, 212, 255, 0.1);
}
.fp-label {
font-size: 13px;
color: var(--text-secondary);
}
.fp-value {
font-size: 12px;
font-family: monospace;
color: var(--accent-cyan);
max-width: 150px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* Challenge Panel */
.challenge-area {
text-align: center;
padding: 20px;
}
.challenge-question {
font-size: 28px;
font-weight: 700;
color: var(--accent-cyan);
margin-bottom: 20px;
font-family: monospace;
}
.challenge-input {
width: 100%;
padding: 15px;
background: var(--bg-primary);
border: 2px solid var(--border-color);
border-radius: 10px;
color: var(--text-primary);
font-size: 18px;
text-align: center;
outline: none;
transition: border-color 0.3s;
}
.challenge-input:focus {
border-color: var(--accent-cyan);
}
.challenge-btn {
width: 100%;
padding: 15px;
margin-top: 15px;
background: linear-gradient(135deg, var(--accent-cyan), var(--accent-green));
border: none;
border-radius: 10px;
color: var(--bg-primary);
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: transform 0.3s, box-shadow 0.3s;
}
.challenge-btn:hover {
transform: scale(1.02);
box-shadow: 0 5px 20px rgba(0, 212, 255, 0.3);
}
.challenge-result {
margin-top: 15px;
padding: 10px;
border-radius: 8px;
font-size: 13px;
}
.challenge-result.success {
background: rgba(0, 255, 136, 0.15);
color: var(--accent-green);
}
.challenge-result.fail {
background: rgba(255, 71, 87, 0.15);
color: var(--accent-red);
}
/* Explainability Panel */
.explanation-chart {
height: 250px;
display: flex;
flex-direction: column;
justify-content: space-around;
}
.feature-bar {
display: flex;
align-items: center;
gap: 15px;
}
.feature-name {
width: 120px;
font-size: 12px;
color: var(--text-secondary);
text-align: right;
}
.feature-track {
flex: 1;
height: 24px;
background: var(--bg-primary);
border-radius: 12px;
overflow: hidden;
position: relative;
}
.feature-fill {
height: 100%;
border-radius: 12px;
transition: width 1s ease;
position: relative;
}
.feature-fill.positive {
background: linear-gradient(90deg, var(--accent-green), rgba(0, 255, 136, 0.5));
}
.feature-fill.negative {
background: linear-gradient(90deg, var(--accent-red), rgba(255, 71, 87, 0.5));
}
.feature-score {
width: 50px;
font-size: 12px;
font-weight: 600;
text-align: right;
}
.explanation-summary {
margin-top: 20px;
padding: 15px;
background: var(--bg-tertiary);
border-radius: 10px;
border-left: 3px solid var(--accent-cyan);
}
.explanation-summary h4 {
font-size: 14px;
margin-bottom: 8px;
color: var(--accent-cyan);
}
.explanation-summary p {
font-size: 13px;
color: var(--text-secondary);
line-height: 1.6;
}
/* Logs Panel */
.logs-container {
max-height: 250px;
overflow-y: auto;
font-family: monospace;
font-size: 11px;
}
.log-entry {
padding: 8px 12px;
border-bottom: 1px solid var(--border-color);
display: flex;
gap: 10px;
}
.log-time {
color: var(--text-secondary);
}
.log-type {
padding: 2px 8px;
border-radius: 4px;
font-size: 10px;
font-weight: 600;
}
.log-type.info { background: rgba(0, 212, 255, 0.2); color: var(--accent-cyan); }
.log-type.warn { background: rgba(255, 165, 2, 0.2); color: var(--accent-orange); }
.log-type.alert { background: rgba(255, 71, 87, 0.2); color: var(--accent-red); }
.log-type.success { background: rgba(0, 255, 136, 0.2); color: var(--accent-green); }
.log-message {
color: var(--text-primary);
}
/* Scrollbar */
::-webkit-scrollbar {
width: 6px;
}
::-webkit-scrollbar-track {
background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
background: var(--border-color);
border-radius: 3px;
}
@media (max-width: 1200px) {
.dashboard-grid {
grid-template-columns: repeat(2, 1fr);
}
.col-span-2 { grid-column: span 1; }
}
@media (max-width: 768px) {
.dashboard-grid {
grid-template-columns: 1fr;
}
.header {
flex-direction: column;
gap: 15px;
}
}
</style>
</head>
<body>
<div id="canvas-container"></div>
<div class="main-container">
<header class="header">
<div class="logo">
<div class="logo-icon">BD</div>
<div>
<h1>Bot Defense Platform</h1>
<span>Multi-Layered Security Analysis</span>
</div>
</div>
<div class="status-badge">
<div class="status-dot"></div>
<span>Protection Active</span>
</div>
</header>
<div class="dashboard-grid">
<!-- Risk Score Panel -->
<div class="panel">
<div class="panel-header">
<div class="panel-title">
<div class="panel-icon" style="background: rgba(0, 212, 255, 0.2); color: var(--accent-cyan);">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>
</svg>
</div>
Risk Assessment
</div>
</div>
<div class="panel-content">
<div class="risk-display">
<div class="risk-circle">
<svg width="180" height="180" viewBox="0 0 180 180">
<circle class="risk-bg" cx="90" cy="90" r="78"/>
<circle class="risk-progress" id="riskProgress" cx="90" cy="90" r="78"
stroke="var(--accent-green)"
stroke-dasharray="490"
stroke-dashoffset="490"/>
</svg>
<div class="risk-value" id="riskValue">0</div>
</div>
<div class="risk-label">Bot Probability Score</div>
<div class="verdict human" id="verdict">Analyzing</div>
</div>
</div>
</div>
<!-- Behavioral Analytics Panel -->
<div class="panel col-span-2">
<div class="panel-header">
<div class="panel-title">
<div class="panel-icon" style="background: rgba(0, 255, 136, 0.2); color: var(--accent-green);">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="22,12 18,12 15,21 9,3 6,12 2,12"/>
</svg>
</div>
Behavioral Analytics
</div>
<span style="font-size: 12px; color: var(--text-secondary);">Move mouse in the area below</span>
</div>
<div class="panel-content">
<div class="behavior-canvas-container">
<canvas id="behaviorCanvas"></canvas>
</div>
<div class="behavior-stats">
<div class="stat-item">
<div class="stat-value" id="mouseSpeed">0</div>
<div class="stat-label">Mouse Velocity</div>
</div>
<div class="stat-item">
<div class="stat-value" id="clickCount">0</div>
<div class="stat-label">Click Events</div>
</div>
<div class="stat-item">
<div class="stat-value" id="keypressCount">0</div>
<div class="stat-label">Keystrokes</div>
</div>
<div class="stat-item">
<div class="stat-value" id="humanScore">--</div>
<div class="stat-label">Human Score</div>
</div>
</div>
</div>
</div>
<!-- Device Fingerprint Panel -->
<div class="panel">
<div class="panel-header">
<div class="panel-title">
<div class="panel-icon" style="background: rgba(168, 85, 247, 0.2); color: var(--accent-purple);">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="4" y="4" width="16" height="16" rx="2"/>
<rect x="9" y="9" width="6" height="6"/>
</svg>
</div>
Device Fingerprint
</div>
</div>
<div class="panel-content">
<div class="fingerprint-list" id="fingerprintList"></div>
</div>
</div>
<!-- JavaScript Challenge Panel -->
<div class="panel">
<div class="panel-header">
<div class="panel-title">
<div class="panel-icon" style="background: rgba(255, 165, 2, 0.2); color: var(--accent-orange);">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/>
</svg>
</div>
JS Challenge
</div>
</div>
<div class="panel-content">
<div class="challenge-area">
<div style="font-size: 13px; color: var(--text-secondary); margin-bottom: 10px;">
Solve this cryptographic puzzle:
</div>
<div class="challenge-question" id="challengeQuestion">--</div>
<input type="text" class="challenge-input" id="challengeInput" placeholder="Enter your answer">
<button class="challenge-btn" id="challengeBtn">Verify Answer</button>
<div class="challenge-result" id="challengeResult" style="display: none;"></div>
</div>
</div>
</div>
<!-- Explainability Panel -->
<div class="panel">
<div class="panel-header">
<div class="panel-title">
<div class="panel-icon" style="background: rgba(0, 212, 255, 0.2); color: var(--accent-cyan);">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"/>
<path d="M12 16v-4M12 8h.01"/>
</svg>
</div>
Decision Explainability
</div>
</div>
<div class="panel-content">
<div class="explanation-chart" id="explanationChart"></div>
<div class="explanation-summary" id="explanationSummary">
<h4>Analysis Summary</h4>
<p>Interact with the page to begin the security analysis. The system will evaluate behavioral patterns, device characteristics, and challenge responses.</p>
</div>
</div>
</div>
<!-- Activity Logs Panel -->
<div class="panel col-span-2">
<div class="panel-header">
<div class="panel-title">
<div class="panel-icon" style="background: rgba(255, 71, 87, 0.2); color: var(--accent-red);">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
<polyline points="14,2 14,8 20,8"/>
<line x1="16" y1="13" x2="8" y2="13"/>
<line x1="16" y1="17" x2="8" y2="17"/>
</svg>
</div>
Activity Logs
</div>
</div>
<div class="panel-content">
<div class="logs-container" id="logsContainer"></div>
</div>
</div>
</div>
</div>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.160.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
// ============== THREE.JS BACKGROUND ==============
class ParticleNetwork {
constructor(container) {
this.container = container;
this.particles = [];
this.connections = [];
this.scene = new THREE.Scene();
this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
this.camera.position.z = 50;
this.renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
this.renderer.setSize(window.innerWidth, window.innerHeight);
this.renderer.setClearColor(0x000000, 0);
container.appendChild(this.renderer.domElement);
this.createParticles();
this.animate();
window.addEventListener('resize', () => this.onResize());
}
createParticles() {
const geometry = new THREE.BufferGeometry();
const count = 150;
const positions = new Float32Array(count * 3);
const colors = new Float32Array(count * 3);
for (let i = 0; i < count; i++) {
positions[i * 3] = (Math.random() - 0.5) * 100;
positions[i * 3 + 1] = (Math.random() - 0.5) * 100;
positions[i * 3 + 2] = (Math.random() - 0.5) * 50;
const color = new THREE.Color();
color.setHSL(0.5 + Math.random() * 0.1, 0.8, 0.6);
colors[i * 3] = color.r;
colors[i * 3 + 1] = color.g;
colors[i * 3 + 2] = color.b;
this.particles.push({
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 0.02,
(Math.random() - 0.5) * 0.02,
(Math.random() - 0.5) * 0.01
)
});
}
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));
const material = new THREE.PointsMaterial({
size: 0.8,
vertexColors: true,
transparent: true,
opacity: 0.8,
sizeAttenuation: true
});
this.points = new THREE.Points(geometry, material);
this.scene.add(this.points);
// Connection lines
this.lineGeometry = new THREE.BufferGeometry();
this.lineMaterial = new THREE.LineBasicMaterial({
color: 0x00d4ff,
transparent: true,
opacity: 0.15
});
this.lines = new THREE.LineSegments(this.lineGeometry, this.lineMaterial);
this.scene.add(this.lines);
}
updateConnections() {
const positions = this.points.geometry.attributes.position.array;
const linePositions = [];
const maxDist = 15;
for (let i = 0; i < this.particles.length; i++) {
for (let j = i + 1; j < this.particles.length; j++) {
const dx = positions[i * 3] - positions[j * 3];
const dy = positions[i * 3 + 1] - positions[j * 3 + 1];
const dz = positions[i * 3 + 2] - positions[j * 3 + 2];
const dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (dist < maxDist) {
linePositions.push(
positions[i * 3], positions[i * 3 + 1], positions[i * 3 + 2],
positions[j * 3], positions[j * 3 + 1], positions[j * 3 + 2]
);
}
}
}
this.lineGeometry.setAttribute('position', new THREE.Float32BufferAttribute(linePositions, 3));
}
animate() {
requestAnimationFrame(() => this.animate());
const positions = this.points.geometry.attributes.position.array;
for (let i = 0; i < this.particles.length; i++) {
positions[i * 3] += this.particles[i].velocity.x;
positions[i * 3 + 1] += this.particles[i].velocity.y;
positions[i * 3 + 2] += this.particles[i].velocity.z;
// Boundary check
if (Math.abs(positions[i * 3]) > 50) this.particles[i].velocity.x *= -1;
if (Math.abs(positions[i * 3 + 1]) > 50) this.particles[i].velocity.y *= -1;
if (Math.abs(positions[i * 3 + 2]) > 25) this.particles[i].velocity.z *= -1;
}
this.points.geometry.attributes.position.needsUpdate = true;
this.points.rotation.y += 0.0005;
this.updateConnections();
this.renderer.render(this.scene, this.camera);
}
onResize() {
this.camera.aspect = window.innerWidth / window.innerHeight;
this.camera.updateProjectionMatrix();
this.renderer.setSize(window.innerWidth, window.innerHeight);
}
}
// ============== BOT DEFENSE SYSTEM ==============
class BotDefenseSystem {
constructor() {
this.behavioralData = {
mouseMovements: [],
clicks: 0,
keystrokes: 0,
scrollEvents: 0,
lastMousePos: { x: 0, y: 0 },
lastMouseTime: Date.now(),
velocities: [],
typingPattern: []
};
this.fingerprint = {};
this.challengeData = {
current: null,
solved: false,
attempts: 0
};
this.scores = {
behavioral: 50,
fingerprint: 50,
challenge: 50
};
this.featureWeights = {
'Mouse Dynamics': { value: 0, weight: 0.25, positive: true },
'Click Patterns': { value: 0, weight: 0.15, positive: true },
'Typing Rhythm': { value: 0, weight: 0.15, positive: true },
'Canvas Hash': { value: 0, weight: 0.10, positive: true },
'WebGL Signature': { value: 0, weight: 0.10, positive: true },
'Audio Context': { value: 0, weight: 0.08, positive: true },
'Challenge Pass': { value: 0, weight: 0.12, positive: true },
'Consistency': { value: 0, weight: 0.05, positive: true }
};
this.logs = [];
this.init();
}
init() {
this.log('info', 'Bot Defense System initialized');
this.log('info', 'Starting multi-layered analysis...');
this.setupBehaviorTracking();
this.collectFingerprint();
this.generateChallenge();
this.updateExplanationChart();
setInterval(() => this.updateRiskScore(), 500);
}
// ============== BEHAVIORAL ANALYTICS ==============
setupBehaviorTracking() {
const canvas = document.getElementById('behaviorCanvas');
const ctx = canvas.getContext('2d');
const resizeCanvas = () => {
canvas.width = canvas.offsetWidth;
canvas.height = canvas.offsetHeight;
};
resizeCanvas();
window.addEventListener('resize', resizeCanvas);
// Mouse tracking
canvas.addEventListener('mousemove', (e) => {
const rect = canvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const now = Date.now();
// Calculate velocity
const dx = x - this.behavioralData.lastMousePos.x;
const dy = y - this.behavioralData.lastMousePos.y;
const dt = now - this.behavioralData.lastMouseTime;
if (dt > 0) {
const velocity = Math.sqrt(dx * dx + dy * dy) / dt * 100;
this.behavioralData.velocities.push(velocity);
if (this.behavioralData.velocities.length > 50) {
this.behavioralData.velocities.shift();
}
}
this.behavioralData.mouseMovements.push({ x, y, time: now });
if (this.behavioralData.mouseMovements.length > 200) {
this.behavioralData.mouseMovements.shift();
}
this.behavioralData.lastMousePos = { x, y };
this.behavioralData.lastMouseTime = now;
// Draw trail
this.drawMouseTrail(ctx, x, y);
// Update stats
this.updateBehaviorStats();
});
// Click tracking
document.addEventListener('click', () => {
this.behavioralData.clicks++;
document.getElementById('clickCount').textContent = this.behavioralData.clicks;
this.featureWeights['Click Patterns'].value = Math.min(100, this.behavioralData.clicks * 5);
this.log('info', `Click event detected (total: ${this.behavioralData.clicks})`);
});
// Keystroke tracking
document.addEventListener('keydown', (e) => {
this.behavioralData.keystrokes++;
this.behavioralData.typingPattern.push({
key: e.key,
time: Date.now()
});
document.getElementById('keypressCount').textContent = this.behavioralData.keystrokes;
this.featureWeights['Typing Rhythm'].value = Math.min(100, this.behavioralData.keystrokes * 3);
});
// Scroll tracking
document.addEventListener('scroll', () => {
this.behavioralData.scrollEvents++;
});
}
drawMouseTrail(ctx, x, y) {
const movements = this.behavioralData.mouseMovements;
ctx.fillStyle = 'rgba(10, 14, 23, 0.05)';
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
// Draw trail
if (movements.length > 1) {
ctx.beginPath();
ctx.moveTo(movements[0].x, movements[0].y);
for (let i = 1; i < movements.length; i++) {
ctx.lineTo(movements[i].x, movements[i].y);
}
ctx.strokeStyle = 'rgba(0, 212, 255, 0.5)';
ctx.lineWidth = 2;
ctx.stroke();
}
// Draw current point
ctx.beginPath();
ctx.arc(x, y, 6, 0, Math.PI * 2);
ctx.fillStyle = '#00d4ff';
ctx.fill();
// Draw glow
const gradient = ctx.createRadialGradient(x, y, 0, x, y, 30);
gradient.addColorStop(0, 'rgba(0, 212, 255, 0.3)');
gradient.addColorStop(1, 'rgba(0, 212, 255, 0)');
ctx.beginPath();
ctx.arc(x, y, 30, 0, Math.PI * 2);
ctx.fillStyle = gradient;
ctx.fill();
}
updateBehaviorStats() {
const velocities = this.behavioralData.velocities;
if (velocities.length > 0) {
const avgVelocity = velocities.reduce((a, b) => a + b, 0) / velocities.length;
document.getElementById('mouseSpeed').textContent = avgVelocity.toFixed(1);
// Human-like velocity variance check
const variance = this.calculateVariance(velocities);
const humanScore = Math.min(100, Math.max(0, 100 - Math.abs(variance - 50) * 2));
document.getElementById('humanScore').textContent = humanScore.toFixed(0);
this.featureWeights['Mouse Dynamics'].value = humanScore;
}
}
calculateVariance(arr) {
if (arr.length === 0) return 0;
const mean = arr.reduce((a, b) => a + b, 0) / arr.length;
return arr.reduce((sum, val) => sum + Math.pow(val - mean, 2), 0) / arr.length;
}
// ============== DEVICE FINGERPRINTING ==============
async collectFingerprint() {
this.log('info', 'Collecting device fingerprint...');
const fp = {};
// Screen info
fp['Screen Resolution'] = `${screen.width}x${screen.height}`;
fp['Color Depth'] = screen.colorDepth;
fp['Device Pixel Ratio'] = window.devicePixelRatio;
// Timezone
fp['Timezone'] = Intl.DateTimeFormat().resolvedOptions().timeZone;
fp['UTC Offset'] = new Date().getTimezoneOffset();
// Language
fp['Language'] = navigator.language;
fp['Languages'] = navigator.languages?.join(', ');
// Platform
fp['Platform'] = navigator.platform;
fp['User Agent'] = navigator.userAgent.substring(0, 50) + '...';
// Hardware
fp['CPU Cores'] = navigator.hardwareConcurrency || 'Unknown';
fp['Device Memory'] = navigator.deviceMemory ? `${navigator.deviceMemory}GB` : 'Unknown';
// Canvas fingerprint
fp['Canvas Hash'] = await this.getCanvasFingerprint();
// WebGL fingerprint
const webgl = this.getWebGLFingerprint();
fp['WebGL Vendor'] = webgl.vendor;
fp['WebGL Renderer'] = webgl.renderer.substring(0, 30) + '...';
// Audio fingerprint
fp['Audio Hash'] = await this.getAudioFingerprint();
// Touch support
fp['Touch Points'] = navigator.maxTouchPoints;
// Plugins
fp['Plugins'] = navigator.plugins?.length || 0;
this.fingerprint = fp;
this.renderFingerprintList();
// Update feature weights
this.featureWeights['Canvas Hash'].value = fp['Canvas Hash'] ? 80 : 0;
this.featureWeights['WebGL Signature'].value = webgl.vendor ? 75 : 0;
this.featureWeights['Audio Context'].value = fp['Audio Hash'] ? 70 : 0;
this.log('success', `Fingerprint collected (${Object.keys(fp).length} attributes)`);
}
async getCanvasFingerprint() {
try {
const canvas = document.createElement('canvas');
canvas.width = 200;
canvas.height = 50;
const ctx = canvas.getContext('2d');
ctx.fillStyle = '#f0f0f0';
ctx.fillRect(0, 0, 200, 50);
ctx.fillStyle = '#333';
ctx.font = '14px Arial';
ctx.fillText('Fingerprint Test 123', 10, 30);
// Add some shapes
ctx.beginPath();
ctx.arc(150, 25, 15, 0, Math.PI * 2);
ctx.fillStyle = '#00d4ff';
ctx.fill();
const dataUrl = canvas.toDataURL();
const hash = this.simpleHash(dataUrl);
return hash;
} catch (e) {
return 'blocked';
}
}
getWebGLFingerprint() {
try {
const canvas = document.createElement('canvas');
const gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
if (!gl) return { vendor: 'none', renderer: 'none' };
const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
return {
vendor: debugInfo ? gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL) : 'unknown',
renderer: debugInfo ? gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) : 'unknown'
};
} catch (e) {
return { vendor: 'error', renderer: 'error' };
}
}
async getAudioFingerprint() {
try {
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
const oscillator = audioContext.createOscillator();
const analyser = audioContext.createAnalyser();
const gain = audioContext.createGain();
const processor = audioContext.createScriptProcessor(4096, 1, 1);
gain.gain.value = 0;
oscillator.type = 'triangle';
oscillator.frequency.value = 10000;
oscillator.connect(analyser);
analyser.connect(processor);
processor.connect(gain);
gain.connect(audioContext.destination);
oscillator.start(0);
const hash = this.simpleHash(audioContext.sampleRate.toString() + analyser.fftSize.toString());
oscillator.stop();
audioContext.close();
return hash;
} catch (e) {
return 'blocked';
}
}
simpleHash(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash;
}
return Math.abs(hash).toString(16).substring(0, 8).toUpperCase();
}
renderFingerprintList() {
const container = document.getElementById('fingerprintList');
container.innerHTML = '';
for (const [key, value] of Object.entries(this.fingerprint)) {
const item = document.createElement('div');
item.className = 'fingerprint-item';
item.innerHTML = `
<span class="fp-label">${key}</span>
<span class="fp-value" title="${value}">${value}</span>
`;
container.appendChild(item);
}
}
// ============== JAVASCRIPT CHALLENGE ==============
generateChallenge() {
const challenges = [
{
question: () => {
const a = Math.floor(Math.random() * 20) + 10;
const b = Math.floor(Math.random() * 20) + 10;
this.challengeData.answer = a + b;
return `${a} + ${b} = ?`;
}
},
{
question: () => {
const arr = Array.from({length: 5}, () => Math.floor(Math.random() * 10));
this.challengeData.answer = Math.max(...arr);
return `Max([${arr.join(',')}]) = ?`;
}
},
{
question: () => {
const str = String.fromCharCode(65 + Math.floor(Math.random() * 26));
const offset = Math.floor(Math.random() * 5) + 1;
this.challengeData.answer = String.fromCharCode(str.charCodeAt(0) + offset);
return `Next char after "${str}" + ${offset} positions?`;
}
}
];
const challenge = challenges[Math.floor(Math.random() * challenges.length)];
document.getElementById('challengeQuestion').textContent = challenge.question();
document.getElementById('challengeBtn').addEventListener('click', () => this.verifyChallenge());
document.getElementById('challengeInput').addEventListener('keypress', (e) => {
if (e.key === 'Enter') this.verifyChallenge();
});
this.log('info', 'New challenge generated');
}
verifyChallenge() {
const input = document.getElementById('challengeInput');
const result = document.getElementById('challengeResult');
const answer = input.value.trim();
this.challengeData.attempts++;
if (answer == this.challengeData.answer) {
this.challengeData.solved = true;
result.className = 'challenge-result success';
result.textContent = 'Challenge passed! JavaScript execution verified.';
result.style.display = 'block';
this.featureWeights['Challenge Pass'].value = 100;
this.log('success', 'Challenge solved successfully');
// Generate new challenge after delay
setTimeout(() => {
input.value = '';
result.style.display = 'none';
this.generateChallenge();
}, 2000);
} else {
result.className = 'challenge-result fail';
result.textContent = `Incorrect. Attempts: ${this.challengeData.attempts}`;
result.style.display = 'block';
this.featureWeights['Challenge Pass'].value = Math.max(0, 50 - this.challengeData.attempts * 10);
this.log('warn', `Challenge failed (attempt ${this.challengeData.attempts})`);
}
}
// ============== RISK SCORING ==============
updateRiskScore() {
let totalWeight = 0;
let weightedScore = 0;
for (const feature of Object.values(this.featureWeights)) {
totalWeight += feature.weight;
weightedScore += feature.value * feature.weight;
}
const humanScore = weightedScore / totalWeight;
const botScore = 100 - humanScore;
// Update display
const riskValue = document.getElementById('riskValue');
const riskProgress = document.getElementById('riskProgress');
const verdict = document.getElementById('verdict');
const circumference = 2 * Math.PI * 78;
const offset = circumference - (botScore / 100) * circumference;
riskProgress.style.strokeDashoffset = offset;
riskValue.textContent = Math.round(botScore);
// Update colors and verdict
if (botScore < 30) {
riskProgress.style.stroke = '#00ff88';
riskValue.style.color = '#00ff88';
verdict.className = 'verdict human';
verdict.textContent = 'HUMAN VERIFIED';
} else if (botScore < 60) {
riskProgress.style.stroke = '#ffa502';
riskValue.style.color = '#ffa502';
verdict.className = 'verdict suspicious';
verdict.textContent = 'SUSPICIOUS';
} else {
riskProgress.style.stroke = '#ff4757';
riskValue.style.color = '#ff4757';
verdict.className = 'verdict bot';
verdict.textContent = 'BOT DETECTED';
}
this.updateExplanationChart();
}
// ============== EXPLAINABILITY ==============
updateExplanationChart() {
const container = document.getElementById('explanationChart');
container.innerHTML = '';
const sortedFeatures = Object.entries(this.featureWeights)
.sort((a, b) => (b[1].positive ? b[1].value : -b[1].value) - (a[1].positive ? a[1].value : -a[1].value));
for (const [name, data] of sortedFeatures) {
const bar = document.createElement('div');
bar.className = 'feature-bar';
const contribution = data.positive ? -(100 - data.value) * data.weight : -(100 - data.value) * data.weight;
bar.innerHTML = `
<span class="feature-name">${name}</span>
<div class="feature-track">
<div class="feature-fill ${data.value > 50 ? 'positive' : 'negative'}"
style="width: ${data.value}%"></div>
</div>
<span class="feature-score" style="color: ${data.value > 50 ? '#00ff88' : '#ff4757'}">
${data.value > 50 ? '+' : ''}${(data.value - 50).toFixed(0)}
</span>
`;
container.appendChild(bar);
}
// Update summary
const avgScore = Object.values(this.featureWeights).reduce((a, b) => a + b.value, 0) / Object.keys(this.featureWeights).length;
const summary = document.getElementById('explanationSummary');
let explanation = '';
if (avgScore > 60) {
explanation = `Strong human indicators detected. Natural mouse movement patterns (${this.featureWeights['Mouse Dynamics'].value.toFixed(0)}% confidence), consistent typing rhythm, and successful challenge completion all suggest legitimate human behavior. Device fingerprint shows normal browser characteristics.`;
} else if (avgScore > 40) {
explanation = `Mixed signals detected. Some behavioral patterns appear human-like, while others show anomalies. Consider monitoring session longer for more accurate classification. Challenge verification status: ${this.challengeData.solved ? 'Passed' : 'Pending'}.`;
} else {
explanation = `Multiple bot indicators detected. Unusual mouse dynamics, lack of natural interaction patterns, or automated behavior signatures detected. Additional verification recommended before granting access.`;
}
summary.innerHTML = `
<h4>Analysis Summary</h4>
<p>${explanation}</p>
`;
}
// ============== LOGGING ==============
log(type, message) {
const time = new Date().toLocaleTimeString();
const entry = { type, message, time };
this.logs.unshift(entry);
if (this.logs.length > 50) this.logs.pop();
this.renderLogs();
}
renderLogs() {
const container = document.getElementById('logsContainer');
container.innerHTML = '';
for (const log of this.logs) {
const entry = document.createElement('div');
entry.className = 'log-entry';
entry.innerHTML = `
<span class="log-time">${log.time}</span>
<span class="log-type ${log.type}">${log.type.toUpperCase()}</span>
<span class="log-message">${log.message}</span>
`;
container.appendChild(entry);
}
}
}
// ============== INITIALIZATION ==============
document.addEventListener('DOMContentLoaded', () => {
new ParticleNetwork(document.getElementById('canvas-container'));
new BotDefenseSystem();
});
</script>
</body>
</html>