Skip to content

Commit 050b551

Browse files
author
continuumsecurity
committed
Updated to zap 2.6.0
1 parent 964aa37 commit 050b551

File tree

5 files changed

+52
-5
lines changed

5 files changed

+52
-5
lines changed

src/main/java/net/continuumsecurity/proxy/LoggingProxy.java

+3
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,7 @@ When a match is found, return the entire HarEntry (request and response).
5353
Return the details of the proxy in Selenium format: org.openqa.selenium.Proxy
5454
*/
5555
Proxy getSeleniumProxy() throws UnknownHostException;
56+
57+
public void setAttackMode() throws ProxyException;
58+
5659
}

src/main/java/net/continuumsecurity/proxy/ZAProxyScanner.java

+28-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void setScannerAttackStrength(String scannerId, String strength) throws P
122122
clientApi.ascan.setScannerAttackStrength(scannerId, strength, null);
123123
} catch (ClientApiException e) {
124124
e.printStackTrace();
125-
throw new ProxyException("Error occurred for setScannerAttackStrength", e);
125+
throw new ProxyException("Error occurred for setScannerAttackStrength for scannerId: "+scannerId+" and strength: "+strength, e);
126126
}
127127
}
128128

@@ -350,7 +350,9 @@ public List<HarEntry> makeRequest(HarRequest request, boolean followRedirect)
350350
throws ProxyException {
351351
try {
352352
String harRequestStr = ClientApiUtils.convertHarRequestToString(request);
353-
return ClientApiUtils.getHarEntries(clientApi.core.sendHarRequest(harRequestStr, Boolean.toString(followRedirect)));
353+
byte[] response = clientApi.core.sendHarRequest(harRequestStr, Boolean.toString(followRedirect));
354+
String responseAsString = new String(response);
355+
return ClientApiUtils.getHarEntries(response);
354356
} catch (ClientApiException e) {
355357
e.printStackTrace();
356358

@@ -450,6 +452,16 @@ public void excludeFromScanner(String regex) {
450452
}
451453
}
452454

455+
@Override
456+
public void setAttackMode() throws ProxyException {
457+
try {
458+
clientApi.core.setMode("attack");
459+
} catch (ClientApiException e) {
460+
e.printStackTrace();
461+
throw new ProxyException(e);
462+
}
463+
}
464+
453465
@Override
454466
public void setMaxDepth(int depth) {
455467
try {
@@ -1610,6 +1622,20 @@ public void runStandAloneScript(String scriptName) throws ProxyException {
16101622
public void setIncludeInContext(String contextName, String regex) {
16111623
try {
16121624
clientApi.context.includeInContext(contextName, regex);
1625+
} catch (ClientApiException e) {
1626+
if ("does_not_exist".equalsIgnoreCase(e.getCode())) {
1627+
createContext(contextName);
1628+
setIncludeInContext(contextName, regex);
1629+
} else {
1630+
e.printStackTrace();
1631+
throw new ProxyException(e);
1632+
}
1633+
}
1634+
}
1635+
1636+
private void createContext(String contextName) {
1637+
try {
1638+
clientApi.context.newContext(contextName);
16131639
} catch (ClientApiException e) {
16141640
e.printStackTrace();
16151641
throw new ProxyException(e);

src/main/java/net/continuumsecurity/proxy/model/ScanInfo.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
package net.continuumsecurity.proxy.model;
22

3-
import org.zaproxy.clientapi.core.ApiResponseElement;
43
import org.zaproxy.clientapi.core.ApiResponseSet;
54

65
/**
76
* Created by stephen on 16/04/15.
87
*/
9-
public class ScanInfo {
8+
public class ScanInfo implements Comparable<ScanInfo> {
109
int progress;
1110
int id;
1211
State state;
1312

13+
@Override
14+
public int compareTo(ScanInfo o) {
15+
return id-o.getId();
16+
}
17+
1418
public enum State {
19+
NOT_STARTED,
1520
FINISHED,
1621
PAUSED,
1722
RUNNING;
1823

1924
public static State parse(String s) {
25+
if ("NOT_STARTED".equalsIgnoreCase(s)) return NOT_STARTED;
2026
if ("FINISHED".equalsIgnoreCase(s)) return FINISHED;
2127
if ("PAUSED".equalsIgnoreCase(s)) return PAUSED;
2228
if ("RUNNING".equalsIgnoreCase(s)) return RUNNING;

src/main/java/net/continuumsecurity/proxy/model/ScanResponse.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package net.continuumsecurity.proxy.model;
22

3-
import net.continuumsecurity.proxy.model.ScanInfo;
43
import org.zaproxy.clientapi.core.ApiResponse;
54
import org.zaproxy.clientapi.core.ApiResponseList;
65
import org.zaproxy.clientapi.core.ApiResponseSet;
76

87
import java.util.ArrayList;
8+
import java.util.Collections;
99
import java.util.List;
1010

1111
/**
@@ -18,6 +18,7 @@ public ScanResponse(ApiResponseList responseList) {
1818
for (ApiResponse rawResponse : responseList.getItems()) {
1919
scans.add(new ScanInfo((ApiResponseSet)rawResponse));
2020
}
21+
Collections.sort(scans);
2122
}
2223

2324
public List<ScanInfo> getScans() {
@@ -32,6 +33,7 @@ public ScanInfo getScanById(int scanId) {
3233
}
3334

3435
public ScanInfo getLastScan() {
36+
if (scans.size() == 0) throw new RuntimeException("No scans found");
3537
return scans.get(scans.size()-1);
3638
}
3739
}

src/test/java/net/continuumsecurity/proxy/SpiderTest.java

+10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package net.continuumsecurity.proxy;
22

3+
import net.continuumsecurity.proxy.model.Context;
34
import org.junit.BeforeClass;
45
import org.junit.Test;
56

67
import java.util.List;
78

9+
import static org.hamcrest.CoreMatchers.is;
810
import static org.hamcrest.MatcherAssert.assertThat;
11+
import static org.hamcrest.Matchers.notNullValue;
912
import static org.hamcrest.core.IsEqual.equalTo;
1013

1114
public class SpiderTest {
@@ -20,6 +23,13 @@ public static void configure() throws Exception {
2023
zaproxy = new ZAProxyScanner(HOST, PORT, "apisecret");
2124
}
2225

26+
@Test
27+
public void testIncludeInContextForNewContext() {
28+
final String MYCONTEXT = "My Special context";
29+
zaproxy.setIncludeInContext(MYCONTEXT, BASEURL.concat(".*"));
30+
Context context = zaproxy.getContextInfo(MYCONTEXT);
31+
assertThat(context.getId(),is(notNullValue()));
32+
}
2333

2434
@Test
2535
public void testSpider() {

0 commit comments

Comments
 (0)