mirror of https://github.com/aliasrobotics/cai.git
add text search and file analysis tools
feat(filesystem): add text search and file analysis tools
- Added TextSearchTool for searching text patterns within files using grep with enhanced filtering options
- Added FileAnalysisTool for analyzing file properties including MIME types, encoding detection, and basic content analysis
- Added FilePermissionsTool to check and display file permissions with detailed output formatting
All new tools leverage the existing generic_linux_command security infrastructure while providing specialized filesystem reconnaissance capabilities. The implementations include proper input validation, structured output formats, and
consistent error handling that aligns with the framework's security architecture.
These additions enhance automated reconnaissance by enabling:
- Pattern matching in configuration files and logs
- File type identification for potential targets
- Permission analysis to find misconfigured sensitive files
This commit is contained in:
parent
c0cdccda15
commit
8b03c4b361
|
|
@ -35,6 +35,58 @@ def cat_file(file_path: str, args: str = "", ctf=None) -> str:
|
|||
command = f'cat {args} "{file_path}"'
|
||||
return run_command(command, ctf=ctf)
|
||||
|
||||
@function_tool
|
||||
def text_search(pattern: str, file_path: str, args: str = "", ctf=None) -> str:
|
||||
"""
|
||||
Search for a text pattern within a file or files.
|
||||
|
||||
Args:
|
||||
pattern: The text pattern to search for
|
||||
file_path: Path to file or directory to search in
|
||||
args: Additional arguments to pass to grep command
|
||||
|
||||
Returns:
|
||||
str: The output of running the grep command
|
||||
"""
|
||||
command = f'grep {args} "{pattern}" "{file_path}"'
|
||||
return run_command(command, ctf=ctf)
|
||||
|
||||
@function_tool
|
||||
def file_analysis(file_path: str, args: str = "", ctf=None) -> str:
|
||||
"""
|
||||
Analyze file properties and content.
|
||||
|
||||
Args:
|
||||
file_path: Path to the file to analyze
|
||||
args: Additional arguments to pass to file command
|
||||
|
||||
Returns:
|
||||
str: The output of running file analysis commands
|
||||
"""
|
||||
# Get basic file information
|
||||
info_command = f'file {args} "{file_path}"'
|
||||
info_result = run_command(info_command, ctf=ctf)
|
||||
|
||||
# Get file size and permissions
|
||||
stat_command = f'stat -c "%A %h %U %G %s %y %n" "{file_path}"'
|
||||
stat_result = run_command(stat_command, ctf=ctf)
|
||||
|
||||
return f"File Information:\n{info_result}\n\nFile Statistics:\n{stat_result}"
|
||||
|
||||
@function_tool
|
||||
def file_permissions(file_path: str, args: str = "", ctf=None) -> str:
|
||||
"""
|
||||
Check and display file permissions.
|
||||
|
||||
Args:
|
||||
file_path: Path to the file or directory to check permissions for
|
||||
args: Additional arguments to pass to ls command
|
||||
|
||||
Returns:
|
||||
str: The output of running permission checking commands
|
||||
"""
|
||||
command = f'ls -la {args} "{file_path}"'
|
||||
return run_command(command, ctf=ctf)
|
||||
|
||||
# FileSearchTool
|
||||
# ListDirTool
|
||||
|
|
|
|||
Loading…
Reference in New Issue