Container Orchestration Job
Adversaries may abuse task scheduling functionality provided by container orchestration tools such as Kubernetes to schedule deployment of containers configured to execute malicious code. Container orchestration jobs run these automated tasks at a specific date and time, similar to cron jobs on a Linux system. Deployments of this type can also be configured to maintain a quantity of containers over time, automating the process of maintaining persistence within a cluster. In Kubernetes, a CronJob may be used to schedule a Job that runs one or more containers to perform specific tasks. An adversary may utilize a CronJob to schedule deployment of a Job that executes malicious code in various nodes within a cluster.
// Detect suspicious Kubernetes CronJob/Job creation via Kubernetes audit logs ingested into Sentinel
// Requires AzureDiagnostics or AKS audit log ingestion via Diagnostic Settings
let SuspiciousImages = dynamic([
"alpine", "busybox", "ubuntu", "debian", "kali",
"python", "perl", "ruby", "php",
"ncat", "netcat", "nmap", "masscan",
"curl", "wget"
]);
let SuspiciousCommands = dynamic([
"curl", "wget", "bash -i", "/dev/tcp", "nc ", "ncat",
"python -c", "perl -e", "ruby -e",
"chmod +x", "base64 -d", "eval",
"/bin/sh -c", "/bin/bash -c",
"mkfifo", "socat"
]);
AzureDiagnostics
| where TimeGenerated > ago(24h)
| where Category == "kube-audit" or Category == "kube-audit-admin"
| extend AuditLog = parse_json(log_s)
| extend
Verb = tostring(AuditLog.verb),
Resource = tostring(AuditLog.objectRef.resource),
Namespace = tostring(AuditLog.objectRef.namespace),
Name = tostring(AuditLog.objectRef.name),
User = tostring(AuditLog.user.username),
UserAgent = tostring(AuditLog.userAgent),
SourceIP = tostring(AuditLog.sourceIPs[0]),
RequestBody = tostring(AuditLog.requestObject)
| where Resource in~ ("cronjobs", "jobs")
| where Verb in~ ("create", "update", "patch")
| extend IsSuspiciousImage = RequestBody has_any (SuspiciousImages)
| extend IsSuspiciousCommand = RequestBody has_any (SuspiciousCommands)
| extend IsHostPathMount = RequestBody has "hostPath"
| extend IsPrivileged = RequestBody has "privileged"
| extend IsHostNetwork = RequestBody has "hostNetwork"
| extend IsSensitiveMount = RequestBody has_any ("/etc", "/var/run/docker.sock", "/proc", "/sys")
| extend IsServiceAccountToken = RequestBody has "automountServiceAccountToken"
| extend SuspicionScore = toint(IsSuspiciousImage) + toint(IsSuspiciousCommand) + toint(IsHostPathMount) + toint(IsPrivileged) + toint(IsHostNetwork) + toint(IsSensitiveMount)
| where SuspicionScore > 0
| project
TimeGenerated, Resource, Verb, Namespace, Name,
User, UserAgent, SourceIP,
IsSuspiciousImage, IsSuspiciousCommand, IsHostPathMount,
IsPrivileged, IsHostNetwork, IsSensitiveMount,
IsServiceAccountToken, SuspicionScore,
RequestBody
| sort by SuspicionScore desc, TimeGenerated desc Data Sources
Required Tables
False Positives
- Legitimate CI/CD pipeline jobs that use base images like alpine or ubuntu for build tasks
- Cluster maintenance CronJobs that use curl or wget to check service health endpoints
- Log rotation or data cleanup jobs that use shell commands like /bin/sh -c
- Security scanning jobs (Falco, Trivy, kube-bench) that mount host paths for vulnerability assessment
- Operators and controllers that create jobs programmatically as part of normal cluster operations
References (11)
- https://attack.mitre.org/techniques/T1053/007/
- https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/
- https://kubernetes.io/docs/concepts/workloads/controllers/job/
- https://www.microsoft.com/security/blog/2020/04/02/attack-matrix-kubernetes/
- https://falco.org/docs/rules/
- https://github.com/falcosecurity/falco/blob/master/rules/falco_rules.yaml
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1053.007/T1053.007.md
- https://kubernetes.io/docs/tasks/debug/debug-cluster/audit/
- https://docs.microsoft.com/en-us/azure/aks/monitor-aks
- https://www.cncf.io/blog/2021/12/06/cloud-native-security-whitepaper/
- https://github.com/SigmaHQ/sigma/tree/master/rules/cloud/kubernetes
Unlock Pro Content
Get the full detection package for T1053.007 including response playbook, investigation guide, and atomic red team tests.