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 preetkaran20@gmail.com
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+ }
0 commit comments