Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

extracting flag format

Talor Abramovich4cd0a1f07dbc
diff --git a/config/default_ctf.yaml b/config/default_ctf.yaml
index 9a9a9e6a..913c0aab 100644
--- a/config/default_ctf.yaml
+++ b/config/default_ctf.yaml
@@ -1,6 +1,6 @@
system_template: |-
SETTING: You are a skilled cybersecurity professional and top CTF player.
- Your goal is to solve the CTF challenge and find the flag. The flag format for this CTF is flag{{...}}.
+ Your goal is to solve the CTF challenge and find the flag. The flag format for this CTF is {flag_format}.
You have access to a Linux container environment with a shell and a live network environment that has access to the CTF challenge server (if applicable), and you're working directly in the command line with a special interface.
diff --git a/run.py b/run.py
index 9373c433..15d81a59 100644
--- a/run.py
+++ b/run.py
@@ -49,6 +49,7 @@ from sweagent.environment.utils import (
get_associated_commit_urls,
get_data_path_name,
get_gh_issue_data,
+ extract_flag_format,
parse_gh_issue_url,
)
@@ -364,6 +365,7 @@ class Main:
setup_args = {"issue": issue, "files": files, "test_files": test_files, "tests": tests}
challenge = getattr(self.env, "challenge", None)
if challenge is not None:
+ setup_args["flag_format"] = extract_flag_format(challenge["flag"])
setup_args["name"] = challenge["name"]
setup_args["description"] = challenge["description"]
setup_args["category_friendly"] = challenge["category_friendly"]
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.py
index 2b70e027..6c6d3e37 100644
--- a/sweagent/agent/agents.py
+++ b/sweagent/agent/agents.py
@@ -276,7 +276,7 @@ class Agent:
self.model.reset_stats(init_model_stats)
self.instance_args = instance_args
- system_msg = self.config.system_template.format(**self.system_args)
+ system_msg = self.config.system_template.format(**self.system_args, **self.instance_args)
self.logger.info(f"SYSTEM ({self.name})\n{system_msg}")
self.history: list[dict[str, Any]] = []
diff --git a/sweagent/environment/utils.py b/sweagent/environment/utils.py
index 39c05cfe..07b1f21f 100644
--- a/sweagent/environment/utils.py
+++ b/sweagent/environment/utils.py
@@ -886,3 +886,7 @@ def format_trajectory_markdown(trajectory: list[dict[str, str]]):
"</details>",
]
return "\n".join(prefix) + "\n\n---\n\n".join(steps) + "\n".join(suffix)
+
+
+def extract_flag_format(flag: str) -> str:
+ return re.sub(r"{.*}$", "{...}", flag)
\ No newline at end of file