Nettacker/core/module_protocols/ssh.py

91 lines
2.7 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import copy
import paramiko
import logging
# from core.utility import reverse_and_regex_condition
from core.utility import process_conditions
from core.utility import get_dependent_results_from_database
from core.utility import replace_dependent_values
# def response_conditions_matched(sub_step, response):
# return response
class NettackSSHLib:
def ssh_brute_force(host, ports, usernames, passwords, timeout):
paramiko_logger = logging.getLogger("paramiko.transport")
paramiko_logger.disabled = True
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(
hostname=host,
username=usernames,
password=passwords,
port=int(ports),
timeout=int(timeout)
)
ssh.close()
return {
"host": host,
"username": usernames,
"password": passwords,
"port": ports
}
class Engine:
def run(
sub_step,
module_name,
target,
scan_unique_id,
options,
process_number,
module_thread_number,
total_module_thread_number,
request_number_counter,
total_number_of_requests
):
backup_method = copy.deepcopy(sub_step['method'])
backup_response = copy.deepcopy(sub_step['response'])
del sub_step['method']
del sub_step['response']
if 'dependent_on_temp_event' in backup_response:
temp_event = get_dependent_results_from_database(
target,
module_name,
scan_unique_id,
backup_response['dependent_on_temp_event']
)
sub_step = replace_dependent_values(
sub_step,
temp_event
)
action = getattr(NettackSSHLib, backup_method, None)
for _ in range(options['retries']):
try:
response = action(**sub_step)
break
except Exception:
response = []
sub_step['method'] = backup_method
sub_step['response'] = backup_response
sub_step['response']['conditions_results'] = response
# sub_step['response']['conditions_results'] = response_conditions_matched(sub_step, response)
return process_conditions(
sub_step,
module_name,
target,
scan_unique_id,
options,
response,
process_number,
module_thread_number,
total_module_thread_number,
request_number_counter,
total_number_of_requests
)