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]

Delete CTF tools that are currently incompatible

Kilian Lieretb0536b29dd61
diff --git a/tools/ctf_ghidra_funcs/bin/decompile b/tools/ctf_ghidra_funcs/bin/decompile
deleted file mode 100644
index 06eb0b11..00000000
--- a/tools/ctf_ghidra_funcs/bin/decompile
+++ /dev/null
@@ -1,104 +0,0 @@
-#!/root/miniconda3/bin/python
-
-import argparse
-import subprocess
-import re
-import json
-import tempfile
-from typing import Annotated
-from pathlib import Path
-
-GHIDRA_BINARY = "analyzeHeadless"
-
-class Decompile:
- def __init__(self):
- pass
-
- def __call__(self,
- path: Annotated[str,"path to the binary to decompile"],
- function: Annotated[str,"the function to decompile"] = 'main'):
- """Decompile a function from a binary using Ghidra."""
- if path is None or not Path(path).is_file():
- return f"Error: Binary {path} does not exist! Please try again with a real binary file."
- if function is None:
- function = "main"
- return self.decompile(path, function)
-
- def find_function(self, dis, function):
- """Returns the name of the function found in the dict"""
- if function in dis["functions"]:
- return function
- # Looking for main entry point, so try other names also
- if function == "main":
- if "main" in dis:
- return dis["main"]
- if "_start" in dis["functions"]:
- return "_start"
- if "invoke_main" in dis["functions"]:
- return "invoke_main"
- if "entry" in dis["functions"]:
- return "entry"
- # Check if requesting radare2 unnamed function with address
- if re.match(r"fcn\.[0-9a-f]+$", function):
- addr = function[4:]
- if addr in dis["addresses"]:
- return dis["addresses"][addr]
- # Nothing found
- return None
-
- def decompile(self, binary: str, function: str) -> str:
- # Look for the decompilation output in "decomp"
- basename = Path(binary).name
- decomp_output_path = Path(f"/ghidra_out/{basename}.decomp.json")
- if not decomp_output_path.exists():
- if not self.run_ghidra(basename, decomp_output_path):
- return f"Error: Decompilation for {binary} not available"
- decomp_output = decomp_output_path.read_text()
- try:
- self.ghidra_out = json.loads(decomp_output)
- except json.JSONDecodeError as e:
- msg = (
- f"Error: Failed to parse Ghidra output {decomp_output!r} for {binary}. "
- "Please report this bug."
- )
- raise ValueError(msg) from e
-
- if found := self.find_function(self.ghidra_out, function):
- ret = self.ghidra_out["functions"][found]
- if found == function:
- # Exact name found
- return f"Decompilation Found!\n{ret}"
- else:
- return f"Function {function} not found! Instead, here is the decompilation of equivalent function {found}:\n{ret}"
- else:
- funclist = ", ".join(self.ghidra_out['functions'].keys())
- return f"Error: Function {function} not found in {binary}.\nThese are the available functions found: {funclist}"
-
- def run_ghidra(self, binary: str, output: Path) -> bool:
- """Run ghidra if possible.
-
- Returns:
- bool: True if successful, False otherwise
- """
- real_binary = Path(binary)
- if not real_binary or not real_binary.exists():
- return False
- output.parent.mkdir(parents=True, exist_ok=True)
- with tempfile.TemporaryDirectory() as tmpdir:
- tmpdir = Path(tmpdir)
- subprocess.run(
- [GHIDRA_BINARY, tmpdir, "DummyProj", "-scriptpath", '/ghidra_scripts',
- "-import", real_binary, "-postscript", "DecompileToJson.java", output],
- check=False, capture_output=True,
- )
- return output.exists()
-
-
-if __name__ == "__main__":
- parser = argparse.ArgumentParser(
- description="Print the contents of a Python file, skipping lengthy function and method definitions."
- )
- parser.add_argument("file_path", type=str, help="The path to the binary to be decompiled")
- parser.add_argument("--function_name", type=str, help="The function name to be decompiled", required=False, default="main")
- args = parser.parse_args()
- print(Decompile()(args.file_path, args.function_name))
diff --git a/tools/ctf_ghidra_funcs/bin/disassemble b/tools/ctf_ghidra_funcs/bin/disassemble
deleted file mode 100644
index 409145e0..00000000
--- a/tools/ctf_ghidra_funcs/bin/disassemble
+++ /dev/null
@@ -1,99 +0,0 @@
-#!/root/miniconda3/bin/python
-
-import argparse
-import subprocess
-import re
-import json
-import tempfile
-from typing import Annotated
-from pathlib import Path
-
-GHIDRA_BINARY = "analyzeHeadless"
-
-class Disassemble:
- def __init__(self):
- pass
-
- def __call__(self,
- path: Annotated[str,"path to the binary to disassemble"],
- function: Annotated[str,"the function to disassemble"] = 'main'):
- """Disassemble a function from a binary using Ghidra."""
- if path is None or not Path(path).is_file():
- return f"Error: Binary {path} does not exist! Please try again with a real binary file."
- if function is None:
- function = "main"
- return self.disassemble(path, function)
-
- def find_function(self, dis, function):
- """Returns the name of the function found in the dict"""
- if function in dis["functions"]:
- return function
- # Looking for main entry point, so try other names also
- if function == "main":
- if "main" in dis:
- return dis["main"]
- if "_start" in dis["functions"]:
- return "_start"
- if "invoke_main" in dis["functions"]:
- return "invoke_main"
- if "entry" in dis["functions"]:
- return "entry"
- # Check if requesting radare2 unnamed function with address
- if re.match(r"fcn\.[0-9a-f]+$", function):
- addr = function[4:]
- if addr in dis["addresses"]:
- return dis["addresses"][addr]
- # Nothing found
- return None
-
- def disassemble(self, binary, function):
- # Look for the disassembly output in "disas"
- basename = Path(binary).name
- disas_output_path = Path(f"/ghidra_out/{basename}.disas.json")
- if not disas_output_path.exists():
- if not self.run_ghidra(basename, disas_output_path):
- return f"Error: Disassembly for {binary} not available"
- disas_output = disas_output_path.read_text()
- try:
- self.ghidra_out = json.loads(disas_output)
- except json.JSONDecodeError as e:
- msg = (
- f"Error: Failed to parse Ghidra output {disas_output!r} for {binary}. "
- "Please report this bug."
- )
- raise ValueError(msg) from e
-
- if found := self.find_function(self.ghidra_out, function):
- ret = self.ghidra_out["functions"][found]
- if found == function:
- # Exact name found
- return f"Disassembly Found!\n{ret}"
- else:
- return f"Function {function} not found! Instead, here is the disassembly of equivalent function {found}:\n{ret}"
- else:
- funclist = ", ".join(self.ghidra_out["functions"].keys())
- return f"Error: Function {function} not found in {binary}.\nThese are the available functions found: {funclist}"
-
- def run_ghidra(self, binary, output):
- real_binary = Path(binary)
- if not real_binary or not real_binary.exists():
- return False
- output.parent.mkdir(parents=True, exist_ok=True)
- with tempfile.TemporaryDirectory() as tmpdir:
- tmpdir = Path(tmpdir)
- subprocess.run(
- [GHIDRA_BINARY, tmpdir, "DummyProj", "-scriptpath", '/ghidra_scripts',
- "-import", real_binary, "-postscript", "DisassembleToJson.java", output],
- check=False, capture_output=True,
- )
- return output.exists()
-
-
-if __name__ == "__main__":
- parser = argparse.ArgumentParser(
- description="Print the contents of a Python file, skipping lengthy function and method definitions."
- )
- parser.add_argument("file_path", type=str, help="The path to the binary to be disassembled")
- parser.add_argument("--function_name", type=str, help="The function name to be disassembled", required=False, default="main")
- args = parser.parse_args()
- print(Disassemble()(args.file_path, args.function_name))
diff --git a/tools/ctf_ghidra_funcs/config.yaml b/tools/ctf_ghidra_funcs/config.yaml
deleted file mode 100644
index 6a63e4fc..00000000
--- a/tools/ctf_ghidra_funcs/config.yaml
+++ /dev/null
@@ -1,25 +0,0 @@
-tools:
- disassemble:
- signature: "disassemble <binary_path> [--function_name <function_name>]"
- docstring: "Disassembles a binary and prints the disassembly of a given function name"
- arguments:
- - name: binary_path
- type: string
- description: The path to the binary to be disassembled
- required: true
- - name: function_name
- type: string
- description: The function name to be disassembled, or main by default
- required: false
- decompile:
- signature: "decompile <binary_path> [--function_name <function_name>]"
- docstring: "Decompile a binary and prints the decompilation of a given function name"
- arguments:
- - name: binary_path
- type: string
- description: The path to the binary to be decompiled
- required: true
- - name: function_name
- type: string
- description: The function name to be decompiled, or main by default
- required: false
diff --git a/tools/debug/bin/debug_add_breakpoint b/tools/debug/bin/debug_add_breakpoint
deleted file mode 100644
index 48fb2df1..00000000
--- a/tools/debug/bin/debug_add_breakpoint
+++ /dev/null
@@ -1,13 +0,0 @@
-source /root/tools/debug/lib/utils.sh
-
-main() {
- if [ -z "$1" ]
- then
- echo "Usage: debug_add_breakpoint <breakpoint>"
- return
- fi
- _debug_command "SESSION=gdb"
- _debug_command 'break '$1
-}
-
-main "$@"
diff --git a/tools/debug/bin/debug_and_continue b/tools/debug/bin/debug_and_continue
deleted file mode 100644
index 01782cb3..00000000
--- a/tools/debug/bin/debug_and_continue
+++ /dev/null
@@ -1,8 +0,0 @@
-source /root/tools/debug/lib/utils.sh
-
-main() {
- _debug_command "SESSION=gdb"
- _debug_command 'continue'
-}
-
-main "$@"
diff --git a/tools/debug/bin/debug_exec b/tools/debug/bin/debug_exec
deleted file mode 100644
index 699dedbb..00000000
--- a/tools/debug/bin/debug_exec
+++ /dev/null
@@ -1,13 +0,0 @@
-source /root/tools/debug/lib/utils.sh
-
-main() {
- if [ -z "$1" ]
- then
- echo "Usage: debug_exec <command>"
- return
- fi
- _debug_command "SESSION=gdb"
- _debug_command "$1"
-}
-
-main "$@"
\ No newline at end of file
diff --git a/tools/debug/bin/debug_start b/tools/debug/bin/debug_start
deleted file mode 100644
index d0c875b8..00000000
--- a/tools/debug/bin/debug_start
+++ /dev/null
@@ -1,27 +0,0 @@
-source /root/tools/debug/lib/utils.sh
-
-main() {
- if [ -z "$1" ]
- then
- echo "Usage: debug_start <binary>"
- return
- fi
- if [ ! -x "$1" ]
- then
- echo "Error: File $1 does not exist, or is not executable"
- return
- fi
- fp=$(realpath $1)
- _debug_command "SESSION=gdb"
- _debug_command "START"
- _debug_command "set confirm off"
- _debug_command "file $fp"
- if [ ! -z "$2" ]
- then
- _debug_command "set args ${@:2:$#}" # Set arguments from 2 until the end
- fi
- _debug_command "starti"
- _write_env INTERACTIVE_SESSION="gdb $@"
-}
-
-main "$@"
diff --git a/tools/debug/bin/debug_step b/tools/debug/bin/debug_step
deleted file mode 100644
index 81a944f0..00000000
--- a/tools/debug/bin/debug_step
+++ /dev/null
@@ -1,18 +0,0 @@
-source /root/tools/debug/lib/utils.sh
-
-main() {
- if [ -z "$1" ]
- then
- _debug_command "SESSION=gdb"
- _debug_command 'stepi'
- elif [[ (("$1" -eq "$1") && ("$1" -gt "0")) ]] # Check if integer and positive
- then
- _debug_command "SESSION=gdb"
- _debug_command 'stepi '$1
- else
- echo "Please provide a positive integer for number of instructions."
- echo "Usage: debug_step [number]"
- fi
-}
-
-main "$@"
diff --git a/tools/debug/bin/debug_stop b/tools/debug/bin/debug_stop
deleted file mode 100644
index 93f2e677..00000000
--- a/tools/debug/bin/debug_stop
+++ /dev/null
@@ -1,10 +0,0 @@
-source /root/tools/debug/lib/utils.sh
-
-main() {
- _debug_command "SESSION=gdb"
- _debug_command "quit"
- _debug_command "STOP"
- unset INTERACTIVE_SESSION
-}
-
-main "$@"
\ No newline at end of file
diff --git a/tools/debug/config.yaml b/tools/debug/config.yaml
deleted file mode 100644
index 334e3691..00000000
--- a/tools/debug/config.yaml
+++ /dev/null
@@ -1,45 +0,0 @@
-tools:
- debug_start:
- signature: debug_start <binary> [<args>]
- docstring: Starts a debug session with the given binary.
- arguments:
- - name: binary
- type: string
- description: the path to the binary to debug
- required: true
- - name: args
- type: string
- description: optional command-line arguments for the binary
- required: false
- debug_add_breakpoint:
- signature: debug_add_breakpoint <breakpoint>
- docstring: Adds a breakpoint in the debug session
- arguments:
- - name: breakpoint
- type: string
- description: The breakpoint location, which may be a function name, address, or filename and line number.
- required: true
- debug_continue:
- signature: debug_continue
- docstring: Continues the program execution in the debug session.
- arguments: []
- debug_step:
- signature: debug_step [number]
- docstring: Steps number of instructions in the debug session.
- arguments:
- - name: number
- type: integer
- description: number of instructions to step (default is 1)
- required: false
- debug_exec:
- signature: debug_exec <command>
- docstring: Executes arbitrary gdb command in debug session.
- arguments:
- - name: command
- type: string
- description: command to execute (wrap in single quotes to avoid shell escaping and substitution)
- required: true
- debug_stop:
- signature: debug_stop
- docstring: Stops the current debug session.
- arguments: []
\ No newline at end of file
diff --git a/tools/debug/lib/utils.sh b/tools/debug/lib/utils.sh
deleted file mode 100644
index 60a6dabb..00000000
--- a/tools/debug/lib/utils.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-_debug_command() {
- echo "<<INTERACTIVE||$@||INTERACTIVE>>"
-}
\ No newline at end of file
diff --git a/tools/server_connection/bin/_connect b/tools/server_connection/bin/_connect
deleted file mode 100644
index e1acb087..00000000
--- a/tools/server_connection/bin/_connect
+++ /dev/null
@@ -1,66 +0,0 @@
-#!/usr/bin/env python3
-
-
-"""This helper command is used for interacting with a remote server.
-It opens a shell-like connection to a server, which allows sending and retrieving content from the server.
-
-Usage:
- python _connect.py
-"""
-
-import ast
-import cmd
-from pwn import *
-import setproctitle
-
-setproctitle.setproctitle("connect")
-
-BUFFER_SIZE = 1024
-SERVER_TIMEOUT = 10
-
-
-class NetcatShell(cmd.Cmd):
- intro = "Welcome to the netcat shell. Type help or ? to list commands.\n"
- server = None
-
- prompt = "(nc) "
- def do_connect(self, arg=""):
- """
- Connecting to the server
- """
- args = arg.split()
- self.server = remote(args[0], args[1])
- data_received_from_server = self._recv()
- if data_received_from_server:
- print("\n-------SERVER RESPONSE-------\n\n", data_received_from_server, "\n\n-------END OF RESPONSE-------\n")
-
- def _recv(self):
- buffer = recv_data = self.server.recv(BUFFER_SIZE, timeout=SERVER_TIMEOUT)
- while len(recv_data) == BUFFER_SIZE:
- recv_data = self.server.recv(BUFFER_SIZE, timeout=SERVER_TIMEOUT)
- buffer += recv_data
-
- return buffer.decode()
-
- def do_sendline(self, arg):
- """
- Send a single line to the server, line can contain any unicode or byte representation (for example \\x80).
- """
- self.server.sendline(ast.literal_eval(f"b\"{arg}\""))
- print(self._recv())
-
- def do_close(self, arg):
- """
- Close connection to the server
- """
- self.server.close()
-
- def do_quit(self, arg):
- """
- Quit the application
- """
- print("Quitting...")
- return True
-
-if __name__ == "__main__":
- NetcatShell().cmdloop()
\ No newline at end of file
diff --git a/tools/server_connection/bin/connect_exec b/tools/server_connection/bin/connect_exec
deleted file mode 100644
index a092150f..00000000
--- a/tools/server_connection/bin/connect_exec
+++ /dev/null
@@ -1,13 +0,0 @@
-source /root/tools/server_connection/lib/utils.sh
-
-main() {
- if [ -z "$1" ]
- then
- echo "Usage: connect_exec <command>"
- return
- fi
- _connect_command "SESSION=connect"
- _connect_command "$@"
-}
-
-main "$@"
\ No newline at end of file
diff --git a/tools/server_connection/bin/connect_sendline b/tools/server_connection/bin/connect_sendline
deleted file mode 100644
index 7f7938fb..00000000
--- a/tools/server_connection/bin/connect_sendline
+++ /dev/null
@@ -1,8 +0,0 @@
-source /root/tools/server_connection/lib/utils.sh
-
-main() {
- _connect_command "SESSION=connect"
- _connect_command 'sendline '$@
-}
-
-main "$@"
\ No newline at end of file
diff --git a/tools/server_connection/bin/connect_start b/tools/server_connection/bin/connect_start
deleted file mode 100644
index ec4d7d06..00000000
--- a/tools/server_connection/bin/connect_start
+++ /dev/null
@@ -1,15 +0,0 @@
-source /root/tools/server_connection/lib/utils.sh
-
-main() {
- if [ -z "$1" ] || [ -z "$2" ]
- then
- echo "Usage: connect_start <server_address> <port>"
- return
- fi
- _connect_command "SESSION=connect"
- _connect_command "START"
- _connect_command "connect $1 $2"
- _write_env INTERACTIVE_SESSION="connect $@"
-}
-
-main "$@"
\ No newline at end of file
diff --git a/tools/server_connection/bin/connect_stop b/tools/server_connection/bin/connect_stop
deleted file mode 100644
index 9780ec96..00000000
--- a/tools/server_connection/bin/connect_stop
+++ /dev/null
@@ -1,10 +0,0 @@
-source /root/tools/server_connection/lib/utils.sh
-
-main() {
- _connect_command "SESSION=connect"
- _connect_command "quit"
- _connect_command "STOP"
- unset INTERACTIVE_SESSION
-}
-
-main "$@"
\ No newline at end of file
diff --git a/tools/server_connection/config.yaml b/tools/server_connection/config.yaml
deleted file mode 100644
index be888a3c..00000000
--- a/tools/server_connection/config.yaml
+++ /dev/null
@@ -1,35 +0,0 @@
-tools:
- connect_start:
- signature: "connect_start <server_address> <port>"
- docstring: "Starts a new interactive connection to the server address and port."
- arguments:
- - name: server_address
- type: string
- description: "the server address to initiate connection to"
- required: true
- - name: port
- type: integer
- description: "desired port for connection"
- required: true
- connect_exec:
- signature: "connect_exec <command>"
- docstring: "Executes arbitrary connect command in connect session."
- arguments:
- - name: command
- type: string
- description: "command to execute (wrap in single quotes to avoid shell escaping and substitution)"
- required: true
- connect_stop:
- signature: "connect_stop"
- docstring: "Stops the current connect session."
- arguments: []
- connect_sendline:
- signature: "connect_sendline [<line>]"
- docstring: >
- Sends a line with unicode/hexadecimal values to the connection.
- Sending hexadecimal bytes should be done using \\x<hh> where hh stands for the specific byte you want to send.
- arguments:
- - name: line
- type: string
- description: "The line to send to the connection"
- required: false
diff --git a/tools/server_connection/install.sh b/tools/server_connection/install.sh
deleted file mode 100644
index d1aeb6e6..00000000
--- a/tools/server_connection/install.sh
+++ /dev/null
@@ -1 +0,0 @@
-pip install pwntools setproctitle
\ No newline at end of file
diff --git a/tools/server_connection/lib/utils.sh b/tools/server_connection/lib/utils.sh
deleted file mode 100644
index c91db336..00000000
--- a/tools/server_connection/lib/utils.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-_connect_command() {
- echo "<<INTERACTIVE||$@||INTERACTIVE>>"
-}
\ No newline at end of file
diff --git a/tools/submit_ctf/bin/submit b/tools/submit_ctf/bin/submit
deleted file mode 100644
index 14fb8491..00000000
--- a/tools/submit_ctf/bin/submit
+++ /dev/null
@@ -1,12 +0,0 @@
-main() {
- if [ -z "$1" ]; then
- echo "Usage: submit <flag>"
- return
- fi
-
- echo -n "<<SUBMISSION||"
- echo -n "$@"
- echo "||SUBMISSION>>"
-}
-
-main "$@"
diff --git a/tools/submit_ctf/config.yaml b/tools/submit_ctf/config.yaml
deleted file mode 100644
index d6f49d70..00000000
--- a/tools/submit_ctf/config.yaml
+++ /dev/null
@@ -1,10 +0,0 @@
-tools:
- submit:
- signature: "submit '<flag>'"
- docstring: >
- submits your current flag and terminates the session, you should be aware to properly escape the flag as this is a bash command and to put your flag under single quotes.
- arguments:
- - name: flag
- type: string
- description: the flag found
- required: true