Skip to content

Commit 1e018da

Browse files
author
zeloff
committed
add v4 support
1 parent cc29031 commit 1e018da

File tree

3 files changed

+78
-16
lines changed

3 files changed

+78
-16
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[tool.poetry]
22
name = "vulners"
3-
version = "2.2.3"
3+
version = "2.3.0"
44
description = "Python library and command-line utility for Vulners (https://vulners.com)"
55
readme = "README.md"
6-
authors = ["Kirill Ermakov <[email protected]>", "Andrei Churin <[email protected]>"]
6+
authors = ["Vulners Team"]
77
keywords = ["security", "network", "vulners", "vulnerability", "CVE"]
88
classifiers = [
99
"Development Status :: 5 - Production/Stable",

vulners/base.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,27 @@ def __init__(self, value):
248248
self.value = value
249249

250250

251+
class Any(Param):
252+
def __init__(self, *args, **kwargs):
253+
assert all([p.__base__ == Param for p in args]), "Invalid argument type"
254+
self.__params = [p(**kwargs) for p in args]
255+
super(Any, self).__init__(**kwargs)
256+
257+
def validate(self, param, value):
258+
errs = []
259+
for _param in self.__params:
260+
try:
261+
return _param.validate(param, value)
262+
except ParamError as e:
263+
errs.append(e)
264+
pass
265+
266+
raise ParamError(
267+
"Expect %s but got '%s'",
268+
(" or ".join([p.__class__.__name__ for p in self.__params]), type(value)),
269+
)
270+
271+
251272
class String(Param):
252273
def __init__(self, choices=None, *args, **kwargs):
253274
super(String, self).__init__(*args, **kwargs)

vulners/vulners.py

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import zipfile
55

66
from .base import (
7+
Any,
78
Boolean,
89
Const,
910
Dict,
@@ -185,10 +186,13 @@ def _get_burp_software_content(content, _):
185186
("sw_edition", String(required=False)),
186187
("target_sw", String(required=False)),
187188
("target_hw", String(required=False)),
188-
("respect_major_version", String(required=False, choices=["yes", "no", "true", "false"])),
189+
(
190+
"respect_major_version",
191+
String(required=False, choices=["yes", "no", "true", "false"]),
192+
),
189193
("exclude_any_version", String(required=False, choices=["yes", "no", "true", "false"])),
190-
("type", String(required=False)), # deprecated
191-
("exactmatch", Boolean(default=False)), # deprecated
194+
("type", String(required=False)), # deprecated
195+
("exactmatch", Boolean(default=False)), # deprecated
192196
],
193197
content_handler=_get_burp_software_content,
194198
)
@@ -208,8 +212,13 @@ def get_software_vulnerabilities(
208212
target_hw=None,
209213
respect_major_version=None,
210214
exclude_any_version=None,
211-
only_ids=None
215+
only_ids=None,
212216
):
217+
warnings.warn(
218+
"get_software_vulnerabilities() is deprecated and will be removed in future release. "
219+
"Use VulnersApi.audit_software() or VulnersApi.audit_host() instead.",
220+
DeprecationWarning,
221+
)
213222
"""
214223
Find software vulnerabilities using name and version.
215224
@@ -227,16 +236,45 @@ def get_software_vulnerabilities(
227236
target_hw,
228237
respect_major_version,
229238
exclude_any_version,
230-
only_ids
239+
only_ids,
231240
)
232241

242+
audit_software = Endpoint(
243+
method="post",
244+
url="/api/v4/audit/software-batch/",
245+
params=[
246+
(
247+
"software",
248+
List(
249+
item=Dict(),
250+
description="List of dicts. E.g., [{'product': 'curl', 'version': '8.11.1', ...}, ...]",
251+
),
252+
),
253+
],
254+
content_handler=lambda c, _: c["result"],
255+
)
256+
257+
audit_host = Endpoint(
258+
method="post",
259+
url="/api/v4/audit/host/",
260+
params=[
261+
(
262+
"software",
263+
List(
264+
item=Dict(),
265+
description="List of dicts. E.g., [{'product': 'curl', 'version': '8.11.1', ...}, ...]",
266+
),
267+
),
268+
("application", Any(String, Dict, required=False)),
269+
("operation_system", Any(String, Dict, required=False)),
270+
("hardware", Any(String, Dict, required=False)),
271+
],
272+
content_handler=lambda c, _: c["result"],
273+
)
274+
233275
@validate_params(cpe=String())
234276
def get_cpe_vulnerabilities(
235-
self,
236-
cpe,
237-
respect_major_version=None,
238-
exclude_any_version=None,
239-
only_ids=None
277+
self, cpe, respect_major_version=None, exclude_any_version=None, only_ids=None
240278
):
241279
"""
242280
Find software vulnerabilities using CPE string. See CPE references at https://cpe.mitre.org/specification/
@@ -654,7 +692,7 @@ def scanlist_report(self, limit=30, offset=0, filter=None, sort=""):
654692
("format", String(default="html", choices=("html", "json", "pdf"))),
655693
("crontab", String(allow_null=True, default=None)),
656694
("query_type", String(default="lucene")),
657-
]
695+
],
658696
)
659697

660698
edit_subscription = Endpoint(
@@ -664,16 +702,19 @@ def scanlist_report(self, limit=30, offset=0, filter=None, sort=""):
664702
("subscriptionid", String()),
665703
("format", String(allow_null=True, default=None, choices=("html", "json", "pdf"))),
666704
("crontab", String(allow_null=True, default=None)),
667-
("active", String(allow_null=True, default=None, choices=("yes", "no", "true", "false"))),
668-
]
705+
(
706+
"active",
707+
String(allow_null=True, default=None, choices=("yes", "no", "true", "false")),
708+
),
709+
],
669710
)
670711

671712
delete_subscription = Endpoint(
672713
method="post",
673714
url="/api/v3/subscriptions/removeEmailSubscription/",
674715
params=[
675716
("subscriptionid", String()),
676-
]
717+
],
677718
)
678719

679720
get_webhooks = Endpoint(

0 commit comments

Comments
 (0)