I am attempting to perform an authenticated spider + scan in ZAP, using the python api. I tried the authentication mode, in vain (didnt work). Now, I am attempting to use python's requests library to fetch the authenticated cookie and use that cookie for scanning using zap's httpsessions object. However, I find that while the tokens are set, they are not used for the spidering and scanning process. Any help would be greatly appreciated!
from zapv2 import ZAPv2
import time
from pprint import pprint
import requests
import json
#requests login session:
login_req = requests.Session()
header_str = {'Accept': 'text/json', 'Referer': '
https://www.testsite.com/signin', 'X-Requested-With': 'XMLHttpRequest', 'X-Prototype-Version': '1.6.0_rc0', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:42.0) Gecko/20100101 Firefox/42.0'}
data_str = {'email': '
user...@user.com', 'password': 'mypassword', 'persistent_login': 't', "service": "", "caller": "homepage", "source": "ui", "action_type": "", "trip_ref": ""}
cookies = login_req.cookies.get_dict()
zap = ZAPv2()
zap.httpsessions.create_empty_session(target, apikey='somekey')
for key,value in cookies.items():
key_value_concat = "%s=%s;" % (key,value)
zap.httpsessions.add_session_token(target, key_value_concat, apikey='somekey')
for token in zap.httpsessions.session_tokens(target):
print token
zap.spider.scan(target,apikey='somekey')
time.sleep(2)
while(int(zap.spider.status()) < 100):
print 'Spider Progress: ' + zap.spider.status() + "%"
time.sleep(1)
print zap.spider.results()
print 'Spider Completed....'