-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
636 lines (563 loc) · 32.6 KB
/
index.html
File metadata and controls
636 lines (563 loc) · 32.6 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
<!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">Từng bước hiểu cách hacker khai thác lỗ hổng SQL Injection</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">Nhập dữ liệu</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">Câu truy vấn</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 xác thực</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">Truy cập dữ liệu</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">Giải pháp</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">Bước 1: Nhập dữ liệu độc hại</h3>
<p class="mb-4">Hacker nhập vào một chuỗi đặc biệt trong ô username:</p>
<div class="bg-gray-900 p-3 rounded mb-4 font-bold text-green-400 text-center">' OR '1'='1</div>
<p>Đây là payload SQL Injection cơ bản nhất, nhằm làm luôn đúng điều kiện WHERE trong câu truy vấn SQL.</p>
</div>
<div id="step2-desc" class="step-desc hidden">
<h3 class="text-xl font-bold text-blue-400 mb-4">Bước 2: Câu truy vấn SQL</h3>
<p class="mb-4">Hệ thống tạo câu truy vấn từ input của người dùng:</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>Payload đã làm thay đổi logic câu truy vấn, khiến điều kiện luôn trả về TRUE.</p>
</div>
<div id="step3-desc" class="step-desc hidden">
<h3 class="text-xl font-bold text-blue-400 mb-4">Bước 3: Bypass xác thực</h3>
<p class="mb-4">Câu truy vấn trở thành:</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>Vì '1'='1' luôn đúng, hệ thống sẽ trả về tất cả bản ghi trong bảng users, cho phép hacker login vào tài khoản đầu tiên.</p>
</div>
<div id="step4-desc" class="step-desc hidden">
<h3 class="text-xl font-bold text-blue-400 mb-4">Bước 4: Truy cập dữ liệu nhạy cảm</h3>
<p class="mb-4">Hacker có thể khai thác thêm để lấy toàn bộ dữ liệu:</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>Lệnh UNION này cho phép lấy thêm dữ liệu từ bảng users, bao gồm cả mật khẩu (thường được hash nhưng vẫn nguy hiểm).</p>
</div>
<div id="step5-desc" class="step-desc hidden">
<h3 class="text-xl font-bold text-blue-400 mb-4">Bước 5: Giải pháp phòng ngừa</h3>
<ul class="list-disc pl-5 space-y-2">
<li><strong>Prepared statements:</strong> Tách biệt code SQL và dữ liệu</li>
<li><strong>Validate input:</strong> Kiểm tra ký tự đặc biệt</li>
<li><strong>Giới hạn quyền:</strong> Tài khoản DB chỉ có quyền cần thiết</li>
<li><strong>Mã hóa:</strong> Những dữ liệu nhạy cảm phải được mã hóa</li>
<li><strong>ORM:</strong> Sử dụng thư viện trừu tượng hóa database</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>
Hệ thống đăng nhập
</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">
Đăng nhập
</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>
Câu truy vấn SQL được tạo
</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>
Bypass xác thực thành công
</h3>
<div class="bg-gray-900 p-4 rounded-lg mb-4">
<p class="text-gray-400">Câu truy vấn đơn giản hóa thành:</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">Đăng nhập thành công!</span>
</div>
<p class="text-gray-300">Hệ thống trả về tất cả người dùng, hacker có thể đăng nhập với tài khoản đầu tiên.</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>
Truy cập dữ liệu nhạy cảm
</h3>
<div class="bg-gray-900 p-4 rounded-lg mb-4 overflow-x-auto">
<p class="text-gray-400">' UNION SELECT username, password FROM users --</p>
</div>
<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>
Giải pháp phòng chống
</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 và dữ liệu được tách biệt hoàn toàn</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">Chỉ cho phép ký tự an toàn</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">Giới hạn quyền truy cập database</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>Trước
</button>
<div class="text-gray-400 flex items-center px-4">
<span id="step-indicator">Bước 1 của 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">
Tiếp theo<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>Bắt đầu lại
</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">Giải thích bước 1</span>
</h3>
<div id="explanation-content">
<p>Trong bước này, hacker nhập vào chuỗi <code class="bg-gray-900 px-2 py-1 rounded text-green-400">' OR '1'='1</code> vào trường username.</p>
<p class="mt-2">Đây là câu lệnh SQL luôn trả về <code class="bg-gray-900 px-2 py-1 rounded">TRUE</code> vì <code class="bg-gray-900 px-2 py-1 rounded">1=1</code> luôn đúng.</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 ? 'Kết thúc' : 'Tiếp theo';
// Update step indicator
stepIndicator.textContent = `Bước ${currentStep} của ${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 = "Giải thích bước 1: Nhập dữ liệu độc hại";
explanationContent.innerHTML = `
<p>Trong bước này, hacker nhập vào chuỗi <code class="bg-gray-900 px-2 py-1 rounded text-green-400">' OR '1'='1</code> vào trường username.</p>
<p class="mt-2">Đây là câu lệnh SQL luôn trả về <code class="bg-gray-900 px-2 py-1 rounded">TRUE</code> vì <code class="bg-gray-900 px-2 py-1 rounded">1=1</code> luôn đúng.</p>
<p class="mt-2">Chuỗi này sẽ được ghép vào câu truy vấn SQL của hệ thống.</p>
`;
break;
case 2:
explanationTitle.textContent = "Giải thích bước 2: Câu truy vấn SQL";
explanationContent.innerHTML = `
<p>Hệ thống tạo câu truy vấn từ input người dùng:</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">Đoạn <code class="bg-gray-900 px-2 py-1 rounded text-red-400">OR '1'='1'</code> làm câu điều kiện luôn đúng.</p>
`;
break;
case 3:
explanationTitle.textContent = "Giải thích bước 3: Bypass xác thực";
explanationContent.innerHTML = `
<p>Vì điều kiện WHERE luôn trả về TRUE, câu truy vấn trở thành:</p>
<div class="bg-gray-900 p-3 rounded my-2">
<code>SELECT * FROM users WHERE TRUE</code>
</div>
<p class="mt-2">Kết quả là hệ thống trả về toàn bộ dữ liệu trong bảng users.</p>
<p class="mt-2">Ứng dụng thường lấy user đầu tiên để xác thực, hacker có thể đăng nhập.</p>
`;
break;
case 4:
explanationTitle.textContent = "Giải thích bước 4: Truy cập dữ liệu";
explanationContent.innerHTML = `
<p>Hacker có thể sử dụng UNION để lấy thêm dữ liệu:</p>
<div class="bg-gray-900 p-3 rounded my-2">
<code>' UNION SELECT username, password FROM users --</code>
</div>
<p class="mt-2">-- là comment trong SQL, loại bỏ phần còn lại của câu truy vấn.</p>
<p class="mt-2">UNION cho phép nối kết quả từ SELECT thứ hai vào kết quả đầu.</p>
`;
break;
case 5:
explanationTitle.textContent = "Giải thích bước 5: Giải pháp phòng ngừa";
explanationContent.innerHTML = `
<p>Các cách phòng chống SQL Injection hiệu quả:</p>
<ul class="list-disc pl-5 space-y-1 mt-2">
<li><strong>Prepared Statements:</strong> Tách biệt code và dữ liệu</li>
<li><strong>Input Validation:</strong> Kiểm tra ký tự đặc biệt</li>
<li><strong>Stored Procedures:</strong> Đóng gói logic truy vấn</li>
<li><strong>Giới hạn quyền:</strong> Database user chỉ có quyền tối thiểu</li>
<li><strong>Error Handling:</strong> Không hiển thị lỗi SQL ra ngoài</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>