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.

4.8 KB
Raw Blame
package opensuite.dashboard;

import opensuite.core.Bytes;
import opensuite.core.HttpMessage;
import opensuite.core.HttpService;
import opensuite.core.LogEntry;
import opensuite.core.ScanTask;
import opensuite.core.Scope;
import opensuite.engine.SessionGuard;
import opensuite.testkit.Expect;
import opensuite.testkit.Harness;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * Tests what the Live crawl view leaves out and what its activity lists: a
 * page the scan refused to request is known by the scan's own limits, and
 * the latest requests are a numbered history, newest first.
 */
public final class LiveViewTest {

    public void run() {
        Harness.suite("Live crawl view");

        Harness.test("a table's counts sort as numbers", () -> {
            List<Object> col = new ArrayList<>(List.of(10, 2, "", 1, 16));
            col.sort(opensuite.ui.NumberSorter.NATURAL);
            Expect.equal(col.toString(), "[, 1, 2, 10, 16]", "a blank first, then 1, 2, 10: not 1, 10, 16, 2");
            List<Object> text = new ArrayList<>(List.of("200", "abc", "99", "1000"));
            text.sort(opensuite.ui.NumberSorter.NATURAL);
            Expect.equal(text.toString(), "[99, 200, 1000, abc]", "numbers written as text too, and text after them");
            javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel(new Object[][] {{10}, {2}, {1}}, new Object[] {"#"});
            opensuite.ui.NumberSorter<javax.swing.table.DefaultTableModel> sorter = new opensuite.ui.NumberSorter<>(m);
            sorter.setSortKeys(List.of(new javax.swing.RowSorter.SortKey(0, javax.swing.SortOrder.ASCENDING)));
            Expect.equal(m.getValueAt(sorter.convertRowIndexToModel(1), 0), 2, "an undeclared column in a real sorter: 2 is second, not 10");
        });

        Harness.test("a scan knows the addresses it refuses", () -> {
            ScanTask t = new ScanTask(ScanTask.Type.LIVE_ACTIVE, "Crawl of 127.0.0.1", "Crawl");
            Expect.isFalse(t.refuses("https://owasp.org/"), "nothing is refused before the limits are known");
            List<String> in = new ArrayList<>();
            for (String p : Scope.sitePrefixes(HttpService.parse("http://127.0.0.1:3000/"))) in.add(Scope.Rule.prefix(p, false).urlRegex());
            t.setReach(in, List.of(SessionGuard.logoutGuess("http://127.0.0.1:3000")));
            Expect.isFalse(t.refuses("http://127.0.0.1:3000/"), "the target");
            Expect.isFalse(t.refuses("http://127.0.0.1:3000/#/login"), "a page of a single-page application");
            Expect.isFalse(t.refuses("http://127.0.0.1:3000/rest/products/search?q=apple"), "with a query");
            Expect.isTrue(t.refuses("https://owasp.org/"), "another site");
            Expect.isTrue(t.refuses("http://127.0.0.1:4200/"), "another port of the host");
            Expect.isTrue(t.refuses("http://127.0.0.1:3000/user/logout"), "a page the logout rule leaves out");
            Expect.isTrue(t.refuses("http://127.0.0.1:3000/user/logout?next=/"), "with a query too");
            Expect.isFalse(t.refuses("about:blank"), "not an address of the web: left to be shown as before");
            t.bar("http://127\\.0\\.0\\.1:3000/shop/.*");
            Expect.isTrue(t.refuses("http://127.0.0.1:3000/shop/a/b/a/b"), "a pattern added while the scan runs");
        });

        Harness.test("the latest requests are a numbered history, newest first", () -> {
            HttpService svc = HttpService.parse("http://127.0.0.1:3000/");
            List<LogEntry> newest = new ArrayList<>();
            for (int i = 0; i < 40; i++)
                newest.add(0, new LogEntry("audit", svc, new HttpMessage(Bytes.bytes(
                        "GET /p" + i + " HTTP/1.1\r\nHost: 127.0.0.1:3000\r\n" + (i % 2 == 0 ? "Cookie: sid=1\r\n" : "") + "\r\n"))));
            CrawlGraph.LatestModel m = new CrawlGraph.LatestModel();
            Expect.isTrue(m.set(newest, Set.of("cookie")), "new rows are taken");
            Expect.equal(m.getRowCount(), 40, "all of them, to scroll through");
            Expect.equal(m.getColumnName(0), "#", "numbered as the other histories are");
            Expect.isTrue((Integer) m.getValueAt(0, 0) > (Integer) m.getValueAt(1, 0), "the highest number at the top");
            Expect.equal(m.getValueAt(0, 3), "http://127.0.0.1:3000/p39", "the newest request first");
            Expect.equal(m.getValueAt(39, 3), "http://127.0.0.1:3000/p0", "the oldest last");
            Expect.equal(m.getValueAt(1, 5), "Sent", "a request that carried the session");
            Expect.equal(m.getValueAt(0, 5), "Not sent", "and one that did not");
            Expect.isFalse(m.set(new ArrayList<>(newest), Set.of("cookie")), "the same rows again change nothing");
            Expect.equal(m.getValueAt(99, 0), "", "a row that is not there");
        });
    }
}