-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenglish.html
More file actions
639 lines (566 loc) · 32.3 KB
/
Copy pathenglish.html
File metadata and controls
639 lines (566 loc) · 32.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SQL Injection Step-by-Step Demo</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@keyframes typing {
from { width: 0 }
to { width: 100% }
}
@keyframes blink-caret {
from, to { border-color: transparent }
50% { border-color: #10B981 }
}
.typing-effect {
overflow: hidden;
white-space: nowrap;
border-right: 2px solid;
width: 0;
}
.animated-border {
animation: border-pulse 2s infinite;
}
@keyframes border-pulse {
0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}
.highlight-box {
transition: all 0.3s ease;
}
.highlight-box.active {
border-left: 4px solid #3B82F6;
background-color: rgba(59, 130, 246, 0.1);
}
.data-entry {
transition: all 0.5s ease;
transform-origin: top;
transform: scaleY(0);
opacity: 0;
}
.data-entry.show {
transform: scaleY(1);
opacity: 1;
}
.fade-in {
animation: fadeIn 1s ease-in;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
</style>
</head>
<body class="bg-gray-900 text-gray-200 min-h-screen font-mono">
<div class="container mx-auto px-4 py-8 max-w-6xl">
<!-- Header -->
<div class="text-center mb-12">
<h1 class="text-3xl font-bold text-red-400 mb-2">SQL Injection Demonstration</h1>
<p class="text-lg text-gray-400">Step-by-step demonstration of how hackers exploit SQL Injection vulnerabilities</p>
</div>
<div class="flex justify-center gap-6 mb-12 fade-in">
<a href="https://github.com/Gianguyen1234" target="_blank" class="text-gray-100 hover:text-white text-2xl">
<i class="fab fa-github"></i>
</a>
<a href="https://www.tiktok.com/@holy_dev5" target="_blank" class="text-gray-100 hover:text-white text-2xl">
<i class="fab fa-tiktok"></i>
</a>
<a href="https://www.youtube.com/@dev-maniac2349" target="_blank"
class="text-gray-100 hover:text-white text-2xl">
<i class="fab fa-youtube"></i>
</a>
<a href="https://www.facebook.com/profile.php?id=61575273337943" target="_blank"
class="text-gray-100 hover:text-white text-2xl">
<i class="fab fa-facebook"></i>
</a>
<a href="https://thaonguyen-portfolio.vercel.app/" target="_blank"
class="text-gray-100 hover:text-white text-2xl">
<i class="fas fa-globe"></i>
</a>
<a href="https://harrypage.hashnode.dev/" target="_blank" class="text-gray-100 hover:text-white text-2xl">
<i class="fab fa-hashnode"></i>
</a>
</div>
<!-- Step Progress -->
<div class="flex justify-between mb-8 relative">
<div class="absolute h-1 bg-gray-700 top-1/2 left-0 right-0 -translate-y-1/2 -z-10"></div>
<div id="progress-bar" class="absolute h-1 bg-blue-500 top-1/2 left-0 -translate-y-1/2 -z-10 transition-all duration-500" style="width: 0%"></div>
<div class="flex justify-between w-full">
<button step="1" class="step-btn flex flex-col items-center w-24 group active">
<div class="w-8 h-8 rounded-full bg-blue-600 flex items-center justify-center text-white font-bold mb-2 group-[.active]:bg-blue-500 group-[.done]:bg-green-500 transition-all">1</div>
<span class="text-xs text-center text-gray-400 group-[.active]:text-white">Input Data</span>
</button>
<button step="2" class="step-btn flex flex-col items-center w-24 group">
<div class="w-8 h-8 rounded-full bg-gray-700 flex items-center justify-center text-gray-400 font-bold mb-2 group-[.active]:bg-blue-500 group-[.done]:bg-green-500 transition-all">2</div>
<span class="text-xs text-center text-gray-400 group-[.active]:text-white">SQL Query</span>
</button>
<button step="3" class="step-btn flex flex-col items-center w-24 group">
<div class="w-8 h-8 rounded-full bg-gray-700 flex items-center justify-center text-gray-400 font-bold mb-2 group-[.active]:bg-blue-500 group-[.done]:bg-green-500 transition-all">3</div>
<span class="text-xs text-center text-gray-400 group-[.active]:text-white">Bypass Auth</span>
</button>
<button step="4" class="step-btn flex flex-col items-center w-24 group">
<div class="w-8 h-8 rounded-full bg-gray-700 flex items-center justify-center text-gray-400 font-bold mb-2 group-[.active]:bg-blue-500 group-[.done]:bg-green-500 transition-all">4</div>
<span class="text-xs text-center text-gray-400 group-[.active]:text-white">Access Data</span>
</button>
<button step="5" class="step-btn flex flex-col items-center w-24 group">
<div class="w-8 h-8 rounded-full bg-gray-700 flex items-center justify-center text-gray-400 font-bold mb-2 group-[.active]:bg-blue-500 group-[.done]:bg-green-500 transition-all">5</div>
<span class="text-xs text-center text-gray-400 group-[.active]:text-white">Solutions</span>
</button>
</div>
</div>
<p class="text-lg text-white-400">Created By Holy_Dev</p>
<!-- Content Sections -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8 mb-8">
<!-- Left Panel - Explanation -->
<div class="lg:col-span-1 bg-gray-800 rounded-lg p-6 h-fit sticky top-4">
<div id="step1-desc" class="step-desc">
<h3 class="text-xl font-bold text-blue-400 mb-4">Step 1: Input Malicious Data</h3>
<p class="mb-4">The hacker enters a special string in the username field:</p>
<div class="bg-gray-900 p-3 rounded mb-4 font-bold text-green-400 text-center">' OR '1'='1</div>
<p>This is the most basic SQL Injection payload, designed to make the WHERE condition in the SQL query always true.</p>
</div>
<div id="step2-desc" class="step-desc hidden">
<h3 class="text-xl font-bold text-blue-400 mb-4">Step 2: SQL Query</h3>
<p class="mb-4">The system creates a query from user input:</p>
<div class="bg-gray-900 p-3 rounded mb-4 overflow-x-auto">
<span class="text-gray-400">SELECT * FROM users WHERE username = '</span>
<span class=" text-red-400">' OR '1'='1</span>
<span class="text-gray-400">' AND password = '...'</span>
</div>
<p>The payload has modified the query logic, making the condition always return TRUE.</p>
</div>
<div id="step3-desc" class="step-desc hidden">
<h3 class="text-xl font-bold text-blue-400 mb-4">Step 3: Bypass Authentication</h3>
<p class="mb-4">The query becomes:</p>
<div class="bg-gray-900 p-3 rounded mb-4 overflow-x-auto">
<span class="text-gray-400">SELECT * FROM users WHERE </span>
<span class="text-red-400">'1'='1'</span>
</div>
<p>Since '1'='1' is always true, the system will return all records from the users table, allowing the hacker to log in as the first account.</p>
</div>
<div id="step4-desc" class="step-desc hidden">
<h3 class="text-xl font-bold text-blue-400 mb-4">Step 4: Access Sensitive Data</h3>
<p class="mb-4">The hacker can further exploit to extract all data:</p>
<div class="bg-gray-900 p-3 rounded mb-4 overflow-x-auto">
<span class="text-gray-400">' UNION SELECT username, password FROM users --</span>
</div>
<p>This UNION command allows retrieving additional data from the users table, including passwords (usually hashed but still dangerous).</p>
</div>
<div id="step5-desc" class="step-desc hidden">
<h3 class="text-xl font-bold text-blue-400 mb-4">Step 5: Prevention Solutions</h3>
<ul class="list-disc pl-5 space-y-2">
<li><strong>Prepared statements:</strong> Separate SQL code from data</li>
<li><strong>Input validation:</strong> Check for special characters</li>
<li><strong>Least privilege:</strong> Database account should have minimal permissions</li>
<li><strong>Encryption:</strong> Sensitive data must be encrypted</li>
<li><strong>ORM:</strong> Use database abstraction libraries</li>
</ul>
</div>
</div>
<!-- Right Panel - Demo -->
<div class="lg:col-span-2 space-y-6">
<!-- Step 1: Login Form -->
<div id="step1-demo" class="step-demo bg-gray-800 rounded-lg p-6">
<h3 class="text-xl font-semibold mb-4 flex items-center">
<i class="fas fa-sign-in-alt mr-2 text-blue-400"></i>
Login System
</h3>
<div class="space-y-4">
<div class="highlight-box active">
<label class="block text-gray-400 mb-1">Username</label>
<div id="username-container" class="bg-gray-700 border border-gray-600 rounded px-4 py-3 flex items-center relative overflow-hidden">
<span id="typing-text" class="typing-effect" style="width: 0; border-right-color: #10B981;"></span>
<span id="static-text" class="hidden text-green-400">' OR '1'='1</span>
</div>
</div>
<div class="highlight-box">
<label class="block text-gray-400 mb-1">Password</label>
<div class="bg-gray-700 border border-gray-600 rounded px-4 py-3">••••••••</div>
</div>
<button class="w-full bg-blue-600 hover:bg-blue-700 text-white py-3 rounded-lg font-medium transition-colors">
Login
</button>
</div>
</div>
<!-- Step 2-3: SQL Query -->
<div id="step2-demo" class="step-demo hidden bg-gray-800 rounded-lg p-6">
<h3 class="text-xl font-semibold mb-4 flex items-center">
<i class="fas fa-database mr-2 text-blue-400"></i>
Generated SQL Query
</h3>
<div id="original-query" class="bg-gray-900 p-4 rounded-lg mb-4">
<p class="text-gray-400">SELECT * FROM users WHERE username = '' AND password = '...'</p>
</div>
<div id="injected-query" class="bg-gray-900 p-4 rounded-lg border border-red-500 hidden animated-border">
<p class="text-gray-400">SELECT * FROM users WHERE username = <span class=" text-red-400">'' OR '1'='1'</span> AND password = '...'</p>
</div>
</div>
<!-- Step 3-4: Authentication Bypass -->
<div id="step3-demo" class="step-demo hidden bg-gray-800 rounded-lg p-6">
<h3 class="text-xl font-semibold mb-4 flex items-center">
<i class="fas fa-unlock-alt mr-2 text-blue-400"></i>
Authentication Bypassed
</h3>
<div class="bg-gray-900 p-4 rounded-lg mb-4">
<p class="text-gray-400">The query simplifies to:</p>
<p class="text-red-400 mt-2 text-lg">SELECT * FROM users WHERE TRUE</p>
</div>
<div id="success-box" class="bg-green-900/30 border border-green-600 p-4 rounded-lg hidden">
<div class="flex items-center text-green-400 mb-2">
<i class="fas fa-check-circle mr-2"></i>
<span class="font-semibold">Login successful!</span>
</div>
<p class="text-gray-300">The system returns all users, and the hacker can log in as the first account.</p>
</div>
</div>
<!-- Step 4: Data Access -->
<div id="step4-demo" class="step-demo hidden bg-gray-800 rounded-lg p-6">
<h3 class="text-xl font-semibold mb-4 flex items-center">
<i class="fas fa-user-secret mr-2 text-blue-400"></i>
Access Sensitive Data
</h3>
<div class="bg-gray-900 p-4 rounded-lg mb-4 overflow-x-auto">
<p class="text-gray-400">Malicious input:</p>
<p class="text-red-400">' UNION SELECT username, password FROM users --</p>
</div>
<h4 class="text-lg font-semibold mb-3 text-green-400">Extracted User Data:</h4>
<table class="w-full border-collapse">
<thead class="bg-gray-700">
<tr>
<th class="px-4 py-3 text-left border-b border-gray-600">Username</th>
<th class="px-4 py-3 text-left border-b border-gray-600">Password (hashed)</th>
</tr>
</thead>
<tbody id="data-table">
<!-- Data will be inserted here -->
</tbody>
</table>
</div>
<!-- Step 5: Solutions -->
<div id="step5-demo" class="step-demo hidden bg-gray-800 rounded-lg p-6 fade-in">
<h3 class="text-xl font-semibold mb-4 flex items-center">
<i class="fas fa-shield-alt mr-2 text-blue-400"></i>
Prevention Solutions
</h3>
<div class="space-y-4">
<div class="flex items-start bg-gray-900/50 p-4 rounded-lg">
<div class="bg-blue-600 text-white p-2 rounded-lg mr-4">
<i class="fas fa-code"></i>
</div>
<div>
<h4 class="font-bold mb-1">Prepared Statements</h4>
<div class="bg-gray-900 rounded p-2 mt-2 overflow-x-auto">
<code class="text-green-400">stmt = conn.prepareStatement("SELECT * FROM users WHERE username = ?");</code><br>
<code class="text-green-400">stmt.setString(1, username);</code>
</div>
<p class="text-gray-300 text-sm mt-2">SQL and data are completely separated</p>
</div>
</div>
<div class="flex items-start bg-gray-900/50 p-4 rounded-lg">
<div class="bg-blue-600 text-white p-2 rounded-lg mr-4">
<i class="fas fa-filter"></i>
</div>
<div>
<h4 class="font-bold mb-1">Input Validation</h4>
<div class="bg-gray-900 rounded p-2 mt-2 overflow-x-auto">
<code class="text-green-400">if(!username.matches("[a-zA-Z0-9_]+")) {</code><br>
<code class="text-green-400 pl-4">throw new Exception("Invalid username");</code><br>
<code class="text-green-400">}</code>
</div>
<p class="text-gray-300 text-sm mt-2">Only allow safe characters</p>
</div>
</div>
<div class="flex items-start bg-gray-900/50 p-4 rounded-lg">
<div class="bg-blue-600 text-white p-2 rounded-lg mr-4">
<i class="fas fa-user-lock"></i>
</div>
<div>
<h4 class="font-bold mb-1">Principle of Least Privilege</h4>
<div class="bg-gray-900 rounded p-2 mt-2 overflow-x-auto">
<code class="text-green-400">CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'password';</code><br>
<code class="text-green-400">GRANT SELECT, INSERT ON database.* TO 'app_user'@'localhost';</code>
</div>
<p class="text-gray-300 text-sm mt-2">Limit database access permissions</p>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Navigation Controls -->
<div class="flex justify-center space-x-4 mt-8">
<button id="prev-btn" class="bg-gray-700 hover:bg-gray-600 text-white py-2 px-6 rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed" disabled>
<i class="fas fa-arrow-left mr-2"></i>Previous
</button>
<div class="text-gray-400 flex items-center px-4">
<span id="step-indicator">Step 1 of 5</span>
</div>
<button id="next-btn" class="bg-blue-600 hover:bg-blue-700 text-white py-2 px-6 rounded-lg transition-colors">
Next<i class="fas fa-arrow-right ml-2"></i>
</button>
<button id="restart-btn" class="bg-gray-700 hover:bg-gray-600 text-white py-2 px-6 rounded-lg transition-colors">
<i class="fas fa-redo mr-2"></i>Restart
</button>
</div>
<!-- Explanation for each step -->
<div id="step-explanation" class="mt-8 bg-gray-800 rounded-lg p-6">
<h3 class="text-xl font-semibold mb-4 flex items-center text-blue-400">
<i class="fas fa-info-circle mr-2"></i>
<span id="explanation-title">Step 1 Explanation</span>
</h3>
<div id="explanation-content">
<p>In this step, the hacker enters the string <code class="bg-gray-900 px-2 py-1 rounded text-green-400">' OR '1'='1</code> in the username field.</p>
<p class="mt-2">This is an SQL statement that always returns <code class="bg-gray-900 px-2 py-1 rounded">TRUE</code> because <code class="bg-gray-900 px-2 py-1 rounded">1=1</code> is always true.</p>
</div>
</div>
</div>
<script>
const steps = 5;
let currentStep = 1;
const sampleData = [
{ username: "admin", password: "$2y$10$N9qo8uLOickgx2ZMRZoTh..." },
{ username: "john_doe", password: "$2y$10$WqZYQ8q3O2eQ3..." },
{ username: "jane_smith", password: "$2y$10$5Zg0pU7WQWJ5..." }
];
// DOM elements
const prevBtn = document.getElementById('prev-btn');
const nextBtn = document.getElementById('next-btn');
const restartBtn = document.getElementById('restart-btn');
const progressBar = document.getElementById('progress-bar');
const stepButtons = document.querySelectorAll('.step-btn');
const stepIndicator = document.getElementById('step-indicator');
const explanationTitle = document.getElementById('explanation-title');
const explanationContent = document.getElementById('explanation-content');
// Initialize
updateUI();
// Event listeners
prevBtn.addEventListener('click', () => {
if (currentStep > 1) {
currentStep--;
updateUI();
}
});
nextBtn.addEventListener('click', () => {
if (currentStep < steps) {
currentStep++;
updateUI();
}
});
restartBtn.addEventListener('click', () => {
currentStep = 1;
updateUI();
});
// Add event listeners to step buttons
stepButtons.forEach(button => {
button.addEventListener('click', () => {
const step = parseInt(button.getAttribute('step'));
if (step <= currentStep || step === 1) {
currentStep = step;
updateUI();
}
});
});
// Update UI based on current step
function updateUI() {
// Update progress bar
progressBar.style.width = `${((currentStep - 1) / (steps - 1)) * 100}%`;
// Update buttons
prevBtn.disabled = currentStep <= 1;
nextBtn.disabled = currentStep >= steps;
nextBtn.textContent = currentStep === steps ? 'Finish' : 'Next';
// Update step indicator
stepIndicator.textContent = `Step ${currentStep} of ${steps}`;
// Update step buttons
updateStepButtons();
// Update content sections
updateContentSections();
// Update explanation
updateExplanation();
}
function updateStepButtons() {
stepButtons.forEach(button => {
const step = parseInt(button.getAttribute('step'));
// Reset all classes
button.classList.remove('active', 'done');
button.querySelector('div').classList.remove('bg-blue-500', 'bg-green-500');
button.querySelector('div').classList.add('bg-gray-700');
button.querySelector('span').classList.remove('text-white');
button.querySelector('span').classList.add('text-gray-400');
if (step === currentStep) {
// Active step
button.classList.add('active');
button.querySelector('div').classList.add('bg-blue-500');
button.querySelector('div').classList.remove('bg-gray-700');
button.querySelector('span').classList.add('text-white');
} else if (step < currentStep) {
// Completed steps
button.classList.add('done');
button.querySelector('div').classList.add('bg-green-500');
button.querySelector('div').classList.remove('bg-gray-700');
}
});
}
function updateContentSections() {
// Hide all description and demo sections
document.querySelectorAll('.step-desc, .step-demo').forEach(el => {
el.classList.add('hidden');
});
// Show current step description
const descSection = document.getElementById(`step${currentStep}-desc`);
descSection.classList.remove('hidden');
descSection.classList.add('fade-in');
// Show demo for current step
const demoSection = document.getElementById(`step${currentStep}-demo`);
demoSection.classList.remove('hidden');
// Handle step-specific animations and content
switch(currentStep) {
case 1:
handleStep1();
break;
case 2:
handleStep2();
break;
case 3:
handleStep3();
break;
case 4:
handleStep4();
break;
case 5:
handleStep5();
break;
}
}
function updateExplanation() {
switch(currentStep) {
case 1:
explanationTitle.textContent = "Step 1 Explanation: Input Malicious Data";
explanationContent.innerHTML = `
<p>In this step, the hacker enters the string <code class="bg-gray-900 px-2 py-1 rounded text-green-400">' OR '1'='1</code> in the username field.</p>
<p class="mt 2">This is an SQL statement that always returns <code class="bg-gray-900 px-2 py-1 rounded">TRUE</code> because <code class="bg-gray-900 px-2 py-1 rounded">1=1</code> is always true.</p>
<p class="mt-2">This string will be concatenated into the system's SQL query.</p>
`;
break;
case 2:
explanationTitle.textContent = "Step 2 Explanation: SQL Query";
explanationContent.innerHTML = `
<p>The system creates a query from user input:</p>
<div class="bg-gray-900 p-3 rounded my-2">
<code>SELECT * FROM users WHERE username = '' OR '1'='1' AND password = '...'</code>
</div>
<p class="mt-2">The <code class="bg-gray-900 px-2 py-1 rounded text-red-400">OR '1'='1'</code> part makes the WHERE condition always true.</p>
`;
break;
case 3:
explanationTitle.textContent = "Step 3 Explanation: Authentication Bypass";
explanationContent.innerHTML = `
<p>Because the WHERE condition always returns TRUE, the query becomes:</p>
<div class="bg-gray-900 p-3 rounded my-2">
<code>SELECT * FROM users WHERE TRUE</code>
</div>
<p class="mt-2">The result is that the system returns all data from the users table.</p>
<p class="mt-2">Applications typically use the first user for authentication, allowing the hacker to login.</p>
`;
break;
case 4:
explanationTitle.textContent = "Step 4 Explanation: Data Access";
explanationContent.innerHTML = `
<p>The hacker can use UNION to extract additional data:</p>
<div class="bg-gray-900 p-3 rounded my-2">
<code>' UNION SELECT username, password FROM users --</code>
</div>
<p class="mt-2">-- is a comment in SQL, removing the rest of the query.</p>
<p class="mt-2">UNION appends the results from the second SELECT to the first results.</p>
<p class="mt-2">This allows the attacker to extract all usernames and passwords from the database.</p>
`;
break;
case 5:
explanationTitle.textContent = "Step 5 Explanation: Prevention Solutions";
explanationContent.innerHTML = `
<p>Effective SQL Injection prevention techniques:</p>
<ul class="list-disc pl-5 space-y-1 mt-2">
<li><strong>Prepared Statements:</strong> Separate code and data</li>
<li><strong>Input Validation:</strong> Check for special characters</li>
<li><strong>Stored Procedures:</strong> Encapsulate query logic</li>
<li><strong>Least Privilege:</strong> Database user has minimum permissions</li>
<li><strong>Error Handling:</strong> Don't expose SQL errors to users</li>
</ul>
`;
break;
}
// Add animation
explanationTitle.classList.remove('fade-in');
explanationContent.classList.remove('fade-in');
setTimeout(() => {
explanationTitle.classList.add('fade-in');
explanationContent.classList.add('fade-in');
}, 10);
}
function handleStep1() {
const typingText = document.getElementById('typing-text');
const staticText = document.getElementById('static-text');
// Reset
typingText.style.width = '0';
staticText.classList.add('hidden');
typingText.classList.remove('hidden');
// Simulate typing animation
setTimeout(() => {
typingText.textContent = "' OR '1'='1";
typingText.style.animation = 'typing 1.5s steps(12, end) forwards, blink-caret .75s step-end infinite';
setTimeout(() => {
typingText.style.animation = 'none';
typingText.style.borderRightColor = 'transparent';
typingText.style.width = '100%';
}, 1500);
}, 500);
}
function handleStep2() {
const originalQuery = document.getElementById('original-query');
const injectedQuery = document.getElementById('injected-query');
// Show original query first
originalQuery.classList.remove('hidden');
injectedQuery.classList.add('hidden');
// After 1 second, show modified query
setTimeout(() => {
originalQuery.classList.add('hidden');
injectedQuery.classList.remove('hidden');
}, 1000);
}
function handleStep3() {
const successBox = document.getElementById('success-box');
// Show success message after delay
setTimeout(() => {
successBox.classList.remove('hidden');
successBox.classList.add('fade-in');
}, 500);
}
function handleStep4() {
const dataTable = document.getElementById('data-table');
dataTable.innerHTML = '';
// Add data rows with animation
sampleData.forEach((user, index) => {
const row = document.createElement('tr');
row.className = 'data-entry';
// Add cells with data
row.innerHTML = `
<td class="px-4 py-3 border-b border-gray-600">${user.username}</td>
<td class="px-4 py-3 border-b border-gray-600 text-red-400">${user.password}</td>
`;
dataTable.appendChild(row);
// Animate each row after a delay
setTimeout(() => {
row.classList.add('show');
}, index * 300);
});
}
function handleStep5() {
// Nothing special needed here, content is static
document.getElementById('step5-demo').classList.add('fade-in');
}
</script>
</body>
</html>