Shell Execution via Celery Worker Processes
Detection of system shell spawning from Celery worker processes indicates potential command or prompt injection exploitation within Python-based AI agent task frameworks.
This threat brief addresses the detection of unauthorized shell execution originating from Celery worker processes, a common pattern observed in recent AI-agent prompt injection attacks. When Celery - a popular distributed task queue for Python - is utilized to power LLM-based agents, malicious input passed as tasks can trigger the evaluation of raw strings in a shell context. This vulnerability typically arises when developers utilize insecure methods like os.system or shell=True in subprocess calls while processing untrusted LLM outputs. This activity is critical to monitor as it represents a post-exploitation phase where an attacker upgrades a prompt injection vulnerability into arbitrary code execution on the worker infrastructure, enabling data exfiltration or internal network pivoting.
Attack Chain
- Attacker crafts a malicious prompt targeting an LLM-powered agent application.
- The LLM processes the input and returns a string containing shell metacharacters intended for system execution.
- The agent backend receives the untrusted output and passes it as an argument to a Celery task.
- The Celery worker process picks up the task from the message broker (e.g., Redis or RabbitMQ).
- The Python task function executes the untrusted string via
os.system,subprocess.callwithshell=True, or similar insecure APIs. - A child shell process (e.g.,
/bin/bashor/bin/sh) is spawned directly from the Python worker process. - The attacker executes arbitrary commands within the spawned shell to maintain persistence or exfiltrate environment variables.
Impact
Successful exploitation results in full remote code execution on the worker infrastructure. Depending on the environment, this can lead to the exfiltration of sensitive LLM credentials, access to internal APIs, and further movement within the organization's cloud or container environment.
Recommendation
- Deploy the provided Sigma rule to identify unauthorized shell spawning from Python-based Celery worker processes.
- Audit codebases for the use of
shell=Trueoros.systemwithin task functions, ensuring that task arguments are properly sanitized or passed as command lists to avoid shell interpretation. - Implement strict network segmentation and apply the principle of least privilege to the service accounts running the Celery workers.
- Enable system-level process monitoring (e.g., Auditd or eBPF-based agents) to capture the full command-line arguments of spawned shells.
Immediate actions
Deploy Sigma rule to monitor for shell spawning by Celery workers.
Threat Hunt
Search for shell process creation events where the parent process includes 'celery' in the command line.
Data: Process creation logs
Mitigations
Audit Python Celery task functions for 'os.system' or 'shell=True' usage.
General vulnerability patterns
Detection coverage 1
Detect Shell Spawned by Celery Worker Process
mediumDetects a system shell interpreter being spawned directly by a Celery worker process, indicating potential command or prompt injection exploitation.
Detection queries are available on the platform. Get full rules →