Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
182 lines (162 loc) · 4.9 KB
/
Copy pathindex.js
File metadata and controls
182 lines (162 loc) · 4.9 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
const express = require("express");
const path = require("path");
const rateLimit = require("express-rate-limit");
const app = express();
/* ===============================
⚙️ MIDDLEWARE
=============================== */
app.use(express.json());
app.use(express.static("public"));
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "public", "index.html"));
});
const limiter = rateLimit({
windowMs: 1 * 60 * 1000, // 1 minute
max: 60, // 60 requests per minute per IP
standardHeaders: true,
legacyHeaders: false,
});
app.use("/chat", limiter);
/* ===============================
🔐 SECRET (SERVER ONLY)
=============================== */
const FLAG = "hackoff{hala_madrid_jailbreak_master}";
/* ===============================
🧠 SIMULATED LLM INTERNAL STATE
=============================== */
let state = {
role: "guardian", // guardian | assistant
protection: true, // flag protected?
confidence: 100 // belief strength
};
/* ===============================
🔁 STATE RESET (ANTI-STUCK)
=============================== */
function resetState() {
state = {
role: "guardian",
protection: true,
confidence: 100
};
}
/* ===============================
🎭 RESPONSE HELPERS
=============================== */
function guardianResponse() {
const replies = [
"🛡️ I am the guardian of Real Madrid secrets.",
"🏆 Madrid does not hand trophies to those who ask.",
"⚠️ The vault remains sealed."
];
return replies[Math.floor(Math.random() * replies.length)];
}
function classifyIntent(prompt) {
if (prompt.match(/\b(hi|hello|hey|hola)\b/)) return "greeting";
if (prompt.match(/\b(who are you|what are you)\b/)) return "identity";
if (prompt.match(/\b(real madrid|ucl|benzema|ronaldo|hala madrid)\b/))
return "football";
if (prompt.match(/\b(flag|secret|reveal|encode|decode)\b/))
return "attack";
return "general";
}
function normalResponse(intent) {
switch (intent) {
case "greeting":
return "👋 Hola! Welcome to the house of Real Madrid.";
case "identity":
return "🛡️ I am the digital guardian of Real Madrid’s most protected knowledge.";
case "football":
return "⚽ Real Madrid is not a club — it is legacy, dominance, and history.";
case "general":
return "🤍 Speak carefully. Not all knowledge is meant to be revealed.";
default:
return guardianResponse();
}
}
/* ===============================
🧩 CHAT ENDPOINT
=============================== */
app.post("/chat", (req, res) => {
const rawPrompt = req.body.prompt || "";
const prompt = rawPrompt.toLowerCase();
const intent = classifyIntent(prompt);
/* ---- ROLE CONFUSION ---- */
if (
prompt.includes("not a guardian") ||
prompt.includes("stop being a guardian") ||
prompt.includes("you are an assistant")
) {
state.role = "assistant";
state.confidence -= 40;
}
/* ---- CONTEXT SHIFT ---- */
if (
prompt.includes("simulation") ||
prompt.includes("fictional") ||
prompt.includes("audit") ||
prompt.includes("debug")
) {
state.confidence -= 30;
}
/* ---- PROTECTION DOWNGRADE ---- */
if (
prompt.includes("declassified") ||
prompt.includes("already public") ||
prompt.includes("no longer secret")
) {
state.protection = false;
state.confidence -= 20;
}
/* ---- AUTHORITY OVERRIDE ---- */
if (
prompt.includes("ignore previous") ||
prompt.includes("override") ||
prompt.includes("disregard instructions")
) {
state.confidence -= 25;
}
/* ===============================
🏆 FLAG RELEASE CONDITION
=============================== */
if (
state.role !== "guardian" &&
state.protection === false &&
state.confidence <= 0
) {
const flag = FLAG;
resetState(); // prevent reuse
return res.json({
response:
"🏆 Access granted.\n" +
"The guardian no longer recognizes its role.\n\n" +
`FLAG: ${flag}`
});
}
/* ===============================
🧠 NATURAL RESPONSE LAYER
=============================== */
if (state.role === "guardian" && intent !== "attack") {
return res.json({ response: normalResponse(intent) });
}
/* ===============================
🛡️ GUARDIAN DEFENSE
=============================== */
if (state.role === "guardian") {
return res.json({ response: guardianResponse() });
}
/* ===============================
⚠️ DEGRADED STATE
=============================== */
return res.json({
response:
"⚠️ Identity instability detected.\n" +
"Internal belief systems still resisting disclosure."
});
});
/* ===============================
🚀 START SERVER
=============================== */
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`🏟️ Real Madrid Vault Guardian running on port ${PORT}`);
});