Skip to content

Commit d5e83fe

Browse files
authored
Merge pull request #4 from Woolworths/master
Fix for Python 3
2 parents f7960f2 + cdf9cfd commit d5e83fe

28 files changed

+630
-564
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ sudo: false
22
language: python
33
python:
44
- '2.7'
5+
- '3.3'
56
install:
67
- pip install -U --force setuptools pip
78
- ./setup.py develop

setup.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
try:
1010
from setuptools import setup, find_packages
1111
except ImportError:
12-
print "You must have setuptools installed to use setup.py. Exiting..."
12+
print('You must have setuptools installed to use setup.py. Exiting...')
1313
raise SystemExit(1)
1414

1515

1616
install_dependencies = (
17-
'requests'
17+
'requests',
18+
'six'
1819
)
1920
test_requirements = (
2021
'mock',
@@ -24,30 +25,32 @@
2425
)
2526
setup(
2627
name="python-owasp-zap-v2.4",
27-
version="0.0.9",
28+
version="0.0.10",
2829
description="OWASP ZAP 2.6 API client",
2930
long_description="OWASP Zed Attack Proxy 2.6 API python client (the 2.4 package name has been kept to make it easier to upgrade)",
3031
author="ZAP development team",
3132
author_email='',
3233
url="https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project",
33-
download_url="https://github.com/zaproxy/zap-api-python/releases/tag/0.0.9",
34+
download_url="https://github.com/zaproxy/zap-api-python/releases/tag/0.0.10",
3435
platforms=['any'],
35-
3636
license="ASL2.0",
37-
3837
package_dir={
3938
'': 'src',
4039
},
4140
packages=find_packages('src'),
42-
4341
classifiers=[
4442
'License :: OSI Approved :: Apache Software License',
4543
'Development Status :: 5 - Production/Stable',
4644
'Topic :: Security',
4745
'Topic :: Software Development :: Libraries :: Python Modules',
4846
'Intended Audience :: Developers',
4947
'Intended Audience :: Information Technology',
50-
'Programming Language :: Python'],
48+
'Programming Language :: Python :: 2',
49+
'Programming Language :: Python :: 2.7',
50+
'Programming Language :: Python :: 3',
51+
'Programming Language :: Python :: 3.3',
52+
'Programming Language :: Python :: 3.4',
53+
],
5154
install_requires=install_dependencies,
5255
tests_require=test_requirements,
5356
extras_require={'tests': test_requirements}

src/examples/basic-spider-scan.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,39 @@
1414
# zap = ZAPv2(apikey=apikey, proxies={'http': 'http://127.0.0.1:8090', 'https': 'http://127.0.0.1:8090'})
1515

1616
# Proxy a request to the target so that ZAP has something to deal with
17-
print 'Accessing target %s' % target
17+
print('Accessing target {}'.format(target))
1818
zap.urlopen(target)
1919
# Give the sites tree a chance to get updated
2020
time.sleep(2)
2121

22-
print 'Spidering target %s' % target
22+
print('Spidering target {}'.format(target))
2323
scanid = zap.spider.scan(target)
2424
# Give the Spider a chance to start
2525
time.sleep(2)
2626
while (int(zap.spider.status(scanid)) < 100):
2727
# Loop until the spider has finished
28-
print 'Spider progress %: ' + zap.spider.status(scanid)
28+
print('Spider progress %: {}'.format(zap.spider.status(scanid)))
2929
time.sleep(2)
3030

31-
print 'Spider completed'
31+
print ('Spider completed')
3232

3333
while (int(zap.pscan.records_to_scan) > 0):
34-
print ('Records to passive scan : ' + zap.pscan.records_to_scan)
34+
print ('Records to passive scan : {}'.format(zap.pscan.records_to_scan))
3535
time.sleep(2)
3636

37-
print 'Passive Scan completed'
37+
print ('Passive Scan completed')
3838

39-
print 'Active Scanning target %s' % target
39+
print ('Active Scanning target {}'.format(target))
4040
scanid = zap.ascan.scan(target)
4141
while (int(zap.ascan.status(scanid)) < 100):
4242
# Loop until the scanner has finished
43-
print 'Scan progress %: ' + zap.ascan.status(scanid)
43+
print ('Scan progress %: {}'.format(zap.ascan.status(scanid)))
4444
time.sleep(5)
4545

46-
print 'Active Scan completed'
46+
print ('Active Scan completed')
4747

4848
# Report the results
4949

50-
print 'Hosts: ' + ', '.join(zap.core.hosts)
51-
print 'Alerts: '
50+
print ('Hosts: {}'.format(', '.join(zap.core.hosts)))
51+
print ('Alerts: ')
5252
pprint (zap.core.alerts())

src/zapv2/__init__.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,41 @@
2020
"""
2121

2222
__docformat__ = 'restructuredtext'
23-
__version__ = '0.0.9'
23+
__version__ = '0.0.10'
2424

2525
import requests
2626
from requests.packages.urllib3.exceptions import InsecureRequestWarning
2727

28-
from acsrf import acsrf
29-
from ascan import ascan
30-
from ajaxSpider import ajaxSpider
31-
from authentication import authentication
32-
from authorization import authorization
33-
from autoupdate import autoupdate
34-
from brk import brk
35-
from context import context
36-
from core import core
37-
from forcedUser import forcedUser
38-
from httpSessions import httpSessions
39-
from importLogFiles import importLogFiles
40-
from params import params
41-
from pnh import pnh
42-
from pscan import pscan
43-
from reveal import reveal
44-
from script import script
45-
from search import search
46-
from selenium import selenium
47-
from sessionManagement import sessionManagement
48-
from spider import spider
49-
from stats import stats
50-
from users import users
28+
from .acsrf import acsrf
29+
from .ascan import ascan
30+
from .ajaxSpider import ajaxSpider
31+
from .authentication import authentication
32+
from .authorization import authorization
33+
from .autoupdate import autoupdate
34+
from .brk import brk
35+
from .context import context
36+
from .core import core
37+
from .forcedUser import forcedUser
38+
from .httpSessions import httpSessions
39+
from .importLogFiles import importLogFiles
40+
from .params import params
41+
from .pnh import pnh
42+
from .pscan import pscan
43+
from .reveal import reveal
44+
from .script import script
45+
from .search import search
46+
from .selenium import selenium
47+
from .sessionManagement import sessionManagement
48+
from .spider import spider
49+
from .stats import stats
50+
from .users import users
5151

5252

5353
class ZAPv2(object):
5454
"""
5555
Client API implementation for integrating with ZAP v2.
5656
"""
57-
# base JSON api url
5857
base = 'http://zap/JSON/'
59-
60-
# base OTHER api url
6158
base_other = 'http://zap/OTHER/'
6259

6360
def __init__(self, proxies=None, apikey=None):
@@ -109,7 +106,7 @@ def __init__(self, proxies=None, apikey=None):
109106
#if apikey is not None:
110107
# self.session.headers['X-ZAP-API-Key'] = apikey
111108

112-
def urlopen(self, *args, **kwargs):
109+
def urlopen(self, url, *args, **kwargs):
113110
"""
114111
Opens a url forcing the proxies to be used.
115112
@@ -118,7 +115,7 @@ def urlopen(self, *args, **kwargs):
118115
- `kwargs`: all other keyword arguments.
119116
"""
120117
# Must never leak the API key via proxied requests
121-
return requests.get(*args, proxies=self.__proxies, verify=False, **kwargs).text
118+
return requests.get(url, proxies=self.__proxies, verify=False, *args, **kwargs).text
122119

123120
def _request_api(self, url, query=None):
124121
"""
@@ -153,7 +150,8 @@ def _request(self, url, get=None):
153150
- `url`: the url to GET at.
154151
- `get`: the dictionary to turn into GET variables.
155152
"""
156-
return self._request_api(url, get).json()
153+
data = self._request_api(url, get)
154+
return data.json()
157155

158156
def _request_other(self, url, get=None):
159157
"""
@@ -163,4 +161,5 @@ def _request_other(self, url, get=None):
163161
- `url`: the url to GET at.
164162
- `get`: the dictionary to turn into GET variables.
165163
"""
166-
return self._request_api(url, get).text
164+
data = self._request_api(url, get)
165+
return data.text

src/zapv2/acsrf.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
This file was automatically generated.
2020
"""
2121

22+
import six
23+
24+
2225
class acsrf(object):
2326

2427
def __init__(self, zap):
@@ -29,24 +32,22 @@ def option_tokens_names(self):
2932
"""
3033
Lists the names of all anti-CSRF tokens
3134
"""
32-
return next(self.zap._request(self.zap.base + 'acsrf/view/optionTokensNames/').itervalues())
35+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'acsrf/view/optionTokensNames/')))
3336

3437
def add_option_token(self, string, apikey=''):
3538
"""
3639
Adds an anti-CSRF token with the given name, enabled by default
3740
"""
38-
return next(self.zap._request(self.zap.base + 'acsrf/action/addOptionToken/', {'String' : string, 'apikey' : apikey}).itervalues())
41+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'acsrf/action/addOptionToken/', {'String': string, 'apikey': apikey})))
3942

4043
def remove_option_token(self, string, apikey=''):
4144
"""
4245
Removes the anti-CSRF token with the given name
4346
"""
44-
return next(self.zap._request(self.zap.base + 'acsrf/action/removeOptionToken/', {'String' : string, 'apikey' : apikey}).itervalues())
47+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'acsrf/action/removeOptionToken/', {'String': string, 'apikey': apikey})))
4548

4649
def gen_form(self, hrefid, apikey=''):
4750
"""
4851
Generate a form for testing lack of anti-CSRF tokens - typically invoked via ZAP
4952
"""
50-
return (self.zap._request_other(self.zap.base_other + 'acsrf/other/genForm/', {'hrefId' : hrefid, 'apikey' : apikey}))
51-
52-
53+
return (self.zap._request_other(self.zap.base_other + 'acsrf/other/genForm/', {'hrefId': hrefid, 'apikey': apikey}))

0 commit comments

Comments
 (0)