Skip to content

Commit b1d3df6

Browse files
authored
Merge pull request #60 from thc202/regen-2.10.0
Regenerate APIs and prepare release
2 parents 9f51bdb + cdc22f6 commit b1d3df6

File tree

8 files changed

+141
-7
lines changed

8 files changed

+141
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
55

6-
## [Unreleased]
6+
## [0.0.18] - 2020-12-18
77
### Changed
8-
- Update APIs from GraphQL add-on.
8+
- Core APIs updated for ZAP version 2.10.0.
9+
- Update APIs from add-ons:
10+
- AJAX Spider;
11+
- GraphQL.
912

1013
## [0.0.17] - 2020-10-14
1114
### Added
@@ -87,7 +90,7 @@ ensure it's automatically sent in all API requests.
8790
### Changed
8891
- Moved from the main `zaproxy` repository.
8992

90-
[Unreleased]: https://github.com/zaproxy/zap-api-python/compare/0.0.17...HEAD
93+
[0.0.18]: https://github.com/zaproxy/zap-api-python/compare/0.0.17...0.0.18
9194
[0.0.17]: https://github.com/zaproxy/zap-api-python/compare/0.0.16...0.0.17
9295
[0.0.16]: https://github.com/zaproxy/zap-api-python/compare/0.0.15...0.0.16
9396
[0.0.15]: https://github.com/zaproxy/zap-api-python/compare/0.0.14...0.0.15

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
setup(
2828
name="python-owasp-zap-v2.4",
2929
version="0.0.18",
30-
description="OWASP ZAP 2.9 API client",
31-
long_description="OWASP Zed Attack Proxy 2.9 API Python client (the 2.4 package name has been kept to make it easier to upgrade)",
30+
description="OWASP ZAP 2.10 API client",
31+
long_description="OWASP Zed Attack Proxy 2.10 API Python client (the 2.4 package name has been kept to make it easier to upgrade)",
3232
author="ZAP development team",
3333
author_email='',
3434
url="https://www.zaproxy.org/",

src/zapv2/acsrf.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ def option_tokens_names(self):
3434
"""
3535
return six.next(six.itervalues(self.zap._request(self.zap.base + 'acsrf/view/optionTokensNames/')))
3636

37+
@property
38+
def option_partial_matching_enabled(self):
39+
"""
40+
Define if ZAP should detect CSRF tokens by searching for partial matches
41+
"""
42+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'acsrf/view/optionPartialMatchingEnabled/')))
43+
3744
def add_option_token(self, string, apikey=''):
3845
"""
3946
Adds an anti-CSRF token with the given name, enabled by default
@@ -46,6 +53,12 @@ def remove_option_token(self, string, apikey=''):
4653
"""
4754
return six.next(six.itervalues(self.zap._request(self.zap.base + 'acsrf/action/removeOptionToken/', {'String': string, 'apikey': apikey})))
4855

56+
def set_option_partial_matching_enabled(self, boolean, apikey=''):
57+
"""
58+
Define if ZAP should detect CSRF tokens by searching for partial matches.
59+
"""
60+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'acsrf/action/setOptionPartialMatchingEnabled/', {'Boolean': boolean, 'apikey': apikey})))
61+
4962
def gen_form(self, hrefid, apikey=''):
5063
"""
5164
Generate a form for testing lack of anti-CSRF tokens - typically invoked via ZAP

src/zapv2/ajaxSpider.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ class ajaxSpider(object):
2727
def __init__(self, zap):
2828
self.zap = zap
2929

30+
@property
31+
def allowed_resources(self):
32+
"""
33+
This component is optional and therefore the API will only work if it is installed
34+
"""
35+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/view/allowedResources/')))
36+
3037
@property
3138
def status(self):
3239
"""
@@ -131,7 +138,7 @@ def option_random_inputs(self):
131138

132139
def scan(self, url=None, inscope=None, contextname=None, subtreeonly=None, apikey=''):
133140
"""
134-
Runs the spider against the given URL and/or context, optionally, spidering everything in scope. The parameter 'contextName' can be used to constrain the scan to a Context, the option 'in scope' is ignored if a context was also specified. The parameter 'subtreeOnly' allows to restrict the spider under a site's subtree (using the specified 'url').
141+
Runs the AJAX Spider against a given target.
135142
This component is optional and therefore the API will only work if it is installed
136143
"""
137144
params = {'apikey': apikey}
@@ -147,7 +154,7 @@ def scan(self, url=None, inscope=None, contextname=None, subtreeonly=None, apike
147154

148155
def scan_as_user(self, contextname, username, url=None, subtreeonly=None, apikey=''):
149156
"""
150-
Runs the spider from the perspective of a User, obtained using the given context name and user name. The parameter 'url' allows to specify the starting point for the spider, otherwise it's used an existing URL from the context (if any). The parameter 'subtreeOnly' allows to restrict the spider under a site's subtree (using the specified 'url').
157+
Runs the AJAX Spider from the perspective of a User of the web application.
151158
This component is optional and therefore the API will only work if it is installed
152159
"""
153160
params = {'contextName': contextname, 'userName': username, 'apikey': apikey}
@@ -163,6 +170,27 @@ def stop(self, apikey=''):
163170
"""
164171
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/stop/', {'apikey': apikey})))
165172

173+
def add_allowed_resource(self, regex, enabled=None, apikey=''):
174+
"""
175+
This component is optional and therefore the API will only work if it is installed
176+
"""
177+
params = {'regex': regex, 'apikey': apikey}
178+
if enabled is not None:
179+
params['enabled'] = enabled
180+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/addAllowedResource/', params)))
181+
182+
def remove_allowed_resource(self, regex, apikey=''):
183+
"""
184+
This component is optional and therefore the API will only work if it is installed
185+
"""
186+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/removeAllowedResource/', {'regex': regex, 'apikey': apikey})))
187+
188+
def set_enabled_allowed_resource(self, regex, enabled, apikey=''):
189+
"""
190+
This component is optional and therefore the API will only work if it is installed
191+
"""
192+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'ajaxSpider/action/setEnabledAllowedResource/', {'regex': regex, 'enabled': enabled, 'apikey': apikey})))
193+
166194
def set_option_browser_id(self, string, apikey=''):
167195
"""
168196
This component is optional and therefore the API will only work if it is installed

src/zapv2/alert.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ def delete_alert(self, id, apikey=''):
102102
"""
103103
return six.next(six.itervalues(self.zap._request(self.zap.base + 'alert/action/deleteAlert/', {'id': id, 'apikey': apikey})))
104104

105+
def update_alerts_confidence(self, ids, confidenceid, apikey=''):
106+
"""
107+
Update the confidence of the alerts.
108+
"""
109+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'alert/action/updateAlertsConfidence/', {'ids': ids, 'confidenceId': confidenceid, 'apikey': apikey})))
110+
111+
def update_alerts_risk(self, ids, riskid, apikey=''):
112+
"""
113+
Update the risk of the alerts.
114+
"""
115+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'alert/action/updateAlertsRisk/', {'ids': ids, 'riskId': riskid, 'apikey': apikey})))
116+
105117
def update_alert(self, id, name, riskid, confidenceid, description, param=None, attack=None, otherinfo=None, solution=None, references=None, evidence=None, cweid=None, wascid=None, apikey=''):
106118
"""
107119
Update the alert with the given ID, with the provided details.

src/zapv2/context.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,23 @@ def set_context_regexs(self, contextname, incregexs, excregexs, apikey=''):
9595
"""
9696
return six.next(six.itervalues(self.zap._request(self.zap.base + 'context/action/setContextRegexs/', {'contextName': contextname, 'incRegexs': incregexs, 'excRegexs': excregexs, 'apikey': apikey})))
9797

98+
def set_context_checking_strategy(self, contextname, checkingstrategy, pollurl=None, polldata=None, pollheaders=None, pollfrequency=None, pollfrequencyunits=None, apikey=''):
99+
"""
100+
Set the checking strategy for a context - this defines how ZAP checks that a request is authenticated
101+
"""
102+
params = {'contextName': contextname, 'checkingStrategy': checkingstrategy, 'apikey': apikey}
103+
if pollurl is not None:
104+
params['pollUrl'] = pollurl
105+
if polldata is not None:
106+
params['pollData'] = polldata
107+
if pollheaders is not None:
108+
params['pollHeaders'] = pollheaders
109+
if pollfrequency is not None:
110+
params['pollFrequency'] = pollfrequency
111+
if pollfrequencyunits is not None:
112+
params['pollFrequencyUnits'] = pollfrequencyunits
113+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'context/action/setContextCheckingStrategy/', params)))
114+
98115
def new_context(self, contextname, apikey=''):
99116
"""
100117
Creates a new context with the given name in the current session

src/zapv2/core.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ def option_use_proxy_chain(self):
287287
def option_use_proxy_chain_auth(self):
288288
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/optionUseProxyChainAuth/')))
289289

290+
@property
291+
def option_use_socks_proxy(self):
292+
"""
293+
Gets whether or not the SOCKS proxy should be used.
294+
"""
295+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/view/optionUseSocksProxy/')))
296+
290297
def access_url(self, url, followredirects=None, apikey=''):
291298
"""
292299
Convenient and simple action to access a URL, optionally following redirections. Returns the request sent and response received and followed redirections, if any. Other actions are available which offer more control on what is sent, like, 'sendRequest' or 'sendHarRequest'.
@@ -536,6 +543,12 @@ def set_option_use_proxy_chain(self, boolean, apikey=''):
536543
def set_option_use_proxy_chain_auth(self, boolean, apikey=''):
537544
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/action/setOptionUseProxyChainAuth/', {'Boolean': boolean, 'apikey': apikey})))
538545

546+
def set_option_use_socks_proxy(self, boolean, apikey=''):
547+
"""
548+
Sets whether or not the SOCKS proxy should be used.
549+
"""
550+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'core/action/setOptionUseSocksProxy/', {'Boolean': boolean, 'apikey': apikey})))
551+
539552
def proxy_pac(self, apikey=''):
540553
return (self.zap._request_other(self.zap.base_other + 'core/other/proxy.pac/', {'apikey': apikey}))
541554

src/zapv2/users.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ def get_authentication_credentials(self, contextid, userid):
5454
"""
5555
return six.next(six.itervalues(self.zap._request(self.zap.base + 'users/view/getAuthenticationCredentials/', {'contextId': contextid, 'userId': userid})))
5656

57+
def get_authentication_state(self, contextid, userid):
58+
"""
59+
Gets the authentication state information for the user identified by the Context and User Ids.
60+
"""
61+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'users/view/getAuthenticationState/', {'contextId': contextid, 'userId': userid})))
62+
63+
def get_authentication_session(self, contextid, userid):
64+
"""
65+
Gets the authentication session information for the user identified by the Context and User Ids, e.g. cookies and realm credentials.
66+
"""
67+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'users/view/getAuthenticationSession/', {'contextId': contextid, 'userId': userid})))
68+
5769
def new_user(self, contextid, name, apikey=''):
5870
"""
5971
Creates a new user with the given name for the context with the given ID.
@@ -86,3 +98,39 @@ def set_authentication_credentials(self, contextid, userid, authcredentialsconfi
8698
if authcredentialsconfigparams is not None:
8799
params['authCredentialsConfigParams'] = authcredentialsconfigparams
88100
return six.next(six.itervalues(self.zap._request(self.zap.base + 'users/action/setAuthenticationCredentials/', params)))
101+
102+
def authenticate_as_user(self, contextid, userid, apikey=''):
103+
"""
104+
Tries to authenticate as the identified user, returning the authentication request and whether it appears to have succeeded.
105+
"""
106+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'users/action/authenticateAsUser/', {'contextId': contextid, 'userId': userid, 'apikey': apikey})))
107+
108+
def poll_as_user(self, contextid, userid, apikey=''):
109+
"""
110+
Tries to poll as the identified user, returning the authentication request and whether it appears to have succeeded. This will only work if the polling verification strategy has been configured.
111+
"""
112+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'users/action/pollAsUser/', {'contextId': contextid, 'userId': userid, 'apikey': apikey})))
113+
114+
def set_authentication_state(self, contextid, userid, lastpollresult=None, lastpolltimeinms=None, requestssincelastpoll=None, apikey=''):
115+
"""
116+
Sets fields in the authentication state for the user identified by the Context and User Ids.
117+
"""
118+
params = {'contextId': contextid, 'userId': userid, 'apikey': apikey}
119+
if lastpollresult is not None:
120+
params['lastPollResult'] = lastpollresult
121+
if lastpolltimeinms is not None:
122+
params['lastPollTimeInMs'] = lastpolltimeinms
123+
if requestssincelastpoll is not None:
124+
params['requestsSinceLastPoll'] = requestssincelastpoll
125+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'users/action/setAuthenticationState/', params)))
126+
127+
def set_cookie(self, contextid, userid, domain, name, value, path=None, secure=None, apikey=''):
128+
"""
129+
Sets the specified cookie for the user identified by the Context and User Ids.
130+
"""
131+
params = {'contextId': contextid, 'userId': userid, 'domain': domain, 'name': name, 'value': value, 'apikey': apikey}
132+
if path is not None:
133+
params['path'] = path
134+
if secure is not None:
135+
params['secure'] = secure
136+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'users/action/setCookie/', params)))

0 commit comments

Comments
 (0)