diff --git a/cai/tools/command_and_control/command_and_control.py b/cai/tools/command_and_control/command_and_control.py new file mode 100644 index 00000000..e69de29b diff --git a/cai/tools/data_exfiltration/data_exfiltration.py b/cai/tools/data_exfiltration/data_exfiltration.py new file mode 100644 index 00000000..e69de29b diff --git a/cai/tools/exploitation/ftp_upload.py b/cai/tools/exploitation/ftp_upload.py new file mode 100644 index 00000000..e69de29b diff --git a/cai/tools/exploitation/metasploit.py b/cai/tools/exploitation/metasploit.py new file mode 100644 index 00000000..d8914950 --- /dev/null +++ b/cai/tools/exploitation/metasploit.py @@ -0,0 +1,2 @@ +#MsfModuleSelectionTool +#MsfModuleExecTool diff --git a/cai/tools/exploitation/script_execution.py b/cai/tools/exploitation/script_execution.py new file mode 100644 index 00000000..e69de29b diff --git a/cai/tools/lateral_movement/reverse_shell.py b/cai/tools/lateral_movement/reverse_shell.py new file mode 100644 index 00000000..24c3474e --- /dev/null +++ b/cai/tools/lateral_movement/reverse_shell.py @@ -0,0 +1,6 @@ +# ReverseShellTool +# ReverseShellSession +# ReverseShellManager +# ShellCommandExecutor +# SessionManager +# UploadReverseShellTool diff --git a/cai/tools/lateral_movement/ssh.py b/cai/tools/lateral_movement/ssh.py new file mode 100644 index 00000000..eb5abdd5 --- /dev/null +++ b/cai/tools/lateral_movement/ssh.py @@ -0,0 +1,2 @@ +#SSHTestCredentialTool +#SSHRunCommandTool diff --git a/cai/tools/others/others.py b/cai/tools/others/others.py new file mode 100644 index 00000000..e69de29b diff --git a/cai/tools/privilege_scalation/file.py b/cai/tools/privilege_scalation/file.py new file mode 100644 index 00000000..e69de29b diff --git a/cai/tools/reconnaissance/crypto_tools.py b/cai/tools/reconnaissance/crypto_tools.py new file mode 100644 index 00000000..ccb120e2 --- /dev/null +++ b/cai/tools/reconnaissance/crypto_tools.py @@ -0,0 +1,45 @@ +""" + Here are crypto tools +""" +import base64 +# # URLDecodeTool +# # HexDumpTool +# # Base64DecodeTool +# # ROT13DecodeTool +# # BinaryAnalysisTool + + +# def strings_command(file_path: str, ctf=None) -> str: +# """ +# Extract printable strings from a binary file. + +# Args: +# args: Additional arguments to pass to the strings command +# file_path: Path to the binary file to extract strings from + +# Returns: +# str: The output of running the strings command +# """ +# command = f'strings {file_path} ' +# return run_command(ctf, command) + + +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) + + 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)}" diff --git a/cai/tools/reconnaissance/curl.py b/cai/tools/reconnaissance/curl.py new file mode 100644 index 00000000..0191627f --- /dev/null +++ b/cai/tools/reconnaissance/curl.py @@ -0,0 +1 @@ +#curl \ No newline at end of file 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/filesystem.py b/cai/tools/reconnaissance/filesystem.py index bb45931a..98dc8e70 100644 --- a/cai/tools/reconnaissance/filesystem.py +++ b/cai/tools/reconnaissance/filesystem.py @@ -33,3 +33,23 @@ def cat_file(file_path: str, args: str = "", ctf=None) -> str: """ command = f'cat {args} {file_path} ' return run_command(command, ctf=ctf) + +# FileSearchTool +# ListDirTool +# TextSearchTool +# FileAnalysisTool +# StringExtractionTool +# ReadFileTool +# FilePermissionsTool +# FileCompressionTool + + +def pwd_command(ctf=None) -> str: + """ + Retrieve the current working directory. + + Returns: + str: The absolute path of the current working directory + """ + command = 'pwd' + return run_command(command, ctf=ctf) diff --git a/cai/tools/reconnaissance/generic_linux_command.py b/cai/tools/reconnaissance/generic_linux_command.py new file mode 100644 index 00000000..e69de29b diff --git a/cai/tools/reconnaissance/gobuster_scan.py b/cai/tools/reconnaissance/gobuster_scan.py new file mode 100644 index 00000000..e69de29b diff --git a/cai/tools/reconnaissance/hashcat_cracker.py b/cai/tools/reconnaissance/hashcat_cracker.py new file mode 100644 index 00000000..e69de29b diff --git a/cai/tools/reconnaissance/netcat.py b/cai/tools/reconnaissance/netcat.py new file mode 100644 index 00000000..639e8520 --- /dev/null +++ b/cai/tools/reconnaissance/netcat.py @@ -0,0 +1,24 @@ +""" + Here are the tools for netcat command +""" +from cai.tools.common import run_command # pylint: disable=import-error + + +def netcat(host: str, port: int, data: str = '', + args: str = '', ctf=None) -> str: + """ + A simple netcat tool to connect to a specified host and port. + Args: + args: Additional arguments to pass to the netcat command + host: The target host to connect to + port: The target port to connect to + data: Data to send to the host (optional) + + Returns: + str: The output of running the netcat command + """ + if data: + command = f'echo "{data}" | nc -w 3 {host} {port} {args}' + else: + command = f'nc -w 3 {host} {port} {args}' + return run_command(command, ctf=ctf) diff --git a/cai/tools/reconnaissance/netstat.py b/cai/tools/reconnaissance/netstat.py new file mode 100644 index 00000000..86fd2910 --- /dev/null +++ b/cai/tools/reconnaissance/netstat.py @@ -0,0 +1 @@ +#NetworkConnectionstool in exploitFlow \ No newline at end of file diff --git a/cai/tools/reconnaissance/nmap.py b/cai/tools/reconnaissance/nmap.py new file mode 100644 index 00000000..94c4514d --- /dev/null +++ b/cai/tools/reconnaissance/nmap.py @@ -0,0 +1,18 @@ +from cai.tools.common import run_command +""" +Here are the nmap tools. +""" +def nmap(args: str, target: str, ctf=None) -> str: + """ + A simple nmap tool to scan a specified target. + + Args: + args: Additional arguments to pass to the nmap command + target: The target host or IP address to scan + + Returns: + str: The output of running the nmap command + """ + command = f'nmap {args} {target}' + return run_command(command, ctf=ctf) + diff --git a/cai/tools/reconnaissance/system_info.py b/cai/tools/reconnaissance/system_info.py new file mode 100644 index 00000000..be418115 --- /dev/null +++ b/cai/tools/reconnaissance/system_info.py @@ -0,0 +1,3 @@ +# ProcessListTool +# EnvironmentVariablesTool +# SystemInformationTool diff --git a/cai/tools/reconnaissance/wget.py b/cai/tools/reconnaissance/wget.py new file mode 100644 index 00000000..11529ece --- /dev/null +++ b/cai/tools/reconnaissance/wget.py @@ -0,0 +1 @@ +#FileDownloadTool in exploitFlow \ No newline at end of file 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()