-
-
Notifications
You must be signed in to change notification settings - Fork 484
New Challenge - Vault Template Injection #1189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
commjoen
merged 11 commits into
OWASP:master
from
nwolniak:command-injection-vault-template
Jan 17, 2024
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
adf7bfa
feat: vault template injection
nwolniak dd1d629
Merge remote-tracking branch 'upstream/master' into command-injection…
nwolniak 4669a57
fix: vault template injection challenge renamed to 46
nwolniak d88ae92
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] a42b30b
fix: new secret for vault templat injection
nwolniak 5accc4b
Merge branch 'command-injection-vault-template' of https://github.com…
nwolniak 657ff68
fix: challenge46_reason example added
nwolniak 5f0916c
Merge branch 'master' into command-injection-vault-template
nwolniak b4eed1a
Update POM file with new version: vaultinjection-2-test
commjoen b4be436
Merge branch 'master' into command-injection-vault-template
commjoen bb46ad7
Apply suggestions from code review
commjoen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,6 @@ server: | |
| affinity: | ||
| ha: | ||
| enabled: true | ||
|
|
||
| injector: | ||
| enabled: true | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/org/owasp/wrongsecrets/challenges/kubernetes/Challenge46.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package org.owasp.wrongsecrets.challenges.kubernetes; | ||
|
|
||
| import com.google.common.base.Strings; | ||
| import org.owasp.wrongsecrets.challenges.FixedAnswerChallenge; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| /** This challenge is about having a secrets injected via Vault template. */ | ||
| @Component | ||
| public class Challenge46 extends FixedAnswerChallenge { | ||
|
|
||
| private final Vaultinjected vaultinjected; | ||
| private final String mockedAnswer; | ||
|
|
||
| public Challenge46(Vaultinjected vaultinjected, @Value("${vaultinjected}") String mockedAnswer) { | ||
| this.vaultinjected = vaultinjected; | ||
| this.mockedAnswer = mockedAnswer; | ||
| } | ||
|
|
||
| @Override | ||
| public String getAnswer() { | ||
| return vaultinjected != null && !Strings.isNullOrEmpty(vaultinjected.getValue()) | ||
| ? vaultinjected.getValue() | ||
| : mockedAnswer; | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/owasp/wrongsecrets/challenges/kubernetes/Vaultinjected.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package org.owasp.wrongsecrets.challenges.kubernetes; | ||
|
|
||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
|
||
| /** Class used to get value from vault using the springboot cloud integration with vault. */ | ||
| @ConfigurationProperties("vaultinjected") | ||
| public class Vaultinjected { | ||
|
|
||
| private String value; | ||
|
|
||
| public void setValue(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public String getValue() { | ||
| return value; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| === HashiCorp Vault Template Injection | ||
|
|
||
| Vault template injection via agent injection typically involves injecting a sidecar container, | ||
| known as the Vault Agent, alongside your main application container. | ||
| The Vault Agent is responsible for interacting with HashiCorp Vault to retrieve secrets and inject them into the application's runtime environment. | ||
|
|
||
| Can you find secret injected into application environment? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| This challenge can be solved using the following steps: | ||
|
|
||
| 1. Run 'kubectl get pods -A' and find secret-challenge-xxx pod name | ||
|
|
||
| 2. Run 'kubectl exec secret-challenge-xxx -c secret-challenge -n default -- cat vault/secrets/challenge46' | ||
commjoen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| to print injected secrets from vault | ||
commjoen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| *Why Vault Template Injection is not always a good idea?* | ||
|
|
||
| While Vault agent injection via templates can be a convenient way to manage secrets in certain scenarios, | ||
| there are situations where it might not be the best approach. | ||
|
|
||
| Templates might accidentally expose sensitive information in logs or temporary files. | ||
| If not properly configured, secrets could end up in places where they are accessible by unauthorized users or processes. | ||
nwolniak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Let's consider an example involving a template injection attack in a scripted language like PHP: | ||
|
|
||
| . Imagine a scenario where PHP application uses a template with sensitive information | ||
| * where template can look like this: $password = "'; system('rm -rf /'); //" | ||
| . When the template is processed it can become: | ||
| * $connection = "password='; system('rm -rf /'); //" | ||
|
|
||
| To prevent such issues its crucial to ensure that the values retrieved from Vault are properly validated. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/test/java/org/owasp/wrongsecrets/challenges/kubernetes/Challenge46Test.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package org.owasp.wrongsecrets.challenges.kubernetes; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class Challenge46Test { | ||
|
|
||
commjoen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Test | ||
| void spoilerShouldGiveAnswerWithVault() { | ||
| var vaultInjected = new Vaultinjected(); | ||
| vaultInjected.setValue("answer"); | ||
| var challenge = new Challenge46(vaultInjected, ""); | ||
| assertThat(challenge.spoiler().solution()).isNotEmpty(); | ||
| assertThat(challenge.answerCorrect(challenge.spoiler().solution())).isTrue(); | ||
| } | ||
|
|
||
| @Test | ||
| void spoilerShouldGiveAnswer() { | ||
| var vaultInjected = new Vaultinjected(); | ||
| vaultInjected.setValue(""); | ||
| var challenge = new Challenge46(vaultInjected, "answer"); | ||
| assertThat(challenge.spoiler().solution()).isEqualTo("answer"); | ||
| assertThat(challenge.answerCorrect(challenge.spoiler().solution())).isTrue(); | ||
| } | ||
|
|
||
| @Test | ||
| void incorrectAnswerShouldNotSolveChallenge() { | ||
| var vaultInjected = new Vaultinjected(); | ||
| vaultInjected.setValue("answer"); | ||
| var challenge = new Challenge46(vaultInjected, ""); | ||
| assertThat(challenge.answerCorrect("wrong answer")).isFalse(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.