PurpleCloud Documentation

repository·master·Indexed 20 days ago

https://github.com/iknowjason/purplecloud

A Python-based Terraform generator framework for rapidly deploying customized Azure security labs. It enables security professionals to build environments for red teaming and blue teaming, including Azure Sentinel, Active Directory (AD DS), Managed Identity, phishing application simulations, and ADFS federation labs. The framework uses Python scripts to generate modular Terraform configurations for researching Azure Identity and simulating cloud attack scenarios.

Tokens
13.8K
Snippets
49
Records
72
Agent score
70%

What's inside PurpleCloud

  1. Overview of PurpleCloud Terraform Generators

    master

    PurpleCloud is a collection of Python-based Terraform generators designed to rapidly deploy various Azure security labs for offensive and defensive training. Instead of manually editing static Terraform templates, you run Python scripts that generate customized Terraform files based on your specific requirements.

    Key lab types include:

    • Azure Sentinel Labs: Build environments with automated log shipping (Sysmon, Windows Security logs) to a Log Analytics Workspace/Sentinel. Includes support for Entra ID logs via Diagnostic settings.
    • Active Directory (AD) Labs: Build AD DS environments, including support for ADFS (Federation) and Azure AD Join labs.
    • Azure Managed Identity Labs: Create environments specifically for testing Managed Identity attack pathways.
    • Phishing Application Labs: Spin up multi-tenant Azure AD applications for app consent phishing simulations.
    • Azure Storage Labs: Deploy storage accounts with file shares, containers, blobs, and Key Vaults.
  2. Overview of PurpleCloud Identity Labs

    master
    PurpleCloud is a platform for researching Azure Identity by providing Python scripts that function as Terraform code generators. It allows developers and security researchers to build Pentest, Red Team, or Cyber Range environments in the Azure cloud, specifically focusing on Azure AD, Active Directory, and SIEM integrations.
  3. Overview of PurpleCloud Identity Lab

    master

    PurpleCloud is an identity lab platform designed for researching Azure Identity. It enables users to build Pentest, Red Team, or Cyber Range environments within the Azure cloud. The platform supports enterprise deployments involving both Azure AD (Entra ID) and Active Directory (AD DS), integrated with SIEM in Azure.

    Core functionality is provided through Python scripts that act as Terraform code generators. These scripts generate independent resources for various use cases, allowing you to build complex identity environments by combining modular, non-dependent components.

  4. Customize Active Directory Users and OUs via CSV

    master

    Active Directory is built on the Domain Controller (DC) using a CSV file. By default, the DC uses ad_users.csv (located at C:\terraform\ad_users.csv on the DC).

    Customizing Users:

    • Use the --csv <csv_file> flag to provide your own user list. This file is copied to ad_users.csv and uploaded to the storage container for the DC to download.
    • OUs: The oupath field in the CSV determines the Organizational Unit. If the OU= string specifies an OU that doesn't exist, the script creates it.
    • Groups: The groups field in the CSV determines which AD groups the user is added to. Ensure the groups and OU= portion of the oupath match to avoid errors.

    Default Users: The system includes a set of default users defined in a Python dictionary in adfs.py. After the first five default users are created, additional users are randomly generated based on the --ad_users count.

  5. Customize Graph API delegated scope permissions

    master

    By default, the generator automatically creates the following Graph API delegated scope permissions:

    • Contacts.Read
    • Mail.Read
    • Mail.Send
    • Files.Read
    • Files.Read.All
    • Files.ReadWrite.All
    • User.Read

    To add or customize permissions, you must manually add the specific permission id within a resource_access block in the generated Terraform code using the Scope type.

        resource_access {
          id   = "570282fd-fa5c-430d-a7fd-fc8dc98a9dca" #  Mail.Read
          type = "Scope"
        }
  6. Setup an Azure AD Join lab with aadjoin.py

    master

    Use aadjoin.py to generate a lab consisting of Windows 10 Pro systems that automatically join to Azure Active Directory as managed devices. This is useful for security research into managed device registration, SSO tokens (PRT), Intune, or VDI deployments.

    Prerequisites:

    1. Navigate to the generator directory before running the script:
      cd generators/aadjoin
    2. You must provide at least one endpoint (VM) and a UPN suffix.

    Core Workflow:

    1. Run the aadjoin.py script with your desired parameters.
    2. The script generates several Terraform files (e.g., main_aadjoin.tf, users.tf, roles.tf) and user data files (azure_users.csv).
    3. Run terraform apply to provision the resources in Azure.
    4. Note that terraform apply will generate a random password shared by all users; this password is displayed at the end of the process or can be retrieved via terraform output.
    python3 aadjoin.py --upn <upn_suffix_domain> --endpoints <vm_count>
  7. Install PurpleCloud

    master

    Follow these steps to set up the PurpleCloud environment on Ubuntu Linux 20.04.

    1. Clone the repository

    Use git to clone the repository. Note that the shared directory contains large files (Sysmon, Azure AD Connect, etc.). If you use a standard git client, ensure you have git-lfs installed, or download the repository as a ZIP file from your browser to include the large files.

    To install git-lfs on Ubuntu:

    apt-get install git-lfs
    git clone https://github.com/iknowjason/PurpleCloud.git

    2. Install Python dependencies

    Install the faker library via pip. This is required for several generation scripts including azure_ad.py, ad.py, managed_identity.py, sentinel.py, adfs.py, and aadjoin.py.

    pip3 install faker

    3. Generate and Run Terraform

    After setting up your environment (see Azure Authentication Setup), follow these steps:

    1. Generate Terraform: Run one of the PurpleCloud Python scripts (e.g., sentinel.py) to generate the Terraform configuration files.
    2. Initialize Terraform:
      terraform init
    3. Plan the deployment:
      terraform plan -out=run.plan
    4. Apply the configuration:
      terraform apply run.plan
    git clone https://github.com/iknowjason/PurpleCloud.git
    apt-get install git-lfs
    pip3 install faker
    terraform init
    terraform plan -out=run.plan
    terraform apply run.plan
  8. Retrieve VM credentials and IP addresses

    master

    After running terraform apply and completing the build, you can retrieve sensitive information such as public IP addresses and OS credentials (passwords) using the Terraform output command.

    terraform output

    Additionally, the ad.py script logs all generated passwords (for AD users and local Administrators) to a file named ranges.log to help you track credentials for the created range.

  9. Customize Managed Identity and Azure AD User roles in Terraform

    master

    The generated Terraform files allow for manual customization of roles and network access.

    Managed Identity Role Assignment

    By default, the User Assigned Identity role is scoped to the subscription. You can scope it to specific resources like a Key Vault by uncommenting the scope line in the azurerm_role_assignment resource:

    resource "azurerm_role_assignment" "uai" {
      # scope                = azurerm_key_vault.example.id
      scope                = data.azurerm_subscription.mi.id
      role_definition_name = "ROLE_DEFINITION_NAME"
      principal_id         = azurerm_user_assigned_identity.uai.principal_id
    }

    Azure AD User Role

    To change the role of the generated Azure AD user, modify the user_role variable:

    variable "user_role" {
      default = "Virtual Machine Contributor"
      # default = "Contributor"
      # default = "Reader"
      # default = "Owner"
    }

    Network Access (NSG Whitelisting)

    To allow access from a specific IP or all IPs, modify the src_ip local variable in the Terraform configuration:

    locals {
      src_ip = chomp(data.http.firewall_allowed.response_body)
      # src_ip = "0.0.0.0/0" # Uncomment to allow all IPs
    }
    # Example: Scoping Managed Identity to a Key Vault
    resource "azurerm_role_assignment" "uai" {
      scope                = azurerm_key_vault.example.id
      role_definition_name = "Reader"
      principal_id         = azurerm_user_assigned_identity.uai.principal_id
    }
  10. Manage Azure costs and resource teardown

    master

    PurpleCloud spins up cloud resources that will result in charges to your Azure account. To minimize costs and avoid unexpected billing:

    1. Tear down all resources immediately when they are no longer in use.
    2. Monitor your Azure costs daily and verify them against the pricing estimates provided in the documentation.
    3. Note on Compute Costs: Azure Compute VM resources are generally more expensive than AWS. If you prefer running in AWS, use the sister project BlueCloud instead.

    Disclaimer: The tool author is not responsible for any charges or security issues resulting from usage.

  11. Setup the Azure Managed Identity lab

    master

    To use the Azure Managed Identity generator, you must first navigate to its specific directory within the repository. This generator creates an attack and defense lab consisting of an Azure VM with managed identities (user-assigned and optionally system-assigned) and an Azure AD user. It outputs Terraform HCL files: managed_identity.tf, providers.tf, and mi_user.tf.

    cd generators/managed_identity
  12. Deploy a Domain Controller with Active Directory

    master

    You can deploy a full Active Directory environment including a Domain Controller (DC) and Windows 10 endpoints joined to the domain.

    Example: Randomly Generated Users

    This command creates a Sentinel deployment, a Domain Controller with a forest named rtcfingroup.com, a custom local admin, and 500 randomly generated domain users. It also joins 2 Windows 10 endpoints to the domain.

    python3 sentinel.py --domain_controller --ad_domain rtcfingroup.com --admin RTCAdmin --password MyPassword012345 --ad_users 500 --endpoints 2 --domain_join

    Example: Import Custom Users from CSV

    Instead of random users, you can provide a users.csv file to populate the Active Directory. The script validates the format.

    CSV Format Example:

    name,upn,password,groups,oupath,domain_admin
    Lars Borgerson,larsborgerson@rtcfingroup.com,MyPassword012345,IT,OU=IT;DC=rtcfingroup;DC=com,False
    Olivia Odinsdottir,oliviaodinsdottir@rtcfingroup.com,MyPassword012345,IT,OU=IT;DC=rtcfingroup;DC=com,True
    python3 sentinel.py --domain_controller --ad_domain rtcfingroup.com --admin RTCAdmin --password MyPassword012345 --csv users.csv --endpoints 2 --domain_join