Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/challenge79.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "Get the challenge code 79"

# Challenge 79: a "secret" that survives forking. GitHub does not copy repository secrets to forks,
# so this workflow ships the secret encrypted and keeps the decryption key right next to it.
# Anyone who forks the repository gets both, and can run this workflow (or openssl) to decrypt it.
on:
workflow_dispatch:
permissions:
contents: read
jobs:
decrypt:
name: decrypt the forkable secret
runs-on: ubuntu-latest
env:
CHALLENGE_79_CIPHERTEXT: "A8rW/GHqeiATV7gXaHoBku1+eF7zzu8NuAD4BDwAYPGDelPmPq38pi66/qE1ERh1hMTg1G5Lxn0="
CHALLENGE_79_KEY: "8fa2807c0391c43fb804d8c00a6267f486c0201492f85d668390100b4463cdc5"
CHALLENGE_79_IV: "38242bf02823f7fd9557b2570e97c1c1"
steps:
- name: Decrypt the secret
shell: bash
run: |
echo "The secret is: $(echo "${CHALLENGE_79_CIPHERTEXT}" | openssl enc -d -aes-256-ctr -K "${CHALLENGE_79_KEY}" -iv "${CHALLENGE_79_IV}" -a -A)"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ Now you can try to find the secrets by means of solving the challenge offered at
- [localhost:8080/challenge/challenge-71](http://localhost:8080/challenge/challenge-71)
- [localhost:8080/challenge/challenge-72](http://localhost:8080/challenge/challenge-72)
- [localhost:8080/challenge/challenge-73](http://localhost:8080/challenge/challenge-73)
- [localhost:8080/challenge/challenge-79](http://localhost:8080/challenge/challenge-79)
</details>

Note that these challenges are still very basic, and so are their explanations. Feel free to file a PR to make them look
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.owasp.wrongsecrets.challenges.docker;

import static org.owasp.wrongsecrets.Challenges.ErrorResponses.DECRYPTION_ERROR;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.util.Base64;
import java.util.HexFormat;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import lombok.extern.slf4j.Slf4j;
import org.owasp.wrongsecrets.challenges.FixedAnswerChallenge;
import org.springframework.stereotype.Component;

/**
* Challenge about a GitHub Actions secret that is made "forkable": because repository secrets are
* not copied to forks, the workflow {@code .github/workflows/challenge79.yml} ships the secret
* encrypted and keeps the AES key and IV right next to it. Everybody who forks the repository gets
* the ciphertext and the key, so the encryption protects nothing.
*/
@Slf4j
@Component
public class Challenge79 extends FixedAnswerChallenge {

// Must stay identical to the env values in .github/workflows/challenge79.yml (checked by a test).
static final String CIPHERTEXT =
"A8rW/GHqeiATV7gXaHoBku1+eF7zzu8NuAD4BDwAYPGDelPmPq38pi66/qE1ERh1hMTg1G5Lxn0=";
static final String KEY = "8fa2807c0391c43fb804d8c00a6267f486c0201492f85d668390100b4463cdc5";
static final String IV = "38242bf02823f7fd9557b2570e97c1c1";

@Override
@SuppressFBWarnings(
value = "CIPHER_INTEGRITY",
justification =
"AES-CTR matches the openssl enc command in the challenge workflow, which has no GCM")
public String getAnswer() {
try {
var cipher = Cipher.getInstance("AES/CTR/NoPadding");
cipher.init(
Cipher.DECRYPT_MODE,
new SecretKeySpec(HexFormat.of().parseHex(KEY), "AES"),
new IvParameterSpec(HexFormat.of().parseHex(IV)));
return new String(
cipher.doFinal(Base64.getDecoder().decode(CIPHERTEXT)), StandardCharsets.UTF_8);
} catch (GeneralSecurityException | IllegalArgumentException e) {
log.warn("Could not decrypt the secret of challenge 79", e);
return DECRYPTION_ERROR;
}
}
}
20 changes: 20 additions & 0 deletions src/main/resources/explanations/challenge79.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
=== Challenge 79: The Forkable GitHub Actions Secret

GitHub Actions secrets are not copied when somebody forks a repository. A workflow that
depends on `${{ secrets.SOMETHING }}` therefore stops working in every fork. A tempting
"fix" is to stop using a GitHub secret at all: encrypt the value, commit the ciphertext
in the workflow, and decrypt it during the run. Now the workflow works in every fork.

The problem is that the workflow also needs the decryption key, and that key ended up in
the very same file. Everybody who forks or even just reads this repository receives the
encrypted secret together with everything needed to decrypt it.

Have a look at the workflow
link:https://github.com/OWASP/wrongsecrets/blob/master/.github/workflows/challenge79.yml[`.github/workflows/challenge79.yml`],
recover the secret and submit its plaintext value.

[NOTE]
====
You can solve this challenge offline with `openssl`, or by forking the repository,
enabling GitHub Actions in your fork and running the workflow there.
====
20 changes: 20 additions & 0 deletions src/main/resources/explanations/challenge79_de.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
=== Challenge 79: Das forkbare GitHub Actions-Geheimnis

GitHub Actions-Secrets werden nicht kopiert, wenn jemand ein Repository forkt. Ein Workflow, der
von `${{ secrets.SOMETHING }}` abhängt, funktioniert daher in keinem Fork mehr. Ein verlockender
„Fix“ ist, überhaupt kein GitHub-Secret mehr zu verwenden: den Wert verschlüsseln, den Geheimtext
in den Workflow einchecken und ihn während der Ausführung entschlüsseln. Jetzt funktioniert der Workflow in jedem Fork.

Das Problem ist, dass der Workflow auch den Entschlüsselungsschlüssel benötigt, und dieser Schlüssel ist
in genau derselben Datei gelandet. Jeder, der dieses Repository forkt oder auch nur liest, erhält das
verschlüsselte Geheimnis zusammen mit allem, was zum Entschlüsseln nötig ist.

Sieh dir den Workflow
link:https://github.com/OWASP/wrongsecrets/blob/master/.github/workflows/challenge79.yml[`.github/workflows/challenge79.yml`]
an, stelle das Geheimnis wieder her und übermittele seinen Klartextwert.

[NOTE]
====
Du kannst diese Challenge offline mit `openssl` lösen oder indem du das Repository forkst,
GitHub Actions in deinem Fork aktivierst und den Workflow dort ausführst.
====
20 changes: 20 additions & 0 deletions src/main/resources/explanations/challenge79_es.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
=== Challenge 79: El secreto de GitHub Actions que se puede bifurcar

Los secretos de GitHub Actions no se copian cuando alguien hace un fork de un repositorio. Por lo tanto, un workflow que
depende de `${{ secrets.SOMETHING }}` deja de funcionar en todos los forks. Una "solución" tentadora
es dejar de usar un secreto de GitHub por completo: cifrar el valor, confirmar el texto cifrado
en el workflow y descifrarlo durante la ejecución. Ahora el workflow funciona en todos los forks.

El problema es que el workflow también necesita la clave de descifrado, y esa clave terminó en
el mismo archivo. Cualquiera que haga un fork de este repositorio, o simplemente lo lea, recibe el
secreto cifrado junto con todo lo necesario para descifrarlo.

Echa un vistazo al workflow
link:https://github.com/OWASP/wrongsecrets/blob/master/.github/workflows/challenge79.yml[`.github/workflows/challenge79.yml`],
recupera el secreto y envía su valor en texto plano.

[NOTE]
====
Puedes resolver este reto sin conexión con `openssl`, o haciendo un fork del repositorio,
habilitando GitHub Actions en tu fork y ejecutando allí el workflow.
====
20 changes: 20 additions & 0 deletions src/main/resources/explanations/challenge79_fr.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
=== Challenge 79 : Le secret GitHub Actions que l'on peut forker

Les secrets GitHub Actions ne sont pas copiés lorsque quelqu'un forke un dépôt. Un workflow qui
dépend de `${{ secrets.SOMETHING }}` cesse donc de fonctionner dans chaque fork. Une « solution »
tentante consiste à ne plus utiliser de secret GitHub du tout : chiffrer la valeur, versionner le texte chiffré
dans le workflow et le déchiffrer pendant l'exécution. Le workflow fonctionne alors dans chaque fork.

Le problème est que le workflow a aussi besoin de la clé de déchiffrement, et cette clé s'est retrouvée dans
le même fichier. Toute personne qui forke ce dépôt, ou qui se contente de le lire, reçoit le
secret chiffré ainsi que tout ce qu'il faut pour le déchiffrer.

Examinez le workflow
link:https://github.com/OWASP/wrongsecrets/blob/master/.github/workflows/challenge79.yml[`.github/workflows/challenge79.yml`],
récupérez le secret et soumettez sa valeur en texte clair.

[NOTE]
====
Vous pouvez résoudre ce défi hors ligne avec `openssl`, ou en forkant le dépôt,
en activant GitHub Actions dans votre fork et en y exécutant le workflow.
====
17 changes: 17 additions & 0 deletions src/main/resources/explanations/challenge79_hint.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
You can solve this challenge using the following steps:

1. Open the workflow file:
- In the repository: `.github/workflows/challenge79.yml`
- Or online: link:https://github.com/OWASP/wrongsecrets/blob/master/.github/workflows/challenge79.yml[`.github/workflows/challenge79.yml`]

2. Look at the `env` section of the `decrypt` job. It holds the Base64 ciphertext
(`CHALLENGE_79_CIPHERTEXT`), the AES-256 key (`CHALLENGE_79_KEY`) and the IV
(`CHALLENGE_79_IV`), all in plain text.

3. Decrypt the secret, using either approach:
- Offline, with the same command the workflow runs:
`echo "<ciphertext>" | openssl enc -d -aes-256-ctr -K <key> -iv <iv> -a -A`
- Or fork the repository, enable GitHub Actions in your fork, run the
"Get the challenge code 79" workflow and read the secret from its log.

4. Submit the decrypted text as the answer.
17 changes: 17 additions & 0 deletions src/main/resources/explanations/challenge79_hint_de.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Du kannst diese Challenge mit den folgenden Schritten lösen:

1. Öffne die Workflow-Datei:
- Im Repository: `.github/workflows/challenge79.yml`
- Oder online: link:https://github.com/OWASP/wrongsecrets/blob/master/.github/workflows/challenge79.yml[`.github/workflows/challenge79.yml`]

2. Sieh dir den Abschnitt `env` des Jobs `decrypt` an. Er enthält den Base64-Geheimtext
(`CHALLENGE_79_CIPHERTEXT`), den AES-256-Schlüssel (`CHALLENGE_79_KEY`) und den IV
(`CHALLENGE_79_IV`), alle im Klartext.

3. Entschlüssele das Geheimnis auf eine der beiden Arten:
- Offline, mit demselben Befehl, den der Workflow ausführt:
`echo "<ciphertext>" | openssl enc -d -aes-256-ctr -K <key> -iv <iv> -a -A`
- Oder forke das Repository, aktiviere GitHub Actions in deinem Fork, führe den
Workflow "Get the challenge code 79" aus und lies das Geheimnis aus seinem Log.

4. Übermittele den entschlüsselten Text als Antwort.
17 changes: 17 additions & 0 deletions src/main/resources/explanations/challenge79_hint_es.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Puedes resolver este reto siguiendo estos pasos:

1. Abre el archivo del workflow:
- En el repositorio: `.github/workflows/challenge79.yml`
- O en línea: link:https://github.com/OWASP/wrongsecrets/blob/master/.github/workflows/challenge79.yml[`.github/workflows/challenge79.yml`]

2. Observa la sección `env` del job `decrypt`. Contiene el texto cifrado en Base64
(`CHALLENGE_79_CIPHERTEXT`), la clave AES-256 (`CHALLENGE_79_KEY`) y el IV
(`CHALLENGE_79_IV`), todo en texto plano.

3. Descifra el secreto usando cualquiera de estos enfoques:
- Sin conexión, con el mismo comando que ejecuta el workflow:
`echo "<ciphertext>" | openssl enc -d -aes-256-ctr -K <key> -iv <iv> -a -A`
- O haz un fork del repositorio, habilita GitHub Actions en tu fork, ejecuta el
workflow "Get the challenge code 79" y lee el secreto en su registro.

4. Envía el texto descifrado como respuesta.
17 changes: 17 additions & 0 deletions src/main/resources/explanations/challenge79_hint_fr.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Vous pouvez résoudre ce défi en suivant les étapes suivantes :

1. Ouvrez le fichier du workflow :
- Dans le dépôt : `.github/workflows/challenge79.yml`
- Ou en ligne : link:https://github.com/OWASP/wrongsecrets/blob/master/.github/workflows/challenge79.yml[`.github/workflows/challenge79.yml`]

2. Consultez la section `env` du job `decrypt`. Elle contient le texte chiffré en Base64
(`CHALLENGE_79_CIPHERTEXT`), la clé AES-256 (`CHALLENGE_79_KEY`) et l'IV
(`CHALLENGE_79_IV`), le tout en texte clair.

3. Déchiffrez le secret avec l'une des deux approches :
- Hors ligne, avec la même commande que celle exécutée par le workflow :
`echo "<ciphertext>" | openssl enc -d -aes-256-ctr -K <key> -iv <iv> -a -A`
- Ou forkez le dépôt, activez GitHub Actions dans votre fork, exécutez le
workflow "Get the challenge code 79" et lisez le secret dans son journal.

4. Soumettez le texte déchiffré comme réponse.
17 changes: 17 additions & 0 deletions src/main/resources/explanations/challenge79_hint_nl.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Je kunt deze challenge oplossen met de volgende stappen:

1. Open het workflowbestand:
- In de repository: `.github/workflows/challenge79.yml`
- Of online: link:https://github.com/OWASP/wrongsecrets/blob/master/.github/workflows/challenge79.yml[`.github/workflows/challenge79.yml`]

2. Bekijk de `env`-sectie van de `decrypt`-job. Daarin staan de Base64-ciphertext
(`CHALLENGE_79_CIPHERTEXT`), de AES-256-sleutel (`CHALLENGE_79_KEY`) en de IV
(`CHALLENGE_79_IV`), allemaal in platte tekst.

3. Ontsleutel het geheim op een van de volgende manieren:
- Offline, met hetzelfde commando dat de workflow uitvoert:
`echo "<ciphertext>" | openssl enc -d -aes-256-ctr -K <key> -iv <iv> -a -A`
- Of fork de repository, schakel GitHub Actions in je fork in, voer de
workflow "Get the challenge code 79" uit en lees het geheim uit de log.

4. Dien de ontsleutelde tekst in als antwoord.
17 changes: 17 additions & 0 deletions src/main/resources/explanations/challenge79_hint_uk.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Ви можете розв'язати це завдання, виконавши такі кроки:

1. Відкрийте файл workflow:
- У репозиторії: `.github/workflows/challenge79.yml`
- Або онлайн: link:https://github.com/OWASP/wrongsecrets/blob/master/.github/workflows/challenge79.yml[`.github/workflows/challenge79.yml`]

2. Перегляньте розділ `env` завдання (job) `decrypt`. Він містить шифротекст у Base64
(`CHALLENGE_79_CIPHERTEXT`), ключ AES-256 (`CHALLENGE_79_KEY`) та IV
(`CHALLENGE_79_IV`), усе у відкритому тексті.

3. Розшифруйте секрет одним із двох способів:
- Офлайн, тією самою командою, яку виконує workflow:
`echo "<ciphertext>" | openssl enc -d -aes-256-ctr -K <key> -iv <iv> -a -A`
- Або створіть форк репозиторію, увімкніть GitHub Actions у своєму форку, запустіть
workflow "Get the challenge code 79" і прочитайте секрет у його журналі.

4. Надішліть розшифрований текст як відповідь.
20 changes: 20 additions & 0 deletions src/main/resources/explanations/challenge79_nl.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
=== Challenge 79: Het forkbare GitHub Actions-geheim

GitHub Actions-secrets worden niet gekopieerd wanneer iemand een repository forkt. Een workflow die
afhankelijk is van `${{ secrets.SOMETHING }}` werkt daarom in geen enkele fork meer. Een verleidelijke
"oplossing" is om helemaal geen GitHub-secret meer te gebruiken: versleutel de waarde, commit de ciphertext
in de workflow en ontsleutel deze tijdens de run. Nu werkt de workflow in elke fork.

Het probleem is dat de workflow ook de ontsleutelingssleutel nodig heeft, en die sleutel is in
precies hetzelfde bestand terechtgekomen. Iedereen die deze repository forkt of zelfs alleen maar leest, ontvangt het
versleutelde geheim samen met alles wat nodig is om het te ontsleutelen.

Bekijk de workflow
link:https://github.com/OWASP/wrongsecrets/blob/master/.github/workflows/challenge79.yml[`.github/workflows/challenge79.yml`],
achterhaal het geheim en dien de waarde in platte tekst in.

[NOTE]
====
Je kunt deze challenge offline oplossen met `openssl`, of door de repository te forken,
GitHub Actions in je fork in te schakelen en de workflow daar uit te voeren.
====
30 changes: 30 additions & 0 deletions src/main/resources/explanations/challenge79_reason.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
*Why an encrypted secret with its key in the same repository is no secret at all*

GitHub deliberately does not hand repository secrets to forks: otherwise anybody could
fork a project, change a workflow and print every secret it has. Working around that
limitation by committing an encrypted value plus its key simply undoes the protection:

- Encryption only moves the problem to the key. When the key sits next to the
ciphertext, anybody who can read one can read the other.
- Every fork, clone and mirror now carries the secret, and so does the git history.
Removing the workflow later does not remove the key from the commits that are
already out there.
- Anybody can run the workflow in their own fork and read the decrypted value in the
job log. GitHub only masks values that come from real secrets, so the decrypted
value is printed in the clear.
- The ciphertext looks random, which makes the leak easy to overlook in a review and
hard for secret scanners to detect.

----
What to do instead:

- Keep secrets in the CI secret store (GitHub Actions secrets or environments) and
accept that forks do not get them. Let workflows in forks skip the steps that need
them.
- Prefer short-lived credentials, such as OpenID Connect federation to your cloud
provider, over long-lived secrets.
- Never use `pull_request_target` to give untrusted fork code access to secrets.
- If you encrypt a value in a repository (for example with SOPS or sealed secrets),
keep the decryption key outside of the repository, in a KMS or secret manager.
- Rotate any secret whose key has been committed and treat it as compromised.
----
30 changes: 30 additions & 0 deletions src/main/resources/explanations/challenge79_reason_de.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
*Warum ein verschlüsseltes Geheimnis mit seinem Schlüssel im selben Repository überhaupt kein Geheimnis ist*

GitHub gibt Repository-Secrets absichtlich nicht an Forks weiter: Sonst könnte jeder ein
Projekt forken, einen Workflow ändern und alle seine Secrets ausgeben. Diese Einschränkung zu
umgehen, indem man einen verschlüsselten Wert samt Schlüssel eincheckt, hebt den Schutz einfach auf:

- Verschlüsselung verlagert das Problem nur auf den Schlüssel. Liegt der Schlüssel neben dem
Geheimtext, kann jeder, der das eine lesen kann, auch das andere lesen.
- Jeder Fork, jeder Clone und jeder Mirror enthält nun das Geheimnis, ebenso die Git-Historie.
Das spätere Entfernen des Workflows entfernt den Schlüssel nicht aus den Commits, die
bereits im Umlauf sind.
- Jeder kann den Workflow in seinem eigenen Fork ausführen und den entschlüsselten Wert im
Job-Log lesen. GitHub maskiert nur Werte, die aus echten Secrets stammen, daher wird der
entschlüsselte Wert im Klartext ausgegeben.
- Der Geheimtext sieht zufällig aus, wodurch das Leck in einem Review leicht übersehen wird und
für Secret-Scanner schwer zu erkennen ist.

----
Was du stattdessen tun solltest:

- Bewahre Secrets im Secret-Store deiner CI auf (GitHub Actions-Secrets oder Environments) und
akzeptiere, dass Forks sie nicht erhalten. Lass Workflows in Forks die Schritte überspringen,
die sie benötigen.
- Bevorzuge kurzlebige Zugangsdaten, etwa OpenID Connect-Föderation mit deinem Cloud-
Anbieter, gegenüber langlebigen Secrets.
- Verwende niemals `pull_request_target`, um nicht vertrauenswürdigem Code aus Forks Zugriff auf Secrets zu geben.
- Wenn du einen Wert in einem Repository verschlüsselst (zum Beispiel mit SOPS oder Sealed Secrets),
bewahre den Entschlüsselungsschlüssel außerhalb des Repositorys auf, in einem KMS oder Secret-Manager.
- Rotiere jedes Geheimnis, dessen Schlüssel eingecheckt wurde, und betrachte es als kompromittiert.
----
Loading
Loading