Skip to content

A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.

2.3 KB
Raw Blame
package opensuite.script;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

/** The sample custom actions offered by "Add samples", by name, in the order they are listed. */
public final class Samples {

    private Samples() {}

    private static final String SIGNATURE = "// void action(HttpRequestResponse requestResponse, Utilities utilities)\n";

    public static final Map<String, String> CUSTOM_ACTIONS;
    static {
        Map<String, String> m = new LinkedHashMap<>();
        m.put("Log status code", SIGNATURE
                + "// Shows the status code of the response.\n"
                + "if (requestResponse.hasResponse()) utilities.log(\"Status: \" + requestResponse.response().statusCode());\n"
                + "else utilities.log(\"No response yet\");\n");
        m.put("Copy response body", SIGNATURE
                + "// Puts the response body on the clipboard.\n"
                + "if (requestResponse.hasResponse()) {\n"
                + "    utilities.clipboard(requestResponse.response().bodyText());\n"
                + "    utilities.log(\"Copied \" + requestResponse.response().body().length + \" bytes\");\n"
                + "} else {\n"
                + "    utilities.log(\"No response yet\");\n"
                + "}\n");
        m.put("Set a header", SIGNATURE
                + "// Sets X-Custom on the request being edited. Nothing is sent until you send it.\n"
                + "requestResponse.setRequest(requestResponse.request().withHeader(\"X-Custom\", \"1\"));\n");
        m.put("Re-sign request (HMAC)", SIGNATURE
                + "// Re-sign the request: X-Timestamp, and X-Signature = hex(HMAC-SHA256(key, timestamp + body)).\n"
                + "// The key below is stored in this file in plain text.\n"
                + "byte[] key = utilities.bytes(\"change-me\");\n"
                + "String ts = String.valueOf(System.currentTimeMillis() / 1000);\n"
                + "HttpRequest r = requestResponse.request().withHeader(\"X-Timestamp\", ts);\n"
                + "r = r.withHeader(\"X-Signature\", utilities.hex(utilities.hmacSha256(key, utilities.concat(utilities.bytes(ts), r.body()))));\n"
                + "requestResponse.setRequest(r);\n"
                + "utilities.log(\"signed at \" + ts);\n");
        CUSTOM_ACTIONS = Collections.unmodifiableMap(m);
    }
}