Update autorecon.py
Added ability to force service scans.
This commit is contained in:
parent
d1863a1cd3
commit
98037302f7
37
autorecon.py
37
autorecon.py
|
@ -412,6 +412,7 @@ class AutoRecon(object):
|
|||
'nmap',
|
||||
'nmap_append',
|
||||
'disable_sanity_checks',
|
||||
'force_services',
|
||||
'accessible',
|
||||
'verbose'
|
||||
]
|
||||
|
@ -434,6 +435,7 @@ class AutoRecon(object):
|
|||
'nmap': '-vv --reason -Pn',
|
||||
'nmap_append': '',
|
||||
'disable_sanity_checks': False,
|
||||
'force_services': None,
|
||||
'accessible': False,
|
||||
'verbose': 0
|
||||
}
|
||||
|
@ -787,6 +789,7 @@ async def service_scan(plugin, service):
|
|||
from autorecon import PortScan
|
||||
semaphore = service.target.autorecon.service_scan_semaphore
|
||||
|
||||
if not service.target.autorecon.config['force_services']:
|
||||
# If service scan semaphore is locked, see if we can use port scan semaphore.
|
||||
while True:
|
||||
if semaphore.locked():
|
||||
|
@ -917,6 +920,24 @@ async def scan_target(target):
|
|||
|
||||
heartbeat = asyncio.create_task(start_heartbeat(target, period=target.autorecon.config['heartbeat']))
|
||||
|
||||
services = []
|
||||
if autorecon.config['force_services']:
|
||||
forced_services = [x.strip().lower() for x in autorecon.config['force_services']]
|
||||
|
||||
for forced_service in forced_services:
|
||||
match = re.search('(?P<protocol>(tcp|udp))\/(?P<port>\d+)\/(?P<service>[\w\-\/]+)\/(?P<secure>secure|insecure)', forced_service)
|
||||
if match:
|
||||
protocol = match.group('protocol')
|
||||
port = int(match.group('port'))
|
||||
service = match.group('service')
|
||||
secure = True if match.group('secure') == 'secure' else False
|
||||
service = Service(protocol, port, service, secure)
|
||||
service.target = target
|
||||
services.append(service)
|
||||
|
||||
if services:
|
||||
pending.append(asyncio.create_task(asyncio.sleep(0)))
|
||||
else:
|
||||
for plugin in target.autorecon.plugin_types['port']:
|
||||
plugin_tag_set = set(plugin.tags)
|
||||
|
||||
|
@ -953,8 +974,10 @@ async def scan_target(target):
|
|||
timed_out = True
|
||||
break
|
||||
|
||||
if not autorecon.config['force_services']:
|
||||
# Extract Services
|
||||
services = []
|
||||
|
||||
async with target.lock:
|
||||
while target.pending_services:
|
||||
services.append(target.pending_services.pop(0))
|
||||
|
@ -1150,6 +1173,7 @@ async def main():
|
|||
nmap_group.add_argument('--nmap', action='store', help='Override the {nmap_extra} variable in scans. Default: %(default)s')
|
||||
nmap_group.add_argument('--nmap-append', action='store', help='Append to the default {nmap_extra} variable in scans. Default: %(default)s')
|
||||
parser.add_argument('--disable-sanity-checks', action='store_true', help='Disable sanity checks that would otherwise prevent the scans from running. Default: %(default)s')
|
||||
parser.add_argument('--force-services', action='store', nargs='+', help='A space separated list of services in the following style: tcp/80/http/insecure tcp/443/https/secure')
|
||||
parser.add_argument('--accessible', action='store_true', help='Attempts to make AutoRecon output more accessible to screenreaders. Default: %(default)s')
|
||||
parser.add_argument('-v', '--verbose', action='count', help='Enable verbose output. Repeat for more verbosity.')
|
||||
parser.add_argument('--version', action='store_true', help='Prints the AutoRecon version and exits.')
|
||||
|
@ -1161,7 +1185,7 @@ async def main():
|
|||
autorecon.argparse = parser
|
||||
|
||||
if args.version:
|
||||
print('AutoRecon v2.0-beta1')
|
||||
print('AutoRecon v2.0-beta2')
|
||||
sys.exit(0)
|
||||
|
||||
# Parse config file and args for global.toml first.
|
||||
|
@ -1332,7 +1356,6 @@ async def main():
|
|||
if key in autorecon.configurable_boolean_keys and autorecon.config[key]:
|
||||
continue
|
||||
autorecon.config[key] = args_dict[key]
|
||||
|
||||
autorecon.args = args
|
||||
|
||||
if autorecon.config['max_scans'] <= 0:
|
||||
|
@ -1367,6 +1390,9 @@ async def main():
|
|||
errors = True
|
||||
|
||||
if not errors:
|
||||
if autorecon.config['force_services']:
|
||||
autorecon.service_scan_semaphore = asyncio.Semaphore(autorecon.config['max_scans'])
|
||||
else:
|
||||
autorecon.port_scan_semaphore = asyncio.Semaphore(autorecon.config['max_port_scans'])
|
||||
# If max scans and max port scans is the same, the service scan semaphore and port scan semaphore should be the same object
|
||||
if autorecon.config['max_scans'] == autorecon.config['max_port_scans']:
|
||||
|
@ -1450,6 +1476,7 @@ async def main():
|
|||
error('A total of ' + str(len(autorecon.pending_targets)) + ' targets would be scanned. If this is correct, re-run with the --disable-sanity-checks option to suppress this check.')
|
||||
errors = True
|
||||
|
||||
if not autorecon.config['force_services']:
|
||||
port_scan_plugin_count = 0
|
||||
for plugin in autorecon.plugin_types['port']:
|
||||
matching_tags = False
|
||||
|
@ -1470,6 +1497,8 @@ async def main():
|
|||
if port_scan_plugin_count == 0:
|
||||
error('There are no port scan plugins that match the tags specified.')
|
||||
errors = True
|
||||
else:
|
||||
port_scan_plugin_count = autorecon.config['max_port_scans'] / 5
|
||||
|
||||
if errors:
|
||||
sys.exit(1)
|
||||
|
@ -1514,6 +1543,10 @@ async def main():
|
|||
port_scan_task_count = 0
|
||||
for targ in autorecon.scanning_targets:
|
||||
for process_list in targ.running_tasks.values():
|
||||
if autorecon.config['force_services']:
|
||||
if issubclass(process_list['plugin'].__class__, ServiceScan):
|
||||
port_scan_task_count += 1
|
||||
else:
|
||||
if issubclass(process_list['plugin'].__class__, PortScan):
|
||||
port_scan_task_count += 1
|
||||
|
||||
|
|
Loading…
Reference in New Issue