// Path: src/main/java/burp/j2ee/PassiveScanner.java
// public class PassiveScanner {
// 
//     /**
//      * List of passive rules
//      */
//     static PassiveRule[] PASSIVE_RULES = {new ApacheTomcatRule(), 
//         new ExceptionRule(), 
//         new HttpServerHeaderRule(), 
//         new SqlQueryRule(),
//         new ApacheStrutsS2023Rule(),
//         new JettyRule(),
//         new SessionIDInURL(),
//         new JSPostMessage(),
//         new SessionFixation(),
//         new LiferayRule()
//     };
// 
//     public static void scanVulnerabilities(IHttpRequestResponse baseRequestResponse,
//                                            IBurpExtenderCallbacks callbacks) {
// 
//         IExtensionHelpers helpers = callbacks.getHelpers();
// 
//         byte[] rawRequest = baseRequestResponse.getRequest();
//         byte[] rawResponse = baseRequestResponse.getResponse();
// 
//         IRequestInfo reqInfo = helpers.analyzeRequest(baseRequestResponse);
//         IResponseInfo respInfo = helpers.analyzeResponse(rawResponse);
// 
//         //Body (without the headers)
//         String reqBody = getBodySection(rawRequest, reqInfo.getBodyOffset());
//         String respBody = getBodySection(rawResponse, respInfo.getBodyOffset());
// 
//         String httpServerHeader = HTTPParser.getResponseHeaderValue(respInfo, "Server");
//         String contentTypeResponse = HTTPParser.getResponseHeaderValue(respInfo, "Content-Type");
//         String xPoweredByHeader = HTTPParser.getResponseHeaderValue(respInfo, "X-Powered-By");
// 
//         for(PassiveRule scanner : PASSIVE_RULES) {
//             scanner.scan(callbacks,baseRequestResponse,reqBody,respBody,reqInfo,respInfo,
//                     httpServerHeader,contentTypeResponse, xPoweredByHeader);
//         }
// 
//     }
// 
// 
//     private static String getBodySection(byte[] respBytes, int bodyOffset) {
//         return new String(respBytes, bodyOffset, respBytes.length - bodyOffset);
//     }
// }


import burp.j2ee.PassiveScanner;
import burp.j2ee.annotation.RunOnlyOnce;
import burp.j2ee.issues.IModule;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLDecoder;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
        try {

            j2eeDBState = File.createTempFile("burpsuite-j2eescan-state", ".db");
            stdout.println("Using temporary db state file: " + j2eeDBState.getAbsolutePath());
            stdout.println("This internal state is used to avoid duplicate infrastructure security "
                    + "checks on the same host, improving the scan performance");

            connectToDatabase(j2eeDBState.getAbsolutePath());

        } catch (IOException ex) {
            stderr.println(ex);
        } catch (SQLException ex) {
            stderr.println(ex);
        } catch (ClassNotFoundException ex) {
            stderr.println(ex);
        }

        alreadyExecutedModule = new HashSet<>();

        // register ourselves as a custom scanner check
        callbacks.registerScannerCheck(this);
    }

    //
    // implement IScannerCheck
    //
    @Override
    public List<IScanIssue> doPassiveScan(IHttpRequestResponse baseRequestResponse) {
        List<IScanIssue> issues = new ArrayList<>();

// Path: src/main/java/burp/j2ee/PassiveScanner.java
// public class PassiveScanner {
// 
//     /**
//      * List of passive rules
//      */
//     static PassiveRule[] PASSIVE_RULES = {new ApacheTomcatRule(), 
//         new ExceptionRule(), 
//         new HttpServerHeaderRule(), 
//         new SqlQueryRule(),
//         new ApacheStrutsS2023Rule(),
//         new JettyRule(),
//         new SessionIDInURL(),
//         new JSPostMessage(),
//         new SessionFixation(),
//         new LiferayRule()
//     };
// 
//     public static void scanVulnerabilities(IHttpRequestResponse baseRequestResponse,
//                                            IBurpExtenderCallbacks callbacks) {
// 
//         IExtensionHelpers helpers = callbacks.getHelpers();
// 
//         byte[] rawRequest = baseRequestResponse.getRequest();
//         byte[] rawResponse = baseRequestResponse.getResponse();
// 
//         IRequestInfo reqInfo = helpers.analyzeRequest(baseRequestResponse);
//         IResponseInfo respInfo = helpers.analyzeResponse(rawResponse);
// 
//         //Body (without the headers)
//         String reqBody = getBodySection(rawRequest, reqInfo.getBodyOffset());
//         String respBody = getBodySection(rawResponse, respInfo.getBodyOffset());
// 
//         String httpServerHeader = HTTPParser.getResponseHeaderValue(respInfo, "Server");
//         String contentTypeResponse = HTTPParser.getResponseHeaderValue(respInfo, "Content-Type");
//         String xPoweredByHeader = HTTPParser.getResponseHeaderValue(respInfo, "X-Powered-By");
// 
//         for(PassiveRule scanner : PASSIVE_RULES) {
//             scanner.scan(callbacks,baseRequestResponse,reqBody,respBody,reqInfo,respInfo,
//                     httpServerHeader,contentTypeResponse, xPoweredByHeader);
//         }
// 
//     }
// 
// 
//     private static String getBodySection(byte[] respBytes, int bodyOffset) {
//         return new String(respBytes, bodyOffset, respBytes.length - bodyOffset);
//     }
// }


// Path: src/main/java/burp/BurpExtender.java
import burp.j2ee.PassiveScanner;
import burp.j2ee.annotation.RunOnlyOnce;
import burp.j2ee.issues.IModule;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLDecoder;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

        try {

            j2eeDBState = File.createTempFile("burpsuite-j2eescan-state", ".db");
            stdout.println("Using temporary db state file: " + j2eeDBState.getAbsolutePath());
            stdout.println("This internal state is used to avoid duplicate infrastructure security "
                    + "checks on the same host, improving the scan performance");

            connectToDatabase(j2eeDBState.getAbsolutePath());

        } catch (IOException ex) {
            stderr.println(ex);
        } catch (SQLException ex) {
            stderr.println(ex);
        } catch (ClassNotFoundException ex) {
            stderr.println(ex);
        }

        alreadyExecutedModule = new HashSet<>();

        // register ourselves as a custom scanner check
        callbacks.registerScannerCheck(this);
    }

    //
    // implement IScannerCheck
    //
    @Override
    public List<IScanIssue> doPassiveScan(IHttpRequestResponse baseRequestResponse) {
        List<IScanIssue> issues = new ArrayList<>();

        PassiveScanner.scanVulnerabilities(baseRequestResponse, callbacks);