@@ -48,6 +48,12 @@ public class ApplicationModuleImpl extends SinkModuleBase implements Application
4848 "org.springframework.web.servlet.DispatcherServlet" ;
4949 private static final String DEFAULT_HTML_ESCAPE = "defaultHtmlEscape" ;
5050 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\" />" ;
5157 private static final String SESSION_TIMEOUT_START_TAG = "<session-timeout>" ;
5258 private static final String SESSION_TIMEOUT_END_TAG = "</session-timeout>" ;
5359 private static final String SECURITY_CONSTRAINT_START_TAG = "<security-constraint>" ;
@@ -64,6 +70,9 @@ public class ApplicationModuleImpl extends SinkModuleBase implements Application
6470 DISPLAY_NAME_START_TAG + TOMCAT_HOST_MANAGER_APP + DISPLAY_NAME_END_TAG ;
6571 public static final String WEB_INF = "WEB-INF" ;
6672 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" ;
6776 static final String SESSION_REWRITING_EVIDENCE_VALUE = "Servlet URL Session Tracking Mode" ;
6877
6978 private static final Pattern PATTERN =
@@ -75,11 +84,21 @@ public class ApplicationModuleImpl extends SinkModuleBase implements Application
7584 TOMCAT_MANAGER_APP_PATTERN ,
7685 TOMCAT_HOST_MANAGER_APP_PATTERN ,
7786 LISTINGS_PATTERN ,
87+ JETTY_LISTINGS_PATTERN ,
7888 SESSION_TIMEOUT_START_TAG ,
7989 SECURITY_CONSTRAINT_START_TAG )
8090 .map (Pattern ::quote )
8191 .collect (Collectors .joining ("|" )));
8292
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+
83102 private static final int NO_LINE = -1 ;
84103
85104 public ApplicationModuleImpl (final Dependencies dependencies ) {
@@ -103,6 +122,10 @@ public void onRealPath(final @Nullable String realPath) {
103122 final AgentSpan span = AgentTracer .activeSpan ();
104123 checkInsecureJSPLayout (root , span );
105124 checkWebXmlVulnerabilities (root , span );
125+ // WEBLOGIC
126+ checkWeblogicVulnerabilities (root , span );
127+ // WEBSPHERE
128+ checkWebsphereVulnerabilities (root , span );
106129 }
107130
108131 /**
@@ -125,8 +148,46 @@ public void checkSessionTrackingModes(@Nonnull Set<String> sessionTrackingModes)
125148 new Evidence (SESSION_REWRITING_EVIDENCE_VALUE )));
126149 }
127150
151+ private void checkWebsphereVulnerabilities (@ Nonnull Path path , AgentSpan span ) {
152+ checkWebsphereXMLVulnerabilities (path , span );
153+ checkWebsphereXMIVulnerabilities (path , span );
154+ }
155+
156+ private void checkWebsphereXMIVulnerabilities (@ Nonnull Path path , 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 Path path , 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 Path path , 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+
128189 private void checkWebXmlVulnerabilities (@ Nonnull Path path , AgentSpan span ) {
129- String webXmlContent = webXmlContent (path );
190+ String webXmlContent = getXmlContent (path , WEB_XML );
130191 if (webXmlContent == null ) {
131192 return ;
132193 }
@@ -152,6 +213,7 @@ private void checkWebXmlVulnerabilities(@Nonnull Path path, AgentSpan span) {
152213 reportAdminConsoleActive (span , TOMCAT_HOST_MANAGER_APP );
153214 break ;
154215 case LISTINGS_PATTERN :
216+ case JETTY_LISTINGS_PATTERN :
155217 checkDirectoryListingLeak (webXmlContent , matcher .start (), span );
156218 break ;
157219 case SESSION_TIMEOUT_START_TAG :
@@ -211,14 +273,18 @@ private void checkDirectoryListingLeak(
211273 int valueLast = webXmlContent .indexOf (PARAM_VALUE_END_TAG , valueIndex );
212274 String data = substringTrim (webXmlContent , valueIndex , valueLast );
213275 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 );
219277 }
220278 }
221279
280+ private void reportDirectoryListingLeak (String webXmlContent , int index , AgentSpan span ) {
281+ report (
282+ span ,
283+ VulnerabilityType .DIRECTORY_LISTING_LEAK ,
284+ "Directory listings configured" ,
285+ getLine (webXmlContent , index ));
286+ }
287+
222288 private void checkSessionTimeOut (final String webXmlContent , int index , final AgentSpan span ) {
223289 try {
224290 String innerText =
@@ -288,8 +354,8 @@ private static int getLine(String webXmlContent, int index) {
288354 }
289355
290356 @ Nullable
291- private static String webXmlContent (final Path realPath ) {
292- Path path = realPath .resolve (WEB_INF ).resolve (WEB_XML );
357+ private static String getXmlContent (final Path realPath , final String fileName ) {
358+ Path path = realPath .resolve (WEB_INF ).resolve (fileName );
293359 if (Files .exists (path )) {
294360 try {
295361 return new String (Files .readAllBytes (path ), StandardCharsets .UTF_8 );
0 commit comments