Skip to content

Commit 73b7e5c

Browse files
authored
Refactor pentesting CI/CD methodology document
Removed redundant sections on CI/CD pipelines and VCS pentesting methodology. Updated references and streamlined content for clarity.
1 parent 3bd61ec commit 73b7e5c

File tree

1 file changed

+0
-93
lines changed

1 file changed

+0
-93
lines changed

src/pentesting-ci-cd/pentesting-ci-cd-methodology.md

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ VCS stands for **Version Control System**, this systems allows developers to **m
1515
- Gitblit
1616
- Cloud providers (they offer their own VCS platforms)
1717

18-
{{#ref}}
19-
gitblit-security/README.md
20-
{{#endref}}
2118

2219
## CI/CD Pipelines
2320

@@ -107,94 +104,4 @@ Check this interesting article about the top 10 CI/CD risks according to Cider:
107104
- [https://www.cidersecurity.io/blog/research/ppe-poisoned-pipeline-execution/?utm_source=github\&utm_medium=github_page\&utm_campaign=ci%2fcd%20goat_060422](https://www.cidersecurity.io/blog/research/ppe-poisoned-pipeline-execution/?utm_source=github&utm_medium=github_page&utm_campaign=ci%2fcd%20goat_060422)
108105

109106

110-
111-
## CI/CD Pipelines
112-
113-
CI/CD pipelines enable developers to **automate the execution of code** for various purposes, including building, testing, and deploying applications. These automated workflows are **triggered by specific actions**, such as code pushes, pull requests, or scheduled tasks. They are useful for streamlining the process from development to production.
114-
115-
However, these systems need to be **executed somewhere** and usually with **privileged credentials to deploy code or access sensitive information**.
116-
117-
## VCS Pentesting Methodology
118-
119-
> [!NOTE]
120-
> Even if some VCS platforms allow to create pipelines for this section we are going to analyze only potential attacks to the control of the source code.
121-
122-
Platforms that contains the source code of your project contains sensitive information and people need to be very careful with the permissions granted inside this platform. These are some common problems across VCS platforms that attacker could abuse:
123-
124-
- **Leaks**: If your code contains leaks in the commits and the attacker can access the repo (because it's public or because he has access), he could discover the leaks.
125-
- **Access**: If an attacker can **access to an account inside the VCS platform** he could gain **more visibility and permissions**.
126-
- **Register**: Some platforms will just allow external users to create an account.
127-
- **SSO**: Some platforms won't allow users to register, but will allow anyone to access with a valid SSO (so an attacker could use his github account to enter for example).
128-
- **Credentials**: Username+Pwd, personal tokens, ssh keys, Oauth tokens, cookies... there are several kind of tokens a user could steal to access in some way a repo.
129-
- **Webhooks**: VCS platforms allow to generate webhooks. If they are **not protected** with non visible secrets an **attacker could abuse them**.
130-
- If no secret is in place, the attacker could abuse the webhook of the third party platform
131-
- If the secret is in the URL, the same happens and the attacker also have the secret
132-
- **Code compromise:** If a malicious actor has some kind of **write** access over the repos, he could try to **inject malicious code**. In order to be successful he might need to **bypass branch protections**. These actions can be performed with different goals in mid:
133-
- Compromise the main branch to **compromise production**.
134-
- Compromise the main (or other branches) to **compromise developers machines** (as they usually execute test, terraform or other things inside the repo in their machines).
135-
- **Compromise the pipeline** (check next section)
136-
137-
## Pipelines Pentesting Methodology
138-
139-
The most common way to define a pipeline, is by using a **CI configuration file hosted in the repository** the pipeline builds. This file describes the order of executed jobs, conditions that affect the flow, and build environment settings.\
140-
These files typically have a consistent name and format, for example — Jenkinsfile (Jenkins), .gitlab-ci.yml (GitLab), .circleci/config.yml (CircleCI), and the GitHub Actions YAML files located under .github/workflows. When triggered, the pipeline job **pulls the code** from the selected source (e.g. commit / branch), and **runs the commands specified in the CI configuration file** against that code.
141-
142-
Therefore the ultimate goal of the attacker is to somehow **compromise those configuration files** or the **commands they execute**.
143-
144-
### PPE - Poisoned Pipeline Execution
145-
146-
The Poisoned Pipeline Execution (PPE) path exploits permissions in an SCM repository to manipulate a CI pipeline and execute harmful commands. Users with the necessary permissions can modify CI configuration files or other files used by the pipeline job to include malicious commands. This "poisons" the CI pipeline, leading to the execution of these malicious commands.
147-
148-
For a malicious actor to be successful performing a PPE attack he needs to be able to:
149-
150-
- Have **write access to the VCS platform**, as usually pipelines are triggered when a push or a pull request is performed. (Check the VCS pentesting methodology for a summary of ways to get access).
151-
- Note that sometimes an **external PR count as "write access"**.
152-
- Even if he has write permissions, he needs to be sure he can **modify the CI config file or other files the config is relying on**.
153-
- For this, he might need to be able to **bypass branch protections**.
154-
155-
There are 3 PPE flavours:
156-
157-
- **D-PPE**: A **Direct PPE** attack occurs when the actor **modifies the CI config** file that is going to be executed.
158-
- **I-DDE**: An **Indirect PPE** attack occurs when the actor **modifies** a **file** the CI config file that is going to be executed **relays on** (like a make file or a terraform config).
159-
- **Public PPE or 3PE**: In some cases the pipelines can be **triggered by users that doesn't have write access in the repo** (and that might not even be part of the org) because they can send a PR.
160-
- **3PE Command Injection**: Usually, CI/CD pipelines will **set environment variables** with **information about the PR**. If that value can be controlled by an attacker (like the title of the PR) and is **used** in a **dangerous place** (like executing **sh commands**), an attacker might **inject commands in there**.
161-
162-
### Exploitation Benefits
163-
164-
Knowing the 3 flavours to poison a pipeline, lets check what an attacker could obtain after a successful exploitation:
165-
166-
- **Secrets**: As it was mentioned previously, pipelines require **privileges** for their jobs (retrieve the code, build it, deploy it...) and this privileges are usually **granted in secrets**. These secrets are usually accessible via **env variables or files inside the system**. Therefore an attacker will always try to exfiltrate as much secrets as possible.
167-
- Depending on the pipeline platform the attacker **might need to specify the secrets in the config**. This means that is the attacker cannot modify the CI configuration pipeline (**I-PPE** for example), he could **only exfiltrate the secrets that pipeline has**.
168-
- **Computation**: The code is executed somewhere, depending on where is executed an attacker might be able to pivot further.
169-
- **On-Premises**: If the pipelines are executed on premises, an attacker might end in an **internal network with access to more resources**.
170-
- **Cloud**: The attacker could access **other machines in the cloud** but also could **exfiltrate** IAM roles/service accounts **tokens** from it to obtain **further access inside the cloud**.
171-
- **Platforms machine**: Sometimes the jobs will be execute inside the **pipelines platform machines**, which usually are inside a cloud with **no more access**.
172-
- **Select it:** Sometimes the **pipelines platform will have configured several machines** and if you can **modify the CI configuration file** you can **indicate where you want to run the malicious code**. In this situation, an attacker will probably run a reverse shell on each possible machine to try to exploit it further.
173-
- **Compromise production**: If you ware inside the pipeline and the final version is built and deployed from it, you could **compromise the code that is going to end running in production**.
174-
175-
## More relevant info
176-
177-
### Tools & CIS Benchmark
178-
179-
- [**Chain-bench**](https://github.com/aquasecurity/chain-bench) is an open-source tool for auditing your software supply chain stack for security compliance based on a new [**CIS Software Supply Chain benchmark**](https://github.com/aquasecurity/chain-bench/blob/main/docs/CIS-Software-Supply-Chain-Security-Guide-v1.0.pdf). The auditing focuses on the entire SDLC process, where it can reveal risks from code time into deploy time.
180-
181-
### Top 10 CI/CD Security Risk
182-
183-
Check this interesting article about the top 10 CI/CD risks according to Cider: [**https://www.cidersecurity.io/top-10-cicd-security-risks/**](https://www.cidersecurity.io/top-10-cicd-security-risks/)
184-
185-
### Labs
186-
187-
- On each platform that you can run locally you will find how to launch it locally so you can configure it as you want to test it
188-
- Gitea + Jenkins lab: [https://github.com/cider-security-research/cicd-goat](https://github.com/cider-security-research/cicd-goat)
189-
190-
### Automatic Tools
191-
192-
- [**Checkov**](https://github.com/bridgecrewio/checkov): **Checkov** is a static code analysis tool for infrastructure-as-code.
193-
194-
## References
195-
196-
- [https://www.cidersecurity.io/blog/research/ppe-poisoned-pipeline-execution/?utm_source=github\&utm_medium=github_page\&utm_campaign=ci%2fcd%20goat_060422](https://www.cidersecurity.io/blog/research/ppe-poisoned-pipeline-execution/?utm_source=github&utm_medium=github_page&utm_campaign=ci%2fcd%20goat_060422)
197-
198107
{{#include ../banners/hacktricks-training.md}}
199-
200-

0 commit comments

Comments
 (0)