# rhinosecuritylabs/pacu architecture

> Architecture diagram of the GitHub repository rhinosecuritylabs/pacu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rhinosecuritylabs/pacu
- Repository: https://github.com/rhinosecuritylabs/pacu

## Overview

#### Purpose and Runtime
Pacu is a Python 3.7+ interactive and command-line AWS offensive-security framework. It executes modular enumeration, privilege-escalation, persistence/backdoor, data-access, and detection-evasion operations against AWS accounts using supplied credentials. It is packaged for local pip/pipx use and Docker deployment via `pyproject.toml`, `Dockerfile`, and `docker_stack.yml`.

#### Entry Points and Command Dispatch
The installed `pacu` command is rooted in `cli.py`; package execution is supported through `pacu/__main__.py`. Framework startup and interactive command handling reside in `pacu/main.py`. Both interactive use and noninteractive CLI actions select a session, inspect/list modules, set regions/credentials, retrieve locally stored data, or execute a named module.

#### Session, State, and Persistence Boundary
Sessions isolate AWS key pairs, selected regions, command/audit history, error output, and discovered data. The persistence layer is initialized by `pacu/setup_database.py`, modeled through `pacu/core/models.py`, and configured in `pacu/settings.py`. The README specifies a local SQLite database accessed through SQLAlchemy; modules should reuse this session data rather than repeatedly calling AWS APIs.

#### Core Framework Services
The reusable framework contract and module-support layer is concentrated in `pacu/core/base.py`, `pacu/core/mixins.py`, and `pacu/core/lib.py`. These components provide common module behavior, shared state/data access, and operational utilities. IAM permission discovery has a dedicated engine under `pacu/core/enumerate_iam/main.py`, including generated brute-force request definitions in `pacu/core/enumerate_iam/generate_bruteforce_tests.py`.

#### Module Plugin Surface
Each capability is a directory under `pacu/modules`, conventionally exposing its executable implementation in `main.py`; `pacu/modules/template.py` is the starting point for new modules. Module names encode target service and action, enabling command dispatch by name. Important families include IAM escalation/persistence (`pacu/modules/iam__privesc_scan/main.py`, `pacu/modules/iam__backdoor_assume_role/main.py`), AWS account/service discovery (`pacu/modules/aws__enum_account/main.py`, `pacu/modules/detection__enum_services/main.py`), and resource enumeration (`pacu/modules/ec2__enum/main.py`, `pacu/modules/s3__download_bucket/main.py`).

#### AWS Execution and Attack Flows
A typical flow is: choose session → load credentials and regions → run module → module calls relevant AWS service APIs → normalize/store results locally → later modules query stored discoveries or create/modify AWS resources. Some modules perform direct state-changing actions, such as EC2 security-group backdoors (`pacu/modules/ec2__backdoor_ec2_sec_groups/main.py`), IAM credential/user changes (`pacu/modules/iam__backdoor_users_keys/main.py`), and SSM-based EC2 command execution (`pacu/modules/systemsmanager__rce_ec2/main.py`). AWS is the principal external service boundary; permissions and regional availability govern success.

#### Specialized Payloads and Data Collection
Several modules bundle deployable or downloadable artifacts rather than only API calls: CloudFormation resource injection includes a Chalice Lambda application at `pacu/modules/cfn__resource_injection/cfn__resource_injection_lambda/app.py`; IAM escalation includes Lambda/zip payload assets in `pacu/modules/iam__privesc_scan/`; secret detection uses regex definitions at `pacu/core/secretfinder/regexs.json`. Download/exploration modules can retrieve sensitive cloud data, including CloudTrail history, CloudWatch logs, EBS snapshots, and RDS snapshots.

#### Operational Boundaries
Pacu is a local operator tool, not a web application or hosted control plane. Docker can mount host `~/.aws` credentials into the container. Its active module set is under `pacu/modules`; legacy capabilities are segregated in `pacu/modules_archive`, avoiding accidental treatment as current plugins.

Main entry points: [`pacu/modules`](https://github.com/rhinosecuritylabs/pacu/tree/master/pacu/modules) (Module plugin surface), [`pacu/core/models.py`](https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/core/models.py) (Session data models), [`pacu/main.py`](https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/main.py) (Command runtime), [`pacu/core/base.py`](https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/core/base.py) (Module framework)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Local Runtime"]
  node_operator(("Operator<br/>user"))
  node_cli["CLI entry point<br/>python command<br/>[cli.py]"]
  node_package_entry["Package entry<br/>python entry point<br/>[__main__.py]"]
  node_command_runtime["Command runtime<br/>interactive dispatcher<br/>[main.py]"]
end

subgraph group_core["Core Services"]
  node_settings["Settings<br/>configuration<br/>[settings.py]"]
  node_database_setup["Database setup<br/>persistence bootstrap<br/>[setup_database.py]"]
  node_models[("Session data models<br/>SQLAlchemy models<br/>[models.py]")]
  node_framework_contract["Module framework<br/>base and mixins<br/>[base.py]"]
  node_core_utilities["Operational utilities<br/>support library<br/>[lib.py]"]
  node_iam_engine["IAM permission engine<br/>enumeration engine<br/>[main.py]"]
end

subgraph group_plugins["Active Modules"]
  node_module_surface["Module plugin surface<br/>plugin directories"]
  node_module_template["Module template<br/>plugin scaffold<br/>[template.py]"]
  node_enum_modules["Discovery modules<br/>enumeration plugins<br/>[main.py]"]
  node_iam_modules["IAM attack modules<br/>escalation and persistence<br/>[main.py]"]
  node_resource_modules["Resource action modules<br/>collection and execution<br/>[main.py]"]
  node_payloads["Bundled payloads<br/>deployable artifacts<br/>[app.py]"]
  node_legacy_modules["Archived modules<br/>legacy capability set"]
end

subgraph group_external["AWS Boundary"]
  node_aws{{"AWS APIs and resources<br/>external cloud boundary"}}
end

node_operator -->|"runs"| node_cli
node_operator -->|"executes"| node_package_entry
node_cli -->|"starts"| node_command_runtime
node_package_entry -->|"starts"| node_command_runtime
node_command_runtime -->|"loads session state"| node_models
node_settings -->|"configures"| node_database_setup
node_database_setup -->|"initializes"| node_models
node_command_runtime -->|"dispatches by name"| node_module_surface
node_module_surface -->|"implements"| node_framework_contract
node_framework_contract -->|"reads and stores discoveries"| node_models
node_framework_contract -->|"uses"| node_core_utilities
node_iam_modules -->|"uses"| node_iam_engine
node_module_surface -->|"includes"| node_enum_modules
node_module_surface -->|"includes"| node_iam_modules
node_module_surface -->|"includes"| node_resource_modules
node_module_template -.->|"scaffolds"| node_module_surface
node_payloads -->|"deploys to"| node_aws
node_enum_modules -->|"enumerates"| node_aws
node_iam_modules -->|"tests and modifies IAM"| node_aws
node_resource_modules -->|"collects or changes resources"| node_aws
node_enum_modules -->|"stores results"| node_models
node_resource_modules -->|"reuses discoveries"| node_models

click node_cli "https://github.com/rhinosecuritylabs/pacu/blob/master/cli.py"
click node_package_entry "https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/__main__.py"
click node_command_runtime "https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/main.py"
click node_settings "https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/settings.py"
click node_database_setup "https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/setup_database.py"
click node_models "https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/core/models.py"
click node_framework_contract "https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/core/base.py"
click node_core_utilities "https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/core/lib.py"
click node_iam_engine "https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/core/enumerate_iam/main.py"
click node_module_surface "https://github.com/rhinosecuritylabs/pacu/tree/master/pacu/modules"
click node_module_template "https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/modules/template.py"
click node_enum_modules "https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/modules/aws__enum_account/main.py"
click node_iam_modules "https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/modules/iam__privesc_scan/main.py"
click node_resource_modules "https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/modules/s3__download_bucket/main.py"
click node_payloads "https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/modules/cfn__resource_injection/cfn__resource_injection_lambda/app.py"
click node_legacy_modules "https://github.com/rhinosecuritylabs/pacu/tree/master/pacu/modules_archive"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_operator,node_cli,node_package_entry,node_command_runtime toneBlue
class node_settings,node_database_setup,node_models,node_framework_contract,node_core_utilities,node_iam_engine toneAmber
class node_module_surface,node_module_template,node_enum_modules,node_iam_modules,node_resource_modules,node_payloads,node_legacy_modules toneMint
class node_aws toneRose
```

## Components

### Local Runtime

Operator-facing CLI and session runtime.

- **Operator**: user
- [CLI entry point](https://github.com/rhinosecuritylabs/pacu/blob/master/cli.py): python command · `cli.py`
- [Package entry](https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/__main__.py): python entry point · `pacu/__main__.py`
- [Command runtime](https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/main.py): interactive dispatcher · Selects sessions and invokes named modules. · `pacu/main.py`

### Core Services

Shared persistence and module support.

- [Settings](https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/settings.py): configuration · `pacu/settings.py`
- [Database setup](https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/setup_database.py): persistence bootstrap · `pacu/setup_database.py`
- [Session data models](https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/core/models.py): SQLAlchemy models · Stores credentials, regions, history, errors, and discoveries. · `pacu/core/models.py`
- [Module framework](https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/core/base.py): base and mixins · Provides shared module behavior and state access. · `pacu/core/base.py`
- [Operational utilities](https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/core/lib.py): support library · `pacu/core/lib.py`
- [IAM permission engine](https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/core/enumerate_iam/main.py): enumeration engine · Uses generated brute-force request definitions. · `pacu/core/enumerate_iam/main.py`

### Active Modules

Current executable capability plugins.

- [Module plugin surface](https://github.com/rhinosecuritylabs/pacu/tree/master/pacu/modules): plugin directories · Named modules are discovered and dispatched as active capabilities. · `pacu/modules`
- [Module template](https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/modules/template.py): plugin scaffold · `pacu/modules/template.py`
- [Discovery modules](https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/modules/aws__enum_account/main.py): enumeration plugins · Account, service, EC2, and stored-data discovery. · `pacu/modules/aws__enum_account/main.py`
- [IAM attack modules](https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/modules/iam__privesc_scan/main.py): escalation and persistence · Includes privilege scanning and role/key backdoors. · `pacu/modules/iam__privesc_scan/main.py`
- [Resource action modules](https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/modules/s3__download_bucket/main.py): collection and execution · Downloads cloud data or modifies and executes against resources. · `pacu/modules/s3__download_bucket/main.py`
- [Bundled payloads](https://github.com/rhinosecuritylabs/pacu/blob/master/pacu/modules/cfn__resource_injection/cfn__resource_injection_lambda/app.py): deployable artifacts · Includes a Chalice Lambda for CloudFormation injection. · `pacu/modules/cfn__resource_injection/cfn__resource_injection_lambda/app.py`
- [Archived modules](https://github.com/rhinosecuritylabs/pacu/tree/master/pacu/modules_archive): legacy capability set · Segregated from active plugin discovery. · `pacu/modules_archive`

### AWS Boundary

Cloud APIs and deployable resources.

- **AWS APIs and resources**: external cloud boundary · Permissions and regional availability determine operation success.

## Connections

- Operator → CLI entry point: runs
- Operator → Package entry: executes
- CLI entry point → Command runtime: starts
- Package entry → Command runtime: starts
- Command runtime → Session data models: loads session state
- Settings → Database setup: configures
- Database setup → Session data models: initializes
- Command runtime → Module plugin surface: dispatches by name
- Module plugin surface → Module framework: implements
- Module framework → Session data models: reads and stores discoveries
- Module framework → Operational utilities: uses
- IAM attack modules → IAM permission engine: uses
- Module plugin surface → Discovery modules: includes
- Module plugin surface → IAM attack modules: includes
- Module plugin surface → Resource action modules: includes
- Module template → Module plugin surface: scaffolds
- Bundled payloads → AWS APIs and resources: deploys to
- Discovery modules → AWS APIs and resources: enumerates
- IAM attack modules → AWS APIs and resources: tests and modifies IAM
- Resource action modules → AWS APIs and resources: collects or changes resources
- Discovery modules → Session data models: stores results
- Resource action modules → Session data models: reuses discoveries
