- if you are using localhost to run the target apps as I am, be sure that you are using a different port for this than ZAP is using from Step 2 above. In my case, I'm running localhost on port 8888.
4.
- Download the attached class files and import them into your Java project in Eclipse.
- Ensure you have the API jar files for Selenium and ZAP in your build path. If they are not, you will see a ton of errors in Eclipse.
5.
- Open up ZapTools.java and change the String value on line 18 to match your ZAP install directory (mine is C:/Program Files (x86)/OWASP/Zed Attack Proxy/).
- Change line 19 as well to the location that you want to save your ZAP Session to (I'm just saving it in the projects base directory in a folder called ZapSessions).
- Save your changes to ZapTools.java
6.
- Open up SeleniumTools.java and change line 13 to the location of your ChromeDriver executable
- Save your changes if necessary
7.
- SecureTest.java and VulnerableTest.java are the same other than the variables on lines 10-15 and the session file name on line 65. You will need to change these to your configuration if:
--- you are not running localhost on port 8888 from the cgi-bin directory using perl
--- you are not using proxy on port 8091
8.
- Configure your Internet Options to proxy through localhost on port 8091 (or whatever port you chose to proxy with)
- Right click on either SecureTest.java and VulnerableTest.java and select Run As... --> Java Application
- you should follow along in the console to see details but more noticeably you should notice ZAP open up, followed by Chrome.
9.
- Once the form is automatically submitted, the spider will begin. This may take a minute or two to complete.
- When the spider completes, the Active Scan will start. Be patient as this may take some time as well (you may think the status is stuck at 0 - just be patient).
- When the Active Scan is done, the alerts/warnings ZAP found will print out in the console in Eclipse.
- The session will then be saved and Chrome and ZAP will close and the program will finish.
Caveats:
I do not know how to use the ApiResponse Object for the ZAP API. You will notice some kludges in my code to determine whether the spider and scan is complete or not. If you have example code for working with the ApiResponse, please share :)
I am not creating a context for ZAP yet - in other words, if you have programs using the internet running on your machine while this is executing, the scan will pick run on those too (i.e. Google Talk, Outlook, etc...). I need to implement a way to only include a target URL regexp into the session context. Again, if you have example code of this, please share!
The URLs are very finicky when performing different functions such as Spider and Active scan. I think that's because I'm running against apps on port 8888 as opposed to 80 or 443. This is why I have ZAP_HOSTNAME, ZAP_URI, and ZAP_URI_PORT. I originally thought these should just all be "http://localhost:8888", but received errors from the ZAP API until I tweaked them to what they are now.