Last active
January 24, 2024 19:50
-
-
Save bluec0re/244271641aa34b8fa187b8faa4911cf2 to your computer and use it in GitHub Desktop.
HTB lab annotate flag owners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getLabId() { | |
return /\d+$/.exec(location.pathname)[0] | |
} | |
async function getActivity() { | |
const lab_id = getLabId(); | |
let page = 1; | |
let data = await (await fetch(`https://enterprise.hackthebox.com/api/v1/product/labs/${lab_id}/activity?page=${page}`)).json(); | |
const activities = data.data; | |
for (page++; page <= data.meta.last_page; page++) { | |
data = await (await fetch(`https://enterprise.hackthebox.com/api/v1/product/labs/${lab_id}/activity?page=${page}`)).json(); | |
activities.push(...data.data); | |
} | |
return activities; | |
} | |
async function annotate() { | |
document.querySelectorAll('.flag-owners').forEach(e => e.remove()); | |
const activities = await getActivity(); | |
const flags = activities.reduce((acc, curr) => { | |
const flag = curr.flag && curr.flag.title || curr.machine.name; | |
const users = acc[flag] || []; | |
users.push(curr.user.name); | |
acc[flag] = users; | |
return acc; | |
}, {}); | |
for (const flag in flags) { | |
const iter = document.evaluate(`//div[contains(text(), "${flag}")]`, document, null, XPathResult.ANY_TYPE, null); | |
const div = iter.iterateNext(); | |
const span = document.createElement("span"); | |
span.style.display = 'block'; | |
span.style.fontSize = 'smaller'; | |
span.style.color = '#aaa'; | |
span.className = 'flag-owners'; | |
span.innerText = flags[flag].join(", "); | |
div.appendChild(span); | |
} | |
} | |
async function getUsers() { | |
const lab_id = getLabId(); | |
return (await (await fetch(`https://enterprise.hackthebox.com/api/v1/product/labs/${lab_id}/users`)).json()).data; | |
} | |
async function points() { | |
document.querySelectorAll('.user-points').forEach(e => e.remove()); | |
const users = await getUsers(); | |
const items = []; | |
const iter = document.evaluate('//div[contains(@id, "user-options-")]', document.getElementById('LabSideContent'), null, XPathResult.ANY_TYPE, null); | |
while ((el = iter.iterateNext()) !== null) { | |
items.push(el); | |
} | |
for (const user of users) { | |
for (const el of items) { | |
if (el.textContent.indexOf(user.name) > -1) { | |
const span = document.createElement('span'); | |
span.textContent = '' + user.total_points; | |
span.className = 'user-points'; | |
el.children[0].appendChild(span); | |
} | |
} | |
} | |
} | |
annotate(); | |
points(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment