Skip to content

Commit

Permalink
Updated to zap 2.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
continuumsecurity committed Jun 18, 2017
1 parent 964aa37 commit 050b551
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/main/java/net/continuumsecurity/proxy/LoggingProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ When a match is found, return the entire HarEntry (request and response).
Return the details of the proxy in Selenium format: org.openqa.selenium.Proxy
*/
Proxy getSeleniumProxy() throws UnknownHostException;

public void setAttackMode() throws ProxyException;

}
30 changes: 28 additions & 2 deletions src/main/java/net/continuumsecurity/proxy/ZAProxyScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void setScannerAttackStrength(String scannerId, String strength) throws P
clientApi.ascan.setScannerAttackStrength(scannerId, strength, null);
} catch (ClientApiException e) {
e.printStackTrace();
throw new ProxyException("Error occurred for setScannerAttackStrength", e);
throw new ProxyException("Error occurred for setScannerAttackStrength for scannerId: "+scannerId+" and strength: "+strength, e);
}
}

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

Expand Down Expand Up @@ -450,6 +452,16 @@ public void excludeFromScanner(String regex) {
}
}

@Override
public void setAttackMode() throws ProxyException {
try {
clientApi.core.setMode("attack");
} catch (ClientApiException e) {
e.printStackTrace();
throw new ProxyException(e);
}
}

@Override
public void setMaxDepth(int depth) {
try {
Expand Down Expand Up @@ -1610,6 +1622,20 @@ public void runStandAloneScript(String scriptName) throws ProxyException {
public void setIncludeInContext(String contextName, String regex) {
try {
clientApi.context.includeInContext(contextName, regex);
} catch (ClientApiException e) {
if ("does_not_exist".equalsIgnoreCase(e.getCode())) {
createContext(contextName);
setIncludeInContext(contextName, regex);
} else {
e.printStackTrace();
throw new ProxyException(e);
}
}
}

private void createContext(String contextName) {
try {
clientApi.context.newContext(contextName);
} catch (ClientApiException e) {
e.printStackTrace();
throw new ProxyException(e);
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/net/continuumsecurity/proxy/model/ScanInfo.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
package net.continuumsecurity.proxy.model;

import org.zaproxy.clientapi.core.ApiResponseElement;
import org.zaproxy.clientapi.core.ApiResponseSet;

/**
* Created by stephen on 16/04/15.
*/
public class ScanInfo {
public class ScanInfo implements Comparable<ScanInfo> {
int progress;
int id;
State state;

@Override
public int compareTo(ScanInfo o) {
return id-o.getId();
}

public enum State {
NOT_STARTED,
FINISHED,
PAUSED,
RUNNING;

public static State parse(String s) {
if ("NOT_STARTED".equalsIgnoreCase(s)) return NOT_STARTED;
if ("FINISHED".equalsIgnoreCase(s)) return FINISHED;
if ("PAUSED".equalsIgnoreCase(s)) return PAUSED;
if ("RUNNING".equalsIgnoreCase(s)) return RUNNING;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package net.continuumsecurity.proxy.model;

import net.continuumsecurity.proxy.model.ScanInfo;
import org.zaproxy.clientapi.core.ApiResponse;
import org.zaproxy.clientapi.core.ApiResponseList;
import org.zaproxy.clientapi.core.ApiResponseSet;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -18,6 +18,7 @@ public ScanResponse(ApiResponseList responseList) {
for (ApiResponse rawResponse : responseList.getItems()) {
scans.add(new ScanInfo((ApiResponseSet)rawResponse));
}
Collections.sort(scans);
}

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

public ScanInfo getLastScan() {
if (scans.size() == 0) throw new RuntimeException("No scans found");
return scans.get(scans.size()-1);
}
}
10 changes: 10 additions & 0 deletions src/test/java/net/continuumsecurity/proxy/SpiderTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package net.continuumsecurity.proxy;

import net.continuumsecurity.proxy.model.Context;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.core.IsEqual.equalTo;

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

@Test
public void testIncludeInContextForNewContext() {
final String MYCONTEXT = "My Special context";
zaproxy.setIncludeInContext(MYCONTEXT, BASEURL.concat(".*"));
Context context = zaproxy.getContextInfo(MYCONTEXT);
assertThat(context.getId(),is(notNullValue()));
}

@Test
public void testSpider() {
Expand Down

0 comments on commit 050b551

Please sign in to comment.