Skip to content

Commit bde4442

Browse files
committed
New Streaming API method: /shodan/vulns/{vulns} to subscribe to IPs that are vulnerable to an issue
Release 1.22.0
1 parent 44fc39e commit bde4442

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='shodan',
10-
version='1.21.3',
10+
version='1.22.0',
1111
description='Python library and command-line utility for Shodan (https://developer.shodan.io)',
1212
long_description=README,
1313
long_description_content_type='text/x-rst',

shodan/__main__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,8 @@ def stats(limit, facets, filename, query):
635635
@click.option('--alert', help='The network alert ID or "all" to subscribe to all network alerts on your account.', default=None, type=str)
636636
@click.option('--tags', help='A comma-separated list of tags to grab data on.', default=None, type=str)
637637
@click.option('--compresslevel', help='The gzip compression level (0-9; 0 = no compression, 9 = most compression', default=9, type=int)
638-
def stream(color, fields, separator, limit, datadir, ports, quiet, timeout, streamer, countries, asn, alert, tags, compresslevel):
638+
@click.option('--vulns', help='A comma-separated list of vulnerabilities to grab data on.', default=None, type=str)
639+
def stream(color, fields, separator, limit, datadir, ports, quiet, timeout, streamer, countries, asn, alert, tags, compresslevel, vulns):
639640
"""Stream data in real-time."""
640641
# Setup the Shodan API
641642
key = get_api_key()
@@ -663,9 +664,11 @@ def stream(color, fields, separator, limit, datadir, ports, quiet, timeout, stre
663664
stream_type.append('alert')
664665
if tags:
665666
stream_type.append('tags')
667+
if vulns:
668+
stream_type.append('vulns')
666669

667670
if len(stream_type) > 1:
668-
raise click.ClickException('Please use --ports, --countries, --tags OR --asn. You cant subscribe to multiple filtered streams at once.')
671+
raise click.ClickException('Please use --ports, --countries, --tags, --vulns OR --asn. You cant subscribe to multiple filtered streams at once.')
669672

670673
stream_args = None
671674

@@ -689,6 +692,9 @@ def stream(color, fields, separator, limit, datadir, ports, quiet, timeout, stre
689692

690693
if tags:
691694
stream_args = tags.split(',')
695+
696+
if vulns:
697+
stream_args = vulns.split(',')
692698

693699
# Flatten the list of stream types
694700
# Possible values are:
@@ -710,6 +716,7 @@ def _create_stream(name, args, timeout):
710716
'countries': api.stream.countries(args, timeout=timeout),
711717
'ports': api.stream.ports(args, timeout=timeout),
712718
'tags': api.stream.tags(args, timeout=timeout),
719+
'vulns': api.stream.vulns(args, timeout=timeout),
713720
}.get(name, 'all')
714721

715722
stream = _create_stream(stream_type, stream_args, timeout=timeout)

shodan/stream.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,14 @@ def tags(self, tags, raw=False, timeout=None):
134134
stream = self._create_stream('/shodan/tags/%s' % ','.join(tags), timeout=timeout)
135135
for line in self._iter_stream(stream, raw):
136136
yield line
137+
138+
def vulns(self, vulns, raw=False, timeout=None):
139+
"""
140+
A filtered version of the "banners" stream to only return banners that match the vulnerabilities of interest.
141+
142+
:param vulns: A list of vulns to return banner data on.
143+
:type vulns: string[]
144+
"""
145+
stream = self._create_stream('/shodan/vulns/%s' % ','.join(vulns), timeout=timeout)
146+
for line in self._iter_stream(stream, raw):
147+
yield line

0 commit comments

Comments
 (0)