-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
304 lines (252 loc) · 12.4 KB
/
script.js
File metadata and controls
304 lines (252 loc) · 12.4 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
// ===== CUSTOMIZATION VARIABLES =====
// Edit these values to customize the simulation for your organization
const ORGANIZATION_NAME = "Example Corp";
const DEMO_ID = "lab01";
const CONTACT_EMAIL = "security@example.local";
const COLOR_THEME = "blue"; // Options: blue, purple, green (not implemented in this version)
// ===== QUIZ ANSWERS =====
const correctAnswers = {
q1: "C", // Verify by calling
q2: "C", // Domain doesn't match
q3: "B" // MFA is best protection
};
const explanations = {
q1: "This is a common 'CEO fraud' or 'business email compromise' attack. Even if the sender address looks legitimate, attackers can spoof email addresses. Always verify unusual or urgent requests through a separate communication channel (phone call, in-person). The legitimate CEO will understand the need for verification.",
q2: "Always check the actual domain of a link, not just keywords in the URL. Attackers often use domains that include your company's name but end in unfamiliar extensions (.xyz, .tk, .top) or misspelled versions of legitimate domains. Your company's real domain is likely .com, .org, or a country-specific extension. When in doubt, don't click—navigate to the service directly by typing the known URL in your browser.",
q3: "While being cautious about email links is important, enabling multi-factor authentication (MFA) provides the strongest protection. Even if an attacker obtains your password through phishing, they cannot access your account without the second factor (code from your phone, security key, etc.). Strong, unique passwords for each account also limit the damage if one password is compromised."
};
// ===== INITIALIZATION =====
let sessionLog = {
demoId: DEMO_ID,
timestamp: new Date().toISOString(),
events: []
};
function init() {
// Set custom values in the page
document.getElementById('org-name').textContent = ORGANIZATION_NAME;
document.getElementById('demo-id').textContent = DEMO_ID;
document.getElementById('contact-email').textContent = CONTACT_EMAIL;
const demoEmailElements = document.querySelectorAll('.demo-email');
demoEmailElements.forEach(el => el.textContent = DEMO_ID + '@test.local');
const contactElements = document.querySelectorAll('.contact-email-text');
contactElements.forEach(el => el.textContent = CONTACT_EMAIL);
// Set current date
const now = new Date();
document.getElementById('current-date').textContent = now.toLocaleDateString('en-US', {
weekday: 'short',
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
// Log page load
logEvent('page_loaded');
console.log('%c🔒 Phishing Simulation Training Loaded', 'color: #667eea; font-size: 16px; font-weight: bold;');
console.log('%cDemo ID: ' + DEMO_ID, 'color: #555;');
console.log('%cOrganization: ' + ORGANIZATION_NAME, 'color: #555;');
console.log('%cAll interactions are logged to localStorage (key: phish-sim-log) and console', 'color: #999;');
console.log('%cTo view stored data: localStorage.getItem("phish-sim-log")', 'color: #999;');
console.log('%cTo clear data: localStorage.removeItem("phish-sim-log")', 'color: #999;');
}
// ===== LOGGING FUNCTIONS =====
function logEvent(eventName, data = {}) {
const event = {
event: eventName,
time: new Date().toISOString(),
...data
};
sessionLog.events.push(event);
// Store in localStorage
try {
localStorage.setItem('phish-sim-log', JSON.stringify(sessionLog));
console.log('📊 Event logged:', event);
} catch (e) {
console.error('Failed to log to localStorage:', e);
}
}
// ===== NAVIGATION FUNCTIONS =====
function showScreen(screenId) {
// Hide all screens
document.querySelectorAll('.screen').forEach(screen => {
screen.classList.remove('active');
});
// Show target screen
document.getElementById(screenId).classList.add('active');
// Update progress indicator
updateProgress(screenId);
// Scroll to top
window.scrollTo(0, 0);
}
function updateProgress(screenId) {
const progressMap = {
'screen-email': ['progress-email'],
'screen-training': ['progress-email', 'progress-training'],
'screen-quiz': ['progress-email', 'progress-training', 'progress-quiz'],
'screen-completion': ['progress-email', 'progress-training', 'progress-quiz', 'progress-complete']
};
// Reset all
document.querySelectorAll('.progress-step').forEach(step => {
step.classList.remove('active', 'completed');
});
// Mark completed and active
const steps = progressMap[screenId] || [];
steps.forEach((stepId, index) => {
const element = document.getElementById(stepId);
if (index < steps.length - 1) {
element.classList.add('completed');
} else {
element.classList.add('active');
}
});
}
function showEmail() {
showScreen('screen-email');
logEvent('returned_to_email');
}
function showTraining() {
showScreen('screen-training');
logEvent('returned_to_training');
}
function showQuiz() {
showScreen('screen-quiz');
logEvent('quiz_started');
}
function showCompletion() {
showScreen('screen-completion');
}
// ===== CTA CLICK =====
function clickCTA() {
logEvent('cta_clicked', { button: 'Verify Account Now' });
showScreen('screen-training');
logEvent('training_started');
}
// ===== QUIZ FUNCTIONS =====
function submitQuiz() {
let score = 0;
let answers = {};
// Check each question
for (let qNum = 1; qNum <= 3; qNum++) {
const selected = document.querySelector(`input[name="q${qNum}"]:checked`);
if (!selected) {
alert(`Please answer Question ${qNum} before submitting.`);
return;
}
const answer = selected.value;
answers[`q${qNum}`] = answer;
const isCorrect = answer === correctAnswers[`q${qNum}`];
if (isCorrect) {
score++;
}
// Show feedback
showFeedback(qNum, answer, isCorrect);
}
// Log quiz completion
logEvent('quiz_completed', { score: score, total: 3, answers: answers });
// Disable all radio buttons
document.querySelectorAll('input[type="radio"]').forEach(input => {
input.disabled = true;
});
// Show completion after a delay
setTimeout(() => {
displayScore(score);
showCompletion();
logEvent('completion_viewed', { score: score });
}, 2000);
}
function showFeedback(questionNum, selectedAnswer, isCorrect) {
const feedback = document.getElementById(`feedback${questionNum}`);
const question = document.getElementById(`q${questionNum}`);
// Highlight selected option
const options = question.querySelectorAll('.quiz-option');
options.forEach(option => {
const input = option.querySelector('input');
if (input.value === correctAnswers[`q${questionNum}`]) {
option.classList.add('correct');
} else if (input.value === selectedAnswer && !isCorrect) {
option.classList.add('incorrect');
}
});
// Show feedback message
feedback.classList.add('show');
if (isCorrect) {
feedback.classList.add('correct');
feedback.innerHTML = `<strong>✓ Correct!</strong><br>${explanations[`q${questionNum}`]}`;
} else {
feedback.classList.add('incorrect');
feedback.innerHTML = `<strong>✗ Incorrect.</strong> The correct answer is ${correctAnswers[`q${questionNum}`]}.<br>${explanations[`q${questionNum}`]}`;
}
}
function displayScore(score) {
const percentage = Math.round((score / 3) * 100);
const scoreDisplay = document.getElementById('final-score');
const scoreMessage = document.getElementById('score-message');
scoreDisplay.textContent = `${score}/3 (${percentage}%)`;
if (score === 3) {
scoreMessage.textContent = "Perfect! You've mastered phishing awareness.";
} else if (score === 2) {
scoreMessage.textContent = "Great job! Review the explanations to strengthen your knowledge.";
} else if (score === 1) {
scoreMessage.textContent = "Good start! Review the training materials and try again.";
} else {
scoreMessage.textContent = "Keep learning! Review the training materials carefully.";
}
}
// ===== DEMO FUNCTIONS =====
function restartDemo() {
// Reset quiz
document.querySelectorAll('input[type="radio"]').forEach(input => {
input.checked = false;
input.disabled = false;
});
document.querySelectorAll('.quiz-option').forEach(option => {
option.classList.remove('correct', 'incorrect');
});
document.querySelectorAll('.feedback').forEach(feedback => {
feedback.classList.remove('show', 'correct', 'incorrect');
feedback.innerHTML = '';
});
// Reset session log
sessionLog = {
demoId: DEMO_ID,
timestamp: new Date().toISOString(),
events: []
};
// Go back to start
showScreen('screen-email');
logEvent('demo_restarted');
console.log('%c🔄 Demo restarted', 'color: #667eea; font-weight: bold;');
}
function viewLogs() {
console.log('%c📊 Current Session Log:', 'color: #667eea; font-size: 14px; font-weight: bold;');
console.log(sessionLog);
console.log('%c💾 LocalStorage Data:', 'color: #667eea; font-size: 14px; font-weight: bold;');
const stored = localStorage.getItem('phish-sim-log');
if (stored) {
console.log(JSON.parse(stored));
} else {
console.log('No data in localStorage');
}
alert('Logs have been printed to the browser console. Press F12 to view them.');
}
// ===== INITIALIZE ON LOAD =====
window.addEventListener('DOMContentLoaded', init);
// ===== EXPORT FUNCTION (for demo purposes) =====
function exportSessionData() {
const dataStr = JSON.stringify(sessionLog, null, 2);
const dataBlob = new Blob([dataStr], { type: 'application/json' });
const url = URL.createObjectURL(dataBlob);
const link = document.createElement('a');
link.href = url;
link.download = `phishing-sim-${DEMO_ID}-${new Date().getTime()}.json`;
link.click();
URL.revokeObjectURL(url);
console.log('%c📥 Session data exported', 'color: #28a745; font-weight: bold;');
}
// Make functions available in console for demo
window.exportSessionData = exportSessionData;
window.viewStoredData = viewLogs;
console.log('%cDemo Functions Available:', 'color: #667eea; font-weight: bold;');
console.log('- exportSessionData() : Download session log as JSON file');
console.log('- viewStoredData() : View localStorage data in console');
console.log('- restartDemo() : Reset and restart the simulation');