How cdk-team/cdk works
Project Type and Purpose
• The project is an open-source container penetration toolkit written in Go. Its purpose is to provide container exploitation, evaluation, and various network tools to help security testing in containerized environments (especially for Kubernetes).
• The README clearly outlines three main modules – Evaluate, Exploit, and Tool – each with its own commands and capabilities. It even demonstrates how users can run “cdk eva” for evaluation and “cdk run” for launching exploits.
Analyzing the File Structure
• Top-Level Directories:
• cmd: Contains command-line entry points. Notably, cmd/cdk/cdk.go is likely the main executable that initializes the application.
• conf: Holds configuration files and functions. It appears to contain various configuration logic (e.g., build, evaluate, exploit, scanner) used to manage settings for different modules.
• pkg: Contains the bulk of the code and is organized into several sub-packages:
◦ cli: Handles command-line banner presentation and argument parsing.
◦ evaluate: Implements information-gathering and vulnerability evaluation functionalities.
◦ exploit: Contains various subdirectories further subdivided by exploit types (e.g., privilege escalation, remote control, discovery, credential access, etc.).
◦ tool: Provides implementations of network tools (e.g., docker handling, netcat, netstat, kubectl wrappers, probe, etc.).
◦ util: Utility functions and helper libraries shared among the modules.
◦ task, plugin, errors: Implement auxiliary functionality, custom error handling, plugin interface, and task execution.
• test: Contains test scripts and deployments that simulate target scenarios like Kubernetes exploit tests.
• Other Files:
• GitHub workflow configurations, change logs, and script files support Continuous Integration/Continuous Delivery, and a “thanks.md” for contributor acknowledgments.
Architectural Modules and Their Interactions
• Main Components:
• CLI Layer (pkg/cli, cmd/): Serves as the user interface for invoking commands like evaluation, exploitation, and tool usage.
• Evaluate Module (pkg/evaluate): Encapsulates the logic for system assessment inside a container by running various information-gathering scripts.
• Exploit Module (pkg/exploit): Contains segregated sub-packages that provide different techniques to escape containers, exploit vulnerabilities, gain persistence, or allow remote control.
• Tool Module (pkg/tool): Provides support commands and network utilities that mimic traditional Linux/Unix tools (e.g., nc, ps, vi) as well as specialized tools for Kubernetes and Docker API interactions.
• Configuration (conf): Holds configuration definitions and evaluation/exploitation parameters. This module feeds settings into the main modules.
• Common Utilities (pkg/util): Offers helper functions (file I/O, HTTP requests, capability definitions, etc.) used by various other modules.
• Auxiliary Modules (pkg/task, pkg/plugin, pkg/errors): Support scheduling, extensibility of exploits, and error wrapping respectively.
• Relationships and Data Flow:
• The main command-line executable (from cmd/cdk) parses user input with pkg/cli and then directs execution flow to the appropriate module (evaluate, exploit, or tool).
• The Evaluate module calls various sub-functions (system info, mounts, namespaces, etc.) and uses configuration data from the conf package.
• Depending on the evaluation output, the exploit module might be triggered for exploitation via commands like “cdk run <exploit-name>”. The exploit modules are further subdivided by tactic (escaping, discovery, remote control, etc.) and may call common utilities.
• The Tool module inter-operates with helper libraries in pkg/util and performs network or system operations akin to standard Linux commands.
• There is also a testing framework (in test/) that emulates cluster deployments and container conditions to validate exploits.
Key Architectural Patterns and Design Principles
• Modularization: The separation of commands into Evaluate, Exploit, and Tool modules along with devoted configuration and utility sub-packages promotes high cohesion and low coupling.
• Layered architecture: The project can be visualized in layers starting from the CLI, moving into an application layer consisting of evaluation, exploitation logic and then further down into configuration and utilities.
• Extensibility: The existence of a plugin interface, separation of exploit tactics, and task modules imply a design that favors extendibility and ease of adding new exploits or tools.