Skip to content

Commit e7dd127

Browse files
committed
f
1 parent 681145a commit e7dd127

File tree

1 file changed

+44
-0
lines changed
  • src/pentesting-ci-cd/github-security/abusing-github-actions

1 file changed

+44
-0
lines changed

src/pentesting-ci-cd/github-security/abusing-github-actions/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,50 @@ For example ([**this**](https://www.legitsecurity.com/blog/github-privilege-esca
316316

317317
<figure><img src="../../../images/image (261).png" alt=""><figcaption></figcaption></figure>
318318

319+
### Dependabot and other trusted bots
320+
321+
As indicated in [**this blog post**](https://boostsecurity.io/blog/weaponizing-dependabot-pwn-request-at-its-finest), several organizations have a Github Action that merges any PRR from `dependabot[bot]` like in:
322+
323+
```yaml
324+
on: pull_request_target
325+
jobs:
326+
auto-merge:
327+
runs-on: ubuntu-latest
328+
if: ${ { github.actor == 'dependabot[bot]' }}
329+
steps:
330+
- run: gh pr merge $ -d -m
331+
```
332+
333+
Which is a problem because the `github.actor` field contains the user who caused the latest event that triggered the workflow. And There are several ways to make the `dependabot[bot]` user to modify a PR. For example:
334+
335+
- Fork the victim repository
336+
- Add the malicious payload to your copy
337+
- Enable Dependabot on your fork adding an outdated dependency. Dependabot will create a branch fixing the dependency with malicious code.
338+
- Open a Pull Request to the victim repository from that branch (the PR will be created by the user so nothing will happen yet)
339+
- Then, attacker goes back to the initial PR Dependabot opened in his fork and runs `@dependabot recreate`
340+
- Then, Dependabot perform some actions in that branch, that modified the PR over the victim repo, which makes `dependabot[bot]` the actor of the latest event that triggered the workflow (and therefore, the workflow runs).
341+
342+
Moving on, what if instead of merging the Github Action would have a command injection like in:
343+
344+
```yaml
345+
on: pull_request_target
346+
jobs:
347+
just-printing-stuff:
348+
runs-on: ubuntu-latest
349+
if: ${ { github.actor == 'dependabot[bot]' }}
350+
steps:
351+
- run: echo ${ { github.event.pull_request.head.ref }}
352+
```
353+
354+
Well, the original blogpost proposes two options to abuse this behavior being the second one:
355+
356+
- Fork the victim repository and enable Dependabot with some outdated dependency.
357+
- Create a new branch with the malicious shell injeciton code.
358+
- Change the default branch of the repo to that one
359+
- Create a PR from this branch to the victim repository.
360+
- Run `@dependabot merge` in the PR Dependabot opened in his fork.
361+
- Dependabot will merge his changes in the default branch of your forked repository, updating the PR in the victim repository making now the `dependabot[bot]` the actor of the latest event that triggered the workflow and using a malicious branch name.
362+
319363
### Vulnerable Third Party Github Actions
320364

321365
#### [dawidd6/action-download-artifact](https://github.com/dawidd6/action-download-artifact)

0 commit comments

Comments
 (0)