// Path: src/main/java/burp/HTTPMatcher.java
// public static Boolean isJavaApplicationByURL(URL url) {
// 
//     if (url == null) {
//         return false;
//     }
// 
//     String curExtension = "";
// 
//     int i = url.getPath().lastIndexOf('.');
//     if (i > 0) {
//         curExtension = url.getPath().substring(i + 1);
//     } else {
//         // If the path does not contain an extension
//         // fallback and return true to minimize false negatives on checks
//         return true;
//     }
// 
//     List notJ2EETechs = new ArrayList<>();
//     notJ2EETechs.add("php");
//     notJ2EETechs.add("asp");
//     notJ2EETechs.add("cgi");
//     notJ2EETechs.add("pl");
// 
//     return (!notJ2EETechs.contains(curExtension));
// 
// }
// 
// 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 static burp.HTTPMatcher.isJavaApplicationByURL;
import burp.IBurpExtenderCallbacks;
import burp.IExtensionHelpers;
import burp.IHttpRequestResponse;
import burp.IParameter;
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.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
package burp.j2ee.issues.impl;



public class ApacheStrutsS2017 implements IModule {

    private static final String TITLE = "Apache Struts S2-017 Injection - Arbitrary Redirect";
    private static final String DESCRIPTION = "J2EEscan identified an Arbitrary Redirect vulnerability;"
            + "the Struts 2 DefaultActionMapper supports a "
            + "method for short-circuit navigation state changes by prefixing "
            + "parameters with <i>action:</i> or <i>redirect:</i>, "
            + "followed by a desired navigational target expression. "
            + "This mechanism was intended to help with attaching navigational "
            + "information to buttons within forms.<br /><br />"
            + "In Struts 2 before 2.3.15.1 the information following <i>action:</i>, <i>redirect:</i> "
            + "or <i>redirectAction:</i> is not properly sanitized. "
            + "<br /><br />Since said information will be evaluated as OGNL expression"
            + " against the value stack, this introduces the possibility to inject "
            + "server side code.<br /><br />"
            + "<b>References</b>:<br /><br />"
            + "http://struts.apache.org/release/2.3.x/docs/s2-017.html<br />"
            + "http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2013-2248";
    private static final String REMEDY = "Update the remote Struts vulnerable library";

    private PrintWriter stderr;

    public List<IScanIssue> scan(IBurpExtenderCallbacks callbacks, IHttpRequestResponse baseRequestResponse, IScannerInsertionPoint insertionPoint) {

        IExtensionHelpers helpers = callbacks.getHelpers();
        stderr = new PrintWriter(callbacks.getStderr(), true);

        IRequestInfo reqInfo = callbacks.getHelpers().analyzeRequest(baseRequestResponse);
        URL curURL = reqInfo.getUrl();

        byte[] modifiedRawRequest = null;
        List<IScanIssue> issues = new ArrayList<>();

// Path: src/main/java/burp/HTTPMatcher.java
// public static Boolean isJavaApplicationByURL(URL url) {
// 
//     if (url == null) {
//         return false;
//     }
// 
//     String curExtension = "";
// 
//     int i = url.getPath().lastIndexOf('.');
//     if (i > 0) {
//         curExtension = url.getPath().substring(i + 1);
//     } else {
//         // If the path does not contain an extension
//         // fallback and return true to minimize false negatives on checks
//         return true;
//     }
// 
//     List notJ2EETechs = new ArrayList<>();
//     notJ2EETechs.add("php");
//     notJ2EETechs.add("asp");
//     notJ2EETechs.add("cgi");
//     notJ2EETechs.add("pl");
// 
//     return (!notJ2EETechs.contains(curExtension));
// 
// }
// 
// 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/ApacheStrutsS2017.java
import static burp.HTTPMatcher.isJavaApplicationByURL;
import burp.IBurpExtenderCallbacks;
import burp.IExtensionHelpers;
import burp.IHttpRequestResponse;
import burp.IParameter;
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.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

package burp.j2ee.issues.impl;



public class ApacheStrutsS2017 implements IModule {

    private static final String TITLE = "Apache Struts S2-017 Injection - Arbitrary Redirect";
    private static final String DESCRIPTION = "J2EEscan identified an Arbitrary Redirect vulnerability;"
            + "the Struts 2 DefaultActionMapper supports a "
            + "method for short-circuit navigation state changes by prefixing "
            + "parameters with <i>action:</i> or <i>redirect:</i>, "
            + "followed by a desired navigational target expression. "
            + "This mechanism was intended to help with attaching navigational "
            + "information to buttons within forms.<br /><br />"
            + "In Struts 2 before 2.3.15.1 the information following <i>action:</i>, <i>redirect:</i> "
            + "or <i>redirectAction:</i> is not properly sanitized. "
            + "<br /><br />Since said information will be evaluated as OGNL expression"
            + " against the value stack, this introduces the possibility to inject "
            + "server side code.<br /><br />"
            + "<b>References</b>:<br /><br />"
            + "http://struts.apache.org/release/2.3.x/docs/s2-017.html<br />"
            + "http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2013-2248";
    private static final String REMEDY = "Update the remote Struts vulnerable library";

    private PrintWriter stderr;

    public List<IScanIssue> scan(IBurpExtenderCallbacks callbacks, IHttpRequestResponse baseRequestResponse, IScannerInsertionPoint insertionPoint) {

        IExtensionHelpers helpers = callbacks.getHelpers();
        stderr = new PrintWriter(callbacks.getStderr(), true);

        IRequestInfo reqInfo = callbacks.getHelpers().analyzeRequest(baseRequestResponse);
        URL curURL = reqInfo.getUrl();

        byte[] modifiedRawRequest = null;
        List<IScanIssue> issues = new ArrayList<>();

        if (!isJavaApplicationByURL(curURL)) {