Skip to content

Commit 3499540

Browse files
authored
Merge pull request #41 from thc202/regen-2.8.0
Regenerate core APIs for 2.8.0
2 parents 0666cb0 + 4017f69 commit 3499540

15 files changed

+479
-63
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
1111
- Minimum Python 3 version is now 3.4.
1212

1313
### Changed
14+
- Update core APIs for ZAP 2.8.0.
1415
- Allow to validate the status code returned by the ZAP API, to fail
1516
sooner if the API request was not successful. This can be enabled when
1617
instantiating the `ZAPv2` class with the argument `validate_status_code`

src/zapv2/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from requests.packages.urllib3.exceptions import InsecureRequestWarning
2727

2828
from .acsrf import acsrf
29+
from .alert import alert
2930
from .ascan import ascan
3031
from .ajaxSpider import ajaxSpider
3132
from .authentication import authentication
@@ -80,6 +81,7 @@ def __init__(self, proxies=None, apikey=None, validate_status_code=False):
8081
self.__validate_status_code=validate_status_code
8182

8283
self.acsrf = acsrf(self)
84+
self.alert = alert(self)
8385
self.ajaxSpider = ajaxSpider(self)
8486
self.ascan = ascan(self)
8587
self.authentication = authentication(self)

src/zapv2/alert.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Zed Attack Proxy (ZAP) and its related class files.
2+
#
3+
# ZAP is an HTTP/HTTPS proxy for assessing web application security.
4+
#
5+
# Copyright 2019 the ZAP development team
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
"""
19+
This file was automatically generated.
20+
"""
21+
22+
import six
23+
24+
25+
class alert(object):
26+
27+
def __init__(self, zap):
28+
self.zap = zap
29+
30+
def alert(self, id):
31+
"""
32+
Gets the alert with the given ID, the corresponding HTTP message can be obtained with the 'messageId' field and 'message' API method
33+
"""
34+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'alert/view/alert/', {'id': id})))
35+
36+
def alerts(self, baseurl=None, start=None, count=None, riskid=None):
37+
"""
38+
Gets the alerts raised by ZAP, optionally filtering by URL or riskId, and paginating with 'start' position and 'count' of alerts
39+
"""
40+
params = {}
41+
if baseurl is not None:
42+
params['baseurl'] = baseurl
43+
if start is not None:
44+
params['start'] = start
45+
if count is not None:
46+
params['count'] = count
47+
if riskid is not None:
48+
params['riskId'] = riskid
49+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'alert/view/alerts/', params)))
50+
51+
def alerts_summary(self, baseurl=None):
52+
"""
53+
Gets number of alerts grouped by each risk level, optionally filtering by URL
54+
"""
55+
params = {}
56+
if baseurl is not None:
57+
params['baseurl'] = baseurl
58+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'alert/view/alertsSummary/', params)))
59+
60+
def number_of_alerts(self, baseurl=None, riskid=None):
61+
"""
62+
Gets the number of alerts, optionally filtering by URL or riskId
63+
"""
64+
params = {}
65+
if baseurl is not None:
66+
params['baseurl'] = baseurl
67+
if riskid is not None:
68+
params['riskId'] = riskid
69+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'alert/view/numberOfAlerts/', params)))
70+
71+
def alerts_by_risk(self, url=None, recurse=None):
72+
"""
73+
Gets a summary of the alerts, optionally filtered by a 'url'. If 'recurse' is true then all alerts that apply to urls that start with the specified 'url' will be returned, otherwise only those on exactly the same 'url' (ignoring url parameters)
74+
"""
75+
params = {}
76+
if url is not None:
77+
params['url'] = url
78+
if recurse is not None:
79+
params['recurse'] = recurse
80+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'alert/view/alertsByRisk/', params)))
81+
82+
def alert_counts_by_risk(self, url=None, recurse=None):
83+
"""
84+
Gets a count of the alerts, optionally filtered as per alertsPerRisk
85+
"""
86+
params = {}
87+
if url is not None:
88+
params['url'] = url
89+
if recurse is not None:
90+
params['recurse'] = recurse
91+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'alert/view/alertCountsByRisk/', params)))
92+
93+
def delete_all_alerts(self, apikey=''):
94+
"""
95+
Deletes all alerts of the current session.
96+
"""
97+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'alert/action/deleteAllAlerts/', {'apikey': apikey})))
98+
99+
def delete_alert(self, id, apikey=''):
100+
"""
101+
Deletes the alert with the given ID.
102+
"""
103+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'alert/action/deleteAlert/', {'id': id, 'apikey': apikey})))

src/zapv2/ascan.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ def excluded_from_scan(self):
6767
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/view/excludedFromScan/')))
6868

6969
def scanners(self, scanpolicyname=None, policyid=None):
70+
"""
71+
Gets the scanners, optionally, of the given scan policy and/or scanner policy/category ID.
72+
"""
7073
params = {}
7174
if scanpolicyname is not None:
7275
params['scanPolicyName'] = scanpolicyname
@@ -159,6 +162,13 @@ def option_target_params_injectable(self):
159162
def option_thread_per_host(self):
160163
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/view/optionThreadPerHost/')))
161164

165+
@property
166+
def option_add_query_param(self):
167+
"""
168+
Tells whether or not the active scanner should add a query parameter to GET request that don't have parameters to start with.
169+
"""
170+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/view/optionAddQueryParam/')))
171+
162172
@property
163173
def option_allow_attack_on_start(self):
164174
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/view/optionAllowAttackOnStart/')))
@@ -272,24 +282,36 @@ def exclude_from_scan(self, regex, apikey=''):
272282
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/action/excludeFromScan/', {'regex': regex, 'apikey': apikey})))
273283

274284
def enable_all_scanners(self, scanpolicyname=None, apikey=''):
285+
"""
286+
Enables all scanners of the scan policy with the given name, or the default if none given.
287+
"""
275288
params = {'apikey': apikey}
276289
if scanpolicyname is not None:
277290
params['scanPolicyName'] = scanpolicyname
278291
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/action/enableAllScanners/', params)))
279292

280293
def disable_all_scanners(self, scanpolicyname=None, apikey=''):
294+
"""
295+
Disables all scanners of the scan policy with the given name, or the default if none given.
296+
"""
281297
params = {'apikey': apikey}
282298
if scanpolicyname is not None:
283299
params['scanPolicyName'] = scanpolicyname
284300
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/action/disableAllScanners/', params)))
285301

286302
def enable_scanners(self, ids, scanpolicyname=None, apikey=''):
303+
"""
304+
Enables the scanners with the given IDs (comma separated list of IDs) of the scan policy with the given name, or the default if none given.
305+
"""
287306
params = {'ids': ids, 'apikey': apikey}
288307
if scanpolicyname is not None:
289308
params['scanPolicyName'] = scanpolicyname
290309
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/action/enableScanners/', params)))
291310

292311
def disable_scanners(self, ids, scanpolicyname=None, apikey=''):
312+
"""
313+
Disables the scanners with the given IDs (comma separated list of IDs) of the scan policy with the given name, or the default if none given.
314+
"""
293315
params = {'ids': ids, 'apikey': apikey}
294316
if scanpolicyname is not None:
295317
params['scanPolicyName'] = scanpolicyname
@@ -392,6 +414,12 @@ def set_option_attack_policy(self, string, apikey=''):
392414
def set_option_default_policy(self, string, apikey=''):
393415
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/action/setOptionDefaultPolicy/', {'String': string, 'apikey': apikey})))
394416

417+
def set_option_add_query_param(self, boolean, apikey=''):
418+
"""
419+
Sets whether or not the active scanner should add a query param to GET requests which do not have parameters to start with.
420+
"""
421+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/action/setOptionAddQueryParam/', {'Boolean': boolean, 'apikey': apikey})))
422+
395423
def set_option_allow_attack_on_start(self, boolean, apikey=''):
396424
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/action/setOptionAllowAttackOnStart/', {'Boolean': boolean, 'apikey': apikey})))
397425

src/zapv2/authentication.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,52 @@ def __init__(self, zap):
2929

3030
@property
3131
def get_supported_authentication_methods(self):
32+
"""
33+
Gets the name of the authentication methods.
34+
"""
3235
return six.next(six.itervalues(self.zap._request(self.zap.base + 'authentication/view/getSupportedAuthenticationMethods/')))
3336

3437
def get_authentication_method_config_params(self, authmethodname):
38+
"""
39+
Gets the configuration parameters for the authentication method with the given name.
40+
"""
3541
return six.next(six.itervalues(self.zap._request(self.zap.base + 'authentication/view/getAuthenticationMethodConfigParams/', {'authMethodName': authmethodname})))
3642

3743
def get_authentication_method(self, contextid):
44+
"""
45+
Gets the name of the authentication method for the context with the given ID.
46+
"""
3847
return six.next(six.itervalues(self.zap._request(self.zap.base + 'authentication/view/getAuthenticationMethod/', {'contextId': contextid})))
3948

4049
def get_logged_in_indicator(self, contextid):
50+
"""
51+
Gets the logged in indicator for the context with the given ID.
52+
"""
4153
return six.next(six.itervalues(self.zap._request(self.zap.base + 'authentication/view/getLoggedInIndicator/', {'contextId': contextid})))
4254

4355
def get_logged_out_indicator(self, contextid):
56+
"""
57+
Gets the logged out indicator for the context with the given ID.
58+
"""
4459
return six.next(six.itervalues(self.zap._request(self.zap.base + 'authentication/view/getLoggedOutIndicator/', {'contextId': contextid})))
4560

4661
def set_authentication_method(self, contextid, authmethodname, authmethodconfigparams=None, apikey=''):
62+
"""
63+
Sets the authentication method for the context with the given ID.
64+
"""
4765
params = {'contextId': contextid, 'authMethodName': authmethodname, 'apikey': apikey}
4866
if authmethodconfigparams is not None:
4967
params['authMethodConfigParams'] = authmethodconfigparams
5068
return six.next(six.itervalues(self.zap._request(self.zap.base + 'authentication/action/setAuthenticationMethod/', params)))
5169

5270
def set_logged_in_indicator(self, contextid, loggedinindicatorregex, apikey=''):
71+
"""
72+
Sets the logged in indicator for the context with the given ID.
73+
"""
5374
return six.next(six.itervalues(self.zap._request(self.zap.base + 'authentication/action/setLoggedInIndicator/', {'contextId': contextid, 'loggedInIndicatorRegex': loggedinindicatorregex, 'apikey': apikey})))
5475

5576
def set_logged_out_indicator(self, contextid, loggedoutindicatorregex, apikey=''):
77+
"""
78+
Sets the logged out indicator for the context with the given ID.
79+
"""
5680
return six.next(six.itervalues(self.zap._request(self.zap.base + 'authentication/action/setLoggedOutIndicator/', {'contextId': contextid, 'loggedOutIndicatorRegex': loggedoutindicatorregex, 'apikey': apikey})))

src/zapv2/autoupdate.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ def installed_addons(self):
4848
"""
4949
return six.next(six.itervalues(self.zap._request(self.zap.base + 'autoupdate/view/installedAddons/')))
5050

51+
@property
52+
def local_addons(self):
53+
"""
54+
Returns a list with all local add-ons, installed or not.
55+
"""
56+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'autoupdate/view/localAddons/')))
57+
5158
@property
5259
def new_addons(self):
5360
"""
@@ -133,6 +140,9 @@ def install_addon(self, id, apikey=''):
133140
"""
134141
return six.next(six.itervalues(self.zap._request(self.zap.base + 'autoupdate/action/installAddon/', {'id': id, 'apikey': apikey})))
135142

143+
def install_local_addon(self, file, apikey=''):
144+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'autoupdate/action/installLocalAddon/', {'file': file, 'apikey': apikey})))
145+
136146
def uninstall_addon(self, id, apikey=''):
137147
"""
138148
Uninstalls the specified add-on

src/zapv2/context.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ def excluded_technology_list(self, contextname):
7171
"""
7272
return six.next(six.itervalues(self.zap._request(self.zap.base + 'context/view/excludedTechnologyList/', {'contextName': contextname})))
7373

74+
def urls(self, contextname):
75+
"""
76+
Lists the URLs accessed through/by ZAP, that belong to the context with the given name.
77+
"""
78+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'context/view/urls/', {'contextName': contextname})))
79+
7480
def exclude_from_context(self, contextname, regex, apikey=''):
7581
"""
7682
Add exclude regex to context
@@ -83,6 +89,12 @@ def include_in_context(self, contextname, regex, apikey=''):
8389
"""
8490
return six.next(six.itervalues(self.zap._request(self.zap.base + 'context/action/includeInContext/', {'contextName': contextname, 'regex': regex, 'apikey': apikey})))
8591

92+
def set_context_regexs(self, contextname, incregexs, excregexs, apikey=''):
93+
"""
94+
Set the regexs to include and exclude for a context, both supplied as JSON string arrays
95+
"""
96+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'context/action/setContextRegexs/', {'contextName': contextname, 'incRegexs': incregexs, 'excRegexs': excregexs, 'apikey': apikey})))
97+
8698
def new_context(self, contextname, apikey=''):
8799
"""
88100
Creates a new context with the given name in the current session

0 commit comments

Comments
 (0)