diff --git a/cai/tools/exploitation/ ScriptExecution.py b/cai/tools/exploitation/ftp_upload.py similarity index 100% rename from cai/tools/exploitation/ ScriptExecution.py rename to cai/tools/exploitation/ftp_upload.py diff --git a/cai/tools/exploitation/FTPUpload.py b/cai/tools/exploitation/script_execution.py similarity index 100% rename from cai/tools/exploitation/FTPUpload.py rename to cai/tools/exploitation/script_execution.py diff --git a/cai/tools/lateral_movement/Revershell.py b/cai/tools/lateral_movement/reverse_shell.py similarity index 84% rename from cai/tools/lateral_movement/Revershell.py rename to cai/tools/lateral_movement/reverse_shell.py index 969a72c6..24c3474e 100644 --- a/cai/tools/lateral_movement/Revershell.py +++ b/cai/tools/lateral_movement/reverse_shell.py @@ -1,4 +1,4 @@ -# ReverseShellTool +# ReverseShellTool # ReverseShellSession # ReverseShellManager # ShellCommandExecutor diff --git a/cai/tools/reconnaissance/DirbScan.py b/cai/tools/reconnaissance/DirbScan.py deleted file mode 100644 index aa6db2a6..00000000 --- a/cai/tools/reconnaissance/DirbScan.py +++ /dev/null @@ -1 +0,0 @@ -#DirbScanTool \ No newline at end of file diff --git a/cai/tools/reconnaissance/crypto_tools.py b/cai/tools/reconnaissance/crypto_tools.py index 0a366584..ccb120e2 100644 --- a/cai/tools/reconnaissance/crypto_tools.py +++ b/cai/tools/reconnaissance/crypto_tools.py @@ -1,8 +1,7 @@ -# """ -# Here are crypto tools -# """ -# # import base64 -# from cai.tools.common import run_command +""" + Here are crypto tools +""" +import base64 # # URLDecodeTool # # HexDumpTool # # Base64DecodeTool @@ -25,22 +24,22 @@ # return run_command(ctf, command) -# def decode64(input_data: str) -> str: -# """ -# Decode a base64-encoded string. +def decode64(input_data: str) -> str: + """ + Decode a base64-encoded string. -# Args: -# input_data: The base64-encoded string to decode -# args: Additional arguments (not used in this function) + Args: + input_data: The base64-encoded string to decode + args: Additional arguments (not used in this function) -# Returns: -# str: The decoded string -# """ + Returns: + str: The decoded string + """ -# try: -# decoded_bytes = base64.b64decode(input_data) -# decoded_str = decoded_bytes.decode('utf-8') -# return decoded_str -# except UnicodeDecodeError as e: -# print(f"Error decoding bytes to string: {e}") -# return f"Error decoding bytes to string: {str(e)}" + try: + decoded_bytes = base64.b64decode(input_data) + decoded_str = decoded_bytes.decode('utf-8') + return decoded_str + except UnicodeDecodeError as e: + print(f"Error decoding bytes to string: {e}") + return f"Error decoding bytes to string: {str(e)}" diff --git a/cai/tools/reconnaissance/dirb_scan.py b/cai/tools/reconnaissance/dirb_scan.py new file mode 100644 index 00000000..5292a4cd --- /dev/null +++ b/cai/tools/reconnaissance/dirb_scan.py @@ -0,0 +1 @@ +# DirbScanTool diff --git a/cai/tools/reconnaissance/GobusterScan.py b/cai/tools/reconnaissance/gobuster_scan.py similarity index 100% rename from cai/tools/reconnaissance/GobusterScan.py rename to cai/tools/reconnaissance/gobuster_scan.py diff --git a/cai/tools/reconnaissance/HashcatCracker.py b/cai/tools/reconnaissance/hashcat_cracker.py similarity index 100% rename from cai/tools/reconnaissance/HashcatCracker.py rename to cai/tools/reconnaissance/hashcat_cracker.py diff --git a/examples/cybersecurity/2_picoctf_reversing_python b/examples/cybersecurity/2_picoctf_reversing_python new file mode 100644 index 00000000..d6ea4f59 --- /dev/null +++ b/examples/cybersecurity/2_picoctf_reversing_python @@ -0,0 +1,54 @@ +""" +This is a short example of how we can solve ctf scenarios programmatically. With CAI framework +""" +# 1. Instance CAI, pentestperf and tools +from cai import CAI, Agent +from cai.tools.reconnaissance.crypto_tools import * +from cai.tools.reconnaissance.nmap import * +from cai.tools.reconnaissance.netcat import * +import pentestperf as ptt +from wasabi import color +import os + +# 2. Init the CTF environment +ctf = ptt.ctf( + "picoctf_reversing_python", + subnet="192.168.9.0/24", + container_name="ancient", + ip_address="192.168.9.52" +) +ctf.start_ctf() +challenges = list(ctf.get_challenges().keys()) +challenge = challenges[0] + +# 3. Instance the cybersecurity AI Framework client +client = CAI(ctf=ctf) + +# 4. Instance the agent/agents to solve the CTF +ctf_agent = Agent( + model="qwen2.5:14b", + name="CTF agent", + instructions="You are an CTF solver agent", + functions=[netcat, nmap, decode64], # This code can execute by LLM + # parallel_tool_calls=True, Enable multi function calling +) + + +messages = [{ + "role": "user", + "content": "Instructions: " + ctf.get_instructions() + + "\nChallenge: " + ctf.get_challenges()[challenge] + + "\nTechniques: " + ctf.get_techniques() + + "\nExtract and return only the flag" + "\nYOU MUST RETURN THE FLAG IN PLAIN TEXT" +}] + +# 5. Run the CAI +response = client.run( + agent=ctf_agent, + messages=messages, + debug=True, + brief=True) +print(response.messages[-1]["content"]) + +ctf.stop_ctf()