コード例 #1
0
ファイル: export.py プロジェクト: piratica/king-phisher
def campaign_visits_to_geojson(rpc, campaign_id, geojson_file):
	"""
	Export the geo location information for all the visits of a campaign into
	the `GeoJSON <http://geojson.org/>`_ format.

	:param rpc: The connected RPC instance to load the information with.
	:type rpc: :py:class:`.KingPhisherRPCClient`
	:param campaign_id: The ID of the campaign to load the information for.
	:param str geojson_file: The destination file for the GeoJSON data.
	"""
	ips_for_georesolution = {}
	ip_counter = collections.Counter()
	for visit in rpc.remote_table('visits', query_filter={'campaign_id': campaign_id}):
		ip_counter.update((visit.visitor_ip,))
		visitor_ip = ipaddress.ip_address(visit.visitor_ip)
		if not isinstance(visitor_ip, ipaddress.IPv4Address):
			continue
		if visitor_ip.is_loopback or visitor_ip.is_private:
			continue
		if not visitor_ip in ips_for_georesolution:
			ips_for_georesolution[visitor_ip] = visit.first_visit
		elif ips_for_georesolution[visitor_ip] > visit.first_visit:
			ips_for_georesolution[visitor_ip] = visit.first_visit
	ips_for_georesolution = [ip for (ip, _) in sorted(ips_for_georesolution.items(), key=lambda x: x[1])]
	locations = {}
	for ip_addresses in iterutils.chunked(ips_for_georesolution, 50):
		locations.update(rpc.geoip_lookup_multi(ip_addresses))
	points = []
	for ip, location in locations.items():
		if not (location.coordinates and location.coordinates[0] and location.coordinates[1]):
			continue
		points.append(geojson.Feature(geometry=location, properties={'count': ip_counter[ip], 'ip-address': ip}))
	feature_collection = geojson.FeatureCollection(points)
	with open(geojson_file, 'w') as file_h:
		json_ex.dump(feature_collection, file_h)
コード例 #2
0
	def do_config_save(self):
		self.logger.info('writing the client configuration to disk')
		config = copy.copy(self.config)
		for key in self.config.keys():
			if 'password' in key or key == 'server_config':
				del config[key]
		with open(os.path.expanduser(self.config_file), 'w') as config_file_h:
			json_ex.dump(config, config_file_h)
コード例 #3
0
 def do_config_save(self):
     self.logger.info('writing the client configuration to disk')
     config = copy.copy(self.config)
     for key in self.config.keys():
         if 'password' in key or key == 'server_config':
             del config[key]
     with open(os.path.expanduser(self.config_file), 'w') as config_file_h:
         json_ex.dump(config, config_file_h)