Skip to content

Commit 21904c5

Browse files
author
Lyes
committed
New XSS Secure Level Added
1 parent 3d5cf8f commit 21904c5

File tree

6 files changed

+163
-0
lines changed

6 files changed

+163
-0
lines changed

.settings/org.eclipse.jdt.core.prefs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3+
org.eclipse.jdt.core.compiler.compliance=1.8
4+
org.eclipse.jdt.core.compiler.source=1.8

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"java.configuration.updateBuildConfiguration": "interactive"
3+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package org.sasanlabs.service.vulnerability.sampleVulnerability;
2+
3+
import org.sasanlabs.internal.utility.LevelConstants;
4+
import org.sasanlabs.internal.utility.Variant;
5+
import org.sasanlabs.internal.utility.annotations.AttackVector;
6+
import org.sasanlabs.internal.utility.annotations.VulnerableAppRequestMapping;
7+
import org.sasanlabs.internal.utility.annotations.VulnerableAppRestController;
8+
import org.sasanlabs.service.vulnerability.bean.GenericVulnerabilityResponseBean;
9+
import org.sasanlabs.vulnerability.types.VulnerabilityType;
10+
import org.springframework.http.ResponseEntity;
11+
import org.springframework.web.bind.annotation.RequestParam;
12+
13+
/**
14+
* This is a sample vulnerability for helping developers in adding a new Vulnerability for
15+
* VulnerableApp
16+
*
17+
* @author KSASAN [email protected]
18+
*/
19+
/**
20+
* {@code VulnerableAppRestController} annotation is similar to {@link
21+
* org.springframework.stereotype.Controller} Annotation
22+
*/
23+
@VulnerableAppRestController(
24+
/**
25+
* "descriptionLabel" parameter of annotation is i18n label stored in {@link
26+
* /VulnerableApp/src/main/resources/i18n/}. This descriptionLabel
27+
* will be shown in the UI as the description of the Vulnerability. It helps students to
28+
* learn about the vulnerability and can also include some of the useful references etc.
29+
*/
30+
descriptionLabel = "SAMPLE_VULNERABILITY",
31+
/**
32+
* "value" parameter of annotation is used to create the request mapping. e.g. for the below
33+
* parameter value, /VulnerableApp/SampleVulnerability will be created as URI Path.
34+
*/
35+
value = "SampleVulnerability")
36+
public class SampleVulnerability {
37+
38+
/**
39+
* {@code AttackVector} annotation is used to create the Hints section in the User Interface.
40+
* This annotation can be mentioned multiple times in case the same vulnerability level
41+
*/
42+
@AttackVector(
43+
/**
44+
* "vulnerabilityExposed" parameter is used to depict the Vulnerability exposed by the
45+
* level. For example say a level is exposing SQL_INJECTION.
46+
*/
47+
vulnerabilityExposed = VulnerabilityType.SAMPLE_VULNERABILITY,
48+
/**
49+
* "description" parameter of annotation is i18n label stored in {@link
50+
* /VulnerableApp/src/main/resources/i18n/}. This description
51+
* will be shown in the UI as hint to give some indication on how the level is handling
52+
* input to help user to crack the level.
53+
*/
54+
description = "SAMPLE_VULNERABILITY_USER_INPUT_HANDLING_INJECTION",
55+
56+
/**
57+
* "payload" parameter of annotation is i18n label stored in {@link
58+
* /VulnerableApp/src/main/resources/attackvectors/*.properties}. This payload will be
59+
* shown in UI to help users find/exploit the vulnerability
60+
*/
61+
payload = "NOT_APPLICABLE")
62+
/**
63+
* This annotation is similar to {@link RequestMapping} SpringBoot annotation. It will map the
64+
* endpoint to /VulnerableApp/SampleVulnerability/LEVEL_1 where LEVEL_1 is coming from the value
65+
* parameter.
66+
*/
67+
@VulnerableAppRequestMapping(
68+
/**
69+
* "value" parameter is used to map the level to URI path
70+
* /VulnerableApp/SampleVulnerability/${value}.
71+
*/
72+
value = LevelConstants.LEVEL_1,
73+
74+
/**
75+
* "htmlTemplate" is used to load the UI for the level for taking input from the user.
76+
* It points to files in directory
77+
* src/main/resource/static/templates/${VulnerabilityName} e.g.
78+
* src/main/resource/static/templates/SampleVulnerability as ${htmlTemplate}.js,
79+
* ${htmlTemplate}.css, ${htmlTemplate}.html. e.g. in this case it will be:
80+
* src/main/resource/static/templates/SampleVulnerability/LEVEL_1/SampleVulnerability_Level1.js
81+
* etc
82+
*
83+
* <p>CSS, JS and HTML are all loaded to render the UI.
84+
*/
85+
htmlTemplate = "LEVEL_1/SampleVulnerability")
86+
public GenericVulnerabilityResponseBean<String> sampleUnsecuredLevel(@RequestParam("name") String key) {
87+
/** Add Business logic here */
88+
return new GenericVulnerabilityResponseBean<>("Not Implemented", true);
89+
}
90+
91+
/** For secured level there is no need for {@link AttackVector} annotation. */
92+
@VulnerableAppRequestMapping(
93+
value = LevelConstants.LEVEL_2,
94+
95+
// Can reuse the same UI template in case it doesn't change between levels
96+
htmlTemplate = "LEVEL_1/SampleVulnerability",
97+
/**
98+
* "variant" parameter defines whether the level is secure or not and same is depicted
99+
* in the UI as a closed lock and open lock icon. Default value of the variant is
100+
* UNSECURE so in case a secure level is added, please add the variant as {@link
101+
* Variant#SECURE}
102+
*/
103+
variant = Variant.SECURE)
104+
public GenericVulnerabilityResponseBean<String> sampleSecuredLevel(@RequestParam("name") String key) {
105+
/** Add Business logic here */
106+
return new GenericVulnerabilityResponseBean<>("Not Implemented", true);
107+
}
108+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#SampleVulnerability {
2+
color: black;
3+
text-align: center;
4+
}
5+
6+
#fetchDetails {
7+
background: blueviolet;
8+
display: inline-block;
9+
padding: 8px 8px;
10+
margin: 10px;
11+
border: 2px solid transparent;
12+
border-radius: 3px;
13+
transition: 0.2s opacity;
14+
color: #FFF;
15+
font-size: 12px;
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<div id="SampleVulnerability">
2+
<div>
3+
<div id="level_info">
4+
This is a Sample Vulnerability. please add the UI components here.
5+
</div>
6+
<button id=fetchDetails>Click Here</button>
7+
<div id="response"></div>
8+
</div>
9+
</div>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function addingEventListenerToFetchData() {
2+
document
3+
.getElementById("fetchDetails")
4+
.addEventListener("click", function () {
5+
/**
6+
* getUrlForVulnerabilityLevel() method provides url to call the Vulnerability Level
7+
* of Sample Vulnerability.
8+
* e.g. /VulnerableApp/SampleVulnerability/LEVEL_1 for LEVEL_1
9+
*/
10+
let url = getUrlForVulnerabilityLevel();
11+
/**
12+
* doGetAjaxCall() method is used to do the ajax get call to the Vulnerability Level
13+
*/
14+
doGetAjaxCall(fetchDataCallback, url + "?name=dummyInput", true);
15+
});
16+
}
17+
// Used to register event on the button or any other component
18+
addingEventListenerToFetchData();
19+
20+
//Callback function to handle the response and render in the UI
21+
function fetchDataCallback(data) {
22+
document.getElementById("response").innerHTML = data.content;
23+
}

0 commit comments

Comments
 (0)