// 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.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.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
            // Remove XML version, and append malicious DTD
            // <?xml version="1.0" encoding="UTF-8" standalone="no"?>
            body = body.replaceAll("<\\?xml(.+?)\\?>", "").trim();
            body = XXE_DTD_DEFINITION + body;
            // TODO FIX ME unwanted encoded payload inserted by burp
            body = body.replaceAll("&amp;xxe;", "&xxe;");
            
            byte[] evilMessage = callbacks.getHelpers().buildHttpMessage(a.getHeaders(), callbacks.getHelpers().stringToBytes(body));
            
            IHttpRequestResponse checkRequestResponse = callbacks.makeHttpRequest(
                    baseRequestResponse.getHttpService(), evilMessage);

            String response = helpers.bytesToString(checkRequestResponse.getResponse());

            // Check if the remote XML Library is not vulnerable based on java
            // xml library error message
            for (Pattern xxeFail : XXE_RE_FAIL){
                Matcher matcherXXEFail = xxeFail.matcher(response);
                if (matcherXXEFail.find()) {
                    stdout.println("Skipping XXE test, library seems to disallow XXE on url " + reqInfo.getUrl());
                    return issues;
                }
            }
            
            for (Pattern xxeMatcher : XXE_RE_MATCHES) {

                Matcher matcher = xxeMatcher.matcher(response);
                
                if (matcher.find()) {

// 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/XXEModule.java
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.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

            // Remove XML version, and append malicious DTD
            // <?xml version="1.0" encoding="UTF-8" standalone="no"?>
            body = body.replaceAll("<\\?xml(.+?)\\?>", "").trim();
            body = XXE_DTD_DEFINITION + body;
            // TODO FIX ME unwanted encoded payload inserted by burp
            body = body.replaceAll("&amp;xxe;", "&xxe;");
            
            byte[] evilMessage = callbacks.getHelpers().buildHttpMessage(a.getHeaders(), callbacks.getHelpers().stringToBytes(body));
            
            IHttpRequestResponse checkRequestResponse = callbacks.makeHttpRequest(
                    baseRequestResponse.getHttpService(), evilMessage);

            String response = helpers.bytesToString(checkRequestResponse.getResponse());

            // Check if the remote XML Library is not vulnerable based on java
            // xml library error message
            for (Pattern xxeFail : XXE_RE_FAIL){
                Matcher matcherXXEFail = xxeFail.matcher(response);
                if (matcherXXEFail.find()) {
                    stdout.println("Skipping XXE test, library seems to disallow XXE on url " + reqInfo.getUrl());
                    return issues;
                }
            }
            
            for (Pattern xxeMatcher : XXE_RE_MATCHES) {

                Matcher matcher = xxeMatcher.matcher(response);
                
                if (matcher.find()) {

                    issues.add(new CustomScanIssue(