2
2
#
3
3
# ZAP is an HTTP/HTTPS proxy for assessing web application security.
4
4
#
5
- # Copyright 2016 the ZAP development team
5
+ # Copyright 2017 the ZAP development team
6
6
#
7
7
# Licensed under the Apache License, Version 2.0 (the "License");
8
8
# you may not use this file except in compliance with the License.
@@ -33,9 +33,9 @@ def alert(self, id):
33
33
"""
34
34
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/view/alert/' , {'id' : id })))
35
35
36
- def alerts (self , baseurl = None , start = None , count = None ):
36
+ def alerts (self , baseurl = None , start = None , count = None , riskid = None ):
37
37
"""
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
39
39
"""
40
40
params = {}
41
41
if baseurl is not None :
@@ -44,15 +44,28 @@ def alerts(self, baseurl=None, start=None, count=None):
44
44
params ['start' ] = start
45
45
if count is not None :
46
46
params ['count' ] = count
47
+ if riskid is not None :
48
+ params ['riskId' ] = riskid
47
49
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/view/alerts/' , params )))
48
50
49
- def number_of_alerts (self , baseurl = None ):
51
+ def alerts_summary (self , baseurl = None ):
50
52
"""
51
- Gets the number of alerts, optionally filtering by URL
53
+ Gets number of alerts grouped by each risk level , optionally filtering by URL
52
54
"""
53
55
params = {}
54
56
if baseurl is not None :
55
57
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
56
69
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/view/numberOfAlerts/' , params )))
57
70
58
71
@property
@@ -69,16 +82,18 @@ def sites(self):
69
82
"""
70
83
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/view/sites/' )))
71
84
72
- @property
73
- def urls (self ):
85
+ def urls (self , baseurl = None ):
74
86
"""
75
- Gets the URLs accessed through/by ZAP
87
+ Gets the URLs accessed through/by ZAP, optionally filtering by (base) URL.
76
88
"""
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 )))
78
93
79
94
def message (self , id ):
80
95
"""
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 .
82
97
"""
83
98
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/view/message/' , {'id' : id })))
84
99
@@ -95,6 +110,12 @@ def messages(self, baseurl=None, start=None, count=None):
95
110
params ['count' ] = count
96
111
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/view/messages/' , params )))
97
112
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
+
98
119
def number_of_messages (self , baseurl = None ):
99
120
"""
100
121
Gets the number of messages, optionally filtering by URL
@@ -121,7 +142,7 @@ def version(self):
121
142
@property
122
143
def excluded_from_proxy (self ):
123
144
"""
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.
125
146
"""
126
147
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/view/excludedFromProxy/' )))
127
148
@@ -164,8 +185,39 @@ def option_proxy_excluded_domains_enabled(self):
164
185
"""
165
186
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/view/optionProxyExcludedDomainsEnabled/' )))
166
187
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
+
167
216
@property
168
217
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
+ """
169
221
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/view/optionDefaultUserAgent/' )))
170
222
171
223
@property
@@ -269,13 +321,13 @@ def snapshot_session(self, apikey=''):
269
321
270
322
def clear_excluded_from_proxy (self , apikey = '' ):
271
323
"""
272
- Clears the regexes of URLs excluded from the proxy .
324
+ Clears the regexes of URLs excluded from the local proxies .
273
325
"""
274
326
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/action/clearExcludedFromProxy/' , {'apikey' : apikey })))
275
327
276
328
def exclude_from_proxy (self , regex , apikey = '' ):
277
329
"""
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 .
279
331
"""
280
332
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/action/excludeFromProxy/' , {'regex' : regex , 'apikey' : apikey })))
281
333
@@ -290,7 +342,7 @@ def set_mode(self, mode, apikey=''):
290
342
291
343
def generate_root_ca (self , apikey = '' ):
292
344
"""
293
- Generates a new Root CA certificate for the Local Proxy .
345
+ Generates a new Root CA certificate for the local proxies .
294
346
"""
295
347
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/action/generateRootCA/' , {'apikey' : apikey })))
296
348
@@ -309,6 +361,12 @@ def delete_all_alerts(self, apikey=''):
309
361
"""
310
362
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/action/deleteAllAlerts/' , {'apikey' : apikey })))
311
363
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
+
312
370
def run_garbage_collection (self , apikey = '' ):
313
371
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/action/runGarbageCollection/' , {'apikey' : apikey })))
314
372
@@ -365,7 +423,31 @@ def disable_all_proxy_chain_excluded_domains(self, apikey=''):
365
423
"""
366
424
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/action/disableAllProxyChainExcludedDomains/' , {'apikey' : apikey })))
367
425
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
+
368
447
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
+ """
369
451
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/action/setOptionDefaultUserAgent/' , {'String' : string , 'apikey' : apikey })))
370
452
371
453
def set_option_proxy_chain_name (self , string , apikey = '' ):
@@ -408,6 +490,9 @@ def set_option_timeout_in_secs(self, integer, apikey=''):
408
490
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/action/setOptionTimeoutInSecs/' , {'Integer' : integer , 'apikey' : apikey })))
409
491
410
492
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
+ """
411
496
return six .next (six .itervalues (self .zap ._request (self .zap .base + 'core/action/setOptionUseProxyChain/' , {'Boolean' : boolean , 'apikey' : apikey })))
412
497
413
498
def set_option_use_proxy_chain_auth (self , boolean , apikey = '' ):
@@ -418,7 +503,7 @@ def proxy_pac(self, apikey=''):
418
503
419
504
def rootcert (self , apikey = '' ):
420
505
"""
421
- Gets the Root CA certificate of the Local Proxy .
506
+ Gets the Root CA certificate used by the local proxies .
422
507
"""
423
508
return (self .zap ._request_other (self .zap .base_other + 'core/other/rootcert/' , {'apikey' : apikey }))
424
509
@@ -437,6 +522,12 @@ def htmlreport(self, apikey=''):
437
522
"""
438
523
return (self .zap ._request_other (self .zap .base_other + 'core/other/htmlreport/' , {'apikey' : apikey }))
439
524
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
+
440
531
def mdreport (self , apikey = '' ):
441
532
"""
442
533
Generates a report in Markdown format
@@ -462,6 +553,12 @@ def messages_har(self, baseurl=None, start=None, count=None, apikey=''):
462
553
params ['count' ] = count
463
554
return (self .zap ._request_other (self .zap .base_other + 'core/other/messagesHar/' , params ))
464
555
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
+
465
562
def send_har_request (self , request , followredirects = None , apikey = '' ):
466
563
"""
467
564
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