Skip to content

Instantly share code, notes, and snippets.

@diegoalbuquerque
Forked from rizemon/ColorMyWSA.js
Created August 15, 2022 12:31
Show Gist options
  • Save diegoalbuquerque/b664fb91ac8162951e01e36e14e4a881 to your computer and use it in GitHub Desktop.
Save diegoalbuquerque/b664fb91ac8162951e01e36e14e4a881 to your computer and use it in GitHub Desktop.
Automatically adds color-coded level information (Apprentice, Practitioner, Expert) to PortSwigger's Web Security Academy "All labs" page
/*
Inspired by this post https://www.deepfryd.com/burp-academy-apprentice/
How to use:
1) Browse to https://portswigger.net/web-security/all-labs.
2) Open your web browser's Developer tools by pressing 'F12' on your keyboard.
3) Click on the console tab.
4) Paste the following Javascript code into the console's prompt and hit 'Enter' on the keyboard.
5) Wait for all the labs to be updated with their respective levels (Tested ~12s)
If you have browser extensions that allow for execution of scripts, you can also use it to automatically load the following Javascript code.
Edit: Added a "sleep" so that we don't end up DDoSing the website. (Wait time ended up dropping from 50s to 12s!)
*/
const labs = [...document.getElementsByClassName("widgetcontainer-lab-link")]
.map(lab_container => [lab_container, lab_container.getElementsByTagName("a")[0].getAttribute("href")]);
const mapping = {
'APPRENTICE': '#70d16d',
'PRACTITIONER': '#4cc1ff',
'EXPERT': '#ae75c3'
}
// Reference from https://stackoverflow.com/a/55307863
const sleep = ms => new Promise(res => setTimeout(res, ms));
(async function() {
for (const idx in labs) {
const [lab_container, url] = labs[idx];
fetch(url)
.then(response => response.text())
.then(data => {
// Get level from the retrieved HTML content
let level = data.match(/<span>(APPRENTICE|PRACTITIONER|EXPERT)<\/span>/)[1];
// Get the "LAB" span element
let lab_element = lab_container.getElementsByTagName("span")[0];
// Update style
lab_element.style.backgroundColor = mapping[level];
lab_element.innerText = level + " LAB";
lab_element.style.width = "13em";
});
await sleep(50);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment