def port_scan(self): scan_port_map = { "test": ScanPortType.TEST, "top100": ScanPortType.TOP100, "top1000": ScanPortType.TOP1000, "all": ScanPortType.ALL } option_scan_port_type = self.options.get("port_scan_type", "test") scan_port_option = { "ports": scan_port_map.get(option_scan_port_type, ScanPortType.TEST), "service_detect": self.options.get("service_detection", False), "os_detect": self.options.get("os_detection", False) } targets = self.ip_target.split() ip_port_result = services.port_scan(targets, **scan_port_option) self.ip_info_list.extend(ip_port_result) for ip_info in ip_port_result: self.ip_set.add(ip_info["ip"]) if not utils.not_in_black_ips(ip_info["ip"]): continue ip_info["task_id"] = self.task_id ip_info["ip_type"] = utils.get_ip_type(ip_info["ip"]) ip_info["geo_asn"] = {} ip_info["geo_city"] = {} if ip_info["ip_type"] == "PUBLIC": ip_info["geo_asn"] = utils.get_ip_asn(ip_info["ip"]) ip_info["geo_city"] = utils.get_ip_city(ip_info["ip"]) utils.conn_db('ip').insert_one(ip_info)
def geo_asn(self): if self._geo_asn: return self._geo_asn else: if self.ip_type == "PUBLIC": self._geo_asn = utils.get_ip_asn(self.ip) else: self._geo_asn = {} return self._geo_asn
def port_scan(self): scan_port_map = { "test": ScanPortType.TEST, "top100": ScanPortType.TOP100, "top1000": ScanPortType.TOP1000, "all": ScanPortType.ALL } option_scan_port_type = self.options.get("port_scan_type", "test") scan_port_option = { "ports": scan_port_map.get(option_scan_port_type, ScanPortType.TEST), "service_detect": self.options.get("service_detection", False), "os_detect": self.options.get("os_detection", False) } targets = self.ip_target.split() ip_port_result = services.port_scan(targets, **scan_port_option) self.ip_info_list.extend(ip_port_result) if self.task_tag == 'monitor': self.set_asset_ip() for ip_info in ip_port_result: curr_ip = ip_info["ip"] self.ip_set.add(curr_ip) if not utils.not_in_black_ips(curr_ip): continue ip_info["task_id"] = self.task_id ip_info["ip_type"] = utils.get_ip_type(curr_ip) ip_info["geo_asn"] = {} ip_info["geo_city"] = {} if ip_info["ip_type"] == "PUBLIC": ip_info["geo_asn"] = utils.get_ip_asn(curr_ip) ip_info["geo_city"] = utils.get_ip_city(curr_ip) # 仅仅资产发现任务将IP全部存储起来 if self.task_tag == 'task': utils.conn_db('ip').insert_one(ip_info) # 监控任务同步IP信息 if self.task_tag == 'monitor': self.async_ip_info()