Skip to content

Commit 2609c3c

Browse files
authored
Merge pull request #23 from thc202/regen-2.7.0
Regenerate core APIs for ZAP version 2.7.0
2 parents e3a9381 + f012e97 commit 2609c3c

20 files changed

+189
-37
lines changed

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
)
2626
setup(
2727
name="python-owasp-zap-v2.4",
28-
version="0.0.12",
28+
version="0.0.13",
2929
description="OWASP ZAP 2.6 API client",
3030
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)",
3131
author="ZAP development team",
3232
author_email='',
3333
url="https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project",
34-
download_url="https://github.com/zaproxy/zap-api-python/releases/tag/0.0.12",
34+
download_url="https://github.com/zaproxy/zap-api-python/releases/tag/0.0.13",
3535
platforms=['any'],
3636
license="ASL2.0",
3737
package_dir={

src/zapv2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"""
2121

2222
__docformat__ = 'restructuredtext'
23-
__version__ = '0.0.12'
23+
__version__ = '0.0.13'
2424

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

src/zapv2/acsrf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# ZAP is an HTTP/HTTPS proxy for assessing web application security.
44
#
5-
# Copyright 2016 the ZAP development team
5+
# Copyright 2017 the ZAP development team
66
#
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.

src/zapv2/ascan.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# ZAP is an HTTP/HTTPS proxy for assessing web application security.
44
#
5-
# Copyright 2016 the ZAP development team
5+
# Copyright 2017 the ZAP development team
66
#
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.
@@ -40,9 +40,15 @@ def scan_progress(self, scanid=None):
4040
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/view/scanProgress/', params)))
4141

4242
def messages_ids(self, scanid):
43+
"""
44+
Gets the IDs of the messages sent during the scan with the given ID. A message can be obtained with 'message' core view.
45+
"""
4346
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/view/messagesIds/', {'scanId': scanid})))
4447

4548
def alerts_ids(self, scanid):
49+
"""
50+
Gets the IDs of the alerts raised during the scan with the given ID. An alert can be obtained with 'alert' core view.
51+
"""
4652
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/view/alertsIds/', {'scanId': scanid})))
4753

4854
@property
@@ -338,6 +344,12 @@ def update_scan_policy(self, scanpolicyname, alertthreshold=None, attackstrength
338344
params['attackStrength'] = attackstrength
339345
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/action/updateScanPolicy/', params)))
340346

347+
def import_scan_policy(self, path, apikey=''):
348+
"""
349+
Imports a Scan Policy using the given file system path.
350+
"""
351+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/action/importScanPolicy/', {'path': path, 'apikey': apikey})))
352+
341353
def add_excluded_param(self, name, type=None, url=None, apikey=''):
342354
"""
343355
Adds a new parameter excluded from the scan, using the specified name. Optionally sets if the new entry applies to a specific URL (default, all URLs) and sets the ID of the type of the parameter (default, ID of any type). The type IDs can be obtained with the view excludedParamTypes.
@@ -368,6 +380,12 @@ def remove_excluded_param(self, idx, apikey=''):
368380
"""
369381
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/action/removeExcludedParam/', {'idx': idx, 'apikey': apikey})))
370382

383+
def skip_scanner(self, scanid, scannerid, apikey=''):
384+
"""
385+
Skips the scanner using the given IDs of the scan and the scanner.
386+
"""
387+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/action/skipScanner/', {'scanId': scanid, 'scannerId': scannerid, 'apikey': apikey})))
388+
371389
def set_option_attack_policy(self, string, apikey=''):
372390
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/action/setOptionAttackPolicy/', {'String': string, 'apikey': apikey})))
373391

src/zapv2/authentication.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# ZAP is an HTTP/HTTPS proxy for assessing web application security.
44
#
5-
# Copyright 2016 the ZAP development team
5+
# Copyright 2017 the ZAP development team
66
#
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.

src/zapv2/authorization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# ZAP is an HTTP/HTTPS proxy for assessing web application security.
44
#
5-
# Copyright 2016 the ZAP development team
5+
# Copyright 2017 the ZAP development team
66
#
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.

src/zapv2/autoupdate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# ZAP is an HTTP/HTTPS proxy for assessing web application security.
44
#
5-
# Copyright 2016 the ZAP development team
5+
# Copyright 2017 the ZAP development team
66
#
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.

src/zapv2/brk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# ZAP is an HTTP/HTTPS proxy for assessing web application security.
44
#
5-
# Copyright 2016 the ZAP development team
5+
# Copyright 2017 the ZAP development team
66
#
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.

src/zapv2/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# ZAP is an HTTP/HTTPS proxy for assessing web application security.
44
#
5-
# Copyright 2016 the ZAP development team
5+
# Copyright 2017 the ZAP development team
66
#
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.

src/zapv2/core.py

Lines changed: 112 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# ZAP is an HTTP/HTTPS proxy for assessing web application security.
44
#
5-
# Copyright 2016 the ZAP development team
5+
# Copyright 2017 the ZAP development team
66
#
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.
@@ -33,9 +33,9 @@ def alert(self, id):
3333
"""
3434
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/alert/', {'id': id})))
3535

36-
def alerts(self, baseurl=None, start=None, count=None):
36+
def alerts(self, baseurl=None, start=None, count=None, riskid=None):
3737
"""
38-
Gets the alerts raised by ZAP, optionally filtering by URL and paginating with 'start' position and 'count' of alerts
38+
Gets the alerts raised by ZAP, optionally filtering by URL or riskId, and paginating with 'start' position and 'count' of alerts
3939
"""
4040
params = {}
4141
if baseurl is not None:
@@ -44,15 +44,28 @@ def alerts(self, baseurl=None, start=None, count=None):
4444
params['start'] = start
4545
if count is not None:
4646
params['count'] = count
47+
if riskid is not None:
48+
params['riskId'] = riskid
4749
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/alerts/', params)))
4850

49-
def number_of_alerts(self, baseurl=None):
51+
def alerts_summary(self, baseurl=None):
5052
"""
51-
Gets the number of alerts, optionally filtering by URL
53+
Gets number of alerts grouped by each risk level, optionally filtering by URL
5254
"""
5355
params = {}
5456
if baseurl is not None:
5557
params['baseurl'] = baseurl
58+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/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
5669
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/numberOfAlerts/', params)))
5770

5871
@property
@@ -69,16 +82,18 @@ def sites(self):
6982
"""
7083
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/sites/')))
7184

72-
@property
73-
def urls(self):
85+
def urls(self, baseurl=None):
7486
"""
75-
Gets the URLs accessed through/by ZAP
87+
Gets the URLs accessed through/by ZAP, optionally filtering by (base) URL.
7688
"""
77-
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/urls/')))
89+
params = {}
90+
if baseurl is not None:
91+
params['baseurl'] = baseurl
92+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/urls/', params)))
7893

7994
def message(self, id):
8095
"""
81-
Gets the HTTP message with the given ID. Returns the ID, request/response headers and bodies, cookies and note.
96+
Gets the HTTP message with the given ID. Returns the ID, request/response headers and bodies, cookies, note, type, RTT, and timestamp.
8297
"""
8398
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/message/', {'id': id})))
8499

@@ -95,6 +110,12 @@ def messages(self, baseurl=None, start=None, count=None):
95110
params['count'] = count
96111
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/messages/', params)))
97112

113+
def messages_by_id(self, ids):
114+
"""
115+
Gets the HTTP messages with the given IDs.
116+
"""
117+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/messagesById/', {'ids': ids})))
118+
98119
def number_of_messages(self, baseurl=None):
99120
"""
100121
Gets the number of messages, optionally filtering by URL
@@ -121,7 +142,7 @@ def version(self):
121142
@property
122143
def excluded_from_proxy(self):
123144
"""
124-
Gets the regular expressions, applied to URLs, to exclude from the Proxy
145+
Gets the regular expressions, applied to URLs, to exclude from the local proxies.
125146
"""
126147
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/excludedFromProxy/')))
127148

@@ -164,8 +185,39 @@ def option_proxy_excluded_domains_enabled(self):
164185
"""
165186
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/optionProxyExcludedDomainsEnabled/')))
166187

188+
@property
189+
def zap_home_path(self):
190+
"""
191+
Gets the path to ZAP's home directory.
192+
"""
193+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/zapHomePath/')))
194+
195+
@property
196+
def option_maximum_alert_instances(self):
197+
"""
198+
Gets the maximum number of alert instances to include in a report.
199+
"""
200+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/optionMaximumAlertInstances/')))
201+
202+
@property
203+
def option_merge_related_alerts(self):
204+
"""
205+
Gets whether or not related alerts will be merged in any reports generated.
206+
"""
207+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/optionMergeRelatedAlerts/')))
208+
209+
@property
210+
def option_alert_overrides_file_path(self):
211+
"""
212+
Gets the path to the file with alert overrides.
213+
"""
214+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/optionAlertOverridesFilePath/')))
215+
167216
@property
168217
def option_default_user_agent(self):
218+
"""
219+
Gets the user agent that ZAP should use when creating HTTP messages (for example, spider messages or CONNECT requests to outgoing proxy).
220+
"""
169221
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/optionDefaultUserAgent/')))
170222

171223
@property
@@ -269,13 +321,13 @@ def snapshot_session(self, apikey=''):
269321

270322
def clear_excluded_from_proxy(self, apikey=''):
271323
"""
272-
Clears the regexes of URLs excluded from the proxy.
324+
Clears the regexes of URLs excluded from the local proxies.
273325
"""
274326
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/action/clearExcludedFromProxy/', {'apikey': apikey})))
275327

276328
def exclude_from_proxy(self, regex, apikey=''):
277329
"""
278-
Adds a regex of URLs that should be excluded from the proxy.
330+
Adds a regex of URLs that should be excluded from the local proxies.
279331
"""
280332
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/action/excludeFromProxy/', {'regex': regex, 'apikey': apikey})))
281333

@@ -290,7 +342,7 @@ def set_mode(self, mode, apikey=''):
290342

291343
def generate_root_ca(self, apikey=''):
292344
"""
293-
Generates a new Root CA certificate for the Local Proxy.
345+
Generates a new Root CA certificate for the local proxies.
294346
"""
295347
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/action/generateRootCA/', {'apikey': apikey})))
296348

@@ -309,6 +361,12 @@ def delete_all_alerts(self, apikey=''):
309361
"""
310362
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/action/deleteAllAlerts/', {'apikey': apikey})))
311363

364+
def delete_alert(self, id, apikey=''):
365+
"""
366+
Deletes the alert with the given ID.
367+
"""
368+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/action/deleteAlert/', {'id': id, 'apikey': apikey})))
369+
312370
def run_garbage_collection(self, apikey=''):
313371
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/action/runGarbageCollection/', {'apikey': apikey})))
314372

@@ -365,7 +423,31 @@ def disable_all_proxy_chain_excluded_domains(self, apikey=''):
365423
"""
366424
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/action/disableAllProxyChainExcludedDomains/', {'apikey': apikey})))
367425

426+
def set_option_maximum_alert_instances(self, numberofinstances, apikey=''):
427+
"""
428+
Sets the maximum number of alert instances to include in a report. A value of zero is treated as unlimited.
429+
"""
430+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/action/setOptionMaximumAlertInstances/', {'numberOfInstances': numberofinstances, 'apikey': apikey})))
431+
432+
def set_option_merge_related_alerts(self, enabled, apikey=''):
433+
"""
434+
Sets whether or not related alerts will be merged in any reports generated.
435+
"""
436+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/action/setOptionMergeRelatedAlerts/', {'enabled': enabled, 'apikey': apikey})))
437+
438+
def set_option_alert_overrides_file_path(self, filepath=None, apikey=''):
439+
"""
440+
Sets (or clears, if empty) the path to the file with alert overrides.
441+
"""
442+
params = {'apikey': apikey}
443+
if filepath is not None:
444+
params['filePath'] = filepath
445+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/action/setOptionAlertOverridesFilePath/', params)))
446+
368447
def set_option_default_user_agent(self, string, apikey=''):
448+
"""
449+
Sets the user agent that ZAP should use when creating HTTP messages (for example, spider messages or CONNECT requests to outgoing proxy).
450+
"""
369451
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/action/setOptionDefaultUserAgent/', {'String': string, 'apikey': apikey})))
370452

371453
def set_option_proxy_chain_name(self, string, apikey=''):
@@ -408,6 +490,9 @@ def set_option_timeout_in_secs(self, integer, apikey=''):
408490
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/action/setOptionTimeoutInSecs/', {'Integer': integer, 'apikey': apikey})))
409491

410492
def set_option_use_proxy_chain(self, boolean, apikey=''):
493+
"""
494+
Sets whether or not the outgoing proxy should be used. The address/hostname of the outgoing proxy must be set to enable this option.
495+
"""
411496
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/action/setOptionUseProxyChain/', {'Boolean': boolean, 'apikey': apikey})))
412497

413498
def set_option_use_proxy_chain_auth(self, boolean, apikey=''):
@@ -418,7 +503,7 @@ def proxy_pac(self, apikey=''):
418503

419504
def rootcert(self, apikey=''):
420505
"""
421-
Gets the Root CA certificate of the Local Proxy.
506+
Gets the Root CA certificate used by the local proxies.
422507
"""
423508
return (self.zap._request_other(self.zap.base_other + 'core/other/rootcert/', {'apikey': apikey}))
424509

@@ -437,6 +522,12 @@ def htmlreport(self, apikey=''):
437522
"""
438523
return (self.zap._request_other(self.zap.base_other + 'core/other/htmlreport/', {'apikey': apikey}))
439524

525+
def jsonreport(self, apikey=''):
526+
"""
527+
Generates a report in JSON format
528+
"""
529+
return (self.zap._request_other(self.zap.base_other + 'core/other/jsonreport/', {'apikey': apikey}))
530+
440531
def mdreport(self, apikey=''):
441532
"""
442533
Generates a report in Markdown format
@@ -462,6 +553,12 @@ def messages_har(self, baseurl=None, start=None, count=None, apikey=''):
462553
params['count'] = count
463554
return (self.zap._request_other(self.zap.base_other + 'core/other/messagesHar/', params))
464555

556+
def messages_har_by_id(self, ids, apikey=''):
557+
"""
558+
Gets the HTTP messages with the given IDs, in HAR format.
559+
"""
560+
return (self.zap._request_other(self.zap.base_other + 'core/other/messagesHarById/', {'ids': ids, 'apikey': apikey}))
561+
465562
def send_har_request(self, request, followredirects=None, apikey=''):
466563
"""
467564
Sends the first HAR request entry, optionally following redirections. Returns, in HAR format, the request sent and response received and followed redirections, if any. The Mode is enforced when sending the request (and following redirections), custom manual requests are not allowed in 'Safe' mode nor in 'Protected' mode if out of scope.

0 commit comments

Comments
 (0)