From 95e3208db71f323470d21731f4e4a3618348932f Mon Sep 17 00:00:00 2001 From: thc202 Date: Thu, 13 Jun 2019 13:49:11 +0100 Subject: [PATCH] Update/add APIs of add-ons Update the APIs of the following add-ons: - Selenium version 15.0.0; - WebSockets version 19. Add the API of the following add-on: - Context Alert Filters version 8. Signed-off-by: thc202 --- CHANGELOG.md | 4 ++- src/zapv2/__init__.py | 2 ++ src/zapv2/alertFilter.py | 67 ++++++++++++++++++++++++++++++++++++++++ src/zapv2/selenium.py | 2 -- src/zapv2/websocket.py | 15 +++++++++ 5 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 src/zapv2/alertFilter.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 16ab8a9..e386e91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ## [Unreleased] ### Added -- Add API for WebSockets add-on, version 15. +- Add API for Context Alert Filters add-on, version 8. +- Add API for WebSockets add-on, version 19. - Add API for SOAP Scanner add-on, version 3. ### Changed - Minimum Python 3 version is now 3.4. +- Update Selenium API, per release of version 15.0.0. ### Changed - Update core APIs for ZAP 2.8.0. diff --git a/src/zapv2/__init__.py b/src/zapv2/__init__.py index 5be58bf..4278fdc 100644 --- a/src/zapv2/__init__.py +++ b/src/zapv2/__init__.py @@ -27,6 +27,7 @@ from .acsrf import acsrf from .alert import alert +from .alertFilter import alertFilter from .ascan import ascan from .ajaxSpider import ajaxSpider from .authentication import authentication @@ -82,6 +83,7 @@ def __init__(self, proxies=None, apikey=None, validate_status_code=False): self.acsrf = acsrf(self) self.alert = alert(self) + self.alertFilter = alertFilter(self) self.ajaxSpider = ajaxSpider(self) self.ascan = ascan(self) self.authentication = authentication(self) diff --git a/src/zapv2/alertFilter.py b/src/zapv2/alertFilter.py new file mode 100644 index 0000000..2f2d2ed --- /dev/null +++ b/src/zapv2/alertFilter.py @@ -0,0 +1,67 @@ +# Zed Attack Proxy (ZAP) and its related class files. +# +# ZAP is an HTTP/HTTPS proxy for assessing web application security. +# +# Copyright 2019 the ZAP development team +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +This file was automatically generated. +""" + +import six + + +class alertFilter(object): + + def __init__(self, zap): + self.zap = zap + + def alert_filter_list(self, contextid): + """ + Lists the alert filters of the context with the given ID. + This component is optional and therefore the API will only work if it is installed + """ + return six.next(six.itervalues(self.zap._request(self.zap.base + 'alertFilter/view/alertFilterList/', {'contextId': contextid}))) + + def add_alert_filter(self, contextid, ruleid, newlevel, url=None, urlisregex=None, parameter=None, enabled=None, apikey=''): + """ + Adds a new alert filter for the context with the given ID. + This component is optional and therefore the API will only work if it is installed + """ + params = {'contextId': contextid, 'ruleId': ruleid, 'newLevel': newlevel, 'apikey': apikey} + if url is not None: + params['url'] = url + if urlisregex is not None: + params['urlIsRegex'] = urlisregex + if parameter is not None: + params['parameter'] = parameter + if enabled is not None: + params['enabled'] = enabled + return six.next(six.itervalues(self.zap._request(self.zap.base + 'alertFilter/action/addAlertFilter/', params))) + + def remove_alert_filter(self, contextid, ruleid, newlevel, url=None, urlisregex=None, parameter=None, enabled=None, apikey=''): + """ + Removes an alert filter from the context with the given ID. + This component is optional and therefore the API will only work if it is installed + """ + params = {'contextId': contextid, 'ruleId': ruleid, 'newLevel': newlevel, 'apikey': apikey} + if url is not None: + params['url'] = url + if urlisregex is not None: + params['urlIsRegex'] = urlisregex + if parameter is not None: + params['parameter'] = parameter + if enabled is not None: + params['enabled'] = enabled + return six.next(six.itervalues(self.zap._request(self.zap.base + 'alertFilter/action/removeAlertFilter/', params))) diff --git a/src/zapv2/selenium.py b/src/zapv2/selenium.py index 6fb93e1..2d6d5fb 100644 --- a/src/zapv2/selenium.py +++ b/src/zapv2/selenium.py @@ -54,7 +54,6 @@ def option_firefox_driver_path(self): @property def option_ie_driver_path(self): """ - Returns the current path to IEDriverServer This component is optional and therefore the API will only work if it is installed """ return six.next(six.itervalues(self.zap._request(self.zap.base + 'selenium/view/optionIeDriverPath/'))) @@ -90,7 +89,6 @@ def set_option_firefox_driver_path(self, string, apikey=''): def set_option_ie_driver_path(self, string, apikey=''): """ - Sets the current path to IEDriverServer This component is optional and therefore the API will only work if it is installed """ return six.next(six.itervalues(self.zap._request(self.zap.base + 'selenium/action/setOptionIeDriverPath/', {'String': string, 'apikey': apikey}))) diff --git a/src/zapv2/websocket.py b/src/zapv2/websocket.py index 3ba0b5a..e968672 100644 --- a/src/zapv2/websocket.py +++ b/src/zapv2/websocket.py @@ -58,9 +58,24 @@ def messages(self, channelid=None, start=None, count=None, payloadpreviewlength= params['payloadPreviewLength'] = payloadpreviewlength return six.next(six.itervalues(self.zap._request(self.zap.base + 'websocket/view/messages/', params))) + @property + def break_text_message(self): + """ + Returns a text representation of an intercepted websockets message + This component is optional and therefore the API will only work if it is installed + """ + return six.next(six.itervalues(self.zap._request(self.zap.base + 'websocket/view/breakTextMessage/'))) + def send_text_message(self, channelid, outgoing, message, apikey=''): """ Sends the specified message on the channel specified by channelId, if outgoing is 'True' then the message will be sent to the server and if it is 'False' then it will be sent to the client This component is optional and therefore the API will only work if it is installed """ return six.next(six.itervalues(self.zap._request(self.zap.base + 'websocket/action/sendTextMessage/', {'channelId': channelid, 'outgoing': outgoing, 'message': message, 'apikey': apikey}))) + + def set_break_text_message(self, message, outgoing, apikey=''): + """ + Sets the text message for an intercepted websockets message + This component is optional and therefore the API will only work if it is installed + """ + return six.next(six.itervalues(self.zap._request(self.zap.base + 'websocket/action/setBreakTextMessage/', {'message': message, 'outgoing': outgoing, 'apikey': apikey})))