-
-
Notifications
You must be signed in to change notification settings - Fork 371
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 #1147 from OWASP/feature-vault-challenge
- Loading branch information
Showing
20 changed files
with
457 additions
and
14 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
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
66 changes: 66 additions & 0 deletions
66
src/main/java/org/owasp/wrongsecrets/challenges/kubernetes/MetaDataChallenge.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,66 @@ | ||
package org.owasp.wrongsecrets.challenges.kubernetes; | ||
|
||
import com.google.common.base.Strings; | ||
import java.util.Map; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.owasp.wrongsecrets.challenges.FixedAnswerChallenge; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.cloud.vault.config.VaultProperties; | ||
import org.springframework.lang.Nullable; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.vault.core.*; | ||
import org.springframework.vault.support.Versioned; | ||
|
||
/** | ||
* This challenge is about having a metadata of secrets stored in a misconfigured Hashicorp Vault. | ||
*/ | ||
@Component | ||
@Slf4j | ||
public class MetaDataChallenge extends FixedAnswerChallenge { | ||
|
||
private final String vaultPasswordString; | ||
private final VaultTemplate vaultTemplate; | ||
|
||
private final VaultProperties.AuthenticationMethod authenticationMethod; | ||
|
||
public MetaDataChallenge( | ||
@Value("${vaultpassword}") String vaultPasswordString, | ||
@Nullable VaultTemplate vaultTemplate, | ||
@Value("${spring.cloud.vault.authentication}") | ||
VaultProperties.AuthenticationMethod vaultAuthmethod) { | ||
this.vaultPasswordString = vaultPasswordString; | ||
this.vaultTemplate = vaultTemplate; | ||
this.authenticationMethod = vaultAuthmethod; | ||
} | ||
|
||
public String getAnswer() { | ||
try { | ||
if (VaultProperties.AuthenticationMethod.NONE.equals(authenticationMethod) | ||
|| vaultTemplate == null) { | ||
log.warn("Vault not setup for challenge 44"); | ||
return vaultPasswordString; | ||
} | ||
VaultVersionedKeyValueOperations versionedOperations = | ||
vaultTemplate.opsForVersionedKeyValue("secret"); | ||
Versioned<Map<String, Object>> versioned = versionedOperations.get("wrongsecret"); | ||
if (versioned == null) { | ||
return vaultPasswordString; | ||
} | ||
var metadata = versioned.getMetadata(); | ||
if (metadata == null) { | ||
return vaultPasswordString; | ||
} | ||
var customMetadata = metadata.getCustomMetadata(); | ||
if (!customMetadata.isEmpty()) { | ||
String customMedataSecret = customMetadata.get("secret"); | ||
if (Strings.isNullOrEmpty(customMedataSecret)) { | ||
return vaultPasswordString; | ||
} | ||
return customMedataSecret; | ||
} | ||
} catch (Exception e) { | ||
log.warn("Exception during execution of challenge44", e); | ||
} | ||
return vaultPasswordString; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/org/owasp/wrongsecrets/challenges/kubernetes/VaultSubKeyChallenge.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,56 @@ | ||
package org.owasp.wrongsecrets.challenges.kubernetes; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.owasp.wrongsecrets.challenges.FixedAnswerChallenge; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.cloud.vault.config.VaultProperties; | ||
import org.springframework.lang.Nullable; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.vault.core.VaultTemplate; | ||
import org.springframework.vault.core.VaultVersionedKeyValueOperations; | ||
import org.springframework.vault.support.Versioned; | ||
|
||
@Component | ||
@Slf4j | ||
public class VaultSubKeyChallenge extends FixedAnswerChallenge { | ||
|
||
private final String vaultPasswordString; | ||
private final VaultTemplate vaultTemplate; | ||
|
||
private final VaultProperties.AuthenticationMethod authenticationMethod; | ||
|
||
public VaultSubKeyChallenge( | ||
@Value("${vaultpassword}") String vaultPasswordString, | ||
@Nullable VaultTemplate vaultTemplate, | ||
@Value("${spring.cloud.vault.authentication}") | ||
VaultProperties.AuthenticationMethod vaultAuthmethod) { | ||
this.vaultPasswordString = vaultPasswordString; | ||
this.vaultTemplate = vaultTemplate; | ||
this.authenticationMethod = vaultAuthmethod; | ||
} | ||
|
||
@Override | ||
public String getAnswer() { | ||
try { | ||
if (VaultProperties.AuthenticationMethod.NONE.equals(authenticationMethod) | ||
|| vaultTemplate == null) { | ||
log.warn("Vault not setup for challenge 45"); | ||
return vaultPasswordString; | ||
} | ||
VaultVersionedKeyValueOperations versionedOperations = | ||
vaultTemplate.opsForVersionedKeyValue("secret"); | ||
Versioned<Map<String, Object>> versioned = versionedOperations.get("wrongsecret"); | ||
if (versioned == null) { | ||
return vaultPasswordString; | ||
} | ||
Optional<String> first = versioned.getRequiredData().keySet().stream().findFirst(); | ||
return first.orElse(vaultPasswordString); | ||
|
||
} catch (Exception e) { | ||
log.warn("Exception during execution of challenge45", e); | ||
} | ||
return vaultPasswordString; | ||
} | ||
} |
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,9 @@ | ||
=== Vault Metadata Challenge | ||
|
||
Secrets management systems now often have metadata support for their secrets! This is awesome, as it allows you to enrich the secret with contextual data further, making it easier to remember the secret. | ||
|
||
But what if you put confidential/secret information into a secret by mistake? | ||
|
||
A developer has put secret metadata on a `wrongsecret` in Vault. Can you find it? | ||
|
||
Tip: take a look at the policies when vault is installed; you can see that the application is only allowed to use the metadata ;-). |
Oops, something went wrong.