Repository navigation
Expand file tree
/
Copy pathOpenWebModules.java
More file actions
97 lines (91 loc) · 4.09 KB
/
Copy pathOpenWebModules.java
File metadata and controls
97 lines (91 loc) · 4.09 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
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 OpenWebModules extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final Logger log = LogManager.getLogger(OpenWebModules.class);
/**
* Control class used to open all Only Web Categories 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 servletName = "servlets.module.OpenWebModules";
String unsafeLevels;
// 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("&&& " + servletName + " &&&");
PrintWriter out = response.getWriter();
out.print(getServletInfo());
String htmlOutput;
HttpSession ses = request.getSession(true);
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";
}
log.debug("Unsafe Levels: " + unsafeLevels);
String ApplicationRoot = getServletContext().getRealPath("");
switch (unsafeLevels) {
case "enable":
Setter.openOnlyWebCategories(ApplicationRoot, 0);
Setter.openOnlyWebCategories(ApplicationRoot, 1);
XxeLesson.createXxeLessonSolutionFile();
XxeChallenge1.createXxeChallenge1SolutionFile();
htmlOutput =
"<p style='color:red'>[WARNING] Server is vulnerable. Unsafe levels open!<p><h3"
+ " class='title'>Only Web Levels Are Now Open (including unsafe"
+ " levels)</h3><p>All of the Security Shepherd Web Application Security levels"
+ " are now open! All other categories have been closed.</p>";
break;
case "disable":
Setter.closeAllModules(ApplicationRoot);
Setter.openOnlyWebCategories(ApplicationRoot, 0);
htmlOutput =
"<h3 class='title'>Only Web Levels Are Now Open</h3><p>All of the Security Shepherd"
+ " Web Application Security levels are now open! All other categories have"
+ " been closed.</p>";
break;
default:
Setter.openOnlyWebCategories(ApplicationRoot, 0);
htmlOutput =
"<h3 class='title'>Only Web Levels Are Now Open</h3><p>All of the Security Shepherd"
+ " Web Application Security levels are now open! All other categories have"
+ " been closed.</p>";
break;
}
} 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 " + servletName + " &&&");
}
}