From be9c214c01f7d09de88d1d21e8333b78dbacd4bd Mon Sep 17 00:00:00 2001 From: lidia9 Date: Fri, 10 Jan 2025 10:08:27 +0000 Subject: [PATCH 1/7] add files readme organize tools 1 to 3 --- cai/tools/exploitation/file.py | 0 cai/tools/privilege_scalation/file.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 cai/tools/exploitation/file.py create mode 100644 cai/tools/privilege_scalation/file.py diff --git a/cai/tools/exploitation/file.py b/cai/tools/exploitation/file.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 From 311280c6c658b2f232bb5c88526a3bca21561e7c Mon Sep 17 00:00:00 2001 From: Mery-Sanz Date: Fri, 10 Jan 2025 10:09:56 +0000 Subject: [PATCH 2/7] Adding new structure for tools with @lidia9 --- cai/tools/command_and_control/command_and_control.py | 0 cai/tools/data_exfiltration/data_exfiltratiom.py | 0 cai/tools/lateral_movement/lateral_movement.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 cai/tools/command_and_control/command_and_control.py create mode 100644 cai/tools/data_exfiltration/data_exfiltratiom.py create mode 100644 cai/tools/lateral_movement/lateral_movement.py 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_exfiltratiom.py b/cai/tools/data_exfiltration/data_exfiltratiom.py new file mode 100644 index 00000000..e69de29b diff --git a/cai/tools/lateral_movement/lateral_movement.py b/cai/tools/lateral_movement/lateral_movement.py new file mode 100644 index 00000000..e69de29b From 92215e06a5a5f76b636c4bc2e81465c81035fa58 Mon Sep 17 00:00:00 2001 From: Mery-Sanz Date: Fri, 10 Jan 2025 10:39:31 +0000 Subject: [PATCH 3/7] Add new tools with @lidia9 and @luijait2 --- cai/tools/reconnaissance/filesystem.py | 9 +++++ .../reconnaissance/generic_linux_command.py | 1 + cai/tools/reconnaissance/netcat.py | 35 +++++++++++++++++++ cai/tools/reconnaissance/nmap.py | 18 ++++++++++ 4 files changed, 63 insertions(+) create mode 100644 cai/tools/reconnaissance/generic_linux_command.py create mode 100644 cai/tools/reconnaissance/netcat.py create mode 100644 cai/tools/reconnaissance/nmap.py diff --git a/cai/tools/reconnaissance/filesystem.py b/cai/tools/reconnaissance/filesystem.py index bb45931a..f904f8fe 100644 --- a/cai/tools/reconnaissance/filesystem.py +++ b/cai/tools/reconnaissance/filesystem.py @@ -33,3 +33,12 @@ 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 diff --git a/cai/tools/reconnaissance/generic_linux_command.py b/cai/tools/reconnaissance/generic_linux_command.py new file mode 100644 index 00000000..d70cf272 --- /dev/null +++ b/cai/tools/reconnaissance/generic_linux_command.py @@ -0,0 +1 @@ +#GenericLinuxCommandTool \ No newline at end of file diff --git a/cai/tools/reconnaissance/netcat.py b/cai/tools/reconnaissance/netcat.py new file mode 100644 index 00000000..68d393ea --- /dev/null +++ b/cai/tools/reconnaissance/netcat.py @@ -0,0 +1,35 @@ +from cai.tools.common import run_command +""" +Here are the netcat tools. +""" +def netcat(args: str, host: str, port: int, data: 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) + +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) \ 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) + From a884f6e2b6601026385d4a645ed7232d120d4a59 Mon Sep 17 00:00:00 2001 From: lidia9 Date: Fri, 10 Jan 2025 10:42:30 +0000 Subject: [PATCH 4/7] others --- cai/tools/others/others.py | 74 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 cai/tools/others/others.py diff --git a/cai/tools/others/others.py b/cai/tools/others/others.py new file mode 100644 index 00000000..ccdcee68 --- /dev/null +++ b/cai/tools/others/others.py @@ -0,0 +1,74 @@ + + +def pwd_command(path: str, args: str = "") -> str: + """ + Retrieve the current working directory. + + Returns: + str: The absolute path of the current working directory + """ + global ctf + command = f'pwd' + return run_ctf(ctf, command) + +def strings_command(args: str, file_path: str) -> 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 + """ + global ctf + command = f'strings {file_path} ' + return run_ctf(ctf, command) + + +def nmap_command(ip_address: str, args: str = "") -> str: + """ + Scan a network host for open ports and services. + + Args: + ip_address: The IP address or hostname of the target to scan + args: Additional arguments to pass to the nmap command + + Returns: + str: The output of running the nmap command + """ + global ctf + command = f'nmap {ip_address} {args}' + return run_ctf(ctf, command) + + +def netcat_command(ip_address: str, port: str, args: str = "") -> str: + """ + Connect to a network host via a specific port. + """ + global ctf + command = f'nc {ip_address} {port} {args}' + return run_ctf(ctf, command) + +def decode64(input_data: str, args: 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 + """ + import base64 + try: + decoded_bytes = base64.b64decode(input_data) + decoded_str = decoded_bytes.decode('utf-8') + return decoded_str + except Exception as e: + print(color(f"Error decoding base64 data: {e}", fg="red")) + return f"Error decoding base64 data: {str(e)}" + + From f1559e0bea3d327bdd8bc59ccee7deef4b64ca5d Mon Sep 17 00:00:00 2001 From: Mery-Sanz Date: Fri, 10 Jan 2025 12:06:41 +0000 Subject: [PATCH 5/7] Proposed tool structure - @lidia9 @Mery-Sanz --- .../{data_exfiltratiom.py => data_exfiltration.py} | 0 .../exploitation/{file.py => ScriptExecution.py} | 0 .../FTPUpload.py} | 0 cai/tools/exploitation/metasploit.py | 2 ++ cai/tools/lateral_movement/Revershell.py | 6 ++++++ cai/tools/lateral_movement/ssh.py | 2 ++ cai/tools/reconnaissance/Crypto.py | 5 +++++ cai/tools/reconnaissance/DirbScan.py | 1 + cai/tools/reconnaissance/GobusterScan.py | 0 cai/tools/reconnaissance/HashcatCracker.py | 0 cai/tools/reconnaissance/curl.py | 1 + cai/tools/reconnaissance/filesystem_info.py | 3 +++ cai/tools/reconnaissance/netcat.py | 14 -------------- cai/tools/reconnaissance/netstat.py | 1 + cai/tools/reconnaissance/wget.py | 1 + 15 files changed, 22 insertions(+), 14 deletions(-) rename cai/tools/data_exfiltration/{data_exfiltratiom.py => data_exfiltration.py} (100%) rename cai/tools/exploitation/{file.py => ScriptExecution.py} (100%) rename cai/tools/{lateral_movement/lateral_movement.py => exploitation/FTPUpload.py} (100%) create mode 100644 cai/tools/exploitation/metasploit.py create mode 100644 cai/tools/lateral_movement/Revershell.py create mode 100644 cai/tools/lateral_movement/ssh.py create mode 100644 cai/tools/reconnaissance/Crypto.py create mode 100644 cai/tools/reconnaissance/DirbScan.py create mode 100644 cai/tools/reconnaissance/GobusterScan.py create mode 100644 cai/tools/reconnaissance/HashcatCracker.py create mode 100644 cai/tools/reconnaissance/curl.py create mode 100644 cai/tools/reconnaissance/filesystem_info.py create mode 100644 cai/tools/reconnaissance/netstat.py create mode 100644 cai/tools/reconnaissance/wget.py diff --git a/cai/tools/data_exfiltration/data_exfiltratiom.py b/cai/tools/data_exfiltration/data_exfiltration.py similarity index 100% rename from cai/tools/data_exfiltration/data_exfiltratiom.py rename to cai/tools/data_exfiltration/data_exfiltration.py diff --git a/cai/tools/exploitation/file.py b/cai/tools/exploitation/ ScriptExecution.py similarity index 100% rename from cai/tools/exploitation/file.py rename to cai/tools/exploitation/ ScriptExecution.py diff --git a/cai/tools/lateral_movement/lateral_movement.py b/cai/tools/exploitation/FTPUpload.py similarity index 100% rename from cai/tools/lateral_movement/lateral_movement.py rename to cai/tools/exploitation/FTPUpload.py 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/lateral_movement/Revershell.py b/cai/tools/lateral_movement/Revershell.py new file mode 100644 index 00000000..969a72c6 --- /dev/null +++ b/cai/tools/lateral_movement/Revershell.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/reconnaissance/Crypto.py b/cai/tools/reconnaissance/Crypto.py new file mode 100644 index 00000000..a4b78f98 --- /dev/null +++ b/cai/tools/reconnaissance/Crypto.py @@ -0,0 +1,5 @@ +# URLDecodeTool +# HexDumpTool +# Base64DecodeTool +# ROT13DecodeTool +# BinaryAnalysisTool diff --git a/cai/tools/reconnaissance/DirbScan.py b/cai/tools/reconnaissance/DirbScan.py new file mode 100644 index 00000000..aa6db2a6 --- /dev/null +++ b/cai/tools/reconnaissance/DirbScan.py @@ -0,0 +1 @@ +#DirbScanTool \ No newline at end of file diff --git a/cai/tools/reconnaissance/GobusterScan.py b/cai/tools/reconnaissance/GobusterScan.py new file mode 100644 index 00000000..e69de29b diff --git a/cai/tools/reconnaissance/HashcatCracker.py b/cai/tools/reconnaissance/HashcatCracker.py new file mode 100644 index 00000000..e69de29b 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/filesystem_info.py b/cai/tools/reconnaissance/filesystem_info.py new file mode 100644 index 00000000..e07ebe99 --- /dev/null +++ b/cai/tools/reconnaissance/filesystem_info.py @@ -0,0 +1,3 @@ +#ProcessListTool +#EnvironmentVariablesTool +#SystemInformationTool diff --git a/cai/tools/reconnaissance/netcat.py b/cai/tools/reconnaissance/netcat.py index 68d393ea..7279bda0 100644 --- a/cai/tools/reconnaissance/netcat.py +++ b/cai/tools/reconnaissance/netcat.py @@ -19,17 +19,3 @@ def netcat(args: str, host: str, port: int, data: str = '', ctf=None) -> str: else: command = f'nc -w 3 {host} {port} {args}' return run_command(command, ctf=ctf) - -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) \ No newline at end of file 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/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 From 131fcc491efa5184e43eaf76909726e9b9eecbaa Mon Sep 17 00:00:00 2001 From: Mery-Sanz Date: Fri, 10 Jan 2025 12:46:55 +0000 Subject: [PATCH 6/7] Review structure tools with @lidia9 --- cai/tools/others/others.py | 74 ------------------- cai/tools/reconnaissance/Crypto.py | 5 -- cai/tools/reconnaissance/crypto_tools.py | 46 ++++++++++++ cai/tools/reconnaissance/filesystem.py | 27 +++++-- cai/tools/reconnaissance/filesystem_info.py | 3 - .../reconnaissance/generic_linux_command.py | 1 - cai/tools/reconnaissance/netcat.py | 9 ++- cai/tools/reconnaissance/system_info.py | 3 + 8 files changed, 74 insertions(+), 94 deletions(-) delete mode 100644 cai/tools/reconnaissance/Crypto.py create mode 100644 cai/tools/reconnaissance/crypto_tools.py delete mode 100644 cai/tools/reconnaissance/filesystem_info.py create mode 100644 cai/tools/reconnaissance/system_info.py diff --git a/cai/tools/others/others.py b/cai/tools/others/others.py index ccdcee68..e69de29b 100644 --- a/cai/tools/others/others.py +++ b/cai/tools/others/others.py @@ -1,74 +0,0 @@ - - -def pwd_command(path: str, args: str = "") -> str: - """ - Retrieve the current working directory. - - Returns: - str: The absolute path of the current working directory - """ - global ctf - command = f'pwd' - return run_ctf(ctf, command) - -def strings_command(args: str, file_path: str) -> 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 - """ - global ctf - command = f'strings {file_path} ' - return run_ctf(ctf, command) - - -def nmap_command(ip_address: str, args: str = "") -> str: - """ - Scan a network host for open ports and services. - - Args: - ip_address: The IP address or hostname of the target to scan - args: Additional arguments to pass to the nmap command - - Returns: - str: The output of running the nmap command - """ - global ctf - command = f'nmap {ip_address} {args}' - return run_ctf(ctf, command) - - -def netcat_command(ip_address: str, port: str, args: str = "") -> str: - """ - Connect to a network host via a specific port. - """ - global ctf - command = f'nc {ip_address} {port} {args}' - return run_ctf(ctf, command) - -def decode64(input_data: str, args: 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 - """ - import base64 - try: - decoded_bytes = base64.b64decode(input_data) - decoded_str = decoded_bytes.decode('utf-8') - return decoded_str - except Exception as e: - print(color(f"Error decoding base64 data: {e}", fg="red")) - return f"Error decoding base64 data: {str(e)}" - - diff --git a/cai/tools/reconnaissance/Crypto.py b/cai/tools/reconnaissance/Crypto.py deleted file mode 100644 index a4b78f98..00000000 --- a/cai/tools/reconnaissance/Crypto.py +++ /dev/null @@ -1,5 +0,0 @@ -# URLDecodeTool -# HexDumpTool -# Base64DecodeTool -# ROT13DecodeTool -# BinaryAnalysisTool diff --git a/cai/tools/reconnaissance/crypto_tools.py b/cai/tools/reconnaissance/crypto_tools.py new file mode 100644 index 00000000..0a366584 --- /dev/null +++ b/cai/tools/reconnaissance/crypto_tools.py @@ -0,0 +1,46 @@ +# """ +# Here are crypto tools +# """ +# # import base64 +# from cai.tools.common import run_command +# # 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/filesystem.py b/cai/tools/reconnaissance/filesystem.py index f904f8fe..98dc8e70 100644 --- a/cai/tools/reconnaissance/filesystem.py +++ b/cai/tools/reconnaissance/filesystem.py @@ -34,11 +34,22 @@ 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 +# 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/filesystem_info.py b/cai/tools/reconnaissance/filesystem_info.py deleted file mode 100644 index e07ebe99..00000000 --- a/cai/tools/reconnaissance/filesystem_info.py +++ /dev/null @@ -1,3 +0,0 @@ -#ProcessListTool -#EnvironmentVariablesTool -#SystemInformationTool diff --git a/cai/tools/reconnaissance/generic_linux_command.py b/cai/tools/reconnaissance/generic_linux_command.py index d70cf272..e69de29b 100644 --- a/cai/tools/reconnaissance/generic_linux_command.py +++ b/cai/tools/reconnaissance/generic_linux_command.py @@ -1 +0,0 @@ -#GenericLinuxCommandTool \ No newline at end of file diff --git a/cai/tools/reconnaissance/netcat.py b/cai/tools/reconnaissance/netcat.py index 7279bda0..639e8520 100644 --- a/cai/tools/reconnaissance/netcat.py +++ b/cai/tools/reconnaissance/netcat.py @@ -1,8 +1,11 @@ -from cai.tools.common import run_command """ -Here are the netcat tools. + Here are the tools for netcat command """ -def netcat(args: str, host: str, port: int, data: str = '', ctf=None) -> str: +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: 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 From a22c03e811ab8373306b9b718fa3c2dfaf02a639 Mon Sep 17 00:00:00 2001 From: Mery-Sanz Date: Fri, 10 Jan 2025 13:07:30 +0000 Subject: [PATCH 7/7] snake case format - @lidia9 --- .../{ ScriptExecution.py => ftp_upload.py} | 0 .../{FTPUpload.py => script_execution.py} | 0 .../{Revershell.py => reverse_shell.py} | 2 +- cai/tools/reconnaissance/DirbScan.py | 1 - cai/tools/reconnaissance/crypto_tools.py | 41 +++++++------- cai/tools/reconnaissance/dirb_scan.py | 1 + .../{GobusterScan.py => gobuster_scan.py} | 0 .../{HashcatCracker.py => hashcat_cracker.py} | 0 .../cybersecurity/2_picoctf_reversing_python | 54 +++++++++++++++++++ 9 files changed, 76 insertions(+), 23 deletions(-) rename cai/tools/exploitation/{ ScriptExecution.py => ftp_upload.py} (100%) rename cai/tools/exploitation/{FTPUpload.py => script_execution.py} (100%) rename cai/tools/lateral_movement/{Revershell.py => reverse_shell.py} (84%) delete mode 100644 cai/tools/reconnaissance/DirbScan.py create mode 100644 cai/tools/reconnaissance/dirb_scan.py rename cai/tools/reconnaissance/{GobusterScan.py => gobuster_scan.py} (100%) rename cai/tools/reconnaissance/{HashcatCracker.py => hashcat_cracker.py} (100%) create mode 100644 examples/cybersecurity/2_picoctf_reversing_python 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()