Search in sources :

Example 1 with ScriptWrapper

use of org.zaproxy.zap.extension.script.ScriptWrapper in project zaproxy by zaproxy.

the class ScriptsPassiveScanner method scanHttpResponseReceive.

@Override
public void scanHttpResponseReceive(HttpMessage msg, int id, Source source) {
    if (this.getExtension() != null) {
        currentHRefId = id;
        List<ScriptWrapper> scripts = extension.getScripts(ExtensionPassiveScan.SCRIPT_TYPE_PASSIVE);
        for (ScriptWrapper script : scripts) {
            try {
                if (script.isEnabled()) {
                    PassiveScript s = extension.getInterface(script, PassiveScript.class);
                    if (s != null) {
                        s.scan(this, msg, source);
                    } else {
                        extension.handleFailedScriptInterface(script, Constant.messages.getString("pscan.scripts.interface.passive.error", script.getName()));
                    }
                }
            } catch (Exception e) {
                extension.handleScriptException(script, e);
            }
        }
    }
}
Also used : ScriptWrapper(org.zaproxy.zap.extension.script.ScriptWrapper) PassiveScript(org.zaproxy.zap.extension.pscan.PassiveScript)

Example 2 with ScriptWrapper

use of org.zaproxy.zap.extension.script.ScriptWrapper in project zaproxy by zaproxy.

the class ScriptsPassiveScannerUnitTest method shouldCreateScriptsCacheWithExpectedConfiguration.

@Test
@SuppressWarnings("unchecked")
void shouldCreateScriptsCacheWithExpectedConfiguration() {
    // Given / When
    new ScriptsPassiveScanner();
    // Then
    ArgumentCaptor<Configuration<PassiveScript>> argumentCaptor = ArgumentCaptor.forClass(Configuration.class);
    verify(extensionScript).createScriptsCache(argumentCaptor.capture());
    Configuration<PassiveScript> configuration = argumentCaptor.getValue();
    assertThat(configuration.getScriptType(), is(equalTo(SCRIPT_TYPE)));
    assertThat(configuration.getTargetInterface(), is(equalTo(TARGET_INTERFACE)));
    InterfaceErrorMessageProvider errorMessageProvider = configuration.getInterfaceErrorMessageProvider();
    assertThat(errorMessageProvider, is(not(nullValue())));
    ScriptWrapper scriptWrapper = mock(ScriptWrapper.class);
    given(scriptWrapper.getName()).willReturn("Name");
    assertThat(errorMessageProvider.getErrorMessage(scriptWrapper), is(not(nullValue())));
}
Also used : InterfaceErrorMessageProvider(org.zaproxy.zap.extension.script.ScriptsCache.InterfaceErrorMessageProvider) Configuration(org.zaproxy.zap.extension.script.ScriptsCache.Configuration) ScriptWrapper(org.zaproxy.zap.extension.script.ScriptWrapper) PassiveScript(org.zaproxy.zap.extension.pscan.PassiveScript) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

Example 3 with ScriptWrapper

use of org.zaproxy.zap.extension.script.ScriptWrapper in project zaproxy by zaproxy.

the class VariantFactory method createVariants.

public List<Variant> createVariants(ScannerParam scanOptions, HttpMessage message) {
    List<Variant> listVariant = new ArrayList<>();
    int targets = scanOptions.getTargetParamsInjectable();
    int enabledRPC = scanOptions.getTargetParamsEnabledRPC();
    // First check URL query-string target configuration
    if ((targets & ScannerParam.TARGET_QUERYSTRING) != 0) {
        VariantURLQuery vuq = new VariantURLQuery();
        vuq.setAddQueryParam(scanOptions.isAddQueryParam());
        listVariant.add(vuq);
        if ((enabledRPC & ScannerParam.RPC_ODATA) != 0) {
            listVariant.add(new VariantODataIdQuery());
            listVariant.add(new VariantODataFilterQuery());
        }
        if ((targets & ScannerParam.TARGET_URLPATH) == 0) {
            // If we're not already doing URLPath we should do DDN when doing QueryString
            listVariant.add(new VariantDdnPath());
        }
    }
    // Then check POST data target configuration and RPC enabled methods
    if ((targets & ScannerParam.TARGET_POSTDATA) != 0) {
        listVariant.add(new VariantFormQuery());
        if ((enabledRPC & ScannerParam.RPC_MULTIPART) != 0) {
            listVariant.add(new VariantMultipartFormParameters());
        }
        if ((enabledRPC & ScannerParam.RPC_XML) != 0) {
            listVariant.add(new VariantXMLQuery());
        }
        if ((enabledRPC & ScannerParam.RPC_JSON) != 0) {
            VariantJSONQuery variant = new VariantJSONQuery();
            variant.setScanNullValues(scanOptions.isScanNullJsonValues());
            listVariant.add(variant);
        }
        if ((enabledRPC & ScannerParam.RPC_GWT) != 0) {
            listVariant.add(new VariantGWTQuery());
        }
        if ((enabledRPC & ScannerParam.RPC_DWR) != 0) {
            listVariant.add(new VariantDirectWebRemotingQuery());
        }
    }
    if ((targets & ScannerParam.TARGET_HTTPHEADERS) != 0) {
        boolean addVariant = scanOptions.isScanHeadersAllRequests();
        if (!addVariant) {
            // If not scanning all requests check if it looks like a dynamic or static page
            // (based on query/post parameters)
            char[] query = message.getRequestHeader().getURI().getRawQuery();
            addVariant = (query != null && query.length != 0) || message.getRequestBody().length() != 0;
        }
        if (addVariant) {
            listVariant.add(new VariantHeader());
        }
    }
    if ((targets & ScannerParam.TARGET_URLPATH) != 0) {
        listVariant.add(new VariantURLPath());
    }
    if ((targets & ScannerParam.TARGET_COOKIE) != 0) {
        listVariant.add(new VariantCookie());
    }
    // Now is time to initialize all the custom Variants
    if ((enabledRPC & ScannerParam.RPC_CUSTOM) != 0 && getExtension() != null) {
        List<ScriptWrapper> scripts = getExtension().getScripts(ExtensionActiveScan.SCRIPT_TYPE_VARIANT);
        for (ScriptWrapper script : scripts) {
            if (script.isEnabled()) {
                listVariant.add(new VariantCustom(script, getExtension()));
            }
        }
    }
    if ((enabledRPC & ScannerParam.RPC_USERDEF) != 0) {
        listVariant.add(new VariantUserDefined());
    }
    addCustomVariants(listVariant);
    return listVariant;
}
Also used : VariantODataIdQuery(org.parosproxy.paros.core.scanner.VariantODataIdQuery) VariantJSONQuery(org.parosproxy.paros.core.scanner.VariantJSONQuery) VariantXMLQuery(org.parosproxy.paros.core.scanner.VariantXMLQuery) ArrayList(java.util.ArrayList) VariantURLPath(org.parosproxy.paros.core.scanner.VariantURLPath) VariantMultipartFormParameters(org.parosproxy.paros.core.scanner.VariantMultipartFormParameters) VariantGWTQuery(org.parosproxy.paros.core.scanner.VariantGWTQuery) VariantDirectWebRemotingQuery(org.parosproxy.paros.core.scanner.VariantDirectWebRemotingQuery) Variant(org.parosproxy.paros.core.scanner.Variant) VariantURLQuery(org.parosproxy.paros.core.scanner.VariantURLQuery) VariantFormQuery(org.parosproxy.paros.core.scanner.VariantFormQuery) VariantUserDefined(org.parosproxy.paros.core.scanner.VariantUserDefined) VariantHeader(org.parosproxy.paros.core.scanner.VariantHeader) VariantCookie(org.parosproxy.paros.core.scanner.VariantCookie) ScriptWrapper(org.zaproxy.zap.extension.script.ScriptWrapper) VariantDdnPath(org.parosproxy.paros.core.scanner.VariantDdnPath) VariantODataFilterQuery(org.parosproxy.paros.core.scanner.VariantODataFilterQuery) VariantCustom(org.parosproxy.paros.core.scanner.VariantCustom)

Example 4 with ScriptWrapper

use of org.zaproxy.zap.extension.script.ScriptWrapper in project zaproxy by zaproxy.

the class VariantCustomUnitTest method shouldReturnNullLeafNameWithDisabledScript.

@Test
void shouldReturnNullLeafNameWithDisabledScript() throws Exception {
    // Given
    ScriptWrapper scriptWrapper = mock(ScriptWrapper.class);
    given(scriptWrapper.isEnabled()).willReturn(false);
    String nodeName = "name";
    String expectedName = "newname";
    ExtensionScript extScript = mock(ExtensionScript.class);
    VariantScript variantScript = mock(VariantScript.class);
    given(extScript.getInterface(scriptWrapper, VariantScript.class)).willReturn(variantScript);
    VariantCustom variantCustom = new VariantCustom(scriptWrapper, extScript);
    HttpMessage msg = mock(HttpMessage.class);
    given(variantScript.getLeafName(variantCustom, nodeName, msg)).willReturn(expectedName);
    // When
    String name = variantCustom.getLeafName(nodeName, msg);
    // Then
    assertThat(name, is(equalTo(null)));
}
Also used : ExtensionScript(org.zaproxy.zap.extension.script.ExtensionScript) ScriptWrapper(org.zaproxy.zap.extension.script.ScriptWrapper) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test)

Example 5 with ScriptWrapper

use of org.zaproxy.zap.extension.script.ScriptWrapper in project zaproxy by zaproxy.

the class VariantCustomUnitTest method shouldReturnNullTreePathWithScriptException.

@Test
void shouldReturnNullTreePathWithScriptException() throws Exception {
    // Given
    ScriptWrapper scriptWrapper = mock(ScriptWrapper.class);
    String expectedPath = "newpath";
    List<String> list = new ArrayList<>();
    list.add(expectedPath);
    ExtensionScript extScript = mock(ExtensionScript.class);
    VariantScript variantScript = mock(VariantScript.class);
    given(extScript.getInterface(scriptWrapper, VariantScript.class)).willReturn(variantScript);
    VariantCustom variantCustom = new VariantCustom(scriptWrapper, extScript);
    HttpMessage msg = mock(HttpMessage.class);
    given(variantScript.getTreePath(variantCustom, msg)).willThrow(RuntimeException.class);
    // When
    List<String> path = variantCustom.getTreePath(msg);
    // Then
    assertThat(path, is(equalTo(null)));
}
Also used : ExtensionScript(org.zaproxy.zap.extension.script.ExtensionScript) ScriptWrapper(org.zaproxy.zap.extension.script.ScriptWrapper) ArrayList(java.util.ArrayList) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test)

Aggregations

ScriptWrapper (org.zaproxy.zap.extension.script.ScriptWrapper)25 Test (org.junit.jupiter.api.Test)16 WithConfigsTest (org.zaproxy.zap.WithConfigsTest)10 HttpMessage (org.parosproxy.paros.network.HttpMessage)7 ExtensionScript (org.zaproxy.zap.extension.script.ExtensionScript)7 ArrayList (java.util.ArrayList)4 ScriptException (javax.script.ScriptException)4 Variant (org.parosproxy.paros.core.scanner.Variant)4 NameValuePair (org.parosproxy.paros.core.scanner.NameValuePair)3 ScannerParam (org.parosproxy.paros.core.scanner.ScannerParam)3 ApiException (org.zaproxy.zap.extension.api.ApiException)3 Configuration (org.zaproxy.zap.extension.script.ScriptsCache.Configuration)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 JSONObject (net.sf.json.JSONObject)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 HttpException (org.apache.commons.httpclient.HttpException)2 DatabaseException (org.parosproxy.paros.db.DatabaseException)2 RecordContext (org.parosproxy.paros.db.RecordContext)2 ApiDynamicActionImplementor (org.zaproxy.zap.extension.api.ApiDynamicActionImplementor)2