Begin Main...
(logger=None)
| 27 | |
| 28 | |
| 29 | def main(logger=None): |
| 30 | """ |
| 31 | Begin Main... |
| 32 | """ |
| 33 | if logger is None: |
| 34 | logger = LoggingUtil.create_log(__name__) |
| 35 | |
| 36 | now = datetime.now() |
| 37 | print("Starting: " + str(now)) |
| 38 | logger.info("Starting...") |
| 39 | |
| 40 | # Create an instance of the VirusTotal class |
| 41 | vt_instance = VirusTotal.VirusTotal() |
| 42 | |
| 43 | # Get collections for the queries |
| 44 | mongo_connector = MongoConnector.MongoConnector() |
| 45 | vt_collection = mongo_connector.get_virustotal_connection() |
| 46 | |
| 47 | jobs_manager = JobsManager.JobsManager(mongo_connector, "get_virustotal_data") |
| 48 | jobs_manager.record_job_start() |
| 49 | |
| 50 | # Collect the list of tracked TLDs |
| 51 | zones = ZoneManager.get_distinct_zones(mongo_connector) |
| 52 | |
| 53 | # For each tracked TLD |
| 54 | for zone in zones: |
| 55 | logger.debug("Checking " + zone) |
| 56 | results = vt_instance.get_domain_report(zone) |
| 57 | |
| 58 | if results is None: |
| 59 | logger.warning("Error querying zone " + zone) |
| 60 | elif results["response_code"] == -1: |
| 61 | logger.warning("VT unhappy with " + zone) |
| 62 | elif results["response_code"] == 0: |
| 63 | logger.warning("VT doesn't have " + zone) |
| 64 | else: |
| 65 | logger.debug("Matched " + zone) |
| 66 | |
| 67 | results["zone"] = zone |
| 68 | results["created"] = datetime.now() |
| 69 | |
| 70 | # Mongo doesn't allow key names with periods in them |
| 71 | # Re-assign to an undotted key name |
| 72 | if "Dr.Web category" in results: |
| 73 | results["Dr Web category"] = results.pop("Dr.Web category") |
| 74 | elif "alphaMountain.ai category" in results: |
| 75 | results["alphaMountain_ai category"] = results.pop( |
| 76 | "alphaMountain.ai category" |
| 77 | ) |
| 78 | |
| 79 | vt_collection.delete_one({"zone": zone}) |
| 80 | |
| 81 | if "last_https_certificate" in results: |
| 82 | if "extensions" in results["last_https_certificate"]: |
| 83 | if ( |
| 84 | "1.3.6.1.4.1.11129.2.4.2" |
| 85 | in results["last_https_certificate"]["extensions"] |
| 86 | ): |
no test coverage detected