예제 #1
0
def campaign_to_xml(rpc, campaign_id, xml_file, encoding='utf-8'):
    """
	Load all information for a particular campaign and dump it to an XML file.

	: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 xml_file: The destination file for the XML data.
	:param str encoding: The encoding to use for strings.
	"""
    tzutc = dateutil.tz.tzutc()
    root = ET.Element('king_phisher')
    # Generate export metadata
    metadata = ET.SubElement(root, 'metadata')
    serializers.to_elementtree_subelement(
        metadata,
        'timestamp',
        datetime.datetime.utcnow().replace(tzinfo=tzutc),
        attrib={'utc': 'true'})
    serializers.to_elementtree_subelement(metadata, 'version', '1.3')

    campaign = ET.SubElement(root, 'campaign')
    campaign_info = rpc.remote_table_row('campaigns', campaign_id)
    for key, value in campaign_info._asdict().items():
        if isinstance(value, datetime.datetime):
            value = value.replace(tzinfo=tzutc)
        serializers.to_elementtree_subelement(campaign, key, value)

    # Tables with a campaign_id field
    for table_name in ('landing_pages', 'messages', 'visits', 'credentials',
                       'deaddrop_deployments', 'deaddrop_connections'):
        table_element = ET.SubElement(campaign, table_name)
        for table_row in rpc.remote_table(
                table_name, query_filter={'campaign_id': campaign_id}):
            table_row_element = ET.SubElement(table_element, table_name[:-1])
            for key, value in table_row._asdict().items():
                if isinstance(value, datetime.datetime):
                    value = value.replace(tzinfo=tzutc)
                serializers.to_elementtree_subelement(table_row_element, key,
                                                      value)

    document = minidom.parseString(ET.tostring(root))
    with open(xml_file, 'wb') as file_h:
        file_h.write(document.toprettyxml(indent='  ', encoding=encoding))
예제 #2
0
def campaign_to_xml(rpc, campaign_id, xml_file, encoding='utf-8'):
	"""
	Load all information for a particular campaign and dump it to an XML file.

	: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 xml_file: The destination file for the XML data.
	:param str encoding: The encoding to use for strings.
	"""
	tzutc = dateutil.tz.tzutc()
	root = ET.Element('king_phisher')
	# Generate export metadata
	metadata = ET.SubElement(root, 'metadata')
	serializers.to_elementtree_subelement(
		metadata,
		'timestamp',
		datetime.datetime.utcnow().replace(tzinfo=tzutc),
		attrib={'utc': 'true'}
	)
	serializers.to_elementtree_subelement(metadata, 'version', '1.3')

	campaign = ET.SubElement(root, 'campaign')
	campaign_info = rpc.remote_table_row('campaigns', campaign_id)
	for key, value in campaign_info._asdict().items():
		if isinstance(value, datetime.datetime):
			value = value.replace(tzinfo=tzutc)
		serializers.to_elementtree_subelement(campaign, key, value)

	# Tables with a campaign_id field
	for table_name in ('landing_pages', 'messages', 'visits', 'credentials', 'deaddrop_deployments', 'deaddrop_connections'):
		table_element = ET.SubElement(campaign, table_name)
		for table_row in rpc.remote_table(table_name, query_filter={'campaign_id': campaign_id}):
			table_row_element = ET.SubElement(table_element, table_name[:-1])
			for key, value in table_row._asdict().items():
				if isinstance(value, datetime.datetime):
					value = value.replace(tzinfo=tzutc)
				serializers.to_elementtree_subelement(table_row_element, key, value)

	document = minidom.parseString(ET.tostring(root))
	with open(xml_file, 'wb') as file_h:
		file_h.write(document.toprettyxml(indent='  ', encoding=encoding))
예제 #3
0
def campaign_to_xml(rpc, campaign_id, xml_file, encoding='utf-8'):
	"""
	Load all information for a particular campaign and dump it to an XML file.

	: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 xml_file: The destination file for the XML data.
	:param str encoding: The encoding to use for strings.
	"""
	tzutc = dateutil.tz.tzutc()
	root = ET.Element('king_phisher')
	# Generate export metadata
	metadata = ET.SubElement(root, 'metadata')
	serializers.to_elementtree_subelement(
		metadata,
		'timestamp',
		datetime.datetime.utcnow().replace(tzinfo=tzutc),
		attrib={'utc': 'true'}
	)
	serializers.to_elementtree_subelement(metadata, 'version', '1.3')

	campaign = ET.SubElement(root, 'campaign')
	logger.info('gathering campaign information for export')
	page_size = 1000
	try:
		campaign_info = rpc.graphql_find_file('get_campaign_export.graphql', id=campaign_id, page=page_size)['db']['campaign']
	except errors.KingPhisherGraphQLQueryError as error:
		logger.error('graphql error: ' + error.message)
		raise
	for key, value in campaign_info.items():
		if key in ('landingPages', 'messages', 'visits', 'credentials', 'deaddropDeployments', 'deaddropConnections'):
			continue
		if isinstance(value, datetime.datetime):
			value = value.replace(tzinfo=tzutc)
		serializers.to_elementtree_subelement(campaign, key, value)

	table_elements = {}
	while True:
		cursor = None  # set later if any table hasNextPage
		for table_name in ('landing_pages', 'messages', 'visits', 'credentials', 'deaddrop_deployments', 'deaddrop_connections'):
			gql_table_name = parse_case_snake_to_camel(table_name, upper_first=False)
			if campaign_info[gql_table_name]['pageInfo']['hasNextPage']:
				cursor = campaign_info[gql_table_name]['pageInfo']['endCursor']
			table = campaign_info[gql_table_name]['edges']
			if table_name not in table_elements:
				table_elements[table_name] = ET.SubElement(campaign, table_name)
			for node in table:
				table_row_element = ET.SubElement(table_elements[table_name], table_name[:-1])
				for key, value in node['node'].items():
					if isinstance(value, datetime.datetime):
						value = value.replace(tzinfo=tzutc)
					serializers.to_elementtree_subelement(table_row_element, key, value)
		if cursor is None:
			break
		campaign_info = rpc.graphql_find_file('get_campaign_export.graphql', id=campaign_id, cursor=cursor, page=page_size)['db']['campaign']
	logger.info('completed processing campaign information for export')

	document = minidom.parseString(ET.tostring(root))
	with open(xml_file, 'wb') as file_h:
		file_h.write(document.toprettyxml(indent='  ', encoding=encoding))
	logger.info('campaign export complete')
예제 #4
0
 def dumps(self, value):
     parent = ET.Element('parent')
     return serializers.to_elementtree_subelement(parent, 'child', value)
예제 #5
0
def campaign_to_xml(rpc, campaign_id, xml_file, encoding='utf-8'):
	"""
	Load all information for a particular campaign and dump it to an XML file.

	: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 xml_file: The destination file for the XML data.
	:param str encoding: The encoding to use for strings.
	"""
	tzutc = dateutil.tz.tzutc()
	root = ET.Element('king_phisher')
	# Generate export metadata
	metadata = ET.SubElement(root, 'metadata')
	serializers.to_elementtree_subelement(
		metadata,
		'timestamp',
		datetime.datetime.utcnow().replace(tzinfo=tzutc),
		attrib={'utc': 'true'}
	)
	serializers.to_elementtree_subelement(metadata, 'version', '1.3')

	campaign = ET.SubElement(root, 'campaign')
	logger.info('gathering campaign information for export')
	campaign_info = _get_graphql_campaignexport(rpc, campaign_id)
	gui_utilities.gtk_sync()
	for key, value in campaign_info.items():
		if key in ('landingPages', 'messages', 'visits', 'credentials', 'deaddropDeployments', 'deaddropConnections'):
			continue
		if isinstance(value, datetime.datetime):
			value = value.replace(tzinfo=tzutc)
		serializers.to_elementtree_subelement(campaign, key, value)
		gui_utilities.gtk_sync()

	# Tables with a campaign_id field
	table_names = ['landing_pages', 'messages', 'visits', 'credentials', 'deaddrop_deployments', 'deaddrop_connections']
	cursor = None
	last_cursor = None
	table_elements = {}
	while True:
		gui_utilities.gtk_sync()
		if not cursor and last_cursor:
			break
		if cursor:
			last_cursor = cursor
			campaign_info = _get_graphql_campaignexport(rpc, campaign_id, cursor)
			cursor = None
			gui_utilities.gtk_sync()
		for table_name in table_names:
			gui_utilities.gtk_sync()
			if campaign_info[parse_case_snake_to_camel(table_name, upper_first=False)]['pageInfo']['hasNextPage']:
				cursor = campaign_info[parse_case_snake_to_camel(table_name, upper_first=False)]['pageInfo']['endCursor']
			table = campaign_info[parse_case_snake_to_camel(table_name, upper_first=False)]['edges']
			if table_name not in table_elements:
				table_elements[table_name] = ET.SubElement(campaign, table_name)
			for node in table:
				gui_utilities.gtk_sync()
				row = node['node']
				table_row_element = ET.SubElement(table_elements[table_name], table_name[:-1])
				for key, value in row.items():
					gui_utilities.gtk_sync()
					if isinstance(value, datetime.datetime):
						value = value.replace(tzinfo=tzutc)
					serializers.to_elementtree_subelement(table_row_element, key, value)
	logger.info('completed processing campaign information for export')

	document = minidom.parseString(ET.tostring(root))
	with open(xml_file, 'wb') as file_h:
		file_h.write(document.toprettyxml(indent='  ', encoding=encoding))
	logger.info('campaign export complete')
예제 #6
0
def campaign_to_xml(rpc, campaign_id, xml_file, encoding='utf-8'):
	"""
	Load all information for a particular campaign and dump it to an XML file.

	: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 xml_file: The destination file for the XML data.
	:param str encoding: The encoding to use for strings.
	"""
	tzutc = dateutil.tz.tzutc()
	root = ET.Element('king_phisher')
	# Generate export metadata
	metadata = ET.SubElement(root, 'metadata')
	serializers.to_elementtree_subelement(
		metadata,
		'timestamp',
		datetime.datetime.utcnow().replace(tzinfo=tzutc),
		attrib={'utc': 'true'}
	)
	serializers.to_elementtree_subelement(metadata, 'version', '1.3')

	campaign = ET.SubElement(root, 'campaign')
	logger.info('gathering campaign information for export')
	try:
		campaign_info = _get_graphql_campaignexport(rpc, campaign_id)
	except errors.KingPhisherGraphQLQueryError as error:
		logger.error('graphql error: ' + error.message)
		raise
	gui_utilities.gtk_sync()
	for key, value in campaign_info.items():
		if key in ('landingPages', 'messages', 'visits', 'credentials', 'deaddropDeployments', 'deaddropConnections'):
			continue
		if isinstance(value, datetime.datetime):
			value = value.replace(tzinfo=tzutc)
		serializers.to_elementtree_subelement(campaign, key, value)
		gui_utilities.gtk_sync()

	# Tables with a campaign_id field
	table_names = ['landing_pages', 'messages', 'visits', 'credentials', 'deaddrop_deployments', 'deaddrop_connections']
	cursor = None
	last_cursor = None
	table_elements = {}
	while True:
		gui_utilities.gtk_sync()
		if not cursor and last_cursor:
			break
		if cursor:
			last_cursor = cursor
			campaign_info = _get_graphql_campaignexport(rpc, campaign_id, cursor)
			cursor = None
			gui_utilities.gtk_sync()
		for table_name in table_names:
			gui_utilities.gtk_sync()
			if campaign_info[parse_case_snake_to_camel(table_name, upper_first=False)]['pageInfo']['hasNextPage']:
				cursor = campaign_info[parse_case_snake_to_camel(table_name, upper_first=False)]['pageInfo']['endCursor']
			table = campaign_info[parse_case_snake_to_camel(table_name, upper_first=False)]['edges']
			if table_name not in table_elements:
				table_elements[table_name] = ET.SubElement(campaign, table_name)
			for node in table:
				gui_utilities.gtk_sync()
				row = node['node']
				table_row_element = ET.SubElement(table_elements[table_name], table_name[:-1])
				for key, value in row.items():
					gui_utilities.gtk_sync()
					if isinstance(value, datetime.datetime):
						value = value.replace(tzinfo=tzutc)
					serializers.to_elementtree_subelement(table_row_element, key, value)
	logger.info('completed processing campaign information for export')

	document = minidom.parseString(ET.tostring(root))
	with open(xml_file, 'wb') as file_h:
		file_h.write(document.toprettyxml(indent='  ', encoding=encoding))
	logger.info('campaign export complete')
예제 #7
0
	def dumps(self, value):
		parent = ET.Element('parent')
		return serializers.to_elementtree_subelement(parent, 'child', value)