I have written a script to scan URL using zap python API, I am using Ubuntu 14.04, Python 2.7 and Zap 2.5 version. I have installed zap by following these instructions.

When I try to run, I'm getting the below error after spider has started.

Below is the stacktrace:

File "scan.py", line 23, in <module>
  File "build/bdist.linux-x86_64/egg/zapv2/spider.py", line 156, in scan
  File "build/bdist.linux-x86_64/egg/zapv2/__init__.py", line 145, in _request
  File "build/bdist.linux-x86_64/egg/zapv2/__init__.py", line 124, in urlopen
  File "/usr/lib/python2.7/urllib.py", line 87, in urlopen
    return opener.open(url)
  File "/usr/lib/python2.7/urllib.py", line 208, in open
    return getattr(self, name)(url)
  File "/usr/lib/python2.7/urllib.py", line 352, in open_http
    'got a bad status line', None)
IOError: ('http protocol error', 0, 'got a bad status line', None)

Below is the code

#!/usr/bin/env python
# coding: latin-1

import time
#import urllib2
from pprint import pprint
from zapv2 import ZAPv2

# Here the target is defined and an instance of ZAP is created.
target = 'http://google-gruyere.appspot.com/start'
zap = ZAPv2()

# Use the line below if ZAP is not listening on 8090.
# zap = ZAPv2(proxies={'http': '', 'https': ''})

# ZAP starts accessing the target.
print 'Accessing target %s' % target

# The spider starts crawling the website for URL’s
print 'Spidering target %s' % target

# Progress of spider
print 'Status %s' % zap.spider.status
while (int(zap.spider.status) < 100):
   print 'Spider progress %: ' + zap.spider.status


print 'Spider completed'

# Give the passive scanner a chance to finish

# The active scanning starts
print 'Scanning target %s' % target
while (int(zap.ascan.status) < 100):
   print 'Scan progress %: ' + zap.ascan.status

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.