// Path: src/main/java/burp/HTTPMatcher.java
// public static String getApplicationContext(URL url) {
// 
//     String path = url.getPath();
//     int i = path.indexOf("/", 1);
//     String context = path.substring(0, i + 1);
// 
//     return context;
// }
// 
// Path: src/main/java/burp/HTTPMatcher.java
// public static String getApplicationContextAndNestedPath(URL url) {
// 
//     String path = url.getPath();
//     int i = path.lastIndexOf('/');
//     String context = path.substring(0, i + 1);
// 
//     return (StringUtils.countMatches(context, "/") == 3) ? context : "";
// }
// 
// Path: src/main/java/burp/HTTPMatcher.java
// public static List<int[]> getMatches(byte[] response, byte[] match, IExtensionHelpers helpers) {
//     List<int[]> matches = new ArrayList<int[]>();
// 
//     int start = 0;
//     while (start < response.length) {
//         start = helpers.indexOf(response, match, true, start, response.length);
//         if (start == -1) {
//             break;
//         }
//         matches.add(new int[]{start, start + match.length});
//         start += match.length;
//     }
// 
//     return matches;
// }
// 
// Path: src/main/java/burp/j2ee/CustomScanIssue.java
// public class CustomScanIssue implements IScanIssue {
// 
//     private IHttpService httpService;
//     private URL url;
//     private IHttpRequestResponse httpMessages;
//     private String name;
//     private String detail;
//     private Risk severity;
//     private String remedy;
//     private Confidence confidence = Confidence.Certain;
//     
//     public CustomScanIssue(
//             IHttpService httpService,
//             URL url,
//             IHttpRequestResponse httpMessages,
//             String name,
//             String detail,
//             String remedy,
//             Risk severity,
//             Confidence confidence) {
//         this.httpService = httpService;
//         this.url = url;
//         this.httpMessages = httpMessages;
//         this.name = "J2EEScan - " + name;
//         this.detail = detail;
//         this.remedy = remedy;
//         this.severity = severity;
//         this.confidence = confidence;
//     }      
//     
// 
//     @Override
//     public URL getUrl() {
//         return url;
//     }
// 
//     @Override
//     public String getIssueName() {
//         return name;
//     }
// 
//     @Override
//     public int getIssueType() {
//         return 0;
//     }
// 
//     @Override
//     public String getSeverity() {
//         return severity.toString();
//     }
// 
//     @Override
//     // "Certain", "Firm" or "Tentative"
//     public String getConfidence() {
//         return confidence.toString();
//     }
// 
//     @Override
//     public String getIssueBackground() {
//         return null;
//     }
// 
//     @Override
//     public String getRemediationBackground() {
//         return null;
//     }
// 
//     @Override
//     public String getIssueDetail() {
//         return detail;
//     }
// 
//     @Override
//     public String getRemediationDetail() {
//         return remedy;
//     }
// 
//     @Override
//     public IHttpRequestResponse[] getHttpMessages() {
//         return new IHttpRequestResponse[]{httpMessages};
//     }
// 
//     @Override
//     public IHttpService getHttpService() {
//         return httpService;
//     }
// 
// }


import burp.CustomHttpRequestResponse;
import static burp.HTTPMatcher.getApplicationContext;
import static burp.HTTPMatcher.getApplicationContextAndNestedPath;
import static burp.HTTPMatcher.getMatches;
import burp.IBurpExtenderCallbacks;
import burp.IExtensionHelpers;
import burp.IHttpRequestResponse;
import burp.IRequestInfo;
import burp.IResponseInfo;
import burp.IScanIssue;
import burp.IScannerInsertionPoint;
import burp.j2ee.Confidence;
import burp.j2ee.CustomScanIssue;
import burp.j2ee.Risk;
import burp.j2ee.issues.IModule;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
                                if (responseHeaders.get(h).toLowerCase().startsWith("www-authenticate")
                                        && responseHeaders.get(h).toLowerCase().contains("tomcat manager")) {

                                    issues.add(new CustomScanIssue(
                                            baseRequestResponse.getHttpService(),
                                            urlToTest,
                                            new CustomHttpRequestResponse(uriNormalizationAttempt, responseBytes, baseRequestResponse.getHttpService()),
                                            TITLE,
                                            DESCRIPTION,
                                            REMEDY,
                                            Risk.High,
                                            Confidence.Certain
                                    ));

                                }
                            }
                        }

                        // URI Normalization test case successful but the Application server replies with:
                        // - /manager/html -> 403 Forbidden
                        // - / -> default apache tomcat page
                        // 
                        // The vulnerability is detected but the business impact is usually lower, if it's not 
                        // possible to access directly to the Tomcat Manager Console
                        
                        final byte[] GREP_STRING = "Apache Tomcat".getBytes();

                        // look for matches of our active check grep string
                        List<int[]> matches = getMatches(responseBytes, GREP_STRING, helpers);
                        if ((matches.size() > 0) && (tomcatManagerInfo.getStatusCode() == 200)) {
// Path: src/main/java/burp/HTTPMatcher.java
// public static String getApplicationContext(URL url) {
// 
//     String path = url.getPath();
//     int i = path.indexOf("/", 1);
//     String context = path.substring(0, i + 1);
// 
//     return context;
// }
// 
// Path: src/main/java/burp/HTTPMatcher.java
// public static String getApplicationContextAndNestedPath(URL url) {
// 
//     String path = url.getPath();
//     int i = path.lastIndexOf('/');
//     String context = path.substring(0, i + 1);
// 
//     return (StringUtils.countMatches(context, "/") == 3) ? context : "";
// }
// 
// Path: src/main/java/burp/HTTPMatcher.java
// public static List<int[]> getMatches(byte[] response, byte[] match, IExtensionHelpers helpers) {
//     List<int[]> matches = new ArrayList<int[]>();
// 
//     int start = 0;
//     while (start < response.length) {
//         start = helpers.indexOf(response, match, true, start, response.length);
//         if (start == -1) {
//             break;
//         }
//         matches.add(new int[]{start, start + match.length});
//         start += match.length;
//     }
// 
//     return matches;
// }
// 
// Path: src/main/java/burp/j2ee/CustomScanIssue.java
// public class CustomScanIssue implements IScanIssue {
// 
//     private IHttpService httpService;
//     private URL url;
//     private IHttpRequestResponse httpMessages;
//     private String name;
//     private String detail;
//     private Risk severity;
//     private String remedy;
//     private Confidence confidence = Confidence.Certain;
//     
//     public CustomScanIssue(
//             IHttpService httpService,
//             URL url,
//             IHttpRequestResponse httpMessages,
//             String name,
//             String detail,
//             String remedy,
//             Risk severity,
//             Confidence confidence) {
//         this.httpService = httpService;
//         this.url = url;
//         this.httpMessages = httpMessages;
//         this.name = "J2EEScan - " + name;
//         this.detail = detail;
//         this.remedy = remedy;
//         this.severity = severity;
//         this.confidence = confidence;
//     }      
//     
// 
//     @Override
//     public URL getUrl() {
//         return url;
//     }
// 
//     @Override
//     public String getIssueName() {
//         return name;
//     }
// 
//     @Override
//     public int getIssueType() {
//         return 0;
//     }
// 
//     @Override
//     public String getSeverity() {
//         return severity.toString();
//     }
// 
//     @Override
//     // "Certain", "Firm" or "Tentative"
//     public String getConfidence() {
//         return confidence.toString();
//     }
// 
//     @Override
//     public String getIssueBackground() {
//         return null;
//     }
// 
//     @Override
//     public String getRemediationBackground() {
//         return null;
//     }
// 
//     @Override
//     public String getIssueDetail() {
//         return detail;
//     }
// 
//     @Override
//     public String getRemediationDetail() {
//         return remedy;
//     }
// 
//     @Override
//     public IHttpRequestResponse[] getHttpMessages() {
//         return new IHttpRequestResponse[]{httpMessages};
//     }
// 
//     @Override
//     public IHttpService getHttpService() {
//         return httpService;
//     }
// 
// }


// Path: src/main/java/burp/j2ee/issues/impl/URINormalizationTomcat.java
import burp.CustomHttpRequestResponse;
import static burp.HTTPMatcher.getApplicationContext;
import static burp.HTTPMatcher.getApplicationContextAndNestedPath;
import static burp.HTTPMatcher.getMatches;
import burp.IBurpExtenderCallbacks;
import burp.IExtensionHelpers;
import burp.IHttpRequestResponse;
import burp.IRequestInfo;
import burp.IResponseInfo;
import burp.IScanIssue;
import burp.IScannerInsertionPoint;
import burp.j2ee.Confidence;
import burp.j2ee.CustomScanIssue;
import burp.j2ee.Risk;
import burp.j2ee.issues.IModule;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;

                                if (responseHeaders.get(h).toLowerCase().startsWith("www-authenticate")
                                        && responseHeaders.get(h).toLowerCase().contains("tomcat manager")) {

                                    issues.add(new CustomScanIssue(
                                            baseRequestResponse.getHttpService(),
                                            urlToTest,
                                            new CustomHttpRequestResponse(uriNormalizationAttempt, responseBytes, baseRequestResponse.getHttpService()),
                                            TITLE,
                                            DESCRIPTION,
                                            REMEDY,
                                            Risk.High,
                                            Confidence.Certain
                                    ));

                                }
                            }
                        }

                        // URI Normalization test case successful but the Application server replies with:
                        // - /manager/html -> 403 Forbidden
                        // - / -> default apache tomcat page
                        // 
                        // The vulnerability is detected but the business impact is usually lower, if it's not 
                        // possible to access directly to the Tomcat Manager Console
                        
                        final byte[] GREP_STRING = "Apache Tomcat".getBytes();

                        // look for matches of our active check grep string
                        List<int[]> matches = getMatches(responseBytes, GREP_STRING, helpers);
                        if ((matches.size() > 0) && (tomcatManagerInfo.getStatusCode() == 200)) {
                            issues.add(new CustomScanIssue(