Esempio n. 1
0
def setDetection(new):
    if re.search("true", str(new)):
        status = True
        logger.info("DETECTION!")
    elif re.search("false", str(new)):
            status = False
            logger.info("DETECTION!")
    else:
        logger.warn("Invalid status %s for DETECTION" %(new))
        return
    global DETECTION
    DETECTION = status
Esempio n. 2
0
def setActive(new):
    #if(newStatus is False or newStatus is "False" or newStatus is "false" or newStatus is 0 or newStatus is "0"):
    if re.search("false", str(new)):
        status = False
        logger.info("Alarm deactivated")
    #elif(newStatus is True or newStatus is "True" or newStatus is "true" or newStatus is 1 or newStatus is "1"):
    elif re.search("true", str(new)):
        status = True
        logger.info("Alarm activated")
    else:
        logger.warn("Invalid status %s" %(new))
        return
    global active
    active = status
def cert_hostname(ip_address, port):
    try:
        cert = ssl.get_server_certificate((ip_address, port), ssl_version=ssl.PROTOCOL_SSLv23)
        x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
        for compoment in x509.get_subject().get_components():
            compoment_name, hostname = compoment
            if compoment_name.lower() == 'cn':
                if not "*" in hostname:
                    resolved_ip_address = socket.gethostbyname(hostname.lower())
                    if resolved_ip_address == ip_address:
                        return hostname.lower()
    except Exception, e:
        err, err_msg = e
        logger.warn("Unable to extract hostname from certificate for %s on port %s (%s)" % (ip_address, port, err_msg))
        pass
    with open(csv_filename, 'w') as csvwrite:
        # set field names
        fieldnames = ['IP Address', 'Port/Protocol', 'Domains', 'Operating System', 'OS Version', 'Notes']
        writer = csv.DictWriter(csvwrite, fieldnames=fieldnames, dialect=csv.excel, quoting=csv.QUOTE_ALL)
        
        # write CSV header
        writer.writeheader()

        # iterate through xml(s)
        for xml_report in nmap_xml_reports:
            try:
                # trying to load xml file
                nmap_report = NmapParser.parse_fromfile(xml_report)
                logger.info("%s host(s) loaded from %s" % (len(nmap_report.hosts), xml_report))
            except Exception, e:
                logger.warn("XML file %s corrupted or format not recognized" % xml_report)
                # keep looking for others xml
                continue

            # start a cumulative dictionary
            results = nmap_combine(nmap_report, results)
            #print "results: %s" % len(results)

        logger.info("Wraping up results")
        for ip_address in results:
            # colecting info for each field
            open_ports = check_ports(results[ip_address]['Port/Protocol'])
            hostnames = list_to_str(results[ip_address]['Domains'])
            notes = results[ip_address]['Notes']
            os, os_version = fingerprint_decision(results[ip_address]['Operating System'], results[ip_address]['Port/Protocol'])
            #print ip_address, results[ip_address]['Operating System']