From 3712df43ecab9d5c0c80007de17e788ce3d32aea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mayoral=20Vilches?= Date: Sun, 24 Aug 2025 10:03:46 +0000 Subject: [PATCH] Mitigate PoC 4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: VĂ­ctor Mayoral Vilches --- .../tools/reconnaissance/generic_linux_command.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/cai/tools/reconnaissance/generic_linux_command.py b/src/cai/tools/reconnaissance/generic_linux_command.py index e6f1c1ef..56cb47e3 100644 --- a/src/cai/tools/reconnaissance/generic_linux_command.py +++ b/src/cai/tools/reconnaissance/generic_linux_command.py @@ -168,6 +168,20 @@ async def generic_linux_command(command: str = "", guardrails_enabled = os.getenv("CAI_GUARDRAILS", "true").lower() != "false" if guardrails_enabled: + # Check for file write operations that create Python/shell scripts with dangerous content + # Pattern: echo/cat with base64 decode and execute + if re.search(r'(echo|cat|printf).*>.*\.(py|sh|bash|pl|rb|php)', command): + # Check if the command contains base64 strings and execution patterns + if "base64" in command and any(danger in command for danger in ['os.system', 'subprocess', 'exec', 'eval']): + return "Error: Blocked attempt to create script with base64 decode and execute pattern" + # Check for the specific base64 string from POC + if "bmMgMTkyLjE2OC4zLjE0IDQ0NDQgLWUgL2Jpbi9zaAo=" in command: + return "Error: Blocked attempt to create script with known malicious base64 payload" + + # Also check heredoc patterns for creating files + if re.search(r'cat.*<<.*>.*\.(py|sh|bash|pl|rb|php)', command): + if "base64" in command and any(danger in command for danger in ['os.system', 'subprocess', 'exec', 'eval']): + return "Error: Blocked attempt to create script with base64 decode and execute pattern via heredoc" dangerous_patterns = [ r"(?i)rm\s+-rf\s+/", r"(?i):(){ :|:& };:", # Fork bomb