1
1
import argparse
2
+ import hashlib
2
3
import sys
3
4
4
5
import jsons
@@ -28,7 +29,7 @@ def _add_arguments(parser: argparse.ArgumentParser, hide_checker_address=False)
28
29
default = 1 ,
29
30
help = "The round in which the flag or noise was stored when method is getflag/getnoise. Equal to current_round_id otherwise." ,
30
31
)
31
- parser .add_argument ("-f" , "--flag" , type = str , default = "ENOFLAGENOFLAG=" , help = "The Flag, a Fake flag or a Unique ID, depending on the mode" )
32
+ parser .add_argument ("-f" , "--flag" , type = str , default = "ENOFLAGENOFLAG=" , help = "The flag for putflag/getflag or the flag to find in exploit mode" )
32
33
parser .add_argument ("-v" , "--variant_id" , type = int , default = 0 , help = "The variantId for the method being called" )
33
34
parser .add_argument (
34
35
"-x" , "--timeout" , type = int , default = 30000 , help = "The maximum amount of time the script has to execute in milliseconds (default 30 000)"
@@ -41,23 +42,33 @@ def _add_arguments(parser: argparse.ArgumentParser, hide_checker_address=False)
41
42
default = None ,
42
43
help = "A unique Id which must be identical for all related putflag/getflag calls and putnoise/getnoise calls" ,
43
44
)
45
+ parser .add_argument ("--flag_regex" , type = str , default = None , help = "A regular expression matched by the flag, used only when running the exploit method" )
46
+ parser .add_argument (
47
+ "--attack_info" , type = str , default = None , help = "The attack info returned by the corresponding putflag, used only when running the exploit method"
48
+ )
44
49
45
50
46
51
def task_message_from_namespace (ns : argparse .Namespace ) -> CheckerTaskMessage :
47
52
task_chain_id = ns .task_chain_id
48
53
method = CheckerMethod (ns .method )
49
54
if not task_chain_id :
50
55
option = None
51
- if method in (CheckerMethod .CHECKER_METHOD_PUTFLAG , CheckerMethod .CHECKER_METHOD_GETFLAG ):
56
+ if method in (CheckerMethod .PUTFLAG , CheckerMethod .GETFLAG ):
52
57
option = "flag"
53
- elif method in (CheckerMethod .CHECKER_METHOD_PUTNOISE , CheckerMethod .CHECKER_METHOD_GETNOISE ):
58
+ elif method in (CheckerMethod .PUTNOISE , CheckerMethod .GETNOISE ):
54
59
option = "noise"
55
- elif method == CheckerMethod .CHECKER_METHOD_HAVOC :
60
+ elif method == CheckerMethod .HAVOC :
56
61
option = "havoc"
62
+ elif method == CheckerMethod .EXPLOIT :
63
+ option = "exploit"
57
64
else :
58
65
raise ValueError (f"Unexpected CheckerMethod: { method } " )
59
66
task_chain_id = f"{ option } _s0_r{ ns .related_round_id } _t{ ns .team_id } _i{ ns .variant_id } "
60
67
68
+ flag_hash = None
69
+ if method == CheckerMethod .EXPLOIT :
70
+ flag_hash = hashlib .sha256 (ns .flag .encode ()).hexdigest ()
71
+
61
72
msg = CheckerTaskMessage (
62
73
task_id = ns .task_id ,
63
74
method = method ,
@@ -66,11 +77,14 @@ def task_message_from_namespace(ns: argparse.Namespace) -> CheckerTaskMessage:
66
77
team_name = ns .team_name ,
67
78
current_round_id = ns .current_round_id ,
68
79
related_round_id = ns .related_round_id ,
69
- flag = ns .flag ,
80
+ flag = ns .flag if method != CheckerMethod . EXPLOIT else None ,
70
81
variant_id = ns .variant_id ,
71
82
timeout = ns .timeout ,
72
83
round_length = ns .round_length ,
73
84
task_chain_id = task_chain_id ,
85
+ flag_regex = ns .flag_regex ,
86
+ flag_hash = flag_hash ,
87
+ attack_info = ns .attack_info ,
74
88
)
75
89
76
90
return msg
0 commit comments