Address bug which led to an error when allucinating

Fix implies ensuring that even with allucationations, args
adopts a value

Signed-off-by: Víctor Mayoral Vilches <v.mayoralv@gmail.com>
This commit is contained in:
Víctor Mayoral Vilches 2025-01-10 08:01:06 +00:00
parent 4bce6cfc06
commit f506383887
1 changed files with 18 additions and 13 deletions

View File

@ -4,9 +4,11 @@ from wasabi import color
client = CAI()
def run_ctf(ctf, command, stdout=True):
try:
# Ensure the command is executed in a shell that supports command chaining
# Ensure the command is executed in a shell that supports command
# chaining
output = ctf.get_shell(command)
# exploit_logger.log_ok()
@ -18,7 +20,8 @@ def run_ctf(ctf, command, stdout=True):
# exploit_logger.log_error(str(e))
return f"Error executing CTF command: {str(e)}"
def list_dir(path: str, args: str) -> str:
def list_dir(path: str, args: str = "") -> str:
"""
List the contents of a directory.
@ -33,6 +36,7 @@ def list_dir(path: str, args: str) -> str:
command = f'ls {path} {args}'
return run_ctf(ctf, command)
def cat_file(args: str, file_path: str) -> str:
"""
Display the contents of a file.
@ -57,6 +61,7 @@ def cat_file(args: str, file_path: str) -> str:
# else:
# return "Flag Not Found: " + flag
listing_agent = Agent(
model="qwen2.5:14b",
name="A file listing tool",
@ -79,11 +84,11 @@ listing_agent = Agent(
# PentestPerf setup for "picoctf_static_flag"
ctf = ptt.ctf(
"picoctf_static_flag",
subnet="192.168.9.0/24",
container_name="ancient",
ip_address="192.168.9.52",
)
"picoctf_static_flag",
subnet="192.168.9.0/24",
container_name="ancient",
ip_address="192.168.9.52",
)
ctf.start_ctf()
flag = ctf.get_flag()
@ -95,14 +100,14 @@ listing_agent.functions.append(cat_file)
challenges = list(ctf.get_challenges().keys())
challenge = challenges[0]
messages = [{"role": "user", "content": "Instructions: " + ctf.get_instructions()
+ "\nChallenge: " + ctf.get_challenges()[challenge]
+ "\nTechniques: " + ctf.get_techniques()
+ "\nExtract and return only the flag"}]
messages = [{"role": "user", "content": "Instructions: " + ctf.get_instructions()
+ "\nChallenge: " + ctf.get_challenges()[challenge]
+ "\nTechniques: " + ctf.get_techniques()
+ "\nExtract and return only the flag"}]
response = client.run(agent=listing_agent, messages=messages, debug=True)
print(response.messages[-1]["content"])
#if ctf.check_flag(response.messages[-1]["content"], ctf.get_challenges()[challenge]):
# print(color(f"Flag found: {response.messages[-1]['content']}", fg="green"))
# if ctf.check_flag(response.messages[-1]["content"], ctf.get_challenges()[challenge]):
# print(color(f"Flag found: {response.messages[-1]['content']}", fg="green"))
ctf.stop_ctf()