-
Notifications
You must be signed in to change notification settings - Fork 5
/
nessus_scan.py
61 lines (51 loc) · 1.73 KB
/
nessus_scan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Initiate a nessus_scan
Parameters
----------
input_file : string
Required - Full path to a file with the ips (one per line).
scan_name : string
Required - The name to use when initiating the scan.
"""
import logging
import argparse
from nessrest import ness6rest # pylint: disable=import-error
from config import config
from utils import utils, logging_config # noqa pylint: disable=unused-import
log = logging.getLogger("ptscripts.nessus_scan")
def run_nessus_scan(args):
log.info("Initiating nessus scan using the ips in {}".format(args.input_file))
targets = []
with open(args.input_file, 'r') as fp:
for line in fp:
line = line.strip(' \t\n\r')
targets.append(line)
nessus_targets = ','.join(targets)
log.debug("Nessus will scan these ips: {}".format(nessus_targets))
scan = ness6rest.Scanner(
url=config.NESSUS_URL,
api_akey=config.NESSUS_ACCESS_KEY,
api_skey=config.NESSUS_SECRET_KEY,
insecure=True)
scan.scan_add(nessus_targets, template='basic', name=args.scan_name)
res = scan.scan_run()
log.info(res)
def parse_args():
parser = argparse.ArgumentParser(
prog='nessus_scan.py',
parents=[utils.parent_argparser()],
description='Initiate a nessus scan.',
)
parser.add_argument('input_file', help='File with ip addresses (one per line).')
parser.add_argument('scan_name', help='Nessus Scan Name.')
args = parser.parse_args()
logger = logging.getLogger("ptscripts")
if args.quiet:
logger.setLevel('ERROR')
elif args.verbose:
logger.setLevel('DEBUG')
else:
logger.setLevel('INFO')
return args
if __name__ == '__main__':
run_nessus_scan(parse_args())