예제 #1
0
def main():
    hostip = '<IP>'
    username = '******'
    password = '******'

    sc = TenableSC(hostip)
    sc.login(username, password)

    for item in sc.get('scanResult').json()['response']['manageable']:
        if 'Running' in item['status']:
            print('{id}: {name}'.format(**item))

    sc.logout()
예제 #2
0
def main():
    if not config:
        print('Creating new config file \u2026 ', end='')
        save(create_new())
        print('Created')
        print('Edit the configuration file with the appropriate information and re-run.')
        exit()

    start = time.time()
    connected = False
    SC = None

    while time.time() < start + 60:
        import logging
        try:
            logging.getLogger().setLevel(logging.NOTSET)
            print(f"Looking for SecurityCenter at: '{config.hostname}' \u2026 ", end='')
            SC = TenableSC(config.hostname)
            print('Found.')
            access_type, (access_name, access_secret) = config.get()
            if access_type == 'api':
                print(f"Attempting to log in with API Key \u2026 ", end='')
                SC.login(access_key=access_name, secret_key=access_secret)
            else:
                print(f"Attempting to log in as: '{access_name}' \u2026 ", end='')
                SC.login(user=access_name, passwd=access_secret)
            logged_in = False
            try:
                logged_in = isinstance(SC.status.status(), dict)
            except tenable.errors.APIError:
                pass
            if logged_in:
                print('Logged In.')
                connected = True
                break
            else:
                print()
        except tenable.errors.ConnectionError as err:
            print(f'{err.msg}\tRetrying for {round(start + 60 - time.time())} more seconds.')
            time.sleep(2)
        except tenable.errors.APIError as err:
            print(err.response.json()['error_msg'])
            break
        except Exception as err:
            raise err
        finally:
            logging.getLogger().setLevel(logging.WARNING)

    if not connected:
        print(f'Unable to connect to {config.hostname}')
        if isinstance(SC, tenable.sc.TenableSC) and 'X-SecurityCenter' in SC.session.headers:
            SC.logout()
        exit(1)

    def loop():
        global exit_loop
        while True:
            key = getKey()
            if key == 'q':
                with threading.Lock():
                    exit_loop = True
                    print('Quitting \u2026')
                    break

    thread = threading.Thread(name='GetKey Thread', target=loop, daemon=True)
    display = None

    thread.start()
    global exit_loop
    exit_loop = False
    while True:
        current_loop = time.time()
        if display:
            os.system('cls' if os.name == 'nt' else 'clear')
            print(display, end='\r\n')
            print("Press 'q' to quit.", end='\r\n')
        display_updated = False

        while time.time() < current_loop + 5:
            if not display_updated:
                if not exit_loop:
                    running_scans = SC.get('scanResult?filter=running&fields=id').json()['response']['manageable']
                if not exit_loop:
                    try:
                        running_scans = [SC.scan_instances.details(int(scan_id['id'])) for scan_id in running_scans]
                    except tenable.errors.APIError:
                        running_scans = []
                if not exit_loop:
                    for index in range(len(running_scans)):
                        try:
                            running_scans[index]['scan'] = SC.scans.details(running_scans[index]['scan']['id'])
                        except tenable.errors.APIError:
                            pass
                if not exit_loop:
                    display = all_scans_display(running_scans=running_scans)
                    display_updated = True
            if exit_loop:
                logged_in = False
                try:
                    logged_in = isinstance(SC.status.status(), dict)
                except tenable.errors.APIError:
                    pass
                if logged_in:
                    SC.logout()
                exit()
# Smayan Daruka
# This script removes "Rollover Scans" from Tenable Security Center.
# You will need Python 3 and the pyTenable module to run this script.
# To install pyTenable - pip install pytenable

from tenable.sc import TenableSC
# Replace the IP ADDRESS below with the IP of the appliance - keep the single quotes.
sc = TenableSC('IP ADDRESS')
# Replace username and password for authentication - keep the single quotes.
sc.login('USERNAME', 'PASSWORD')
for scan in sc.get('scan', params={
        'fields': 'status,name,type,schedule'
}).json()['response']['usable']:
    if scan['schedule']['type'] == 'rollover':
        sc.delete('scan/{}'.format(scan['id']))
        # The line below is used for verbose output as it prints the name of the scan being deleted.
        # It can be safely removed without impacting functionality.
        print('Removed {}'.format(scan['name']))
예제 #4
0
#note you need to run pip install pytenable
import requests
import json
import sys

from tenable.sc import TenableSC
sc = TenableSC('10.10.89.251', port=443)
sc.login('svc-jenkins', 'R#*3AduDTNIqJ*g')
iplist=sys.argv
iplist.pop(0)
try:
    resp=sc.get('scan/2298')
    responsedict=resp.json()
    print (responsedict)
    sc.scans.edit(2298, name='VULN-Standard Scan Configurable',targets=iplist)
    running = sc.scans.launch(2298)
    print('The Scan Result ID is {}'.format(running['scanResult']['id']))    
except Exception as e:
    print(e)