示例#1
0
    def setUp(self):
        self.credentials = ["cisco/cisco", "ps/ps1234", "nburnykov/!QAZ2wsx"]
        self.td = yaml_load("..\\decisionTreeCLI.yaml")
        self.qd = yaml_load("..\\queriesCLI.yaml")
        self.q = yaml_load("..\\_DeviceQueryScripts\\CiscoCatSwitch.yaml")

        with open('./testing_database/openportslist.pickle', 'rb') as f:
            self.portslist = pickle.load(f)
示例#2
0
def collected_data_parse(scan_name: str):

    scandr = PROJECTPATH + '\\' + DATADIR + '\\' + scan_name + '\\'

    # TODO try finally
    maindict = yaml_load(scandr + scan_name + ".yaml")

    dbh = DataBaseHandler(scandr + scan_name + ".db")

    for dev in maindict['Discovered Data']:

        if dev['is data collected']:
            query_dict = yaml_load(PROJECTPATH + '_DeviceQueryScripts\\' +
                                   dev['queryscript'])

            for fl in dev['filepath']:
                f = fl.split('\\')[::-1]
                parser_list = _find_parser(f[0], query_dict)

                if len(parser_list) > 0:

                    for i, parser in enumerate(parser_list):

                        parser_fullpath = PROJECTPATH + '\\_ParseTemplates\\' + parser[
                            'parser']
                        cli_output_file_fullpath = PROJECTPATH + '_DATA\\' + fl
                        parsed_data = _parse_cli_output(
                            cli_output_file_fullpath, parser_fullpath)

                        if parsed_data is not None:
                            processor_list = _get_postprocessors(parser)
                            if len(processor_list) > 0:
                                parsed_data = _apply_postprocessors(
                                    processor_list, parsed_data)

                            if parser.get('table') is not None:
                                logger.debug(parsed_data[0])
                                [
                                    logger.debug(line)
                                    for line in parsed_data[1:]
                                ]
                                dbh.add_data(parser['table'], parsed_data[0],
                                             parsed_data[1:], dev['IP'])

                            with open(cli_output_file_fullpath +
                                      '.parser_{}.csv'.format(str(i + 1)),
                                      'w',
                                      newline='') as csv_file:
                                writer = csv.writer(csv_file, delimiter=';')
                                writer.writerows(parsed_data)

    dbh.disconnect()
    logger.debug('Finish load data to DB')
    def setUp(self):
        self.td = yaml_load("..\\decision_tree_cli.yaml")
        self.qd = yaml_load("..\\queriesCLI.yaml")
        self.fol = []

        ol = loadcsv()

        for row in ol:
            with open(TESTDATABASEPATH+row[0]) as textfile:
                txt = textfile.read()

            self.fol.append([txt, 'CLI_Data ' + row[1] + ' ' + row[2], row[0]])
示例#4
0
    def on_start(self):
        self.root.start_log_listener()

        scan_list = yaml_load('scans.yaml')
        self.root.set_scan_list(scan_list)
        for scan in scan_list:
            self.root.add_saved_scan_button(scan['Scan name'])
示例#5
0
    def load_project_data(self, scan_name: str, *args):

        collected_config = yaml_load(
            f"{DIR_PROJECT}/_DATA/{scan_name}/{scan_name}.yaml")
        if collected_config.get('Credentials List', None) is not None:
            self.clear_credentials()
            for cred in collected_config['Credentials List']:
                self.add_credentials(cred[0], cred[1])

        if collected_config.get('Scan Name', None) is not None:
            self.scan_name.text = collected_config['Scan Name']

        if collected_config.get('Scan List', None) is not None:
            self.form_scan_list.text = "\n".join(collected_config['Scan List'])

        if collected_config.get('Do Not Scan List', None) is not None:
            self.form_do_not_scan_list.text = "\n".join(
                collected_config['Do Not Scan List'])

        self.screen1.manager.transition.direction = 'left'
        self.screen_manager.current = 'Config_net'
        self.is_data_load = True
示例#6
0
            SnmpEngine(),
            CommunityData(community),
            UdpTransportTarget((host, port)),
            ContextData(),
            ObjectType(ObjectIdentity(oid['OID'])))

        if errorIndication:
            raise IOError(errorIndication)
        else:
            if errorStatus:
                raise IOError('%s at %s' % (
                    errorStatus.prettyPrint(),
                    errorIndex and varBindTable[-1][int(errorIndex) - 1] or '?'
                    )
                )
            else:
                ls = []
                for varBindTableRow in varBindTable:
                    ls.append([(name.prettyPrint(), val.prettyPrint()) for name, val in varBindTableRow])


def getoid(queryname):
    pass

oid = {'OID': '1.3.6.1.2.1.1.1.0', 'type': 'single'}
oid = {'OID': '1.3.6.1.4.1.9.9.23', 'type': 'multiple'}

snmpqueries = fileProc.yaml_load(file="..\\snmpQueries.json")
print(getsnmpdata('NTM', '10.171.18.203', oid))
print(getsnmpdata('NTM', '10.171.2.5', oid))
print(getsnmpdata('public', '10.171.254.105', oid))
示例#7
0
def rangeproc(scandata: ScanData):

    logger.info(scandata)

    scanset = confnetparse.composeset(scandata.scan_list)
    dontscanset = confnetparse.composeset(scandata.do_not_scan_list)

    scanset ^= dontscanset

    scanlist = []

    timeout = 1

    for ip in scanset:
        for port in [22, 23]:
            scanlist.append((confnetparse.dectoIP(ip), port, timeout))

    portslist = task_threader(scanlist, istcpportopen)

    openportslist = []

    for i in range(0, len(portslist), 2):
        if portslist[i][1] or portslist[i + 1][1]:

            connection_args1, connection_result1, connection_thread1 = portslist[
                i]
            host1, port1, timeout1 = connection_args1

            connection_args2, connection_result2, connection_thread2 = portslist[
                i + 1]
            host2, port2, timeout2 = connection_args2
            if connection_result1.func_result or connection_result2.func_result:
                openportslist.append(
                    (host1, port1, connection_result1.func_result, port2,
                     connection_result2.func_result))

    logger.info(f'Found {(len(openportslist))} open ports')

    if len(openportslist):
        logger.info(f'Open ports:')
    for port in openportslist:
        logger.info(port)

    td = yaml_load(PROJECTPATH + "/decisionTreeCLI.yaml")

    dcwlist = dev_task_threader(openportslist, scandata.credential_list,
                                scandata.scan_name, td, 50)

    conffile = {
        'Scan Name': scandata.scan_name,
        'Scan List': scandata.scan_list,
        'Do Not Scan List': scandata.do_not_scan_list,
        'Credentials List': [list(cred) for cred in scandata.credential_list],
        'Discovered Data': dcwlist
    }

    # TODO crypt passwords and logins

    yaml_dump(
        f'{PROJECTPATH}_DATA/{scandata.scan_name}/{scandata.scan_name}.yaml',
        conffile)
示例#8
0
    def run(self):
        while True:

            res_dict = {
                'IP': '',
                'port': '',
                'credentials': [],  # type: List[str]
                'is login successful': False,
                'is device recognized': False,
                'is data collected': False,
                'filepath': [],  # type: List[str]
                'queryscript': ''
            }

            dev, pos_num, resultobj = self.thread_queue.get()

            res_dict['IP'] = dev[0]
            ccresult = check_credentials(dev, self.creds)

            if ccresult is None:
                logger.debug('IP {}, login failed'.format(res_dict['IP']))
                self.result_list[pos_num] = res_dict
                self.thread_queue.task_done()
                continue
            logger.debug('IP {}, login successful'.format(res_dict['IP']))
            res_dict['is login successful'] = True

            devdata, tr = ccresult
            res_dict['credentials'] = [
                tr.func_data.login, tr.func_data.password
            ]
            res_dict['port'] = tr.func_data.connectiontype

            dcw = DecisionTreeWalkCLI(tr.func_data, self.treedict)
            dcw.getlog()

            if dcw.istreeconfigerror():
                self.result_list[pos_num] = res_dict
                self.thread_queue.task_done()
                continue

            logger.debug('IP {}, device recognized'.format(res_dict['IP']))
            res_dict['is device recognized'] = True

            plist: List[str] = dcw.getpathlist()

            dpath = '\\'.join([directory for directory, script in plist])

            dp = self.scanname + '\\' + dpath

            plist.reverse()
            qname = plist[0][1]

            self.lock.acquire()

            query_scheme = yaml_load(PROJECTPATH + "/_DeviceQueryScripts/" +
                                     qname)
            self.lock.release()

            if not query_scheme:
                self.result_list[pos_num] = res_dict
                self.thread_queue.task_done()
                continue

            logger.debug('IP {}, data collected'.format(res_dict['IP']))
            res_dict['is data collected'] = True

            res_dict['filepath'] = _device_query(tr.func_data, query_scheme,
                                                 dp, self.lock)
            res_dict['queryscript'] = qname

            self.result_list[pos_num] = res_dict
            self.thread_queue.task_done()