-
-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1189 from nwolniak/command-injection-vault-template
New Challenge - Vault Template Injection
- Loading branch information
Showing
16 changed files
with
171 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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,8 @@ | ||
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` where `xxx` is the rest of the randomly generated pod name. | ||
to print injected secrets from vault. | ||
Note: if you are running this on a hosted environment, where you do not have access to the Kubernetes cluster, ask the organizer of the hosted solution to execute the commands for you and return the results. |
This file contains 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. | ||
|
||
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 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 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 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 { | ||
|
||
@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 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