Skip to content

Commit

Permalink
New Streaming API method: /shodan/vulns/{vulns} to subscribe to IPs t…
Browse files Browse the repository at this point in the history
…hat are vulnerable to an issue

Release 1.22.0
  • Loading branch information
achillean committed Mar 17, 2020
1 parent 44fc39e commit bde4442
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='shodan',
version='1.21.3',
version='1.22.0',
description='Python library and command-line utility for Shodan (https://developer.shodan.io)',
long_description=README,
long_description_content_type='text/x-rst',
Expand Down
11 changes: 9 additions & 2 deletions shodan/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,8 @@ def stats(limit, facets, filename, query):
@click.option('--alert', help='The network alert ID or "all" to subscribe to all network alerts on your account.', default=None, type=str)
@click.option('--tags', help='A comma-separated list of tags to grab data on.', default=None, type=str)
@click.option('--compresslevel', help='The gzip compression level (0-9; 0 = no compression, 9 = most compression', default=9, type=int)
def stream(color, fields, separator, limit, datadir, ports, quiet, timeout, streamer, countries, asn, alert, tags, compresslevel):
@click.option('--vulns', help='A comma-separated list of vulnerabilities to grab data on.', default=None, type=str)
def stream(color, fields, separator, limit, datadir, ports, quiet, timeout, streamer, countries, asn, alert, tags, compresslevel, vulns):
"""Stream data in real-time."""
# Setup the Shodan API
key = get_api_key()
Expand Down Expand Up @@ -663,9 +664,11 @@ def stream(color, fields, separator, limit, datadir, ports, quiet, timeout, stre
stream_type.append('alert')
if tags:
stream_type.append('tags')
if vulns:
stream_type.append('vulns')

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

stream_args = None

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

if tags:
stream_args = tags.split(',')

if vulns:
stream_args = vulns.split(',')

# Flatten the list of stream types
# Possible values are:
Expand All @@ -710,6 +716,7 @@ def _create_stream(name, args, timeout):
'countries': api.stream.countries(args, timeout=timeout),
'ports': api.stream.ports(args, timeout=timeout),
'tags': api.stream.tags(args, timeout=timeout),
'vulns': api.stream.vulns(args, timeout=timeout),
}.get(name, 'all')

stream = _create_stream(stream_type, stream_args, timeout=timeout)
Expand Down
11 changes: 11 additions & 0 deletions shodan/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,14 @@ def tags(self, tags, raw=False, timeout=None):
stream = self._create_stream('/shodan/tags/%s' % ','.join(tags), timeout=timeout)
for line in self._iter_stream(stream, raw):
yield line

def vulns(self, vulns, raw=False, timeout=None):
"""
A filtered version of the "banners" stream to only return banners that match the vulnerabilities of interest.
:param vulns: A list of vulns to return banner data on.
:type vulns: string[]
"""
stream = self._create_stream('/shodan/vulns/%s' % ','.join(vulns), timeout=timeout)
for line in self._iter_stream(stream, raw):
yield line

0 comments on commit bde4442

Please sign in to comment.