#!/usr/bin/env python # -*- coding: utf-8 -*- import string import random import json from core.alert import messages from core.compatible import version def start(graph_flag, language, data, _HOST, _USERNAME, _PASSWORD, _PORT, _TYPE, _DESCRIPTION): """ generate the d3_tree_v1_graph with events Args: graph_flag: graph name language: language data: events in JSON _HOST: host key _USERNAME: username key _PASSWORD: password key _PORT: port key _TYPE: module name key _DESCRIPTION: description key Returns: a graph in HTML """ # define a normalised_json normalisedjson = { "name": "Started attack", "children": {} } # get data for normalised_json for each_scan in data: if each_scan['HOST'] not in normalisedjson['children']: normalisedjson['children'].update({each_scan['HOST']: {}}) normalisedjson['children'][each_scan['HOST']].update( {each_scan['TYPE']: []}) if each_scan['TYPE'] not in normalisedjson['children'][each_scan['HOST']]: normalisedjson['children'][each_scan['HOST']].update( {each_scan['TYPE']: []}) normalisedjson['children'][each_scan['HOST']][each_scan['TYPE']].append("HOST: \"%s\", PORT:\"%s\", DESCRIPTION:\"%s\", USERNAME:\"%s\", PASSWORD:\"%s\"" % ( each_scan['HOST'], each_scan['PORT'], each_scan['DESCRIPTION'], each_scan['USERNAME'], each_scan['PASSWORD'])) # define a d3_structure_json d3_structure = {"name": "Starting attack", "children": []} # get data for normalised_json for host in list(normalisedjson['children'].keys()): d3_structure["children"].append({"name": host, "children": [{"name": otype, "children": [{"name": description} for description in normalisedjson['children'][host][otype]]} for otype in list(normalisedjson['children'][host].keys())]}) data = ''' __html_title_to_replace__

OWASP Nettacker

__title_to_replace__

__description_to_replace__




'''.replace('__data_will_locate_here__', json.dumps(d3_structure)) \ .replace('__title_to_replace__', messages(language, "pentest_graphs")) \ .replace('__description_to_replace__', messages(language, "graph_message")) \ .replace('__html_title_to_replace__', messages(language, "nettacker_report")) if version() is 2: return data.decode('utf8') return data