Repository navigation
Expand file tree
/
Copy pathOpenAllModules.java
More file actions
100 lines (92 loc) · 4.13 KB
/
Copy pathOpenAllModules.java
File metadata and controls
100 lines (92 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package servlets.admin.moduleManagement;
import dbProcs.Setter;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import servlets.module.challenge.XxeChallenge1;
import servlets.module.lesson.XxeLesson;
import utils.ShepherdLogManager;
import utils.Validate;
public class OpenAllModules extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final String SERVLET_NAME = "servlets.module.OpenAllModules";
private static final Logger log = LogManager.getLogger(OpenAllModules.class);
/**
* Control class used to open all modules when called by an administrator
*
* @param request the HTTP request
* @param response the HTTP response
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String unsafeLevels;
String htmlOutput;
// Setting IpAddress To Log and taking header for original IP if forwarded from proxy
ShepherdLogManager.setRequestIp(request.getRemoteAddr(), request.getHeader("X-Forwarded-For"));
log.debug("&&& " + SERVLET_NAME + " &&&");
PrintWriter out = response.getWriter();
out.print(getServletInfo());
HttpSession ses = request.getSession(true);
if (request.getCookies() == null) {
log.warn("Cookies are null");
htmlOutput = "<img src=\"css/images/loggedOutSheep.jpg\" /><br/>";
} else {
Cookie tokenCookie = Validate.getToken(request.getCookies());
Object tokenParmeter = request.getParameter("csrfToken");
if (Validate.validateAdminSession(ses, tokenCookie, tokenParmeter)) {
ShepherdLogManager.setRequestIp(
request.getRemoteAddr(),
request.getHeader("X-Forwarded-For"),
ses.getAttribute("userName").toString());
if (Validate.validateTokens(tokenCookie, tokenParmeter)) {
unsafeLevels = request.getParameter("unsafeLevels");
if (unsafeLevels == null) {
unsafeLevels = "disable";
}
String ApplicationRoot = getServletContext().getRealPath("");
switch (unsafeLevels) {
case "enable":
Setter.openAllModules(ApplicationRoot, false);
Setter.openAllModules(ApplicationRoot, true);
XxeLesson.createXxeLessonSolutionFile();
XxeChallenge1.createXxeChallenge1SolutionFile();
htmlOutput =
"<p style='color:red'>[WARNING] Server is vulnerable. Unsafe levels open!<p><h3"
+ " class='title'>All Modules are Now Open (including unsafe"
+ " levels)</h3><p>All of the Security Shepherd levels are now open and"
+ " available for any user to access!</p>";
break;
case "disable":
Setter.closeAllModules(ApplicationRoot);
Setter.openAllModules(ApplicationRoot, false);
htmlOutput =
"<h3 class='title'>All Modules are Now Open</h3><p>All of the Security Shepherd"
+ " levels are now open and available for any user to access!</p>";
break;
default:
Setter.openAllModules(ApplicationRoot, false);
htmlOutput =
"<h3 class='title'>All Modules are Now Open</h3><p>All of the Security Shepherd"
+ " levels are now open and available for any user to access!</p>";
}
} else {
log.debug("CSRF Tokens did not match");
htmlOutput =
"<h3 class='title'>Error</h3><p>CSRF Tokens Did Not Match. Function Aborted</p>";
}
} else {
log.error("Invalid Session Detected");
htmlOutput = "<img src=\"css/images/loggedOutSheep.jpg\" /><br/>";
}
}
out.write(htmlOutput);
log.debug("&&& END " + SERVLET_NAME + " &&&");
}
}