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.
Java application-securityappsecbug-bountyburp-alternativeburp-suitedasthttp-proxyinfosecintercepting-proxyjavaowaspowasp-zappenetration-testingpentestingsecuritysecurity-toolsvulnerability-scannerweb-application-securityweb-security
package opensuite.engine;
import opensuite.core.RuleProgress;
import opensuite.core.ScanTask;
import opensuite.gate.RuleSteps;
import opensuite.testkit.Expect;
import opensuite.testkit.Harness;
import java.util.ArrayList;
import java.util.List;
/** An audit's figures for each address come from what the engine did there, and from nothing else. */
public final class RuleProgressTest {
private static final String SITE = "http://shop.test:8080";
private static String rule(int id, String kind, String state, boolean skipped, boolean missed, String name) {
return SITE + "\t" + id + "\t" + kind + "\t" + state + "\t" + (skipped ? 1 : 0) + "\t" + (missed ? 1 : 0) + "\t" + name;
}
/** What the add-on answers, as Open Suite reads it. */
private static ZapApi.RuleSteps answer(RuleSteps kept, String rules, int after, int names, int addresses, int most) {
RuleSteps.Batch b = kept.after(after, names, addresses, most);
return new ZapApi.RuleSteps(rules, b.steps(), b.names(), b.addresses(), b.next(), b.more());
}
public void run() {
Harness.suite("RuleProgress");
Harness.test("the engine's progress line is read as a rule and an address", () -> {
String[] got = RuleSteps.parse("Path Traversal: http://shop.test:8080/basket?id=7#top");
Expect.equal(got[0], "Path Traversal", "the rule");
Expect.equal(got[1], "http://shop.test:8080/basket", "the address, without query or fragment");
Expect.equal(RuleSteps.parse("SQL Injection - MySQL: https://shop.test/a")[0], "SQL Injection - MySQL", "a name with a dash");
Expect.isTrue(RuleSteps.parse("host process finished") == null, "another line is no step");
Expect.isTrue(RuleSteps.parse(null) == null, "nothing is no step");
});
Harness.test("an address has the rules started on it, out of those that apply", () -> {
RuleSteps kept = new RuleSteps();
kept.started("Path Traversal", SITE + "/");
kept.started("Path Traversal", SITE + "/basket");
kept.started("SQL Injection", SITE + "/");
String rules = String.join("\n",
rule(6, "A", "C", false, false, "Path Traversal"),
rule(40018, "A", "R", false, false, "SQL Injection"),
rule(40012, "A", "P", false, false, "Cross Site Scripting (Reflected)"),
rule(20015, "H", "P", false, false, "Heartbleed OpenSSL Vulnerability"),
rule(90019, "A", "C", true, false, "Server Side Code Injection"));
RuleProgress p = new RuleProgress();
RuleFeed.take(answer(kept, rules, 0, 0, 0, 1000), new ArrayList<>(), new ArrayList<>(), p);
Expect.equal(p.count(SITE + "/").percent(), 66, "shown as a rough percentage");
Expect.equal(new RuleProgress.Count(0, 0).percent(), 0, "nothing applies: no division by nothing");
Expect.equal(new RuleProgress.Count(5, 3).percent(), 100, "never over the whole");
Expect.equal(p.count(SITE + "/").toString(), "2 of 3", "two started; the site rule and the skipped rule are not counted");
Expect.equal(p.count(SITE + "/basket?id=7").toString(), "1 of 3", "the same address with a query");
Expect.equal(p.waiting(SITE + "/basket"), List.of("SQL Injection", "Cross Site Scripting (Reflected)"), "what is still to run, in the engine's order");
Expect.isTrue(p.count("http://other.test/") == null, "a site whose rules are not known has no figure");
Expect.equal(p.skipped(SITE + "/"), List.of("Server Side Code Injection"), "the skipped rule is named");
Expect.equal(p.addresses(0), List.of(SITE + "/", SITE + "/basket"), "the addresses, in the order first started");
Expect.isTrue(!p.count(SITE + "/").done(), "not done while a rule is still to start");
});
Harness.test("steps are taken in batches, each from where the last stopped", () -> {
RuleSteps kept = new RuleSteps();
for (int r = 0; r < 3; r++) for (int a = 0; a < 5; a++) kept.started("Rule " + r, SITE + "/page" + a);
String rules = String.join("\n", rule(1, "A", "C", false, false, "Rule 0"),
rule(2, "A", "C", false, false, "Rule 1"), rule(3, "A", "R", false, false, "Rule 2"));
RuleProgress p = new RuleProgress();
List<String> names = new ArrayList<>(), addresses = new ArrayList<>();
int next = 0, rounds = 0;
while (true) {
ZapApi.RuleSteps got = answer(kept, rules, next, names.size(), addresses.size(), 4);
next = RuleFeed.take(got, names, addresses, p);
rounds++;
if (!got.more()) break;
}
Expect.equal(rounds, 4, "15 steps, 4 at a time");
Expect.equal(next, 15, "every step taken");
for (int a = 0; a < 5; a++) Expect.equal(p.count(SITE + "/page" + a).toString(), "3 of 3", "page " + a);
Expect.equal(p.totals()[0], 5, "five addresses");
Expect.equal(p.totals()[1], 5, "all five with every rule started");
int before = p.version();
RuleFeed.take(answer(kept, rules, next, names.size(), addresses.size(), 4), names, addresses, p);
Expect.equal(p.version(), before, "nothing new changes nothing");
});
Harness.test("a rule whose first starts were not heard counts only once the engine reports it complete", () -> {
RuleProgress p = new RuleProgress();
p.started("Rule B", SITE + "/a");
p.rules(List.of(new RuleProgress.Rule(SITE, 1, "Rule A", false, 'R', false, true),
new RuleProgress.Rule(SITE, 2, "Rule B", false, 'R', false, false)));
Expect.equal(p.count(SITE + "/a").toString(), "1 of 2", "running and not heard: not counted");
p.rules(List.of(new RuleProgress.Rule(SITE, 1, "Rule A", false, 'C', false, true),
new RuleProgress.Rule(SITE, 2, "Rule B", false, 'C', false, false)));
Expect.equal(p.count(SITE + "/a").toString(), "2 of 2", "complete: counted");
});
Harness.test("addresses and sites are written one way", () -> {
Expect.equal(RuleProgress.key("HTTP://Shop.Test:80/Basket?x=1"), "http://shop.test/Basket", "the usual port is dropped, the path kept as it is");
Expect.equal(RuleProgress.key("https://shop.test:443"), "https://shop.test/", "no path is the root");
Expect.equal(RuleProgress.key("https://shop.test:8443/a#b"), "https://shop.test:8443/a", "another port stays");
Expect.equal(RuleProgress.site("https://shop.test/a"), "https://shop.test:443", "a site always has its port");
Expect.equal(RuleProgress.site("http://shop.test:8080"), "http://shop.test:8080", "as the engine writes it");
});
Harness.test("a full record says so, and its rules then count only when complete", () -> {
RuleSteps kept = new RuleSteps();
for (int i = 0; i < 1024; i++) kept.started("Rule " + i, SITE + "/");
Expect.isTrue(!kept.full(), "1024 rule names fit");
kept.started("One more", SITE + "/");
Expect.isTrue(kept.full(), "another does not");
Expect.equal(kept.count(), 1024, "and is not kept");
});
Harness.test("a task keeps its figures in a project", () -> {
ScanTask t = new ScanTask(ScanTask.Type.AUDIT, "t", "c");
t.rules().started("Rule A", SITE + "/a");
t.rules().started("Rule B", SITE + "/a");
t.rules().started("Rule A", SITE + "/b");
t.rules().rules(List.of(new RuleProgress.Rule(SITE, 1, "Rule A", false, 'C', false, false),
new RuleProgress.Rule(SITE, 2, "Rule B", false, 'R', false, false),
new RuleProgress.Rule(SITE, 3, "Site rule", true, 'P', false, false)));
ScanTask back = ScanTask.fromSnapshot(t.snapshot());
Expect.equal(back.rules().count(SITE + "/a").toString(), "2 of 2", "the first address");
Expect.equal(back.rules().count(SITE + "/b").toString(), "1 of 2", "the second");
Expect.equal(back.rules().waiting(SITE + "/b"), List.of("Rule B"), "and what it was waiting for");
Expect.isTrue(!new ScanTask(ScanTask.Type.AUDIT, "u", "c").rules().known(), "a task with no audit has none");
Expect.isTrue(!ScanTask.fromSnapshot(new ScanTask(ScanTask.Type.AUDIT, "v", "c").snapshot()).rules().known(), "and none after a project");
});
}
}