import React, { useState, useEffect } from 'react'; import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts'; interface TrafficDataPoint { time: string; requests: number; } interface LogEntry { message: string; timestamp: string; } const DDoSSimulator: React.FC = () => { // State for attack configuration const [target, setTarget] = useState('example.com'); const [threads, setThreads] = useState(50); const [timeout, setTimeout] = useState(10); const [isAttacking, setIsAttacking] = useState(false); // State for statistics const [requestsSent, setRequestsSent] = useState(0); const [bytesSent, setBytesSent] = useState(0); const [successRate, setSuccessRate] = useState(95); // State for traffic data (20-second rolling window) const [trafficData, setTrafficData] = useState(() => Array.from({ length: 20 }, (_, i) => ({ time: `${i}s`, requests: 0 })) ); // Log messages with timestamps const [logs, setLogs] = useState([ { message: 'System initialized', timestamp: new Date().toLocaleTimeString() }, { message: 'Ready to launch attack simulation', timestamp: new Date().toLocaleTimeString() } ]); // Simulate attack progress useEffect(() => { let interval: NodeJS.Timeout | null = null; if (isAttacking) { interval = setInterval(() => { // Compute dynamic values for this second const baseRps = 10 + Math.random() * 20; // Base 10-30 RPS const rps = Math.floor(baseRps * (threads / 50)); // Scale by threads const newRequests = Math.floor(rps * (1 + Math.random() * 0.5)); // Variability const newBytes = Math.floor(newRequests * (500 + Math.random() * 1000)); // Bytes per request const newSuccessRate = 90 + Math.random() * 8; // Fluctuate 90-98% // Update statistics setRequestsSent((prev) => prev + newRequests); setBytesSent((prev) => prev + newBytes); setSuccessRate(newSuccessRate); // Update traffic data (shift oldest, add new 1s point) setTrafficData((prev) => { const newData = [...prev]; newData.shift(); // Remove oldest (rolling window) const lastTimeNum = parseInt(newData[newData.length - 1]?.time || '0'); newData.push({ time: `${lastTimeNum + 1}s`, requests: rps }); return newData; }); // Generate dynamic log message const timestamp = new Date().toLocaleTimeString(); const logMessages = [ `Flooding ${target} with ${newRequests} requests/sec (${rps} RPS target)`, `Active threads: ${threads}, generating ${rps} RPS`, `Request timeout: ${timeout}ms, bytes/sec: ${(newBytes / 1024).toFixed(1)} KB`, `Success rate updated: ${newSuccessRate.toFixed(1)}%`, `Target responded: 200 OK (simulated)`, `Maintaining HTTP connection flood...`, `Total requests: ${requestsSent + newRequests}, bytes: ${(bytesSent + newBytes) / 1024 / 1024} MB` ]; const selectedLog = logMessages[Math.floor(Math.random() * logMessages.length)]; setLogs((prev) => { const newLogs = [...prev, { message: selectedLog, timestamp }]; if (newLogs.length > 20) { newLogs.shift(); // Keep last 20 logs } return newLogs; }); }, 1000); } return () => { if (interval) clearInterval(interval); }; }, [isAttacking, target, threads, timeout]); // Removed successRate to avoid restarts; computed inside const startAttack = () => { setIsAttacking(true); const timestamp = new Date().toLocaleTimeString(); setLogs((prev) => [ ...prev, { message: `Attack simulation started on ${target}`, timestamp } ]); }; const stopAttack = () => { setIsAttacking(false); const timestamp = new Date().toLocaleTimeString(); setLogs((prev) => [ ...prev, { message: 'Attack simulation stopped', timestamp } ]); }; const resetStats = () => { setRequestsSent(0); setBytesSent(0); setSuccessRate(95); setTrafficData(Array.from({ length: 20 }, (_, i) => ({ time: `${i}s`, requests: 0 }))); const timestamp = new Date().toLocaleTimeString(); setLogs([ { message: 'System reset complete', timestamp }, { message: 'Ready to launch new simulation', timestamp: new Date().toLocaleTimeString() } ]); setIsAttacking(false); }; return (
{/* Header with improved spacing and centering */}

Torshammer DDoS Simulator

An educational tool simulating HTTP flood DDoS attacks to raise awareness about cybersecurity threats. Configure parameters, launch simulated attacks, and monitor real-time metrics.

⚠️ For educational purposes only. Real DDoS attacks are illegal and unethical.

{/* Configuration Panel with better form styling */}

🎯 Attack Configuration

) => setTarget(e.target.value)} className="w-full bg-gray-700/80 border border-gray-600 rounded-xl px-4 py-3 text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-red-500 focus:border-transparent transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed" placeholder="https://example.com" disabled={isAttacking} />
) => setThreads(parseInt(e.target.value))} className="w-full h-2 bg-gray-600 rounded-lg appearance-none cursor-pointer accent-red-500 disabled:cursor-not-allowed disabled:opacity-50" disabled={isAttacking} />
Low (10) High (200)
) => setTimeout(parseInt(e.target.value))} className="w-full h-2 bg-gray-600 rounded-lg appearance-none cursor-pointer accent-red-500 disabled:cursor-not-allowed disabled:opacity-50" disabled={isAttacking} />
Fast (1ms) Slow (30ms)
{/* Action buttons with improved layout and transitions */}
{/* Statistics Panel with card grid */}

📊 Live Statistics

Requests Sent
{requestsSent.toLocaleString()}
Data Transferred
{(bytesSent / 1024 / 1024).toFixed(2)} MB
Success Rate
{successRate.toFixed(1)}%
Attack Status
{isAttacking ? '🔥 ACTIVE' : '⏸️ IDLE'}
{/* Enhanced Traffic Chart */}

📈 Real-Time Traffic (RPS - Last 20s)

{/* Logs Panel with scrollable mono font */}

📝 Attack Console

{logs.map((log, index) => (
[{log.timestamp}] {log.message}
))}
{/* Disclaimer Section */}

Important Disclaimer

This simulator is strictly for educational and awareness purposes. It performs no real network activity.

DDoS attacks are criminal offenses under laws like the CFAA. Use knowledge to defend, not attack.

{/* Footer with better styling */}

Torshammer DDoS Simulator • Educational Cybersecurity Tool • v2.0

Built with ❤️ for security awareness. Report issues or learn more about DDoS mitigation.

); }; export default DDoSSimulator;
تعليقات