@@ -124,7 +124,6 @@ async def execute(self, cmd, blocking=True, outfile=None, errfile=None):
124
124
125
125
if target .autorecon .config ['verbose' ] >= 1 :
126
126
info ('Service scan {bblue}' + plugin .name + ' (' + tag + '){rst} is running the following command against {byellow}' + address + '{rst}: ' + cmd )
127
- #info('{blue}[{bright}' + address + ' ' + tag + '{srst}]{rst} Running command: ' + cmd)
128
127
129
128
if outfile is not None :
130
129
outfile = os .path .abspath (os .path .join (target .scandir , e (outfile )))
@@ -384,15 +383,6 @@ def __init__(self):
384
383
def add_argument (self , plugin , name , ** kwargs ):
385
384
# TODO: make sure name is simple.
386
385
name = '--' + plugin .slug + '.' + slugify (name )
387
- '''if 'action' in kwargs.keys() and kwargs['action'] != 'store':
388
- if kwargs['action'] in ['store_true']
389
- else:
390
- if 'metavar' not in kwargs.keys():
391
- kwargs['metavar'] = 'VALUE'
392
-
393
- if 'metavar' not in kwargs.keys() and 'choices' not in kwargs.keys() and ('action' in kwargs.keys() and kwargs['action'] not in ['store_true', 'store_false']):
394
- kwargs['metavar'] = 'VALUE'
395
- '''
396
386
397
387
if self .argparse_group is None :
398
388
self .argparse_group = self .argparse .add_argument_group ('plugin arguments' , description = 'These are optional arguments for certain plugins.' )
@@ -639,7 +629,10 @@ def cancel_all_tasks(signal, frame):
639
629
for target in autorecon .scanning_targets :
640
630
for process_list in target .running_tasks .values ():
641
631
for process_dict in process_list ['processes' ]:
642
- process_dict ['process' ].kill ()
632
+ try :
633
+ process_dict ['process' ].kill ()
634
+ except ProcessLookupError : # Will get raised if the process finishes before we get to killing it.
635
+ pass
643
636
644
637
async def start_heartbeat (target , period = 60 ):
645
638
while True :
@@ -712,24 +705,12 @@ async def service_scan(plugin, service):
712
705
while True :
713
706
if semaphore .locked ():
714
707
if semaphore != service .target .autorecon .port_scan_semaphore : # This will be true unless user sets max_scans == max_port_scans
715
- # port_scan_task_count = 0
716
- # for t in asyncio.all_tasks():
717
- # frame = inspect.getframeinfo(t.get_stack(limit=1)[0])
718
- # if frame.function == 'port_scan' and 'await plugin.run(target)' in frame.code_context[0]:
719
- # #print(frame)
720
- # port_scan_task_count += 1
721
- # print("Old Port Scan Task Count: " + str(port_scan_task_count))
722
708
723
709
port_scan_task_count = 0
724
710
for targ in service .target .autorecon .scanning_targets :
725
711
for process_list in targ .running_tasks .values ():
726
- #print('Length: ' + str(len(process_list)))
727
- #for process_dict in process_list['processes']:
728
712
if issubclass (process_list ['plugin' ].__class__ , PortScan ):
729
- #for process_dict in process_list['processes']:
730
- # print(str(process_dict['process'].returncode) + ': ' + process_dict['cmd'])
731
713
port_scan_task_count += 1
732
- #print("New Port Scan Task Count: " + str(new_port_scan_task_count))
733
714
734
715
if not service .target .autorecon .pending_targets and (service .target .autorecon .config ['max_port_scans' ] - port_scan_task_count ) >= 1 : # If no more targets, and we have room, use port scan semaphore.
735
716
if service .target .autorecon .port_scan_semaphore .locked ():
@@ -892,8 +873,6 @@ async def scan_target(target):
892
873
else :
893
874
continue
894
875
895
- #plugin = task.result()['plugin']
896
- #info('Port scan {bblue}' + plugin.name + ' (' + plugin.slug + '){srst}]{rst} found {bmagenta}' + service.name + '{rst} on {bmagenta}' + service.protocol + '/' + str(service.port) + '{rst} on {byellow}' + target.address + '{rst}')
897
876
info ('Found {bmagenta}' + service .name + '{rst} on {bmagenta}' + service .protocol + '/' + str (service .port ) + '{rst} on {byellow}' + target .address + '{rst}' )
898
877
899
878
service .target = target
@@ -1116,7 +1095,7 @@ async def main():
1116
1095
for key , val in global_toml .items ():
1117
1096
if key == 'global' and isinstance (val , dict ): # Process global plugin options.
1118
1097
for gkey , gvals in global_toml ['global' ].items ():
1119
- if isinstance (gvals , dict ):# and 'help' in gvals:
1098
+ if isinstance (gvals , dict ):
1120
1099
options = {'metavar' :'VALUE' }
1121
1100
1122
1101
if 'default' in gvals :
@@ -1360,8 +1339,6 @@ async def main():
1360
1339
1361
1340
start_time = time .time ()
1362
1341
1363
- #sys.exit(0)
1364
-
1365
1342
pending = []
1366
1343
i = 0
1367
1344
while autorecon .pending_targets :
@@ -1385,19 +1362,11 @@ async def main():
1385
1362
if autorecon .pending_targets :
1386
1363
pending .add (asyncio .create_task (scan_target (Target (autorecon .pending_targets .pop (0 ), autorecon ))))
1387
1364
1388
- #port_scan_task_count = 0
1389
- #for t in asyncio.all_tasks():
1390
- # if inspect.getframeinfo(t.get_stack(limit=1)[0]).function == 'port_scan':
1391
- # port_scan_task_count += 1
1392
- #print("Old Port Scan Task Count: " + str(port_scan_task_count))
1393
-
1394
1365
port_scan_task_count = 0
1395
1366
for targ in autorecon .scanning_targets :
1396
1367
for process_list in targ .running_tasks .values ():
1397
1368
if issubclass (process_list ['plugin' ].__class__ , PortScan ):
1398
- #print(process_list)
1399
1369
port_scan_task_count += 1
1400
- #print("New Port Scan Task Count: " + str(port_scan_task_count))
1401
1370
1402
1371
num_new_targets = math .ceil ((autorecon .config ['max_port_scans' ] - port_scan_task_count ) / port_scan_plugin_count )
1403
1372
if num_new_targets > 0 :
0 commit comments