Giter Club home page Giter Club logo

gato-x's Introduction

Supported Python versions Code style: black

Gato (Github Attack TOolkit) - Extreme Edition

Gato-X is a FAST scanning and attack tool for GitHub Actions pipelines. You can use it to identify Pwn Requests, Actions Injection, TOCTOU Vulnerabilities, and Self-Hosted Runner takeover at scale using just a single API token.

As an example, you can scan all repositories Apache's GitHub organization in minutes from a MacBook Air with a broadband internet connection.

Gato-X is an operator focused tool that is tuned to avoid false negatives. It will have a higher false positive rate than SAST tools like CodeQL, but Gato-X will give you everything you need to quickly determine if something is a true positive or not!

The search and enumerate modes are safe to run on all public repositories, and you will not violate any rules by doing so.

Gato-X's attack features should only be used with authorization, and make sure to follow responsible disclosure if you find vulnerabilities with Gato-X.

Gato-X is a powerful tool and should only be used for ethical security research purposes.

Table of Contents

What is Gato-X?

Gato Extreme Edition is a hard fork of Gato, which was originally developed by @AdnaneKhan, @mas0nd, and @DS-koolaid. Gato-X is maintained by @AdnaneKhan and serves to automate advanced enumeration and exploitation techniques against GitHub repositories and organizations for security research purposes.

Gato-X accompanies the BlackHat USA 2024 talk: Self-Hosted GitHub CI/CD Runners: Continuous Integration, Continuous Destruction and the DEF CON 32 talk Grand Theft Actions: Abusing Self-Hosted GitHub Runners at scale.

New Features

Automated Self-Hosted Runner Attacks

Gato-X automates the "Runner-on-Runner" (RoR) technique used extensively by Adnan Khan and John Stawinski during their self-hosted runner bug bounty campaign. This feature replaces the basic attack PoC functionality included in the original version of Gato.

Gato-X supports deploying RoR through fork pull requests. Gato-X also supports creating a RoR payload only, which can be used in conjunction with the push workflow functionality to jump to internal self-hosted runners.

Under the hood, Gato-X will perform the following steps:

  • Prepare RoR C2 Repository
  • Prepare payload Gist files
  • Deploy the RoR implantation payload.
  • Confirm successful callback and runner installation.
  • Provide user with an interactive webshell upon successful connection.

From the user's persective, it's simply: run command, get shell. What more could a hacker want?

Enumeration for GitHub Actions Injection and Pwn Requests

Gato-X contains a powerful scanning engine for GitHub Actions Injection and Pwn Request vulnerabilities. As of writing, Gato-X is one of the fastest tools for the task. It is capable of scanning 35-40 thousand repositories in 1-2 hours using a single GitHub PAT. This is the most sophisticated new feature in Gato-X and is the result of countless hours of development and iteration in my spare time over the last six months.

  • Reachability Analysis
  • Same and Cross-Repository Transitive Workflow Analysis
  • Parsing and Simulation of "If Statements"
  • Gate Check Detection (permission checks, etc.)
  • Lightweight Source-Sink Analysis for Variables
  • Priority Guidelines

As an operator facing tool, Gato-X is tuned with a higher false positive rate than a tool designed to generate alerts, but it provides contextual information to quickly determine if something is worth investigating or not. To aid in triage, Gato-X attempts to apply confidence ratings to its reports.

Other Improvements

  • Improved Secrets Exfiltration.
  • Enumeration of deployment environment secrets.
  • Speed improvements for runlog analysis.
  • General speed improvements throughout.
  • Improved CLI interface and reports.
  • Removed dependancy on Git.

Features Coming Soon

There are a number of features I plan to add to Gato-X in the coming weeks or months.

Analyze Referenced Composite Actions

Currently, Gato-X does not analyze referenced composite actions. In some cases, risky operations can be performed within composite actions (such as referencing user-controlled context variables or checking out PR code).

The problem with this is that retrieving an additional file requires an addition round trip request. This can significantly slow down enumeration. This will probably be an option that is disabled by default when I add it.

LLM Powered Result Analysis

Gato-X's biggest weakness is identifying injection points that are outputs of steps that run arbitrary code. This creates a lot of 'UNKNOWN' confidence Actions Injection Reports. Using LLMs to reason about whether a variable is user control or not based on context will allow further narrowing down results. This feature will likely include support for passing an OpenAI API key and some Gato-X system prompts that I will use to inform ChatGPT of what to look for and how to respond.

Similarly, this can apply to capture code that performs permission checks or enforces immutable references.

Hall of Fame

In order to motivate hackers to use Gato-X to find and report vulnerabilities in open-source repositories, I've created a mini hall of fame. If you found an issue with Gato-X and reported it, feel free to follow the instructions on the page so I can add your accomplishment for all to see!

Quick Start

Perform Self Hosted Runner Takeover

To perform a public repository self-hosted runner takeover attack, Gato-X requires a PAT with the following scopes:

repo, workflow, and gist.

This should be a PAT for an account that is a contributor to the target repository (i.e. submitted a typo fix).

gato-x a --runner-on-runner --target ORG/REPO --target-os [linux,osx,windows] --target-arch [arm,arm64,x64]

It is very rare that maintainers select allowing workflows on pull request from all external users without approval, but it has happened.

Next, Gato-X will automatically prepare a C2 repository and begin the operation. Gato-X will monitor each step as the attack continues, exiting as gracefully as possible at each phase in case of a failure. If workflow approval is required, Gato-X will wait a short period of time before exiting.

If the full chain succeeds, Gato-X will drop to an interactive prompt. This will execute shell commands on the self-hosted runner.

If the target runner is non-ephemeral, use the --keep-alive flag. This will keep the workflow running. GitHub Actions allows workflow runs on self-hosted runners to run for up to 5 days (as of writing, this might change - it was 30 days).

Search For GitHub Actions Vulnerabilities at GitHub Scale

First, create a GitHub PAT with the repo scope. Set that PAT to the GH_TOKEN environment variable.

Next, use the search feature to retrieve a list of candidate repositories:

gato-x s -sg -q 'count:75000 /(issue_comment|pull_request_target|issues:)/ file:.github/workflows/ lang:yaml' -oT checks.txt

Finally, run Gato-X on the list of repositories:

gato-x e -R checks.txt -sr | tee gatox_output.txt

This will take some time depending on your computer and internet connection speed. Since the results are very long, use tee to save them to a file for later review. Gato-X also supports JSON output, but that is intended for further machine analysis.

Complex Attacks

These automated attacks only scratch the surface of the kinds of post-compromise attacks paths that a red teamer may encounter within large GitHub Enterprise tenants. See the wiki for complex cases and how Gato-X may help.

Examples

  • Deploying RoR using custom workflow via the push trigger.
  • Deploying RoR using a PAT that only has the repo scope but can obtain execution via workflow_dispatch / push triggers.
  • Leveraging a repo scoped token to bypass external contributor approval requirements, but leveraging Gato-X for RoR infrastructure setup.
  • Using a GITHUB_TOKEN with actions: write from a Pwn Request to approve a fork PR from an external contributor.

Getting Started

Installation

Gato supports OS X and Linux with at least Python 3.10.

Gato-X is published on PyPi, so you can simply install it with pip install gato-x

In order to install the tool from source, simply clone the repository and use pip install.

We recommend performing this within a virtual environment.

git clone https://github.com/AdnaneKhan/gato-x
cd gato-x
python3 -m venv venv
source venv/bin/activate
pip install .

OR You can use pipx

git clone https://github.com/AdnaneKhan/gato-x
cd gato-x
pipx install .

If you need to make on-the-fly modifications, then install it in editable mode with pip install -e.

Usage

After installing the tool, it can be launched by running gato-x.

We recommend viewing the parameters for the base tool using gato -h, and the parameters for each of the tool's modules by running the following:

  • gato-x search -h
  • gato-x enum -h
  • gato-x attack -h

The tool requires a GitHub classic PAT in order to function. To create one, log in to GitHub, go to GitHub Developer Settings and select Generate New Token and then Generate new token (classic).

After creating this token set the GH_TOKEN environment variable within your shell by running export GH_TOKEN=<YOUR_CREATED_TOKEN>. Alternatively, enter it when the application prompts you.

For troubleshooting and additional details, such as installing in developer mode or running unit tests, please see the wiki.

Bugs

As an operator facing tool with rapidly developed features, Gato-X will have bugs. Typically, these are related to edge cases with run log formatting or YAML files.

If you believe you have identified a bug within the software, please open an issue containing the tool's output, along with the actions you were trying to conduct.

Contributing

Contributions are welcome! Please review the design methodology before working on a new feature!

Additionally, if you are proposing significant changes to the tool, please open an issue open an issue to start a conversation about the motivation for the changes.

License

Gato-X is licensed under the Apache License, Version 2.0.

Gato-X:

Copyright 2024, Adnan Khan

Original Gato Implementation:

Copyright 2023 Praetorian Security, Inc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

gato-x's People

Contributors

adnanekhan avatar mas0nd avatar dependabot[bot] avatar jimmyscchang avatar jstawinski avatar ds-koolaid avatar pswalia2u avatar rtrompier avatar

Stargazers

shopper avatar Nicolas Vincent avatar Jack Swindell avatar Subham Ray avatar Marzuki avatar Perseverance avatar Manuel Berrueta avatar  avatar  avatar Rahul Vivek Nair avatar Francois Allard avatar Behlül Şahin avatar SaTy avatar Osirys avatar Life avatar Ross avatar KZTTTTAZ avatar M.Griffiths avatar Leyart avatar . avatar Cory avatar 0xff avatar Chasen Bettinger avatar Valerian avatar AdrienIT avatar Vladimír Urík avatar 4shen0ne avatar Swissky avatar  avatar Kelvin Ndungu avatar  avatar 0x1622 avatar Sascha D. avatar Evan avatar Milan Kyselica avatar  avatar atkVktr avatar Luís Freitas avatar Guilherme Caulada avatar Pedro Lourenço avatar stuwifu avatar Constant Learner avatar nnon avatar Computer button pusher // Pousseur de boutons en informatique  || SIN - SIN HACK - HACK || NO-CODE evangelist || Black coffee like my sense of humor avatar l4ms02 avatar Harun Mansor avatar Jaymin Tanna avatar Eldar avatar PikPikcU avatar Martin Fuchs avatar owlonex avatar  avatar Sean Pesce avatar  avatar Jaikishan Tulswani avatar  avatar Yogesh Ojha avatar  avatar Rick Ridgley avatar  avatar Julien Bouquillon avatar nopcorn avatar cerry_moli avatar HoiDam avatar Felix Erkinger avatar  avatar Michael Eder avatar  avatar  avatar agtian avatar reza.duty avatar  avatar Nick0lass avatar Pranay Shah avatar CJ avatar xrkk avatar Devanshu avatar  avatar echoonly avatar Matthew Linney avatar Matthew McCorkle avatar Erik avatar ₪Ʊןןζ€ avatar Chiira avatar leo avatar Nishant Bhagat avatar Aashita Pandey avatar Nicolas RUFF avatar Mohamed Walid - l0da avatar farhan nadim pial avatar tudouya avatar  avatar  avatar Khaled Mohamed avatar  avatar  avatar covertshell avatar souhail avatar simone ragonesi avatar  avatar

Watchers

 avatar  avatar Francois Allard avatar Arun avatar Ag3nt_57 avatar

gato-x's Issues

Multiprocessing Enumeration Flow

Currently, Gato-X's enumeration flow is very much single threaded. This makes it hard to add enumeration passes for more in-depth analysis.

Re-write Gato-X's enumeration flow to use worker processes, this way it will be possible to add more in-depth analysis modules and makes Gato-X a better architected too.

Use of GitHub App installation access token not allowed

Describe the bug
There is code that validates token format, and app installation access tokens are not allowed

if not ("ghp_" in gh_token or "gho_" in gh_token or "ghu_" in

Such tokens start with ghs_
https://github.blog/engineering/platform-security/behind-githubs-new-authentication-token-formats/#identifiable-prefixes

To Reproduce
Use an App installation access token
You will see this error

Provided GitHub PAT is malformed!

Expected behavior
App installation access tokens should also work

Check user owned repos and repos user is a collaborator with self enum.

Describe the bug
It seems like this tool doesn't enum internal repos and only scans public and private repos. Correct me if I am wrong. It would be great if it can also scan for internal repos.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

** Environment (please complete the following information):**

  • OS: [e.g. iOS]
  • Python Version: [e.g. 3.11]

Additional context

Add any other context about the problem here.

Reorganize Workflow Parsing

Gato-X’s workflow parsing was bolted on to the minimal parsing that Gato used to determine if a workflow might use a self-hosted runner.

Now that Gato-X contains a SAST scanning engine for workflows, this approach has grown bloated, messy, and hard to maintain. As a result, it makes it hard to add changes with the purpose of reducing the false positive rate and increasing the accuracy of reports.

It is time to overhaul the workflow representation using a proper Graph library. It must be something that does not require installing a Graph databases and must be Apache 2.0 compatible.

I am currently looking at the NetworkX library.

This way I can represent the relationships between repositories, workflows, jobs, runners, steps, referenced actions in a cleaner manner than “self-rolled” graph that Gato-X currently has. It is likely that this structure will reveal opportunities for some very interesting analyses such as workflow lateral movement opportunities due to shared runners as well as cache poisoning lateral movement opportunities.

False negative if reusable workflow uses self-hosted runners during org enum

Describe the bug

When enumerating organizations, Gato-X uses a heuristic to only pull run logs for workflows that potentially use self-hosted runners. This is for speed and to prevent hitting secondary rate limits when pulling run logs.

The problem is that the workflow run log is associated with the calling workflow, so the callee containing the job using a self-hosted runner will not have runs associated with it. The fix here is to use the same parsing logic Gato-X uses for detecting Pwn requests/Injection in called workflows to identify the calling workflow.

Support Single-Repo Enumeration with GitHub App Tokens

Currently, Gato-X only supports enumeration using Classic PATs or OAuth tokens. This works for CLI enumeration, but makes it difficult to include Gato-X as part of repository monitoring automation that is installed as an app.

It would be useful to add a machine execution flag to Gato-X that allows enumerating a single repository's workflows and run logs using a GitHub App token( ghs_ or ghu_). The expectation would be that the token has the correct actions: read and contents: read scope on the repository.

Query

Hi AdnaneKhan,

I am new to github actions vulnerability so pardon me with my queries

I have few questions I hope you can answer since you are very well knowledgable about github actions vulnerabilities.

  1. The gato-x tool requires workflow permissions on the token to exfilterate secrets, it does that by creating workflows and executing those. But wouldn't that be possible also if the token just have repo scope. cant i create a PR or push changes to a branch which will execute my malicious workflow(exfil secrets) using push or pull_request events?

also, same method could be used to takeover self hosted runners where the token has write permissions?

Also, would like to chat with you if you are on discord or any other messaging platform.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.