def ip_OS_hostname(image_path, temp_mount):

	os = get_OS_version(temp_mount)

	if(os.find("Windows") != -1):
		get_win_ipos(image_path)
	else:
		get_lin_ipos(temp_mount)
def getOsPackageCommands(os, linuxDistro=""):
    command = ''
    options = ''
    if os.find("linux") > -1:
        if linuxDistro.find("Debian") > -1 or linuxDistro.find("Ubuntu") > -1:
            command = "dpkg"
            options = "-c"
        else:
            command = "rpm"
            options = "-qpvl"
    elif os.find("solaris") > -1:
        command = "pkgchk"
        options = "-ld"
    elif os.find("HP-UX") > -1:
        command = "swlist"
        options = "-l file -vd @"
    elif os.find("AIX") > -1:
        command = "restore"
        options = "-qTlvf"
    return command, options
Esempio n. 3
0
def get_os():
	'''
	get os 类型
	'''
	
	os = platform.system()
	if os == "Windows":
		return "n"
	elif os.find("CYGWIN") >= 0:
		return 'n'
	else:
		return "c"
Esempio n. 4
0
	def __init__(self):
		self.ftp=FTP()
		self.ftp.connect(CONFIG.FTPIP)
		self.ftp.login(CONFIG.FUSER,CONFIG.FPASSWD)
		self.isLinux = os.find('Linux')
		self.isWindows = os.find('Windows')
		self.isUbuntu = os.find('Ubuntu')
		self.isRedHat = os.find('redhat')
		self.isCentOS = os.find('centos')
		self.is64 = os.find('x86_64')
		self.is32 = os.find('i686')
		self.dbackup = '/ftp_product_installer/wddps/2015/5.1/dev/'
		self.dbackup3=''
Esempio n. 5
0
def parse_report(src):
    tree = elemTree.parse(src)
    root = tree.getroot()

    host = root.find("host")
    os = host.find("os")
    osmatch = os.find("osmatch")
    osclass = osmatch.find("osclass")
    os = osclass.attrib["osfamily"].lower()

    ports = host.find("ports")
    port = ports.findall("port")
    temps = []
    for e in port:
        temps.append((e.attrib["protocol"].lower(), e.attrib["portid"]))
    ports = temps

    return (os, ports)
 def crawl_phones_models_specification(self, li):
     phone_data = {}
     for link in li:
         print(link)
         try:
             soup = self.crawl_html_page(link)
             model = soup.find(
                 class_='page__section page__section_quickSpecs')
             model_name = model.find("header").h1.text
             model_img_html = model.find(class_='head-image')
             model_img = model_img_html.find('img')['data-src']
             specs_html = model.find(
                 class_="phone__section phone__section_widget_quickSpecs")
             release_date = specs_html.find(class_="calendar")
             release_date = release_date.find(class_="title").p.text
             display = specs_html.find(class_="display")
             display = display.find(class_="title").p.text
             camera = specs_html.find(class_="camera")
             camera = camera.find(class_="title").p.text
             hardware = specs_html.find(class_="hardware")
             hardware = hardware.find(class_="title").p.text
             storage = specs_html.find(class_="storage")
             storage = storage.find(class_="title").p.text
             battery = specs_html.find(class_="battery")
             battery = battery.find(class_="title").p.text
             os = specs_html.find(class_="os")
             os = os.find(class_="title").p.text
             phone_data[model_name] = {
                 "image": model_img,
                 "release_date": release_date,
                 "display": display,
                 "camera": camera,
                 "hardware": hardware,
                 "storage": storage,
                 "battery": battery,
                 "os": os
             }
             with open(obj.absolute_path+'-PhoneSpecs.json', 'w+') as of:
                 json.dump(phone_data, of)
         except:
             print("Exception happened!")
             continue
     return phone_data
Esempio n. 7
0
 def update_ip(self, name, ip):
     conn = self.conn
     vm = conn.lookupByName(name)
     xml = vm.XMLDesc(0)
     root = ET.fromstring(xml)
     if not vm:
         print("VM %s not found" % name)
     if vm.isActive() == 1:
         print("Machine up. Change will only appear upon next reboot")
     os = root.getiterator('os')[0]
     smbios = os.find('smbios')
     if smbios is None:
         newsmbios = ET.Element("smbios", mode="sysinfo")
         os.append(newsmbios)
     sysinfo = root.getiterator('sysinfo')
     system = root.getiterator('system')
     if not sysinfo:
         sysinfo = ET.Element("sysinfo", type="smbios")
         root.append(sysinfo)
     sysinfo = root.getiterator('sysinfo')[0]
     if not system:
         system = ET.Element("system")
         sysinfo.append(system)
     system = root.getiterator('system')[0]
     versionfound = False
     for entry in root.getiterator('entry'):
         attributes = entry.attrib
         if attributes['name'] == 'version':
             entry.text = ip
             versionfound = True
     if not versionfound:
         version = ET.Element("entry", name="version")
         version.text = ip
         system.append(version)
     newxml = ET.tostring(root)
     conn.defineXML(newxml)
Esempio n. 8
0
    def __init__(self, file, test):
        parser = le.XMLParser(resolve_entities=False)
        nscan = le.parse(file, parser)
        root = nscan.getroot()

        if 'nmaprun' not in root.tag:
            raise NamespaceErr("This doesn't seem to be a valid Nmap xml file.")
        dupes = {}
        hostInfo = ""

        for host in root.iter("host"):
            ip = host.find("address[@addrtype='ipv4']").attrib['addr']
            fqdn = host.find("hostnames/hostname[@type='PTR']").attrib['name'] if host.find("hostnames/hostname[@type='PTR']") is not None else None

            for os in root.iter("os"):
                if ip is not None:
                    hostInfo += "IP Address: %s\n" % ip
                if  fqdn is not None:
                    fqdn += "FQDN: %s\n" % ip     
                if 'name' in os.find('osmatch').attrib:
                    hostInfo += "Host OS: %s\n" % os.find('osmatch').attrib['name']
                if 'accuracy' in os.find('osmatch').attrib:
                    hostInfo += "Accuracy: {0}%\n".format(os.find('osmatch').attrib['accuracy'])

                hostInfo += "\n"

            for portelem in host.xpath("ports/port[state/@state='open']"):
                port = portelem.attrib['portid']
                protocol = portelem.attrib['protocol']

                title = "Open port: %s/%s" % (port, protocol)
                description = hostInfo
                description += "Port: %s\n" % (port)
                serviceinfo = ""

                if portelem.find('service') is not None:
                    if 'product' in portelem.find('service').attrib:
                        serviceinfo += "Product: %s\n" % portelem.find('service').attrib['product']

                    if 'version' in portelem.find('service').attrib:
                        serviceinfo += "Version: %s\n" % portelem.find('service').attrib['version']

                    if 'extrainfo' in portelem.find('service').attrib:
                        serviceinfo += "Extra Info: %s\n" % portelem.find('service').attrib['extrainfo']

                    description += serviceinfo

                description += '\n\n'

                severity = "Info"

                dupe_key = port

                if dupe_key in dupes:
                    find = dupes[dupe_key]
                    if description is not None:
                        find.description += description
                else:
                    find = Finding(title=title,
                                    test=test,
                                    active=False,
                                    verified=False,
                                    description=description,
                                    severity=severity,
                                    numerical_severity=Finding.get_numerical_severity(severity))
                    find.unsaved_endpoints = list()
                    dupes[dupe_key] = find

                find.unsaved_endpoints.append(Endpoint(host=ip, fqdn=fqdn, port=port, protocol=protocol))
        self.items = dupes.values()
Esempio n. 9
0
    def __init__(self, file, test):
        parser = le.XMLParser(resolve_entities=False)
        nscan = le.parse(file, parser)
        root = nscan.getroot()

        if 'nmaprun' not in root.tag:
            raise NamespaceErr(
                "This doesn't seem to be a valid Nmap xml file.")
        dupes = {}
        hostInfo = ""

        for host in root.iter("host"):
            ip = host.find("address[@addrtype='ipv4']").attrib['addr']
            fqdn = host.find(
                "hostnames/hostname[@type='PTR']").attrib['name'] if host.find(
                    "hostnames/hostname[@type='PTR']") is not None else None

            for os in root.iter("os"):
                if ip is not None:
                    hostInfo += "IP Address: %s\n" % ip
                if fqdn is not None:
                    fqdn += "FQDN: %s\n" % ip
                if 'name' in os.find('osmatch').attrib:
                    hostInfo += "Host OS: %s\n" % os.find(
                        'osmatch').attrib['name']
                if 'accuracy' in os.find('osmatch').attrib:
                    hostInfo += "Accuracy: {0}%\n".format(
                        os.find('osmatch').attrib['accuracy'])

                hostInfo += "\n"

            for portelem in host.xpath("ports/port[state/@state='open']"):
                port = portelem.attrib['portid']
                protocol = portelem.attrib['protocol']

                title = "Open port: %s/%s" % (port, protocol)
                description = hostInfo
                description += "Port: %s\n" % (port)
                serviceinfo = ""

                if portelem.find('service') is not None:
                    if 'product' in portelem.find('service').attrib:
                        serviceinfo += "Product: %s\n" % portelem.find(
                            'service').attrib['product']

                    if 'version' in portelem.find('service').attrib:
                        serviceinfo += "Version: %s\n" % portelem.find(
                            'service').attrib['version']

                    if 'extrainfo' in portelem.find('service').attrib:
                        serviceinfo += "Extra Info: %s\n" % portelem.find(
                            'service').attrib['extrainfo']

                    description += serviceinfo

                description += '\n\n'

                severity = "Info"

                dupe_key = port

                if dupe_key in dupes:
                    find = dupes[dupe_key]
                    if description is not None:
                        find.description += description
                else:
                    find = Finding(
                        title=title,
                        test=test,
                        active=False,
                        verified=False,
                        description=description,
                        severity=severity,
                        numerical_severity=Finding.get_numerical_severity(
                            severity))
                    find.unsaved_endpoints = list()
                    dupes[dupe_key] = find

                find.unsaved_endpoints.append(
                    Endpoint(host=ip, fqdn=fqdn, port=port, protocol=protocol))
        self.items = dupes.values()
Esempio n. 10
0
def select_test_cases(args, catalog=None):
    DEFAULT_CATALOG = "_ExecutionConfig/OTC/TC/TP/support/plangenerator/tc_catalog.xml"

    if not catalog:
        catalog = DEFAULT_CATALOG

    tree = ET.parse(catalog)
    root = tree.getroot()

    testcases = root.findall("testcase")
    print "Total Test Cases in Catalog: " + str(len(testcases))

    selected_tcs = []
    for tc in testcases:
        selected_test_case = {}

        # Only handle ACS test cases
        if not tc.attrib["runner"] == "ACS":
            continue
        # Check the Doamin
        if not tc.attrib["domain"] == args.domain:
            continue

        # Check the Android OS
        os = tc.find("targets/target[@version='{os}']".format(os=args.os))
        if os is None:
            continue

        # Check the platform
        platform = os.find(
            "variant[@name='{platform}']".format(platform=args.platform))
        if platform is None:
            continue
        # Check the Priority
        if args.priority is not None:
            priority_list = str.lower(args.priority).split(",")
            if not str.lower(tc.attrib["priority"][:2]) in priority_list:
                continue
        # Check the Test Case Type
        if args.type is not None:
            type_list = str.lower(args.type).split(",")
            if not str.lower(tc.attrib["tctype"]) in type_list:
                continue
        # Check the CI Ready status
        if args.ci is not None:
            ci_list = str.lower(args.ci).split(",")
            if not str.lower(tc.attrib["ci_ready"]) in ci_list:
                continue
        # Check the AREQ
        if args.areq is not None:
            areq_list = str.lower(args.areq).split(",")
            areqs = tc.findall("requirements/requirement")
            matched = False
            for a in areqs:
                try:
                    if not str.lower(
                            a.attrib["name"]
                        [:a.attrib["name"].index(" ")]) in areq_list:
                        continue
                    matched = True
                except:
                    continue
            if not matched:
                continue

        # Composite the node attribute
        selected_test_case["id"] = tc.attrib["id"]
        selected_test_case["template"] = tc.attrib["template"]

        selected_tcs.append(selected_test_case)
        print tc.attrib["domain"], os.attrib["version"], platform.attrib[
            "name"], tc.attrib["priority"], tc.attrib["tctype"], tc.attrib[
                "id"]
    return selected_tcs
Esempio n. 11
0
 def _parse_results(self, file_nmaprun):
     
     tree = etree.parse(file_nmaprun)
     
     nmaprun = tree.getroot()    
     nmap_scan=NmapScan()
     nmap_scan.startstr = nmaprun.get('startstr')
     nmap_scan.profile_name = nmaprun.get('profile_name')
     nmap_scan.scanner = nmaprun.get('scanner')
     nmap_scan.version = nmaprun.get('version')
     nmap_scan.args = nmaprun.get('args')
     
     scaninfo = nmaprun.find('scaninfo')
     nmap_scan.services = scaninfo.get('services')
     nmap_scan.protocol = scaninfo.get('protocol')
     nmap_scan.numservices = scaninfo.get('numservices')
     nmap_scan.type = scaninfo.get('type')
     
     output = nmaprun.find('output')
     if output is not None:
         nmap_scan.output = output.text
     
     for host in nmaprun.findall('host'):
         nmap_host=NmapHost()
         
         nmap_host.status = host.find('status').get('state')
         
         for address in host.findall('address'):
             if address.get('addrtype')=='ipv4':
                 nmap_host.addr_ipv4=address.get('addr')
             if address.get('addrtype')=='ipv6':
                 nmap_host.addr_ipv6=address.get('addr')
             if address.get('addrtype')=='mac':
                 nmap_host.addr_mac=address.get('addr')
                 nmap_host.addr_mac_vendor=address.get('vendor')
         
         hostnames = host.find('hostnames')
         for hostname in hostnames.findall('hostname'):
             nmap_host.hostnames.append(hostname.get('name'))
         
         os=host.find('os')
         if os is not None:
             osmatch=os.find('osmatch')
             if osmatch is not None:
                 nmap_host.os_name = osmatch.get('name')
                 nmap_host.os_accuracy = int(osmatch.get('accuracy'))
                 osclass=osmatch.find('osclass')
                 if osclass is not None:
                     nmap_host.os_type=osclass.get('type')
                     nmap_host.os_family=osclass.get('osfamily')
                     nmap_host.os_vendor=osclass.get('vendor')
                     nmap_host.os_gen=osclass.get('osgen')
         
         hostscript=host.find('hostscript')
         if hostscript is not None:
             scripts=hostscript.findall('script')
             for script in scripts:
                 nmap_host_script=NmapHostScript()
                 nmap_host_script.host_script_id=script.get('id')
                 nmap_host_script.host_script_output=script.get('output')
                 nmap_host.host_scripts.append(nmap_host_script)
             
         
         ports=host.find('ports')
         for port in ports.findall('port'):
             nmap_port=NmapPort()
             nmap_port.protocol=port.get('protocol')
             nmap_port.portid=port.get('portid')
             nmap_port.state=port.find('state').get('state')
             nmap_port.svc_name=port.find('service').get('name')
             nmap_port.svc_product=port.find('service').get('product')
             nmap_port.svc_version=port.find('service').get('version')
             nmap_port.svc_extrainfo=port.find('service').get('extrainfo')
             nmap_port.svc_conf=port.find('service').get('conf')
             
             scripts=port.findall('script')
             for script in scripts:
                 nmap_port_script=NmapPortScript()
                 nmap_port_script.port_script_id=script.get('id')
                 nmap_port_script.port_script_output=script.get('output')
                 nmap_port.port_scripts.append(nmap_port_script)
             
             nmap_host.ports.append(nmap_port)
         
         nmap_scan.hosts.append(nmap_host)
         
     self.reports.append(nmap_scan)
Esempio n. 12
0
def get_repo_type(os):
    if os.find('deb') != -1:
        return 'deb'
    return 'yum'
Esempio n. 13
0
def save_attributes_to_db(response, db_file, state_vector, logging,
                          dictionary):
    """
    1. Parses XML returned by CTI_OS service into desired parts which will represent database table attributes
    2. Connects to Export_vse.db
    3. Alters table by adding OS_ID column if not exists
    4. Updates attributes for all posidents in SQLITE3 table rows
    Keyword arguments: xml file returned by CTI_OS service, path to the database file and state information vector, logging
    Returns: failed! if problem appears otherwise updated state vector
    """

    root = et.fromstring(response)

    for os in root.findall('.//{http://katastr.cuzk.cz/ctios/types/v2.8}os'):

        # check errors of given posidents, if error occurs continue back to the function beginning
        if os.find('{http://katastr.cuzk.cz/ctios/types/v2.8}chybaPOSIdent'
                   ) is not None:
            posident = os.find(
                '{http://katastr.cuzk.cz/ctios/types/v2.8}pOSIdent').text

            if os.find('{http://katastr.cuzk.cz/ctios/types/v2.8}chybaPOSIdent'
                       ).text == "NEPLATNY_IDENTIFIKATOR":
                state_vector[0] = state_vector[0] + 1
                logging.error(
                    'POSIDENT {} NEPLATNY IDENTIFIKATOR'.format(posident))
                continue
            if os.find('{http://katastr.cuzk.cz/ctios/types/v2.8}chybaPOSIdent'
                       ).text == "EXPIROVANY_IDENTIFIKATOR":
                state_vector[1] = state_vector[1] + 1
                logging.error(
                    'POSIDENT {}: EXPIROVANY IDENTIFIKATOR'.format(posident))
                continue
            if os.find('{http://katastr.cuzk.cz/ctios/types/v2.8}chybaPOSIdent'
                       ).text == "OPRAVNENY_SUBJEKT_NEEXISTUJE":
                state_vector[2] = state_vector[2] + 1
                logging.error(
                    'POSIDENT {}: OPRAVNENY SUBJEKT NEEXISTUJE'.format(
                        posident))
                continue
        else:
            state_vector[3] = state_vector[3] + 1  # no error

        # Parse XML returned by CTI_OS service into desired parts
        # create the dictionary, where will be XML child attribute names and particular texts
        xml_attributes = {}
        database_attributes = {}

        for child in os:
            name = child.tag
            if name == '{http://katastr.cuzk.cz/ctios/types/v2.8}pOSIdent':
                pos = os.find(name)
                posident = pos.text
            if name == '{http://katastr.cuzk.cz/ctios/types/v2.8}osId':
                o = os.find(name)
                osid = o.text

        for child in os.find(
                './/{http://katastr.cuzk.cz/ctios/types/v2.8}osDetail'):
            name2 = child.tag
            xml_attributes[child.tag[child.tag.index('}') + 1:]] = os.find(
                './/{}'.format(name2)).text

        # Find out the names of columns in database and if column os_id doesnt exist, add it
        try:
            conn = create_connection(db_file)
            cur = conn.cursor()
            cur.execute("PRAGMA read_committed = true;")
            cur.execute('select * from OPSUB')
            col_names = list(map(lambda x: x[0], cur.description))
            if 'OS_ID' not in col_names:
                cur.execute('ALTER TABLE OPSUB ADD COLUMN OS_ID TEXT')
            cur.close()
        except conn.Error:
            cur.close()
            conn.close()
            logging.exception('Pripojeni k databazi selhalo')
            raise Exception("CONNECTION TO DATABSE FAILED")

        #  Transform xml_names to database_names
        for xml_name, xml_value in xml_attributes.items():
            database_name = transform_names(xml_name)
            if database_name not in col_names:
                database_name = transform_names_dict(xml_name, dictionary)
            database_attributes.update({database_name: xml_value})

        #  Update table OPSUB by database_attributes items
        try:
            cur = conn.cursor()
            cur.execute("BEGIN TRANSACTION")
            for dat_name, dat_value in database_attributes.items():
                cur.execute(
                    """UPDATE OPSUB SET {0} = ? WHERE id = ?""".format(
                        dat_name), (dat_value, posident))
            cur.execute("""UPDATE OPSUB SET OS_ID = ? WHERE id = ?""",
                        (osid, posident))
            cur.execute("COMMIT TRANSACTION")
            cur.close()
            logging.info(
                'Radky v databazi u POSIdentu {} aktualizovany'.format(
                    posident))
        except conn.Error:
            print("failed!")
            cur.execute("ROLLBACK TRANSACTION")
            cur.close()
            conn.close()

        conn.close()
    return state_vector
Esempio n. 14
0
def get_repo_type(os):
    if os.find('deb') != -1:
        return 'deb'
    return 'yum'