-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenges.js
More file actions
116 lines (99 loc) · 3.94 KB
/
Copy pathchallenges.js
File metadata and controls
116 lines (99 loc) · 3.94 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
class Challenge {
constructor(level, description, validator) {
this.level = level;
this.description = description;
this.validator = validator;
this.completed = false;
}
analyzePayload(input) {
let analysis = [];
if (input.includes('>') || input.includes('<')) {
analysis.push({
issue: "HTML tags detected - might be filtered",
tip: "Try learning about HTML encoding techniques",
resource: "https://www.w3schools.com/html/html_entities.asp"
});
}
if (input.includes('"') || input.includes("'")) {
analysis.push({
issue: "Quotes detected - encode and try again",
tip: "Learn about different quote bypass techniques",
resource: "https://owasp.org/www-community/xss-filter-evasion-cheatsheet"
});
}
if (input.toLowerCase().includes('script')) {
analysis.push({
issue: "'script' might be blocked",
tip: "There are many other event handlers in HTML. Research 'DOM event handlers'",
resource: "https://developer.mozilla.org/en-US/docs/Web/Events"
});
}
if (input.toLowerCase().includes('alert')) {
analysis.push({
issue: "Direct JavaScript functions might be filtered",
tip: "Try learning about JavaScript obfuscation techniques",
tool: "https://obfuscator.io"
});
}
return analysis;
}
}
const challenges = {
level1: new Challenge(
1,
"Craft an XSS payload to make the horse speak!",
(input) => {
return input.toLowerCase().includes('alert(') ||
input.toLowerCase().includes('console.log(') ||
input.toLowerCase().includes('prompt(');
}
)
};
function processSearch(query) {
const resultDiv = document.getElementById('search-results');
const horseMascot = new HorseMascot();
resultDiv.innerHTML = `<div>Search results for: ${query}</div>`;
const analysis = challenges.level1.analyzePayload(query);
if (analysis.length > 0) {
let feedback = '<div class="payload-analysis">';
feedback += '<h3> Improve your payload</h3>';
feedback += '<ul>';
analysis.forEach(item => {
feedback += `
<li>
<strong>${item.issue}</strong><br>
💡 ${item.tip}<br>
${item.resource ? `🔗 <a href="${item.resource}" target="_blank">Learn about this</a>` : ''}
${item.tool ? `🛠️ <a href="${item.tool}" target="_blank">Try this tool</a>` : ''}
</li>`;
});
feedback += '</ul>';
feedback += '</div>';
resultDiv.innerHTML += feedback;
horseMascot.speak("Keep experimenting! Every failed attempt teaches something new!", "hint");
}
}
document.addEventListener('DOMContentLoaded', () => {
const searchBox = document.getElementById('search-box');
searchBox.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
processSearch(e.target.value);
}
});
searchBox.addEventListener('input', (e) => {
processSearch(e.target.value);
});
});
function getHint(currentPayload) {
const hints = {
script: "Think about alternative ways to execute JavaScript without using <script> tags",
alert: "JavaScript functions can be called in many different ways",
default: "Start by understanding how HTML elements can execute JavaScript"
};
for (let key in hints) {
if (currentPayload.toLowerCase().includes(key)) {
return hints[key];
}
}
return hints.default;
}