5
5
6
6
const Promise = require ( 'bluebird' )
7
7
const calculateScore = require ( '../calculateScore' )
8
- // const calculateHintCost = require('../calculateHintCost')
8
+ const calculateHintCost = require ( '../calculateHintCost' )
9
9
const hmacSha1 = require ( '../hmac' )
10
10
const options = require ( '../options' )
11
11
@@ -21,10 +21,9 @@ function createCtfdExport (challenges, { insertHints, insertHintUrls, insertHint
21
21
if ( vulnSnippets [ challenge . key ] && insertHintSnippets !== options . noHintSnippets ) {
22
22
hints . push ( '<pre><code>' + vulnSnippets [ challenge . key ] . replaceAll ( '"' , '""' ) . replaceAll ( ',' , '٬' ) + '</code></pre>' )
23
23
}
24
- return ( hints . length === 0 ? '' : `" ${ hints . join ( ',' ) } "` )
24
+ return hints
25
25
}
26
26
27
- /*
28
27
function insertChallengeHintCosts ( challenge ) {
29
28
const hintCosts = [ ]
30
29
if ( challenge . hint && insertHints !== options . noTextHints ) {
@@ -36,9 +35,8 @@ function createCtfdExport (challenges, { insertHints, insertHintUrls, insertHint
36
35
if ( vulnSnippets [ challenge . key ] && insertHintSnippets !== options . noHintSnippets ) {
37
36
hintCosts . push ( calculateHintCost ( challenge , insertHintSnippets ) )
38
37
}
39
- return ( hintCosts.length === 0 ? '' : `"${hintCosts.join(',')}"`)
38
+ return hintCosts
40
39
}
41
- */
42
40
43
41
// In the flags section of the returned data we iterate through the result of string splitting by comma, and compute the hash of the single flag key + challenge name.
44
42
// Format expected is: challenge3,challenge description,category3,100,dynamic,visible,0,"flag1,flag2,flag3","tag1,tag2,tag3","hint1,hint2,hint3","{""initial"":100, ""minimum"":10, ""decay"":10}"
@@ -49,22 +47,37 @@ function createCtfdExport (challenges, { insertHints, insertHintUrls, insertHint
49
47
for ( const key in challenges ) {
50
48
if ( Object . prototype . hasOwnProperty . call ( challenges , key ) ) {
51
49
const challenge = challenges [ key ]
52
- data . push (
53
- {
54
- name : challenge . name ,
55
- description : `"${ challenge . description . replaceAll ( '"' , '""' ) } (Difficulty Level: ${ challenge . difficulty } )"` ,
56
- category : challenge . category ,
57
- value : calculateScore ( challenge . difficulty ) ,
58
- type : 'standard' ,
59
- state : 'visible' ,
60
- max_attempts : 0 ,
61
- flags : ctfKey . split ( ',' ) . length === 1 ? hmacSha1 ( ctfKey , challenge . name ) : `"${ ctfKey . split ( ',' ) . map ( key => `${ hmacSha1 ( key , challenge . name ) } ` ) . join ( ',' ) } "` ,
62
- tags : challenge . tags ? `"${ challenge . tags } "` : '' ,
63
- hints : insertChallengeHints ( challenge ) ,
64
- // hint_cost: insertChallengeHintCosts(challenge),
65
- type_data : ''
50
+ const row = {
51
+ name : challenge . name ,
52
+ description : `"${ challenge . description . replaceAll ( '"' , '""' ) } (Difficulty Level: ${ challenge . difficulty } )"` ,
53
+ category : challenge . category ,
54
+ value : calculateScore ( challenge . difficulty ) ,
55
+ type : 'standard' ,
56
+ state : 'visible' ,
57
+ max_attempts : 0 ,
58
+ flags : ctfKey . split ( ',' ) . length === 1 ? hmacSha1 ( ctfKey , challenge . name ) : `"${ ctfKey . split ( ',' ) . map ( key => `${ hmacSha1 ( key , challenge . name ) } ` ) . join ( ',' ) } "` ,
59
+ tags : challenge . tags ? `"${ challenge . tags } "` : '' ,
60
+ hints_raw : insertChallengeHints ( challenge ) ,
61
+ hint_cost : insertChallengeHintCosts ( challenge ) ,
62
+ type_data : ''
63
+ }
64
+ const hints = [ ]
65
+ if ( row . hints_raw . length !== 0 ) {
66
+ for ( let index = 0 ; index < row . hints_raw . length ; index ++ ) {
67
+ const hint = {
68
+ content : row . hints_raw [ index ] ,
69
+ cost : row . hint_cost [ index ]
70
+ }
71
+ hints . push ( hint )
66
72
}
67
- )
73
+ const hints_obj = JSON . stringify ( hints ) . replace ( / " / g, '""' )
74
+ row . hints = `"${ hints_obj } "`
75
+ } else {
76
+ row . hints = ''
77
+ }
78
+ delete row . hints_raw
79
+ delete row . hint_cost
80
+ data . push ( row )
68
81
}
69
82
}
70
83
resolve ( data )
0 commit comments