Skip to content

Commit

Permalink
Release 1.11.0
Browse files Browse the repository at this point in the history
New command: shodan alert info
Improved output of alert and trigger information
  • Loading branch information
achillean committed Feb 20, 2019
1 parent 23cbc68 commit c798e75
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
CHANGELOG
=========

unreleased
1.11.0
----------
* New command **shodan scan list** to list recently launched scans
* New command **shodan alert triggers** to list the available notification triggers
* New command **shodan alert enable** to enable a notification trigger
* New command **shodan alert disable** to disable a notification trigger
* New command **shodan alert info** to show details of a specific alert
* Include timestamp, vulns and tags in CSV converter (#85)
* Fixed bug that caused an exception when parsing uncompressed data files in Python3
* Code quality improvements
* Thank you for contributions from @wagner-certat, @cclauss, @opt9, @voldmar and Antoine Neuenschwander

1.10.4
------
Expand Down
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.10.4',
version='1.11.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
65 changes: 53 additions & 12 deletions shodan/cli/alert.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import click
import shodan

from operator import itemgetter
from shodan.cli.helpers import get_api_key


Expand Down Expand Up @@ -45,6 +46,42 @@ def alert_create(name, netblock):
click.secho('Alert ID: {}'.format(alert['id']), fg='cyan')


@alert.command(name='info')
@click.argument('alert', metavar='<alert id>')
def alert_info(alert):
"""Show information about a specific alert"""
key = get_api_key()
api = shodan.Shodan(key)

try:
info = api.alerts(aid=alert)
except shodan.APIError as e:
raise click.ClickException(e.value)

click.secho(info['name'], fg='cyan')
click.secho('Created: ', nl=False, dim=True)
click.secho(info['created'], fg='magenta')

click.secho('Notifications: ', nl=False, dim=True)
if 'triggers' in info and info['triggers']:
click.secho('enabled', fg='green')
else:
click.echo('disabled')

click.echo('')
click.secho('Network Range(s):', dim=True)

for network in info['filters']['ip']:
click.echo(u' > {}'.format(click.style(network, fg='yellow')))

click.echo('')
if 'triggers' in info and info['triggers']:
click.secho('Triggers:', dim=True)
for trigger in info['triggers']:
click.echo(u' > {}'.format(click.style(trigger, fg='yellow')))
click.echo('')


@alert.command(name='list')
@click.option('--expired', help='Whether or not to show expired alerts.', default=True, type=bool)
def alert_list(expired):
Expand Down Expand Up @@ -100,7 +137,7 @@ def alert_remove(alert_id):

@alert.command(name='triggers')
def alert_list_triggers():
"""List all the available triggers"""
"""List the available notification triggers"""
key = get_api_key()

# Get the list
Expand All @@ -111,16 +148,20 @@ def alert_list_triggers():
raise click.ClickException(e.value)

if len(results) > 0:
click.echo(u'# {:14} {:<21} {:<15s}'.format('Name', 'Description', 'Rule'))
click.secho('The following triggers can be enabled on alerts:', dim=True)
click.echo('')

for trigger in results:
click.echo(
u'{:16} {:<30} {:<35} '.format(
click.style(trigger['name'], fg='yellow'),
click.style(trigger['description'], fg='cyan'),
trigger['rule']
)
)
for trigger in sorted(results, key=itemgetter('name')):
click.secho('{:<12} '.format('Name'), dim=True, nl=False)
click.secho(trigger['name'], fg='yellow')

click.secho('{:<12} '.format('Description'), dim=True, nl=False)
click.secho(trigger['description'], fg='cyan')

click.secho('{:<12} '.format('Rule'), dim=True, nl=False)
click.echo(trigger['rule'])

click.echo('')
else:
click.echo("No triggers currently available.")

Expand All @@ -139,7 +180,7 @@ def alert_enable_trigger(alert_id, trigger):
except shodan.APIError as e:
raise click.ClickException(e.value)

click.secho('Successfully enabled the trigger {}'.format(trigger), color='green')
click.secho('Successfully enabled the trigger: {}'.format(trigger), fg='green')


@alert.command(name='disable')
Expand All @@ -156,4 +197,4 @@ def alert_disable_trigger(alert_id, trigger):
except shodan.APIError as e:
raise click.ClickException(e.value)

click.secho('Successfully disabled the trigger {}'.format(trigger), color='green')
click.secho('Successfully disabled the trigger: {}'.format(trigger), fg='green')

0 comments on commit c798e75

Please sign in to comment.