@@ -48,6 +48,12 @@ public class ApplicationModuleImpl extends SinkModuleBase implements Application
48
48
"org.springframework.web.servlet.DispatcherServlet" ;
49
49
private static final String DEFAULT_HTML_ESCAPE = "defaultHtmlEscape" ;
50
50
private static final String LISTINGS_PATTERN = "<param-name>listings</param-name>" ;
51
+ private static final String JETTY_LISTINGS_PATTERN = "<param-name>dirAllowed</param-name>" ;
52
+ private static final String WEBLOGIC_LISTING_PATTERN =
53
+ "<index-directory-enabled>true</index-directory-enabled>" ;
54
+ private static final String WEBSPHERE_XMI_LISTING_PATTERN = "directoryBrowsingEnabled=\" true\" " ;
55
+ private static final String WEBSPHERE_XML_LISTING_PATTERN =
56
+ "<enable-directory-browsing value=\" true\" />" ;
51
57
private static final String SESSION_TIMEOUT_START_TAG = "<session-timeout>" ;
52
58
private static final String SESSION_TIMEOUT_END_TAG = "</session-timeout>" ;
53
59
private static final String SECURITY_CONSTRAINT_START_TAG = "<security-constraint>" ;
@@ -64,6 +70,9 @@ public class ApplicationModuleImpl extends SinkModuleBase implements Application
64
70
DISPLAY_NAME_START_TAG + TOMCAT_HOST_MANAGER_APP + DISPLAY_NAME_END_TAG ;
65
71
public static final String WEB_INF = "WEB-INF" ;
66
72
public static final String WEB_XML = "web.xml" ;
73
+ public static final String WEBLOGIC_XML = "weblogic.xml" ;
74
+ public static final String IBM_WEB_EXT_XMI = "ibm-web-ext.xmi" ;
75
+ public static final String IBM_WEB_EXT_XML = "ibm-web-ext.xml" ;
67
76
static final String SESSION_REWRITING_EVIDENCE_VALUE = "Servlet URL Session Tracking Mode" ;
68
77
69
78
private static final Pattern PATTERN =
@@ -75,11 +84,21 @@ public class ApplicationModuleImpl extends SinkModuleBase implements Application
75
84
TOMCAT_MANAGER_APP_PATTERN ,
76
85
TOMCAT_HOST_MANAGER_APP_PATTERN ,
77
86
LISTINGS_PATTERN ,
87
+ JETTY_LISTINGS_PATTERN ,
78
88
SESSION_TIMEOUT_START_TAG ,
79
89
SECURITY_CONSTRAINT_START_TAG )
80
90
.map (Pattern ::quote )
81
91
.collect (Collectors .joining ("|" )));
82
92
93
+ private static final Pattern WEBLOGIC_PATTERN =
94
+ Pattern .compile (WEBLOGIC_LISTING_PATTERN , Pattern .CASE_INSENSITIVE );
95
+
96
+ private static final Pattern WEBSPHERE_XMI_PATTERN =
97
+ Pattern .compile (WEBSPHERE_XMI_LISTING_PATTERN , Pattern .CASE_INSENSITIVE );
98
+
99
+ private static final Pattern WEBSPHERE_XML_PATTERN =
100
+ Pattern .compile (WEBSPHERE_XML_LISTING_PATTERN , Pattern .CASE_INSENSITIVE );
101
+
83
102
private static final int NO_LINE = -1 ;
84
103
85
104
public ApplicationModuleImpl (final Dependencies dependencies ) {
@@ -103,6 +122,10 @@ public void onRealPath(final @Nullable String realPath) {
103
122
final AgentSpan span = AgentTracer .activeSpan ();
104
123
checkInsecureJSPLayout (root , span );
105
124
checkWebXmlVulnerabilities (root , span );
125
+ // WEBLOGIC
126
+ checkWeblogicVulnerabilities (root , span );
127
+ // WEBSPHERE
128
+ checkWebsphereVulnerabilities (root , span );
106
129
}
107
130
108
131
/**
@@ -125,8 +148,46 @@ public void checkSessionTrackingModes(@Nonnull Set<String> sessionTrackingModes)
125
148
new Evidence (SESSION_REWRITING_EVIDENCE_VALUE )));
126
149
}
127
150
128
- private void checkWebXmlVulnerabilities (@ Nonnull Path path , AgentSpan span ) {
129
- String webXmlContent = webXmlContent (path );
151
+ private void checkWebsphereVulnerabilities (@ Nonnull final Path path , final AgentSpan span ) {
152
+ checkWebsphereXMLVulnerabilities (path , span );
153
+ checkWebsphereXMIVulnerabilities (path , span );
154
+ }
155
+
156
+ private void checkWebsphereXMIVulnerabilities (@ Nonnull final Path path , final AgentSpan span ) {
157
+ String xmlContent = getXmlContent (path , IBM_WEB_EXT_XMI );
158
+ if (xmlContent == null ) {
159
+ return ;
160
+ }
161
+ Matcher matcher = WEBSPHERE_XMI_PATTERN .matcher (xmlContent );
162
+ while (matcher .find ()) {
163
+ reportDirectoryListingLeak (xmlContent , matcher .start (), span );
164
+ }
165
+ }
166
+
167
+ private void checkWebsphereXMLVulnerabilities (@ Nonnull final Path path , final AgentSpan span ) {
168
+ String xmlContent = getXmlContent (path , IBM_WEB_EXT_XML );
169
+ if (xmlContent == null ) {
170
+ return ;
171
+ }
172
+ Matcher matcher = WEBSPHERE_XML_PATTERN .matcher (xmlContent );
173
+ while (matcher .find ()) {
174
+ reportDirectoryListingLeak (xmlContent , matcher .start (), span );
175
+ }
176
+ }
177
+
178
+ private void checkWeblogicVulnerabilities (@ Nonnull final Path path , final AgentSpan span ) {
179
+ String xmlContent = getXmlContent (path , WEBLOGIC_XML );
180
+ if (xmlContent == null ) {
181
+ return ;
182
+ }
183
+ Matcher matcher = WEBLOGIC_PATTERN .matcher (xmlContent );
184
+ while (matcher .find ()) {
185
+ reportDirectoryListingLeak (xmlContent , matcher .start (), span );
186
+ }
187
+ }
188
+
189
+ private void checkWebXmlVulnerabilities (@ Nonnull final Path path , final AgentSpan span ) {
190
+ String webXmlContent = getXmlContent (path , WEB_XML );
130
191
if (webXmlContent == null ) {
131
192
return ;
132
193
}
@@ -152,6 +213,7 @@ private void checkWebXmlVulnerabilities(@Nonnull Path path, AgentSpan span) {
152
213
reportAdminConsoleActive (span , TOMCAT_HOST_MANAGER_APP );
153
214
break ;
154
215
case LISTINGS_PATTERN :
216
+ case JETTY_LISTINGS_PATTERN :
155
217
checkDirectoryListingLeak (webXmlContent , matcher .start (), span );
156
218
break ;
157
219
case SESSION_TIMEOUT_START_TAG :
@@ -211,14 +273,19 @@ private void checkDirectoryListingLeak(
211
273
int valueLast = webXmlContent .indexOf (PARAM_VALUE_END_TAG , valueIndex );
212
274
String data = substringTrim (webXmlContent , valueIndex , valueLast );
213
275
if (data .equalsIgnoreCase ("true" )) {
214
- report (
215
- span ,
216
- VulnerabilityType .DIRECTORY_LISTING_LEAK ,
217
- "Directory listings configured" ,
218
- getLine (webXmlContent , index ));
276
+ reportDirectoryListingLeak (webXmlContent , index , span );
219
277
}
220
278
}
221
279
280
+ private void reportDirectoryListingLeak (
281
+ final String webXmlContent , int index , final AgentSpan span ) {
282
+ report (
283
+ span ,
284
+ VulnerabilityType .DIRECTORY_LISTING_LEAK ,
285
+ "Directory listings configured" ,
286
+ getLine (webXmlContent , index ));
287
+ }
288
+
222
289
private void checkSessionTimeOut (final String webXmlContent , int index , final AgentSpan span ) {
223
290
try {
224
291
String innerText =
@@ -288,8 +355,8 @@ private static int getLine(String webXmlContent, int index) {
288
355
}
289
356
290
357
@ Nullable
291
- private static String webXmlContent (final Path realPath ) {
292
- Path path = realPath .resolve (WEB_INF ).resolve (WEB_XML );
358
+ private static String getXmlContent (final Path realPath , final String fileName ) {
359
+ Path path = realPath .resolve (WEB_INF ).resolve (fileName );
293
360
if (Files .exists (path )) {
294
361
try {
295
362
return new String (Files .readAllBytes (path ), StandardCharsets .UTF_8 );
0 commit comments