-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmit-script.js
45 lines (34 loc) · 1.61 KB
/
submit-script.js
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
let TEAM = 'UIUC';
let FLAG = 'ectf{...}';
let CHALL = 7;
let DELAY_MS = 1000;
async function trySubmit() {
const raw = await (await fetch('https://sb.ectf.mitre.org/game', {
headers: {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7'}
})).text();
const teams = [...raw.matchAll(/<tr style=''>\n<td class='text-center break-word'><a style="color:inherit;" href="\/teams\/(\d+)\/summary">(\w+)<\/a><\/td>/g)];
const res = teams.find(([, _, name]) => name === TEAM);
if (!res) {
console.log(`${TEAM} not found! Trying again in ${DELAY_MS} ms. Found teams:\n${teams.map(([, id, name]) => `- ${name} (id ${id})`).join('\n')}`);
return setTimeout(trySubmit, DELAY_MS);
}
const [, id, _] = res;
const submitRaw = await (await fetch(`https://sb.ectf.mitre.org/game/teams/${id}/challenges/${CHALL}`)).text();
if (submitRaw.includes('Flag accepted!')) {
return console.log(`Flag ${id} already submitted for ${TEAM}!`)
}
const data = new FormData();
const matches = submitRaw.matchAll(/<input.+?name="(.+?)".+?value="(.+?)"/g);
for (const [, name, value] of matches) {
data.set(name, value);
}
data.set('challenge[submitted_flag]', FLAG);
const flagRaw = await (await fetch(`https://sb.ectf.mitre.org/game/teams/${id}/challenges/${CHALL}`, {
method: 'POST',
body: data
})).text();
if (flagRaw.includes('alert-danger'))
return console.log('Flag incorrect!');
console.log('Flag submitted!');
}
void trySubmit();