Skip to content

Instantly share code, notes, and snippets.

@likuilin
Last active November 21, 2019 22:47
Show Gist options
  • Save likuilin/d71aa7ba42d52031a026acc655a03ca5 to your computer and use it in GitHub Desktop.
Save likuilin/d71aa7ba42d52031a026acc655a03ca5 to your computer and use it in GitHub Desktop.
/*
Quick n' Dirty In-Browser CTFD Importer
by Kuilin
INSTRUCTIONS:
1. Put the data into json, with form array of object {name, points, flag}. Example data below in input_data
2. Log into admin on ctfd, open JS console, get data into it, paste code into it, etc etc
3. Edit the visibility, flag case sensitivity, etc, if you want, in the code itself
4. Run ctfd_import(data) (commented out to prevent accidents)
*/
let input_data = [{"name":"test chal 1","points":50 ,"flag":"test flag 1", "description": "test"},
{"name":"test chal 2","points":100,"flag":"test flag 2", "description": "test"}];
let category = "PicoCTF 2018";
let ctfd = "https://ctf.sigpwny.com/api";
let ctfd_import = async data => {
while (data.length) {
let chal = data.shift();
let req = await fetch(ctfd + "/v1/challenges", {
credentials: "include",
headers: {
"csrf-token": csrf_nonce, // Set by ctfd globally
"content-type": "application/json"
},
body: JSON.stringify({
name: chal.name,
category: category,
description: chal.description,
value: chal.points,
state: "hidden",
type: "standard"
}),
method: "POST"
});
let resp = await req.json();
if (!resp || !resp.success) console.log("Error creating", chal, req, resp);
let id = resp.data.id;
await fetch(ctfd + "/v1/flags", {
credentials: "include",
headers: {
"csrf-token": csrf_nonce,
"content-type": "application/json"
},
body: JSON.stringify({
content: chal.flag,
type: "static",
challenge: resp.data.id
}),
method: "POST"
});
console.log("Created " + chal.name + ". " + data.length + " left.");
}
}
// await ctfd_import(input_data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment