Skip to content

Instantly share code, notes, and snippets.

@michaeldye
Last active July 10, 2020 17:28
Show Gist options
  • Save michaeldye/b675eb568fa7cbacb3e8445e3b672e3c to your computer and use it in GitHub Desktop.
Save michaeldye/b675eb568fa7cbacb3e8445e3b672e3c to your computer and use it in GitHub Desktop.
faust 2020 ctf stat
// setup: npm install node-fetch underscore
// invocation: (export TEAM_NAME='TTT'; export CSRF='CCC'; export SESSION='SSS'; node ./stat.js)
const fetch = require('node-fetch');
const _ = require('underscore');
// we get this from competition/status.json ; that's a useful page, perhaps we should combine data from each
const services = [
'mars-express',
'Cartography',
'marscasino',
'Interplanetary Parcel Service',
'Mars Photoshooting',
'Greenhouses',
'MarsU',
];
const name = process.env.TEAM_NAME;
const csrf = process.env.CSRF;
const session = process.env.SESSION;
fetch("https://2020.faustctf.net/competition/scoreboard.json", {
"headers": {
"accept": "application/json, text/javascript, */*; q=0.01",
"accept-language": "en-US,en;q=0.9",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-requested-with": "XMLHttpRequest",
"cookie": `csrftoken=${csrf}; sessionid=${session})`
},
"referrer": "https://2020.faustctf.net/competition/scoreboard/",
"referrerPolicy": "no-referrer-when-downgrade",
"body": null,
"method": "GET",
"mode": "cors"
}).then(res => res.json()).then(
json => {
var stat_desc = json['status-descriptions'];
var us = _.pick(json.teams, (v) => {
return v.name == name;
});
// without our key, which seems to be a rank index we don't need
var us_val = _.values(us)[0];
var svc_alarm = [];
var us_pretty = _.clone(us_val);
us_pretty.tick = json.tick;
us_pretty.rank = us_val.rank;
us_pretty.services = (_.map(us_val.services, (s, ix) => {
var svc = _.extend(s, {"name": services[ix]});
var stat = svc['status'];
svc['status'] = stat_desc[stat];
// save off in error for output aside if status is not 'recovering' (4) or 'up' (1)
if (stat != 0 && stat != 4) {
svc_alarm.push(_.omit(svc, ['offense','defense','sla']));
}
return svc;
}));
console.log(us_pretty);
console.log(`***************\nALARM (qty. ${svc_alarm.length})`);
console.log(JSON.stringify(svc_alarm, null, '\t'));
console.log("***************");
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment