From 1944eec5e3d844975a85a6a701bbe03150e26417 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Sat, 8 Jun 2024 14:22:43 +0200 Subject: [PATCH 1/4] Rename ECSC parser to ECSC2021 --- front/src/ctfnote/parsers/{ecsc.ts => ecsc2021.ts} | 8 ++++---- front/src/ctfnote/parsers/index.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) rename front/src/ctfnote/parsers/{ecsc.ts => ecsc2021.ts} (80%) diff --git a/front/src/ctfnote/parsers/ecsc.ts b/front/src/ctfnote/parsers/ecsc2021.ts similarity index 80% rename from front/src/ctfnote/parsers/ecsc.ts rename to front/src/ctfnote/parsers/ecsc2021.ts index 66ad18fd1..9a3935855 100644 --- a/front/src/ctfnote/parsers/ecsc.ts +++ b/front/src/ctfnote/parsers/ecsc2021.ts @@ -1,9 +1,9 @@ import { ParsedTask, Parser } from '.'; import { parseJson, parseJsonStrict } from '../utils'; -const ECSCParser: Parser = { - name: 'ECSC parser', - hint: 'paste ecsc /stats.json', +const ECSC2021Parser: Parser = { + name: 'ECSC 2021 (Prague) parser', + hint: 'paste ECSC platform /stats.json', parse(s: string): ParsedTask[] { const tasks = []; @@ -26,4 +26,4 @@ const ECSCParser: Parser = { }, }; -export default ECSCParser; +export default ECSC2021Parser; diff --git a/front/src/ctfnote/parsers/index.ts b/front/src/ctfnote/parsers/index.ts index a2ec5ab97..f537cf929 100644 --- a/front/src/ctfnote/parsers/index.ts +++ b/front/src/ctfnote/parsers/index.ts @@ -1,5 +1,5 @@ import CTFDParser from './ctfd'; -import ECSCParser from './ecsc'; +import ECSC2021Parser from './ecsc2021'; import RawParser from './raw'; import HTBParser from './htb'; import PicoParser from './pico'; @@ -23,7 +23,7 @@ export type Parser = { export default [ RawParser, CTFDParser, - ECSCParser, + ECSC2021Parser, HTBParser, PicoParser, justCTFParser, From 381a0ca6c1dbda2a74a46855e40503fd03633761 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Sat, 8 Jun 2024 14:36:34 +0200 Subject: [PATCH 2/4] Add CINI parser (ECSC 2024) --- front/src/ctfnote/parsers/cini.ts | 55 ++++++++++++++++++++++++++++++ front/src/ctfnote/parsers/index.ts | 2 ++ 2 files changed, 57 insertions(+) create mode 100644 front/src/ctfnote/parsers/cini.ts diff --git a/front/src/ctfnote/parsers/cini.ts b/front/src/ctfnote/parsers/cini.ts new file mode 100644 index 000000000..491120034 --- /dev/null +++ b/front/src/ctfnote/parsers/cini.ts @@ -0,0 +1,55 @@ +import { ParsedTask, Parser } from '.'; +import { parseJson, parseJsonStrict } from '../utils'; + +interface Events { + gamePause?: unknown; + events: [ + { + id: number; + name: string; + sections: [ + { + id: number; + name: string; + challenges: [ + { + id: number; + title: string; + tags: string[]; + authors: string[]; + currentScore: number; + currentGlobalSolves: number; + hidden: boolean; + } + ]; + } + ]; + } + ]; +} + +const CINIParser: Parser = { + name: 'Cybersecurity National Lab (CINI) platform and ECSC 2024 (Turin) parser', + hint: 'paste platform /api/challenges', + + parse(s: string): ParsedTask[] { + const tasks = []; + const data = parseJsonStrict(s); + + for (const event of data.events) { + for (const section of event.sections) { + for (const chall of section.challenges) { + tasks.push({ title: chall.title, tags: chall.tags }); + } + } + } + + return tasks; + }, + isValid(s) { + const data = parseJson(s); + return !Array.isArray(data); + }, +}; + +export default CINIParser; diff --git a/front/src/ctfnote/parsers/index.ts b/front/src/ctfnote/parsers/index.ts index f537cf929..9de03f6d9 100644 --- a/front/src/ctfnote/parsers/index.ts +++ b/front/src/ctfnote/parsers/index.ts @@ -5,6 +5,7 @@ import HTBParser from './htb'; import PicoParser from './pico'; import justCTFParser from './justctf'; import AngstromParser from './angstrom'; +import CINIParser from './cini'; export type ParsedTask = { title: string; @@ -28,4 +29,5 @@ export default [ PicoParser, justCTFParser, AngstromParser, + CINIParser, ]; From 53d136a04aec4bf7b30fa699fced37af6078b6a7 Mon Sep 17 00:00:00 2001 From: JJ-8 <34778827+JJ-8@users.noreply.github.com> Date: Sun, 14 Jul 2024 21:32:23 +0200 Subject: [PATCH 3/4] Fix isValid of CINI parser --- front/src/ctfnote/parsers/cini.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/front/src/ctfnote/parsers/cini.ts b/front/src/ctfnote/parsers/cini.ts index 491120034..d1d9c311f 100644 --- a/front/src/ctfnote/parsers/cini.ts +++ b/front/src/ctfnote/parsers/cini.ts @@ -48,7 +48,8 @@ const CINIParser: Parser = { }, isValid(s) { const data = parseJson(s); - return !Array.isArray(data); + if (data == null) return false; + return data.gamePause !== undefined && data.events !== undefined; }, }; From a7290b10adc409cf6d39bc80eda6c9492e16907c Mon Sep 17 00:00:00 2001 From: JJ-8 <34778827+JJ-8@users.noreply.github.com> Date: Sun, 14 Jul 2024 21:35:18 +0200 Subject: [PATCH 4/4] Drop ECSC2021/2022 parser The parser was introduced in https://github.com/TFNS/CTFNote/pull/184 but I don't think anyone will be using this parser since the project is dead for years and ENISA is not using this gameboard in the last couple of years. Since it conflicts with the parsing of the other CTF formats, it is better to drop it and reintroduce it when necessary. --- front/src/ctfnote/parsers/ecsc2021.ts | 29 --------------------------- front/src/ctfnote/parsers/index.ts | 2 -- 2 files changed, 31 deletions(-) delete mode 100644 front/src/ctfnote/parsers/ecsc2021.ts diff --git a/front/src/ctfnote/parsers/ecsc2021.ts b/front/src/ctfnote/parsers/ecsc2021.ts deleted file mode 100644 index 9a3935855..000000000 --- a/front/src/ctfnote/parsers/ecsc2021.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { ParsedTask, Parser } from '.'; -import { parseJson, parseJsonStrict } from '../utils'; - -const ECSC2021Parser: Parser = { - name: 'ECSC 2021 (Prague) parser', - hint: 'paste ECSC platform /stats.json', - - parse(s: string): ParsedTask[] { - const tasks = []; - const data = parseJsonStrict<[{ task: string; contract: string }]>(s); - if (!Array.isArray(data)) { - return []; - } - - for (const task of data) { - if (!task.task || !task.contract) { - continue; - } - tasks.push({ title: task.task, tags: [task.contract] }); - } - return tasks; - }, - isValid(s) { - const data = parseJson<[{ task: string; contract: string }]>(s); - return Array.isArray(data); - }, -}; - -export default ECSC2021Parser; diff --git a/front/src/ctfnote/parsers/index.ts b/front/src/ctfnote/parsers/index.ts index 5fe29ab3c..ca4c13606 100644 --- a/front/src/ctfnote/parsers/index.ts +++ b/front/src/ctfnote/parsers/index.ts @@ -1,5 +1,4 @@ import CTFDParser from './ctfd'; -import ECSC2021Parser from './ecsc2021'; import RawParser from './raw'; import HTBParser from './htb'; import PicoParser from './pico'; @@ -25,7 +24,6 @@ export type Parser = { export default [ RawParser, CTFDParser, - ECSC2021Parser, HTBParser, PicoParser, justCTFParser,