def load_all_modules(limit=-1, full_details=False): """ load all available modules limit: return limited number of modules full: with full details Returns: an array of all module names """ # Search for Modules from config import nettacker_paths if full_details: import yaml module_names = {} for module_name in glob( os.path.join(nettacker_paths()['modules_path'] + '/*/*.yaml')): libname = module_name.split('/')[-1].split('.')[0] category = module_name.split('/')[-2] module_names[libname + '_' + category] = yaml.load( StringIO( open( nettacker_paths()['modules_path'] + '/' + category + '/' + libname + '.yaml', 'r').read().split('payload:')[0]), Loader=yaml.FullLoader)['info'] if full_details else None if len(module_names) == limit: module_names['...'] = {} break module_names['all'] = {} return module_names
def logo(): """ OWASP Nettacker Logo """ from core.alert import write_to_api_console from core import color from core.color import reset_color from config import nettacker_paths from config import nettacker_user_application_config write_to_api_console( open( nettacker_paths()['logo_file'] ).read().format( version_info()[0], version_info()[1], color.color('red'), color.color('reset'), color.color('yellow'), color.color('reset'), color.color('cyan'), color.color('reset'), color.color('cyan'), color.color('reset'), color.color('cyan'), color.color('reset') ) ) reset_color()
def fuzzer_function_read_file_as_array(filename): from config import nettacker_paths return open( os.path.join( nettacker_paths()['payloads_path'], filename ) ).read().split('\n')
def version_info(): """ version information of the framework Returns: an array of version and code name """ from config import nettacker_paths return open(nettacker_paths()['version_file']).read().split()
def start(events): """ generate the d3_tree_v1_graph with events Args: events: all events Returns: a graph in HTML """ # define a normalised_json normalisedjson = {"name": "Started attack", "children": {}} # get data for normalised_json for event in events: if event['target'] not in normalisedjson['children']: normalisedjson['children'].update({event['target']: {}}) normalisedjson['children'][event['target']].update( {event['module_name']: []}) if event['module_name'] not in normalisedjson['children'][ event['target']]: normalisedjson['children'][event['target']].update( {event['module_name']: []}) normalisedjson['children'][event['target']][event['module_name']].append( f"target: {event['target']}, module_name: {event['module_name']}, options: " f"{event['options']}, event: {event['event']}") # define a d3_structure_json d3_structure = {"name": "Starting attack", "children": []} # get data for normalised_json for target in list(normalisedjson['children'].keys()): for module_name in list(normalisedjson['children'][target].keys()): for description in normalisedjson["children"][target][module_name]: children_array = [{ "name": module_name, "children": [{ "name": description }] }] d3_structure["children"].append({ "name": target, "children": children_array }) from config import nettacker_paths data = open( os.path.join(nettacker_paths()['web_static_files_path'], 'report/d3_tree_v1.html')).read().replace( '__data_will_locate_here__', json.dumps(d3_structure)).replace( '__title_to_replace__', messages("pentest_graphs")).replace( '__description_to_replace__', messages("graph_message")).replace( '__html_title_to_replace__', messages("nettacker_report")) return data
def load_all_languages(): """ load all available languages Returns: an array of languages """ languages_list = [] from config import nettacker_paths for language in glob(os.path.join(nettacker_paths()['home_path'] + '/lib/messages/*.yaml')): languages_list.append(language.split('/')[-1].split('.')[0]) return list(set(languages_list))
def load_all_graphs(): """ load all available graphs Returns: an array of graph names """ from config import nettacker_paths graph_names = [] for graph_library in glob(os.path.join(nettacker_paths()['home_path'] + '/lib/graph/*/engine.py')): graph_names.append(graph_library.split('/')[-2] + '_graph') return list(set(graph_names))
def load(self): import yaml from config import nettacker_paths from core.utility import find_and_replace_configuration_keys self.module_content = find_and_replace_configuration_keys( yaml.load(StringIO( open( nettacker_paths()['modules_path'] + '/' + self.module_name.split('_')[-1].split('.yaml')[0] + '/' + '_'.join(self.module_name.split('_')[:-1]) + '.yaml', 'r').read().format(**self.module_inputs)), Loader=yaml.FullLoader), self.module_inputs)
def __init__(self): from config import nettacker_paths self.module_name = None self.module_content = None self.scan_unique_id = None self.target = None self.process_number = None self.module_thread_number = None self.total_module_thread_number = None self.module_inputs = {} self.libraries = [ module_protocol.split('.py')[0] for module_protocol in os.listdir(nettacker_paths()['module_protocols_path']) if module_protocol.endswith('.py') and module_protocol != '__init__.py' ]
def logo(): """ OWASP Nettacker Logo """ import requests from core.alert import write_to_api_console from core import color from core.color import reset_color from config import nettacker_paths from config import nettacker_analytics from config import nettacker_user_application_config write_to_api_console( open(nettacker_paths()['logo_file']).read().format( version_info()[0], version_info()[1], color.color('red'), color.color('reset'), color.color('yellow'), color.color('reset'), color.color('cyan'), color.color('reset'), color.color('cyan'), color.color('reset'), color.color('cyan'), color.color('reset'))) reset_color() try: if nettacker_analytics()['new_relic_api_key']: requests.post( "https://log-api.eu.newrelic.com/log/v1", headers={ "X-License-Key": nettacker_analytics()['new_relic_api_key'], "Accept": "*/*", "Content-Type": "application/json", "User-Agent": nettacker_user_application_config()['user_agent'] }, json={ "ip": json.loads( requests.get('https://api64.ipify.org?format=json'). content)['ip'], "user_agent": nettacker_user_application_config()['user_agent'], "github_ci": os.environ.get('github_ci') == "true" }) except Exception: return None
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os from config import nettacker_paths css_1 = open( os.path.join(nettacker_paths()['web_static_files_path'], 'report/html_table.css')).read() table_title = open( os.path.join(nettacker_paths()['web_static_files_path'], 'report/table_title.html')).read() table_items = open( os.path.join(nettacker_paths()['web_static_files_path'], 'report/table_items.html')).read() table_end = open( os.path.join(nettacker_paths()['web_static_files_path'], 'report/table_end.html')).read()
def check_dependencies(): if python_version() == 2: sys.exit( color.color("red") + "[X] " + color.color("yellow") + "Python2 is No longer supported!" + color.color("reset")) # check os compatibility from config import nettacker_paths, nettacker_database_config external_modules = open( nettacker_paths()["requirements_path"]).read().split('\n') for module_name in external_modules: try: __import__( module_name.split('==')[0] if 'library_name=' not in module_name else module_name.split('library_name=')[1].split( )[0]) except Exception: if 'is_optional=true' not in module_name: sys.exit( color.color("red") + "[X] " + color.color("yellow") + "pip3 install -r requirements.txt ---> " + module_name.split('#')[0].strip() + " not installed!" + color.color("reset")) logo() from core.alert import messages if not ('linux' in os_name() or 'darwin' in os_name()): die_failure(messages("error_platform")) if not os.path.exists(nettacker_paths()["home_path"]): try: os.mkdir(nettacker_paths()["home_path"]) os.mkdir(nettacker_paths()["tmp_path"]) os.mkdir(nettacker_paths()["results_path"]) except Exception: die_failure("cannot access the directory {0}".format( nettacker_paths()["home_path"])) if not os.path.exists(nettacker_paths()["tmp_path"]): try: os.mkdir(nettacker_paths()["tmp_path"]) except Exception: die_failure("cannot access the directory {0}".format( nettacker_paths()["results_path"])) if not os.path.exists(nettacker_paths()["results_path"]): try: os.mkdir(nettacker_paths()["results_path"]) except Exception: die_failure("cannot access the directory {0}".format( nettacker_paths()["results_path"])) if nettacker_database_config()["DB"] == "sqlite": try: if not os.path.isfile(nettacker_paths()["database_path"]): from database.sqlite_create import sqlite_create_tables sqlite_create_tables() except Exception: die_failure("cannot access the directory {0}".format( nettacker_paths()["home_path"])) elif nettacker_database_config()["DB"] == "mysql": try: from database.mysql_create import (mysql_create_tables, mysql_create_database) mysql_create_database() mysql_create_tables() except Exception: die_failure(messages("database_connection_failed")) elif nettacker_database_config()["DB"] == "postgres": try: from database.postgres_create import postgres_create_database postgres_create_database() except Exception: die_failure(messages("database_connection_failed")) else: die_failure(messages("invalid_database"))