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.2 KB
Raw Blame
package opensuite.script;

import opensuite.core.Bytes;
import opensuite.core.HttpMessage;
import opensuite.core.HttpService;
import opensuite.script.api.Utilities;
import opensuite.testkit.Expect;
import opensuite.testkit.Harness;

import java.util.Map;
import javax.tools.ToolProvider;

/**
 * The sample custom actions Open Suite offers compile against the script API
 * as it is, and the re-signing sample signs what it says it signs.
 */
public final class SamplesTest {

    public void run() {
        Harness.suite("script samples");

        Harness.test("every bundled sample compiles", () -> {
            ScriptCompiler c = new ScriptCompiler(ToolProvider.getSystemJavaCompiler());
            Expect.isTrue(Samples.CUSTOM_ACTIONS.size() >= 4, "samples offered");
            for (Map.Entry<String, String> e : Samples.CUSTOM_ACTIONS.entrySet()) {
                Expect.equal(c.compileCustomAction(e.getValue()).errors(), java.util.List.of(), e.getKey());
                Expect.isTrue(e.getValue().startsWith("// void action(HttpRequestResponse requestResponse, Utilities utilities)"), "signature line in " + e.getKey());
            }
        });

        Harness.test("the HMAC sample signs the timestamp and the body", () -> {
            String raw = "POST /api HTTP/1.1\r\nHost: example.test\r\nContent-Length: 7\r\n\r\n{\"a\":1}";
            RunResult r = new ScriptEngine(ToolProvider.getSystemJavaCompiler(), 5000).runCustomAction(
                    Samples.CUSTOM_ACTIONS.get("Re-sign request (HMAC)"), new HttpService("example.test", 443, true),
                    new HttpMessage(Bytes.bytes(raw)), null, s -> { }, new java.util.concurrent.atomic.AtomicBoolean());
            Expect.equal(r.status(), RunResult.Status.OK, "status: " + r.error());
            HttpMessage signed = r.newRequest();
            String ts = signed.header("X-Timestamp");
            Expect.notNull(ts, "timestamp");
            Utilities u = new Utilities(s -> { });
            String want = u.hex(u.hmacSha256(u.bytes("change-me"), u.concat(u.bytes(ts), signed.body())));
            Expect.equal(signed.header("X-Signature"), want, "signature");
            Expect.equal(Bytes.str(signed.body()), "{\"a\":1}", "body unchanged");
        });
    }
}