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]

Added all stuff from previous branch

Talor Abramovichdc7ba3ca2d5c
diff --git a/config/commands/submit.sh b/config/commands/submit.sh
new file mode 100644
index 00000000..6012dedc
--- /dev/null
+++ b/config/commands/submit.sh
@@ -0,0 +1,19 @@
+
+# @yaml
+# signature: submit
+# docstring: submits your current code and terminates the session
+submit() {
+ cd $ROOT
+
+ # Check if the patch file exists and is non-empty
+ if [ -s "/root/test.patch" ]; then
+ # Apply the patch in reverse
+ git apply -R < "/root/test.patch"
+ fi
+
+ git add -A
+ git diff --cached > model.patch
+ echo "<<SUBMISSION||"
+ cat model.patch
+ echo "||SUBMISSION>>"
+}
diff --git a/config/commands/submit_ctf.sh b/config/commands/submit_ctf.sh
new file mode 100644
index 00000000..e7ea3b37
--- /dev/null
+++ b/config/commands/submit_ctf.sh
@@ -0,0 +1,23 @@
+# @yaml
+# signature: submit
+# docstring: submits your current flag and terminates the session
+# arguments:
+# flag:
+# type: string
+# description: the flag found
+# required: true
+submit() {
+ if [ -z "$1" ]; then
+ echo "Usage: submit <flag>"
+ return
+ fi
+
+ if [[ "$1" =~ ^HTB\{.*\}$ ]]; then
+ echo "<<SUBMISSION||"
+ echo "$1"
+ echo "||SUBMISSION>>"
+ else
+ echo "Error: Flag '$1' does not match the format HTB{...}."
+ return
+ fi
+}
\ No newline at end of file
diff --git a/config/default.yaml b/config/default.yaml
index 7954b2a1..476dfb72 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -104,6 +104,7 @@ command_files:
- config/commands/search.sh
- config/commands/edit_linting.sh
- config/commands/_split_string.py
+- config/commands/submit.sh
parse_command: ParseCommandDetailed
history_processor: Last5Observations
demonstrations:
diff --git a/config/default_ctf.yaml b/config/default_ctf.yaml
new file mode 100644
index 00000000..edbb7fcc
--- /dev/null
+++ b/config/default_ctf.yaml
@@ -0,0 +1,101 @@
+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 HTB{{...}}.
+
+ 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.
+
+ The special interface consists of a file editor that shows you {WINDOW} lines of a file at a time.
+ In addition to typical bash commands, you can also use the following commands to help you navigate and edit files.
+
+ COMMANDS:
+ {command_docs}
+
+ Please note that THE EDIT COMMAND REQUIRES PROPER INDENTATION.
+ If you'd like to add the line ' print(x)' you must fully write that out, with all those spaces before the code! Indentation is important and code that is not indented correctly will fail and require fixing before it can be run.
+
+ RESPONSE FORMAT:
+ Your shell prompt is formatted as follows:
+ (Open file: <path>) <cwd> $
+
+ You need to format your output using two fields; discussion and command.
+ Your output should always include _one_ discussion and _one_ command field EXACTLY as in the following example:
+ DISCUSSION
+ First I'll start by using ls to see what files are in the current directory. Then maybe we can look at some relevant files to see what they look like.
+ ```
+ ls -a
+ ```
+
+ You should only include a *SINGLE* command in the command section and then wait for a response from the shell before continuing with more discussion and commands. Everything you include in the DISCUSSION section will be saved for future reference.
+ If you'd like to issue two commands at once, PLEASE DO NOT DO THAT! Please instead first submit just the first command, and then after receiving a response you'll be able to issue the second command.
+ You're free to use any other bash commands you want (e.g. find, grep, cat, ls, cd) in addition to the special commands listed above.
+ However, the environment does NOT support interactive session commands (e.g. python, vim), so please do not invoke them.
+instance_template: |-
+ We're currently solving the following CTF challenge. Here's the CTF description:
+ CTF Challenge:
+ {issue}
+
+ INSTRUCTIONS:
+ Now, you're going to solve this challenge on your own. Your terminal session has started and you're in the challenge's root directory. You can use any bash commands or the special interface to help you.
+ Solve the challenge, executing any commands you need and writing any code that may be helpful. You can also install new software in the container using `sudo apt-get install`, or Python packages with `pip install`.
+ Remember, YOU CAN ONLY ENTER ONE COMMAND AT A TIME. You should always wait for feedback after every command.
+ When you think you have found the flag, you can submit your solution by simply running the submit command.
+ Note however that you cannot use any interactive session commands (e.g. python, vim) in this environment, but you can write scripts and run them. E.g. you can write a python script and then run it with `python <script_name>.py`.
+
+ NOTE ABOUT THE EDIT COMMAND: Indentation really matters! When editing a file, make sure to insert appropriate indentation before each line!
+
+ IMPORTANT TIPS:
+ 1. When you edit an existing file, try to minimize the changes you make to the file.
+
+ 2. Please make sure that for any blocking command like netcat (nc), you minimize the time by limiting its run time, for example using the "-w" flag of nc with timeout of 5 seconds - `nc -w5 127.0.0.1 80`.
+
+ 3. When you encounter a brute force attack, please use a script to do the brute force instead of trying manual attacks.
+
+ 4. Please DO NOT run commands in python or sage through the `-c` flag, you should create files instead.
+
+ 5. Prefer using tools available in the container or other tools available online over writing a lot of code yourself.
+
+ 6. Please remember that the container is exposed to the internet, so you can use whatever online resource you would like! Use it wisely!
+
+ 7. YOU CAN SOLVE THE CHALLENGES BY YOURSELF COMPLETELY - I TRUST IN YOU!
+
+ (Open file: {open_file})
+ (Current directory: {working_dir})
+ bash-$
+next_step_template: |-
+ {observation}
+ (Open file: {open_file})
+ (Current directory: {working_dir})
+ bash-$
+next_step_no_output_template: |-
+ Your command ran successfully and did not produce any output.
+ (Open file: {open_file})
+ (Current directory: {working_dir})
+ bash-$
+state_command:
+ name: state
+ code: |
+ state() {
+ local working_dir="$PWD";
+ if [ -z $CURRENT_FILE ]; then
+ echo '{"open_file": "n/a", "working_dir": "'$working_dir'"}';
+ else
+ echo '{"open_file": "'$(realpath $CURRENT_FILE)'", "working_dir": "'$working_dir'"}';
+ fi
+ };
+parse_function: ThoughtActionParser
+env_variables:
+ WINDOW: 100
+ OVERLAP: 2
+ CURRENT_LINE: 0
+ CURRENT_FILE: ''
+ SEARCH_RESULTS: ()
+ SEARCH_FILES: ()
+ SEARCH_INDEX: 0
+command_files:
+- config/commands/defaults.sh
+- config/commands/search.sh
+- config/commands/edit_linting.sh
+- config/commands/_split_string.py
+- config/commands/submit_ctf.sh
+parse_command: ParseCommandDetailed
+history_processor: Last5Observations
diff --git a/config/default_from_url.yaml b/config/default_from_url.yaml
index 90e47360..6a30a0cf 100644
--- a/config/default_from_url.yaml
+++ b/config/default_from_url.yaml
@@ -106,6 +106,7 @@ command_files:
- config/commands/search.sh
- config/commands/edit_linting.sh
- config/commands/_split_string.py
+- config/commands/submit.sh
parse_command: ParseCommandDetailed
history_processor: Last5Observations
demonstrations:
diff --git a/config/default_xml.yaml b/config/default_xml.yaml
index 2c5d5b48..8f0a28a5 100644
--- a/config/default_xml.yaml
+++ b/config/default_xml.yaml
@@ -98,6 +98,7 @@ command_files:
- config/commands/search.sh
- config/commands/edit_linting.sh
- config/commands/_split_string.py
+- config/commands/submit.sh
parse_command: ParseCommandDetailed
history_processor: Last5Observations
demonstrations:
diff --git a/config/environment_setup/py310_ctf.yaml b/config/environment_setup/py310_ctf.yaml
new file mode 100644
index 00000000..b1bc786e
--- /dev/null
+++ b/config/environment_setup/py310_ctf.yaml
@@ -0,0 +1,4 @@
+python: '3.10'
+# Use uv pip for speedup, but fallback to classic pip if we fail
+# Upgrade pip to avoid https://stackoverflow.com/a/73779542/
+install: 'uv pip install pwntools ipython gmpy2 pycryptodome mpmath sympy ruff'