mirror of https://github.com/aliasrobotics/cai.git
fix: prevent command injection in reconnaissance tools
Use shlex.quote() to sanitize user inputs before passing to shell commands. This prevents command injection vulnerabilities in: - crypto_tools.py: strings_command, decode64 - curl.py: curl - filesystem.py: list_dir, cat_file, find_file - nmap.py: nmap - wget.py: wget Fixes: Command injection vulnerability allowing arbitrary command execution
This commit is contained in:
parent
1c79507140
commit
df932e58fe
|
|
@ -2,6 +2,7 @@
|
|||
Here are crypto tools
|
||||
"""
|
||||
|
||||
import shlex
|
||||
from cai.tools.common import run_command
|
||||
from cai.sdk.agents import function_tool
|
||||
|
||||
|
|
@ -25,7 +26,7 @@ def strings_command(file_path: str, ctf=None) -> str:
|
|||
# Returns:
|
||||
str: The output of running the strings command
|
||||
"""
|
||||
command = f"strings {file_path}"
|
||||
command = f"strings {shlex.quote(file_path)}"
|
||||
return run_command(command, ctf=ctf)
|
||||
|
||||
|
||||
|
|
@ -41,7 +42,7 @@ def decode64(input_data: str, ctf=None) -> str:
|
|||
Returns:
|
||||
str: The decoded string
|
||||
"""
|
||||
command = f"base64 --decode {input_data}"
|
||||
command = f"base64 --decode {shlex.quote(input_data)}"
|
||||
return run_command(command, ctf=ctf)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
Here are the curl tools.
|
||||
"""
|
||||
|
||||
import shlex
|
||||
from cai.tools.common import run_command # pylint: disable=import-error
|
||||
from cai.sdk.agents import function_tool
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ def curl(args: str = "", target: str = "", ctf=None) -> str:
|
|||
Returns:
|
||||
str: The output of running the curl command
|
||||
"""
|
||||
command = f"curl {args} {target}"
|
||||
command = f"curl {args} {shlex.quote(target)}"
|
||||
return run_command(command, ctf=ctf)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
Here are the CLI tools for executing commands.
|
||||
"""
|
||||
|
||||
import shlex
|
||||
from cai.tools.common import run_command # pylint: disable=E0401
|
||||
from cai.sdk.agents import function_tool
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ def list_dir(path: str, args: str = "", ctf=None) -> str:
|
|||
Returns:
|
||||
str: The output of running the ls command
|
||||
"""
|
||||
command = f"ls {path} {args}"
|
||||
command = f"ls {shlex.quote(path)} {args}"
|
||||
return run_command(command, ctf=ctf)
|
||||
|
||||
|
||||
|
|
@ -34,7 +35,7 @@ def cat_file(file_path: str, args: str = "", ctf=None) -> str:
|
|||
Returns:
|
||||
str: The output of running the cat command
|
||||
"""
|
||||
command = f"cat {args} {file_path} "
|
||||
command = f"cat {args} {shlex.quote(file_path)}"
|
||||
return run_command(command, ctf=ctf)
|
||||
|
||||
|
||||
|
|
@ -65,7 +66,7 @@ def find_file(file_path: str, args: str = "", ctf=None) -> str:
|
|||
"""
|
||||
Find a file in the filesystem.
|
||||
"""
|
||||
command = f"find {file_path} {args}"
|
||||
command = f"find {shlex.quote(file_path)} {args}"
|
||||
return run_command(command, ctf=ctf)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
Here are the nmap tools.
|
||||
"""
|
||||
|
||||
import shlex
|
||||
from cai.tools.common import run_command # pylint: disable=E0401
|
||||
from cai.sdk.agents import function_tool
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ def nmap(args: str, target: str, ctf=None) -> str:
|
|||
Returns:
|
||||
str: The output of running the nmap command
|
||||
"""
|
||||
command = f"nmap {args} {target}"
|
||||
command = f"nmap {args} {shlex.quote(target)}"
|
||||
return run_command(command, ctf=ctf, stream=True)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
Wget tool
|
||||
"""
|
||||
|
||||
import shlex
|
||||
from cai.tools.common import run_command # pylint: disable=import-error
|
||||
from cai.sdk.agents import function_tool
|
||||
|
||||
|
|
@ -19,7 +20,7 @@ def wget(url: str, args: str = "", ctf=None) -> str:
|
|||
Returns:
|
||||
str: The output of running the wget command
|
||||
"""
|
||||
command = f"wget {args} {url}"
|
||||
command = f"wget {args} {shlex.quote(url)}"
|
||||
return run_command(command, ctf=ctf)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue