def __init__(self, nmap_weight=0.3, stat_weight=0.7): """ class initialization method :param nmap_weight: nmap list priority :param stat_weight: statistical list priority """ self.log = Log(name='PortMaster') self.DIR = Path( os.path.abspath(os.path.join(os.path.dirname(__file__), '../data'))) self.man_port_rating_file = Path( os.path.abspath(os.path.join(self.DIR, 'ManPortRating.csv'))) self.nmap_port_rating_file = Path( os.path.abspath(os.path.join(self.DIR, 'NmapPortRating.csv'))) self.stat_port_rating_file = Path( os.path.abspath(os.path.join(self.DIR, 'StatPortRating.csv'))) self.nmap_weight = nmap_weight self.stat_weight = stat_weight self.tcp_port = list() self.udp_port = list() self.__man_port_rating = dict() self.__nmap_port_rating = dict() self.__stat_port_rating = dict() self.__port_rating = dict() self.__udp_port_rating = dict() self.__tcp_port_rating = dict() self.__get_man_port_rating() self.__get_nmap_port_rating() self.__get_stat_port_rating() self.__get_port_rating() self.__sort_port()
def __init__(self, prog_path, db, scans_path): """ initialization nmap scanner class object :param prog_path: path to the program :param scans_path: gummy_scan directory """ self.log = Log(name='nscan') self.db = db self.parser = Parser() self._prog_path = prog_path self._scans_path = scans_path self.scan_name = None self.target = None self.port = None self.udp_port = None self.scan_type = None self.version = None self._ox_last_name = None self.ox_last_path = None self._t_missing = 'Missing required parameter: {}' self._args = list() self.counter = 0 self._check_prog() self._args_basic = [ '-sV', '-Pn', '--disable-arp-ping', '-T4', '-O', '--version-light', '--stats-every', '1s' ] self._args_arp = ['-PR', '-sn', '--stats-every', '1s'] self._args_dns = ['-sL']
def __init__(self): """initialization of the argument class""" self.log = Log(name='argum') self.target = None self.workspase = None self.port = None self.top_ports = None self.rate = None self.nmap_scan_type = None self.force = None self.config = None self.create_default_config = None
def __init__(self): """This class is designed to get a vendor by poppy address.""" self.log = Log(name='OuiMasver') self.DIR = Path( os.path.abspath(os.path.join(os.path.dirname(__file__), '../data'))) self.oui_file_path = Path( os.path.abspath( os.path.join(self.DIR, 'OrganizationallyUniqueIdentifier.csv'))) self.oui = dict() self.__get_oui()
def __init__(self): """class initialization""" self.log = Log(name='pars ') self.file_path = None # xml.etree.ElementTree.ElementTree object self.tree = None # information about scanning self.scan = dict() # result current pars self.result = list() self.tcp_sockets = dict() self.udp_sockets = dict() self.hosts = list() self.all_scans = list()
def run(): log = Log(name='main ') # parse start arguments args = ArgPars() args() # display current version if args.version: print(f'Gummy version {gummy.__version__} (https://github.com/v-yar/gummy)') sys.exit() # get default config config = Config() # create a default configuration if required if args.create_default_config: config.create_default_config() sys.exit() config.read_default_config() # set logger settings log.initialization(config.default_config['LOGING']) db = Storage() scanner = Scanner(db) log.info(f'Start time: {datetime.datetime.now().strftime("%Y.%m.%d %H:%M:%S")}') # set workspace name if args.workspase is None: workspace = datetime.datetime.now().strftime('%Y%m%d-%H%M%S') else: workspace = args.workspase config.start_config.set('MAIN', 'workspase', workspace) config + args.to_dict() # set current network cidr if args.target == 'auto': config.start_config.set('MASSCAN', 'target', get_ip()) # start shell shell = GummyShell(config=config, db=db, scanner=scanner) shell()
def __init__(self, db=None): """class object initialization""" # basic param: self.db = db self.log = Log(name='gummy') self.port_master = PortMaster() self.counter = 0 # complex gummy_scan param: self.complex_n_scan = None self.complex_m_scan = None self.complex_pars = None self.complex_res = None self.complex_hosts_file_last_path = None self.complex_step1 = False self.complex_step2 = False self.complex_step3 = False self.complex_step4 = False self.complex_confirmation_time = datetime.datetime.now() # config param: self.config = None self.masscan_path = None self.nmap_path = None self.workspace_path = None self.target = None self.target_exclude = None self.port = None self.top_ports = None self.rate = None self.scan_type = None # port ranges param: self.tcp_stage_1 = self.port_master(start=1, end=1000, protocol='tcp') self.tcp_stage_2 = self.port_master(start=1001, end=65535, protocol='tcp') self.udp_stage_1 = self.port_master(start=1, end=1000, protocol='udp') self.udp_stage_2 = self.port_master(start=1001, end=4000, protocol='udp')
def __init__(self, prog_path, scans_path, db): """ Initialization masscan scanner class object :param prog_path: path to the program :param scans_path: gummy_scan directory """ self.log = Log(name='mscan') self.db = db self._prog_path = prog_path self._scans_path = scans_path self.scan_name = None self.target = None self.target_exclude = None self.target_exclude_file = None self.port = None self.udp_port = None self.top_ports = None self.rate = None self._ob_last_name = '' self._ox_last_name = '' self._conf_last_name = '' self._hosts_file_last_name = '' self.ob_last_path = '' self.ox_last_path = '' self.conf_last_path = '' self.hosts_file_last_path = '' self._args = [] self.counter = 0 self.version = '' self.host = {} self._check_prog()
def __init__(self): """class initialization method""" self.log = Log(name='storg') self.data = list() self.sockets = dict() self.last_received = None self.v_schema = { "$schema": "http://json-schema.org/draft-04/schema#", "title": "gummy_scan result", "definitions": { "host": { "type": "object", "properties": { "addr": { "type": "string", "oneOf": [ { "format": "ipv4" }, { "format": "ipv6" }, ] }, "mac": { "type": "string" }, "hostname": { "type": "string" }, "vendor": { "type": "string" }, "ports": { "type": "array", "items": { "$ref": "#/definitions/port" } } }, "required": ["addr"], "additionalProperties": False }, "port": { "type": "object", "properties": { "portid": { "type": "string" }, "protocol": { "enum": ["tcp", "udp"] }, "state": { "type": "string" } }, "required": ["portid", "protocol"], "additionalProperties": False } }, "type": "array", "items": { "$ref": "#/definitions/host" } } self.m_schema = { 'mergeStrategy': 'arrayMergeById', 'mergeOptions': { 'idRef': 'addr' }, "items": { "properties": { "ports": { 'mergeStrategy': 'arrayMergeById', 'mergeOptions': { 'idRef': '/' } } } } } self.DIR = Path( os.path.abspath(os.path.join(os.path.dirname(__file__), '../data'))) self.ports_des_file = Path( os.path.abspath(os.path.join(self.DIR, 'PortDescription.csv'))) self.ports_rating_file = Path( os.path.abspath(os.path.join(self.DIR, 'NmapPortRating.csv'))) self.ports_des = None self.__get_ports_des()
def __init__(self): """initializing the configuration class.""" DIR = Path( os.path.abspath(os.path.join(os.path.dirname(__file__), '../'))) self.log = Log(name='conf ') self.default_config = None self.start_config_path = None self.start_config = None self.default_config_path = os.path.join(DIR, 'setting.ini') self.DEFAULT_CONFIG = { 'MAIN': { '# Contains the main application settings': None, '# Path:': None, 'result_path': Path(os.path.abspath(os.path.join(DIR, '../', 'scans'))), 'masscan_path': '/usr/bin/masscan', 'nmap_path': '/usr/bin/nmap', '# Reporting:': None, 'rep_type': 'None' }, 'LOGING': { '# Contains the logging settings': None, '# Logging:': None, '# log_level: DEBUG, INFO, WARNING, ERROR, CRITICAL': None, '# log_format: https://docs.python.org/3/library/logging.html#logrecord-attributes': None, '# log_format_date: ‘%Y-%m-%d %H:%M:%S,uuu’': None, 'log_level': 'INFO', 'log_format': '%(asctime)s | %(name)s | %(levelname)s | %(message)s', 'log_format_date': '%H:%M:%S', 'log_file_path': os.path.join(DIR, 'log') }, 'CONSTANTS': { '# Contains non-modifiable values': None, 'private_cidr': '10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16' }, 'MASSCAN': { '# The first step - hosts discovery': None, 'target': '127.0.0.1', 'target_exclude': '', 'port': '', 'top_ports': '', 'rate': '10000' }, 'NMAP': { '# The second step - detailed scanning of discovered hosts': None, 'scan_type': 'basic' }, }
def __init__(self, config, db, scanner): """class object initialization""" self.log = Log(name='shell') self.config = config self.db = db self.scan = scanner self.parser = Parser() self.collors = ( '#000000', '#800000', '#008000', '#808000', '#000080', '#800080', '#008080', '#c0c0c0', '#808080', '#ff0000', '#00ff00', '#ffff00', '#0000ff', '#ff00ff', '#00ffff', '#ffffff', '#000000', '#00005f', '#000087', '#0000af', '#0000d7', '#0000ff', '#005f00', '#005f5f', '#005f87', '#005faf', '#005fd7', '#005fff', '#008700', '#00875f', '#008787', '#0087af', '#0087d7', '#0087ff', '#00af00', '#00af5f', '#00af87', '#00afaf', '#00afd7', '#00afff', '#00d700', '#00d75f', '#00d787', '#00d7af', '#00d7d7', '#00d7ff', '#00ff00', '#00ff5f', '#00ff87', '#00ffaf', '#00ffd7', '#00ffff', '#5f0000', '#5f005f', '#5f5fd7', '#5faf5f', '#5f0087', '#5f00af', '#5f00d7', '#5f00ff', '#5f5f00', '#5f5f5f', '#5f5f87', '#5f5faf', '#5f5fff', '#5f8700', '#5f875f', '#5f8787', '#5f87af', '#5f87d7', '#5f87ff', '#5faf00', '#5faf87', '#5fafaf', '#5fafd7', '#5fafff', '#5fd700', '#5fd75f', '#5fd787', '#5fd7af', '#5fd7ff', '#5fff00', '#5fff5f', '#5fff87', '#5fffaf', '#5fffd7', '#5fffff', '#870000', '#870087', '#8700af', '#8700d7', '#8700ff', '#875f00', '#875f5f', '#875f87', '#875faf', '#875fff', '#878700', '#87875f', '#878787', '#8787af', '#8787d7', '#8787ff', '#87af00', '#87af87', '#87afaf', '#87afd7', '#87afff', '#87d700', '#87d75f', '#87d787', '#87d7af', '#87d7ff', '#87ff00', '#87ff5f', '#87ff87', '#87ffaf', '#87ffd7', '#87ffff', '#af0000', '#af0087', '#af00af', '#af00d7', '#af00ff', '#af5f00', '#af5f5f', '#af5f87', '#af5faf', '#af5fff', '#af8700', '#af875f', '#af8787', '#af87af', '#af87d7', '#af87ff', '#afaf00', '#afaf87', '#afafaf', '#afafd7', '#afafff', '#afd700', '#afd75f', '#afd787', '#afd7af', '#afd7ff', '#afff00', '#afff5f', '#afff87', '#afffaf', '#afffd7', '#afffff', '#d70000', '#d70087', '#d700af', '#d700d7', '#d700ff', '#d75f00', '#d75f5f', '#d75f87', '#d75faf', '#d75fff', '#d78700', '#d7875f', '#d78787', '#d787af', '#d787d7', '#d787ff', '#d7af00', '#d7af87', '#d7afaf', '#d7afd7', '#d7afff', '#d7d700', '#d7d75f', '#d7d787', '#d7d7af', '#d7d7ff', '#d7ff00', '#d7ff5f', '#d7ff87', '#d7ffaf', '#d7ffd7', '#d7ffff', '#ff0000', '#ff0087', '#ff00af', '#ff00d7', '#ff00ff', '#ff5f00', '#ff5f5f', '#ff5f87', '#ff5faf', '#ff5fff', '#ff8700', '#ff875f', '#ff8787', '#ff87af', '#ff87d7', '#ff87ff', '#ffaf00', '#ffaf87', '#ffafaf', '#ffafd7', '#ffafff', '#ffd700', '#ffd75f', '#ffd787', '#ffd7af', '#ffd7ff', '#ffff00', '#ffff5f', '#ffff87', '#ffffaf', '#ffffd7', '#ffffff', '#080808', '#1c1c1c', '#262626', '#303030', '#3a3a3a', '#444444', '#4e4e4e', '#585858', '#626262', '#767676', '#808080', '#8a8a8a', '#949494', '#9e9e9e', '#a8a8a8', '#b2b2b2', '#bcbcbc', '#d0d0d0', '#dadada', '#e4e4e4', '#eeeeee', '#5fd7d7', '#87005f', '#875fd7', '#875fd7', '#87af5f', '#87d7d7', '#af005f', '#af5fd7', '#afaf5f', '#afd7d7', '#d7005f', '#d75fd7', '#d7af5f', '#d7d7d7', '#ff005f', '#ff5fd7', '#ffaf5f', '#ffd7d7', '#121212', '#6c6c6c', '#c6c6c6', ) self.commands = { 'set': self.config.get_all_start_config_key(), 'show': { 'config': 'print curent config (takes param)', 'host': 'print host table (takes param)', 'port': 'print port table', 'task': 'print running tasks', 'log': 'print the last n lines of the log file' }, 'sync': { 'config': 'synchronizes the configuration file' }, 'run': self.get_scanner_methods(self.scan), 'workspase': self.get_all_workspase(), 'flush': {}, 'kill': {}, 'help': {}, 'exit': {} } self.c_function = { 'set': self.f_set, 'show': self.f_show, 'sync': self.f_sync, 'run': self.f_run, 'workspase': self.f_workspase, 'flush': self.f_flush, 'kill': self.f_kill, 'help': self.f_help, 'exit': self.f_exit } self.grammar = compile(""" (\s* (?P<command>[a-z]+) \s*) | (\s* (?P<command>[a-z]+) \s+ (?P<operator>[A-Za-z0-9_-]+) \s*) | (\s* (?P<command>[a-z]+) \s+ (?P<operator>[A-Za-z0-9_-]+) \s+ (?P<parameter>[A-Za-z0-9.,-_/+*]+) \s*) """) self.style = Style.from_dict({ 'command': '#216f21 bold', 'operator': '#6f216f bold', 'parameter': '#ff0000 bold', 'trailing-input': 'bg:#662222 #ffffff', 'bottom-toolbar': '#6f216f bg:#ffffff', # Logo. 'bear': random.choice(self.collors), 'text': random.choice(self.collors), # User input (default text). '': '#ff0066', # Prompt. 'prompt_for_input': '#6f216f', }) self.lexer = GrammarLexer(self.grammar, lexers={ 'command': SimpleLexer('class:command'), 'operator': SimpleLexer('class:operator'), 'parameter': SimpleLexer('class:parameter') }) self.completer = GCompleter(self.commands) self.history_path = Path( os.path.abspath( os.path.join(os.path.dirname(__file__), '../.history'))) self.history = FileHistory(self.history_path) version_str = ''.join(['v', gummy.__version__, ' ']) self.logo = HTML(f''' <text> </text><bear> _ _ </bear> <text> _____ _ _ __ __ __ ____ __</text><bear> (c).-.(c) </bear> <text> / ____| | | | \/ | \/ \ \ / /</text><bear> / ._. \ </bear> <text> | | __| | | | \ / | \ / |\ \_/ / </text><bear> __\( Y )/__ </bear> <text> | | |_ | | | | |\/| | |\/| | \ / </text><bear> (_.-/'-'\-._)</bear> <text> | |__| | |__| | | | | | | | | | </text><bear> || </bear><text>G</text><bear> || </bear> <text> \_____|\____/|_| |_|_| |_| |_| </text><bear> _.' `-' '._ </bear> <text> </text><bear> (.-./`-'\.-.)</bear> <text>{version_str:>38}</text><bear> `-' `-'</bear> ''') self.prompt_str = [('class:prompt_for_input', '>>> ')] self.counter = 0 self.sync_config_stat = 0
import os import re import socket import subprocess import psutil from gummy.tools.log import Log log = Log(name='tool ') def get_ip(): """bad method for detecting current network""" s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) cur_ip = '127.0.0.1' try: s.connect(('10.255.255.255', 1)) ip_s = s.getsockname()[0] proc = subprocess.Popen(['ip', 'a'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) output = proc.communicate()[0] for line in output.split(os.linesep): if ip_s in line: cur_ip = re.search(r'(?P<ip>[\d.]+/\d*) ', line).group('ip') except Exception: log.warning('Сould not determine current ip address') finally: s.close()