-
-
Notifications
You must be signed in to change notification settings - Fork 372
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
Draft: Challenge X: nexus credentials as part of a project pushed (#810) #1046
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<settings> | ||
<mirrors> | ||
<mirror> | ||
<id>nexus</id> | ||
<mirrorOf>*</mirrorOf> | ||
<url>http://localhost:8081/nexus/content/groups/public</url> | ||
</mirror> | ||
</mirrors> | ||
<activeProfiles> | ||
<activeProfile>nexus</activeProfile> | ||
</activeProfiles> | ||
<profiles> | ||
<profile> | ||
<id>nexus</id> | ||
<repositories> | ||
<repository> | ||
<id>central</id> | ||
<url>http://central</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>central</id> | ||
<url>http://central</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</pluginRepository> | ||
Comment on lines
+28
to
+37
Check failure Code scanning / CodeQL Failure to use HTTPS or SFTP URL in Maven artifact upload/download High
Downloading or uploading artifacts over insecure protocol (eg. http or ftp) to/from repository http://central
|
||
</pluginRepositories> | ||
</profile> | ||
</profiles> | ||
<pluginGroups> | ||
<pluginGroup>org.owsap.plugins</pluginGroup> | ||
</pluginGroups> | ||
<servers> | ||
<server> | ||
<id>nexus</id> | ||
<username>admin</username> | ||
<password>admin123</password> | ||
</server> | ||
</servers> | ||
</settings> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,88 @@ | ||||||
package org.owasp.wrongsecrets.challenges.docker; | ||||||
|
||||||
import java.io.StringReader; | ||||||
import java.nio.charset.Charset; | ||||||
import java.util.List; | ||||||
import lombok.extern.slf4j.Slf4j; | ||||||
import org.apache.commons.configuration2.XMLConfiguration; | ||||||
import org.owasp.wrongsecrets.RuntimeEnvironment; | ||||||
import org.owasp.wrongsecrets.ScoreCard; | ||||||
import org.owasp.wrongsecrets.challenges.Challenge; | ||||||
import org.owasp.wrongsecrets.challenges.ChallengeTechnology; | ||||||
import org.owasp.wrongsecrets.challenges.Difficulty; | ||||||
import org.owasp.wrongsecrets.challenges.Spoiler; | ||||||
import org.springframework.beans.factory.annotation.Value; | ||||||
import org.springframework.core.annotation.Order; | ||||||
import org.springframework.core.io.Resource; | ||||||
import org.springframework.stereotype.Component; | ||||||
|
||||||
/** | ||||||
* This is a challenge based on leaking secrets due to keeping the encryption key and secret | ||||||
* together | ||||||
*/ | ||||||
@Slf4j | ||||||
@Component | ||||||
@Order(42) | ||||||
public class Challenge42 extends Challenge { | ||||||
|
||||||
private final Resource resource; | ||||||
|
||||||
public Challenge42( | ||||||
ScoreCard scoreCard, @Value("classpath:maven/settings/settings.xml") Resource resource) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This resource does not exist (see below), can you instead have a look at the code of Challenge12.java? here you can see how a file is loaded either from test resources or from a filepath within a docker container or from the resources. |
||||||
super(scoreCard); | ||||||
this.resource = resource; | ||||||
} | ||||||
|
||||||
@Override | ||||||
public boolean canRunInCTFMode() { | ||||||
return true; | ||||||
} | ||||||
|
||||||
@Override | ||||||
public Spoiler spoiler() { | ||||||
return new Spoiler(getSolution()); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public boolean answerCorrect(String answer) { | ||||||
return getSolution().equals(answer); | ||||||
} | ||||||
|
||||||
/** {@inheritDoc} */ | ||||||
@Override | ||||||
public int difficulty() { | ||||||
return Difficulty.EASY; | ||||||
} | ||||||
|
||||||
/** {@inheritDoc} Cryptography based. */ | ||||||
@Override | ||||||
public String getTech() { | ||||||
return ChallengeTechnology.Tech.CRYPTOGRAPHY.id; | ||||||
} | ||||||
|
||||||
@Override | ||||||
public boolean isLimitedWhenOnlineHosted() { | ||||||
return false; | ||||||
} | ||||||
|
||||||
@Override | ||||||
public List<RuntimeEnvironment.Environment> supportedRuntimeEnvironments() { | ||||||
return List.of(RuntimeEnvironment.Environment.DOCKER); | ||||||
} | ||||||
|
||||||
private String getSolution() { | ||||||
try { | ||||||
String config = resource.getContentAsString(Charset.defaultCharset()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am getting java.io.FileNotFoundException: class path resource [maven/settings/settings.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:211) ~[spring-core-6.0.12.jar:6.0.12]
at org.springframework.core.io.Resource.getContentAsString(Resource.java:165) ~[spring-core-6.0.12.jar:6.0.12] |
||||||
StringReader stringReader = new StringReader(config); | ||||||
|
||||||
XMLConfiguration xmlConfiguration = new XMLConfiguration(); | ||||||
xmlConfiguration.read(stringReader); | ||||||
|
||||||
// Retrieve the Nexus password | ||||||
return xmlConfiguration.getString("nexus.password"); | ||||||
Comment on lines
+76
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this gives quite a few different exceptions. Can we do it with the jdk based parser? DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
dbFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
Document doc = dBuilder.parse(Paths.get(filepath "settings.xml").toFile());
doc.getDocumentElement().normalize();
return doc.getDocumentElement().getElementsByTagName("servers").item(0).getChildNodes().item(0).getNextSibling().getChildNodes().item(4).getNextSibling().getTextContent(); or something among these lines. And can you remove the entry from the pom.xml ? |
||||||
} catch (Exception e) { | ||||||
log.warn("there was an exception with decrypting content in challenge42", e); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return "error_decryption"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,3 @@ | ||||||||
=== Nexus credential read | ||||||||
|
||||||||
Storing nexus deployment credentials in your github project hardcoded is generally considered a bad practice because it undermines the security provided by encryption. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
This challenge can be solved by decrypting the base64 encoded secret in `secrchallenge.json`. You can do this either by: | ||
|
||
1. Using an online aes decryption tool like https://www.devglan.com/online-tools/aes-encryption-decryption[https://www.devglan.com/online-tools/aes-encryption-decryption] | ||
- Copy the value of `secret` from `secrchallenge.json` and paste it into the textbox of the decryptor. | ||
- Ensure the input format is `Base64` and the cipher mode is `ECB`. | ||
- Use the value of `key` from `secrchallenge.json` as decryption key and click on `Decrypt` to get the secret. | ||
Comment on lines
+3
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this looks like a left-over from challenge41, can you remove this please? |
||
|
||
2. Using the terminal | ||
- Launch the terminal while you are in the `maven` directory. | ||
- Copy the value of `password` from `settings.xml`. |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,7 @@ | ||||||||||||||||||||||||||||
*Why you should not have nexus deployment credentials in your github project hardcoded* | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
Storing nexus deployment credentials in your github project hardcoded is generally considered a bad practice because it undermines the security provided by encryption. | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
In such scenarios, an attacker has the key the moment the file is in his possession. | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
It is always recommended to store your credentials securely. | ||||||||||||||||||||||||||||
Comment on lines
+3
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,41 @@ | ||||||||
package org.owasp.wrongsecrets.challenges.docker; | ||||||||
|
||||||||
import static org.mockito.Mockito.when; | ||||||||
|
||||||||
import java.io.IOException; | ||||||||
import java.nio.charset.Charset; | ||||||||
import org.assertj.core.api.Assertions; | ||||||||
import org.junit.jupiter.api.BeforeEach; | ||||||||
import org.junit.jupiter.api.Test; | ||||||||
import org.junit.jupiter.api.extension.ExtendWith; | ||||||||
import org.mockito.Mock; | ||||||||
import org.mockito.junit.jupiter.MockitoExtension; | ||||||||
import org.owasp.wrongsecrets.ScoreCard; | ||||||||
import org.springframework.core.io.Resource; | ||||||||
|
||||||||
@ExtendWith(MockitoExtension.class) | ||||||||
class Challenge42Test { | ||||||||
@Mock private ScoreCard scoreCard; | ||||||||
|
||||||||
@Mock private Resource resource; | ||||||||
|
||||||||
@BeforeEach | ||||||||
void setUp() throws IOException { | ||||||||
when(resource.getContentAsString(Charset.defaultCharset())) | ||||||||
.thenReturn( | ||||||||
"<root><nexus><username>test_user</username><password>test_password</password></nexus></root>"); | ||||||||
} | ||||||||
|
||||||||
@Test | ||||||||
void spoilerShouldGiveAnswer() { | ||||||||
var challenge = new Challenge42(scoreCard, resource); | ||||||||
Assertions.assertThat(challenge.spoiler().solution()).isNotEmpty(); | ||||||||
Assertions.assertThat(challenge.answerCorrect(challenge.spoiler().solution())).isTrue(); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
} | ||||||||
|
||||||||
@Test | ||||||||
void incorrectAnswerShouldNotSolveChallenge() { | ||||||||
var challenge = new Challenge42(scoreCard, resource); | ||||||||
Assertions.assertThat(challenge.answerCorrect("wrong answer")).isFalse(); | ||||||||
} | ||||||||
} |
Check failure
Code scanning / CodeQL
Failure to use HTTPS or SFTP URL in Maven artifact upload/download High