コード例 #1
0
ファイル: attack.py プロジェクト: jai2033shankar/Nettacker
def start_attack(target, num, total, scan_method, users, passwds, timeout_sec,
                 thread_number, ports, log_in_file, time_sleep, language):
    info(str(messages(language, 45).format(str(target), str(num), str(total))))

    # Calling Engines
    # BruteForce Engines
    if scan_method[-6:] == '_brute':
        try:
            start = getattr(
                __import__('lib.brute.%s.engine' %
                           (scan_method.rsplit('_brute')[0]),
                           fromlist=['start']), 'start')
        except:
            sys.exit(error(messages(language, 46).format(scan_method)))
        start(target, users, passwds, ports, timeout_sec, thread_number, num,
              total, log_in_file, time_sleep, language)
    # Scanners Engines
    if scan_method[-5:] == '_scan':
        try:
            start = getattr(
                __import__('lib.scan.%s.engine' %
                           (scan_method.rsplit('_scan')[0]),
                           fromlist=['start']), 'start')
        except:
            sys.exit(error(messages(language, 46).format(scan_method)))
        start(target, users, passwds, ports, timeout_sec, thread_number, num,
              total, log_in_file, time_sleep, language)
コード例 #2
0
def start_attack(target, num, total, scan_method, users, passwds, timeout_sec, thread_number, ports, log_in_file,
                 time_sleep, language, verbose_level, show_version, check_update, proxies, retries, ping_flag, methods_args):
    info(messages(language, 45).format(str(target), str(num), str(total)))
    # Calling Engines
    # BruteForce Engines
    if scan_method[-6:] == '_brute':
        try:
            start = getattr(
                __import__('lib.brute.%s.engine' % (scan_method.rsplit('_brute')[0]),
                           fromlist=['start']),
                'start')
        except:
            error(messages(language, 46).format(scan_method))
            from core.color import finish
            finish()
            sys.exit(1)
        start(target, users, passwds, ports, timeout_sec, thread_number, num, total, log_in_file, time_sleep, language,
              verbose_level, show_version, check_update, proxies, retries, ping_flag, methods_args)
    # Scanners Engines
    if scan_method[-5:] == '_scan':
        try:
            start = getattr(
                __import__('lib.scan.%s.engine' % (scan_method.rsplit('_scan')[0]),
                           fromlist=['start']),
                'start')
        except:
            error(messages(language, 46).format(scan_method))
            from core.color import finish
            finish()
            sys.exit(1)
        start(target, users, passwds, ports, timeout_sec, thread_number, num, total, log_in_file, time_sleep, language,
              verbose_level, show_version, check_update, proxies, retries, ping_flag, methods_args)
コード例 #3
0
ファイル: exit_helper.py プロジェクト: ArianPH/OWASP-Honeypot
def exit_failure(msg):
    """
    exit the framework with code 1

    Args:
        msg: the error message
    """
    # TODO : Fix the cyclic dependency later
    from core.alert import error
    error(msg)
    reset_cmd_color()
    sys.exit(1)
コード例 #4
0
ファイル: die.py プロジェクト: greatspider135/OWASP-Nettacker
def die_failure(msg):
    """
    exit the framework with code 1

    Args:
        msg: the error message
    """
    from core.color import reset_color
    from core.alert import error
    error(msg)
    reset_color()
    sys.exit(1)
コード例 #5
0
ファイル: _die.py プロジェクト: starling021/OWASP-Nettacker-
def __die_failure(msg):
    """
    exit the framework with code 1

    Args:
        msg: the error message
    """
    from core.color import finish
    from core.alert import error
    error(msg)
    finish()
    sys.exit(1)
コード例 #6
0
def build_graph(graph_flag, language, data, _HOST, _USERNAME, _PASSWORD, _PORT, _TYPE, _DESCRIPTION):
    info(messages(language, 88))
    try:
        start = getattr(
            __import__('lib.graph.%s.engine' % (graph_flag.rsplit('_graph')[0]),
                       fromlist=['start']),
            'start')
    except:
        error(messages(language, 98).format(graph_flag))
        from core.color import finish
        finish()
        sys.exit(1)

    info(messages(language, 89))
    return start(graph_flag, language, data, _HOST, _USERNAME, _PASSWORD, _PORT, _TYPE, _DESCRIPTION)
コード例 #7
0
ファイル: load.py プロジェクト: sumodgeorge/Python-Honeypot
def wait_until_interrupt(virtual_machine_container_reset_factory_time_seconds,
                         configuration, new_network_events_thread,
                         run_as_test):
    """
    wait for opened threads/honeypots modules

    Returns:
        True
    """
    # running_time variable will be use to check
    # if its need to reset the container after a while
    # if virtual_machine_container_reset_factory_time_seconds < 0,
    # it will keep containers until user interruption
    running_time = 0
    while True:
        # while True sleep until user send ctrl + c
        try:
            time.sleep(1)
            running_time += 1
            # check if running_time is equal to reset factory time
            if running_time == virtual_machine_container_reset_factory_time_seconds:
                # reset the run time
                running_time = 0
                # stop old containers (in case they are not stopped)
                stop_containers(configuration)
                # remove old containers (in case they are not updated)
                remove_old_containers(configuration)
                # start containers based on selected modules
                start_containers(configuration)
            if not new_network_events_thread.is_alive():
                return error(
                    "Interrupting the application because network capturing process is not alive!"
                )
            if containers_are_unhealthy(configuration):
                return error(
                    "Interrupting the application because \"{0}\" container(s) is(are) not alive!"
                    .format(", ".join(
                        containers_are_unhealthy(configuration))))
            if run_as_test:
                break
        except KeyboardInterrupt:
            # break and return for stopping and removing containers/images
            info(
                "interrupted by user, please wait to stop the containers and remove the containers and images"
            )
            break
    return True
コード例 #8
0
def start_attack(target, num, total, scan_method, users, passwds, timeout_sec,
                 thread_number, ports, log_in_file, time_sleep, language,
                 verbose_level, socks_proxy, retries, ping_flag, methods_args,
                 scan_id, scan_cmd):
    info(messages(language, 45).format(str(target), str(num), str(total)))
    # Calling Engines
    try:
        start = getattr(
            __import__('lib.{0}.{1}.engine'.format(
                scan_method.rsplit('_')[-1],
                '_'.join(scan_method.rsplit('_')[:-1])),
                       fromlist=['start']), 'start')
    except:
        error(messages(language, 46).format(scan_method))
        from core.color import finish
        finish()
        sys.exit(1)
    start(target, users, passwds, ports, timeout_sec, thread_number, num,
          total, log_in_file, time_sleep, language, verbose_level, socks_proxy,
          retries, ping_flag, methods_args, scan_id, scan_cmd)
    return 0
コード例 #9
0
def __die_failure(msg):
    error(msg)
    finish()
    sys.exit(1)
コード例 #10
0
def check_all_required(targets, targets_list, thread_number,
                       thread_number_host, log_in_file, scan_method,
                       exclude_method, users, users_list, passwds,
                       passwds_list, timeout_sec, ports, parser, module_names,
                       language, verbose_level, show_version, check_update,
                       proxies, proxies_file, retries, graph_flag,
                       help_menu_flag):
    # Checking Requirements
    # Check Help Menu
    if help_menu_flag is True:
        parser.print_help()
        from core.color import finish
        finish()
        sys.exit(0)
    # Check version
    if show_version is True:
        from core import compatible
        from core import color
        info(
            messages(language,
                     84).format(color.color('yellow'), compatible.__version__,
                                color.color('reset'), color.color('cyan'),
                                compatible.__code_name__, color.color('reset'),
                                color.color('green')))
        from core.color import finish
        finish()
        sys.exit(0)
    # Check update
    if check_update is True:
        info(messages(language, 85))
        from core.color import finish
        finish()
        sys.exit(0)
    # Check the target(s)
    if targets is None and targets_list is None:
        parser.print_help()
        write("\n")
        error(messages(language, 26))
        from core.color import finish
        finish()
        sys.exit(1)
    else:
        if targets is not None:
            targets = list(set(targets.rsplit(",")))
        elif targets_list is not None:
            try:
                targets = list(set(open(targets_list, "rb").read().rsplit()))
            except:
                error(messages(language, 27).format(targets_list))
                from core.color import finish
                finish()
                sys.exit(1)
    # Check thread number
    if thread_number > 100 or thread_number_host > 100:
        warn(messages(language, 28))
    # Check timeout number
    if timeout_sec is not None and timeout_sec >= 15:
        warn(messages(language, 29).format(timeout_sec))
    # Check scanning method
    if scan_method is not None and scan_method == "all":
        scan_method = module_names
        scan_method.remove("all")
    elif scan_method is not None and scan_method not in module_names:
        if "," in scan_method:
            scan_method = scan_method.rsplit(",")
            for sm in scan_method:
                if sm not in module_names:
                    error(messages(language, 30).format(sm))
                    from core.color import finish
                    finish()
                    sys.exit(1)
                if sm == "all":
                    scan_method = module_names
                    scan_method.remove("all")
                    break
        else:
            error(messages(language, 31).format(scan_method))
            from core.color import finish
            finish()
            sys.exit(1)
    elif scan_method is None:
        error(messages(language, 41))
        from core.color import finish
        finish()
        sys.exit(1)
    else:
        scan_method = scan_method.rsplit()
    if exclude_method is not None:
        exclude_method = exclude_method.rsplit(",")
        for exm in exclude_method:
            if exm in scan_method:
                if "all" == exm:
                    messages(language, 32)
                    from core.color import finish
                    finish()
                    sys.exit(1)
                else:
                    scan_method.remove(exm)
                    if len(scan_method) is 0:
                        messages(language, 33)
                        from core.color import finish
                        finish()
                        sys.exit(1)
            else:
                messages(language, 34).format(exm)
                from core.color import finish
                finish()
                sys.exit(1)
    # Check port(s)
    if ports is None:
        error(messages(language, 35))
        from core.color import finish
        finish()
        sys.exit(1)
    if type(ports) is not list and "-" in ports:
        ports = ports.rsplit("-")
        ports = range(int(ports[0]), int(ports[1]) + 1)
    elif type(ports) is not list:
        ports = ports.rsplit(",")
    # Check user list
    if users is None and users_list is None and scan_method is not None:
        for imethod in scan_method:
            if "_brute" in imethod:
                error(messages(language, 36))
                from core.color import finish
                finish()
                sys.exit(1)
    else:
        if users is not None:
            users = list(set(users.rsplit(",")))
        if users_list is not None:
            try:
                users = list(set(
                    open(users_list).read().rsplit("\n")))  # fix later
            except:
                error(messages(language, 37).format(targets_list))
                from core.color import finish
                finish()
                sys.exit(1)
    # Check password list
    if passwds is None and passwds_list is None and scan_method is not None:
        for imethod in scan_method:
            if "_brute" in imethod:
                error(messages(language, 38))
                from core.color import finish
                finish()
                sys.exit(1)
    else:
        if passwds is not None:
            passwds = list(set(passwds.rsplit(",")))
        if passwds_list is not None:
            try:
                passwds = list(set(
                    open(passwds_list).read().rsplit("\n")))  # fix later
            except:
                error(messages(language, 39).format(targets_list))
                from core.color import finish
                finish()
                sys.exit(1)
    # Check output file
    try:
        tmpfile = open(log_in_file, "w")
    except:
        error(messages(language, 40).format(log_in_file))
        from core.color import finish
        finish()
        sys.exit(1)
    # Check Proxies
    if proxies is not None:
        proxies = list(set(proxies.rsplit(',')))
    elif proxies_file is not None:
        if os.path.isfile(proxies_file):
            try:
                proxies = list(set(open(proxies_file).read().rsplit()))
            except:
                error(messages(language, 82).format(proxies_file))
                from core.color import finish
                finish()
                sys.exit(1)
        else:
            error(messages(language, 83).format(proxies_file))
            from core.color import finish
            finish()
            sys.exit(1)
    # Check Graph
    if graph_flag is not None:
        if not (len(log_in_file) >= 5 and log_in_file[-5:] == '.html') or (
                not len(log_in_file) >= 4 and log_in_file[-4:] == '.htm'):
            error(messages(language, 87))
            from core.color import finish
            finish()
            sys.exit(1)
        if graph_flag not in load_all_graphs():
            error(messages(language, 97).format(graph_flag))
            from core.color import finish
            finish()
            sys.exit(1)

    # Return the values
    return [
        targets, targets_list, thread_number, thread_number_host, log_in_file,
        scan_method, exclude_method, users, users_list, passwds, passwds_list,
        timeout_sec, ports, parser, module_names, language, verbose_level,
        show_version, check_update, proxies, proxies_file, retries, graph_flag,
        help_menu_flag
    ]
コード例 #11
0
def load_all_args(module_names):
    # Language Options
    language_list = [lang for lang in messages(-1, 0)]
    if "-L" in sys.argv or "--language" in sys.argv:
        try:
            index = sys.argv.index("-L") + 1
        except:
            index = sys.argv.index("-language") + 1
    else:
        index = -1
    if index is -1:
        language = "en"
    else:
        language = sys.argv[index]
        if language not in language_list:
            sys.exit(
                error("Please select one of these languages {0}".format(
                    language_list)))

    # Check if compatible
    check(language)

    # Start Parser
    parser = OptionParser(usage=messages(language, 1),
                          description=messages(language, 2),
                          epilog=messages(language, 3))
    # Engine Options
    engineOpt = OptionGroup(parser, messages(language, 4),
                            messages(language, 5))
    engineOpt.add_option("-L",
                         "--language",
                         action="store",
                         dest="language",
                         default="en",
                         help=messages(language, 6).format(language_list))
    engineOpt.add_option("-v",
                         "--verbose",
                         action="store",
                         dest="verbose_level",
                         default=0,
                         help=messages(language, 59))
    engineOpt.add_option("-V",
                         "--version",
                         action="store_true",
                         default=False,
                         dest="show_version",
                         help=messages(language, 60))
    engineOpt.add_option("-c",
                         "--update",
                         action="store_true",
                         default=False,
                         dest="check_update",
                         help=messages(language, 61))
    engineOpt.add_option("-o",
                         "--output",
                         action="store",
                         default="results.txt",
                         dest="log_in_file",
                         help=messages(language, 11))

    # Build Engine Options
    parser.add_option_group(engineOpt)

    # Target Options
    target = OptionGroup(parser, messages(language, 12),
                         messages(language, 13))
    target.add_option("-i",
                      "--targets",
                      action="store",
                      dest="targets",
                      default=None,
                      help=messages(language, 14))
    target.add_option("-l",
                      "--targets-list",
                      action="store",
                      dest="targets_list",
                      default=None,
                      help=messages(language, 15))
    # Build Options
    parser.add_option_group(target)

    # Methods Options
    method = OptionGroup(parser, "Method", messages(language, 16))
    method.add_option("-m",
                      "--method",
                      action="store",
                      dest="scan_method",
                      default=None,
                      help=messages(language, 17).format(module_names))
    method.add_option("-x",
                      "--exclude",
                      action="store",
                      dest="exclude_method",
                      default=None,
                      help=messages(language, 18).format(module_names))
    method.add_option("-u",
                      "--usernames",
                      action="store",
                      dest="users",
                      default=None,
                      help=messages(language, 19))
    method.add_option("-U",
                      "--users-list",
                      action="store",
                      dest="users_list",
                      default=None,
                      help=messages(language, 20))
    method.add_option("-p",
                      "--passwords",
                      action="store",
                      dest="passwds",
                      default=None,
                      help=messages(language, 21))
    method.add_option("-P",
                      "--passwords-list",
                      action="store",
                      dest="passwds_list",
                      default=None,
                      help=messages(language, 22))
    method.add_option("-g",
                      "--ports",
                      action="store",
                      dest="ports",
                      default=None,
                      help=messages(language, 23))
    method.add_option("-T",
                      "--timeout",
                      action="store",
                      dest="timeout_sec",
                      default=None,
                      type="float",
                      help=messages(language, 24))
    method.add_option("-w",
                      "--time-sleep",
                      action="store",
                      dest="time_sleep",
                      default=None,
                      type="float",
                      help=messages(language, 25))
    method.add_option("-r",
                      "--range",
                      action="store_true",
                      default=False,
                      dest="check_ranges",
                      help=messages(language, 7))
    method.add_option("-s",
                      "--sub-domains",
                      action="store_true",
                      default=False,
                      dest="check_subdomains",
                      help=messages(language, 8))
    method.add_option("-t",
                      "--thread-connection",
                      action="store",
                      default=10,
                      type="int",
                      dest="thread_number",
                      help=messages(language, 9))
    method.add_option("-M",
                      "--thread-hostscan",
                      action="store",
                      default=10,
                      type="int",
                      dest="thread_number_host",
                      help=messages(language, 10))
    method.add_option("-R",
                      "--proxy",
                      action="store",
                      dest="proxies",
                      default=None,
                      help=messages(language, 62))
    method.add_option("--proxy-list",
                      action="store",
                      dest="proxies",
                      default=None,
                      help=messages(language, 63))
    method.add_option("--retries",
                      action="store",
                      dest="retries",
                      default=3,
                      help=messages(language, 64))
    # Build Options
    parser.add_option_group(method)

    # Return Options
    return [parser, parser.parse_args()]
コード例 #12
0
ファイル: engine.py プロジェクト: z740493980/OWASP-Nettacker
def generate(data, register, gtype):
    length = len(data)
    if gtype == 'int':
        flag_8 = True
        try:
            data = hex(int(data, 8))
        except:
            flag_8 = False
        if flag_8 is False:
            try:
                data = hex(int(data, 16))
            except:
                error('hex or digit required!\nExit\n')
    if gtype == 'string':
        data = st(data)
    if length <= 3:
        if gtype == 'string':
            data = str('0x') + str(data)
        if len(data) % 2 is not 0:
            data = data.replace('0x', '0x0')
        if len(data) is 8:
            data = data + '90\npop %s\nshr $0x8,%s\npush %s\n' % (
                register, register, register)
        if len(data) is 6:
            data = data + '9090\npop %s\nshr $0x10,%s\npush %s\n' % (
                register, register, register)
        if len(data) is 4:
            data = data + '909090\npop %s\nshr $0x10,%s\nshr $0x8,%s\npush %s\n' % (
                register, register, register, register)
        data = str('push $') + str(data)
    if length >= 4:
        if gtype == 'int':
            data = data[2:]
        stack_content = data
        shr_counter = len(stack_content) % 8
        shr = None
        if shr_counter is 2:
            shr = '\npop %s\nshr    $0x10,%s\nshr    $0x8,%s\npush %s\n' % (
                register, register, register, register)
            stack_content = stack_content[0:2] + '909090' + stack_content[2:]
        if shr_counter is 4:
            shr = '\npop %s\nshr    $0x10,%s\npush %s\n' % (register, register,
                                                            register)
            stack_content = stack_content[0:4] + '9090' + stack_content[4:]
        if shr_counter is 6:
            shr = '\npop %s\nshr    $0x8,%s\npush %s\n' % (register, register,
                                                           register)
            stack_content = stack_content[0:6] + '90' + stack_content[6:]
        zshr = shr
        m = int(len(stack_content))
        n = int(len(stack_content) / 8)
        file_shellcode = ''
        if (len(stack_content) % 8) is 0:
            shr_n = 0
            r = ''
            while (n is not 0):
                if shr is not None:
                    shr_n += 1
                    zx = m - 8
                    file_shellcode = 'push $0x' + str(
                        stack_content[zx:m]) + '\n' + file_shellcode
                    m -= 8
                    n = n - 1
                    shr = None
                if shr is None:
                    shr_n += 1
                    zx = m - 8
                    file_shellcode = 'push $0x' + str(
                        stack_content[zx:m]) + '\n' + file_shellcode
                    m -= 8
                    n = n - 1
            if zshr is None:
                file_z = file_shellcode
            if zshr is not None:
                rep1 = file_shellcode[:16]
                rep2 = rep1 + zshr
                file_z = file_shellcode.replace(rep1, rep2)
        data = file_z
    return data
コード例 #13
0
ファイル: log.py プロジェクト: sbambach/OWASP-Nettacker
# -*- coding: utf-8 -*-

import json
import sys
from core.alert import messages
from core.alert import info
from core.alert import error
from core import compatible
from core._time import now

try:
    import texttable
except:
    from core.color import finish

    error('pip install -r requirements.txt')
    finish()
    sys.exit(1)


def build_graph(graph_flag, language, data, _HOST, _USERNAME, _PASSWORD, _PORT,
                _TYPE, _DESCRIPTION):
    info(messages(language, 88))
    try:
        start = getattr(
            __import__('lib.graph.%s.engine' %
                       (graph_flag.rsplit('_graph')[0]),
                       fromlist=['start']), 'start')
    except:
        error(messages(language, 98).format(graph_flag))
        from core.color import finish
コード例 #14
0
def network_traffic_capture(configuration, honeypot_events_queue,
                            network_events_queue, network_config):
    """
    Capture network traffic and submit new network and honeypot events to the database

    Args:
        configuration: user final configuration
        honeypot_events_queue: multiprocessing queue for storing honeypot events
        network_events_queue: multiprocessing queue for storing network events
        network_config: network configuration

    Returns:
        True
    """
    info(messages["network_traffic_capture_start"])

    for selected_module in configuration:
        port_number = configuration[selected_module][
            "real_machine_port_number"]

        honeypot_ports[port_number] = selected_module

    # get ip addresses
    virtual_machine_ip_addresses = [
        configuration[selected_module]["ip_address"]
        for selected_module in configuration
    ]

    # Ignore VM IPs + IPs in config.py
    # VM = virtual machine, RM = real machine
    ignore_rm_ip_addresses = network_config["ignore_real_machine_ip_address"]
    ignore_vm_ip_addresses = network_config[
        "ignore_virtual_machine_ip_addresses"]

    # Ignore real machine IPs
    ignore_ip_addresses = network_config["ignore_real_machine_ip_addresses"] \
        if ignore_rm_ip_addresses else [] + virtual_machine_ip_addresses \
        if ignore_vm_ip_addresses else []

    ignore_ip_addresses.extend(get_gateway_ip_addresses(configuration))

    # Ignore ports
    ignore_ports = network_config["ignore_real_machine_ports"]

    # Display filter to be applied to the Live Captured network traffic
    display_filter = ' and '.join(
        ['ip.src!={0} and ip.dst!={0}'.format(_) for _ in ignore_ip_addresses])
    display_filter += ' and ' if ignore_ip_addresses and ignore_ports else ""
    display_filter += ' and '.join([
        'tcp.srcport!={0} and tcp.dstport!={0}'.format(_) for _ in ignore_ports
    ])

    store_pcap = network_config["store_network_captured_files"]
    timeout = network_config["split_pcap_file_timeout"]

    # Make the pcapfiles directory for storing the Network captured files
    base_dir_path = os.path.join(sys.path[0], "pcapfiles")

    def packet_callback(packet):
        """
        Callback function, called by apply_on_packets
        Args:
            packet
        """
        process_packet(packet, honeypot_events_queue, network_events_queue)

    # Run infinite loop and split the capture in multiple files using the timeout set
    # in the network configuration
    while True:
        # Timestamp to be used in file name
        file_timestamp = int(time.time())
        generation_time = datetime.fromtimestamp(file_timestamp).strftime(
            "%Y-%m-%d %H:%M:%S")
        # File path of the network capture file with the timestamp
        output_file_path = os.path.join(
            base_dir_path, "captured-traffic-" + str(file_timestamp) + ".pcap")

        if store_pcap:
            info(messages["network_capture_getting_stored"].format(
                output_file_path))

        try:
            capture = pyshark.LiveCapture(
                interface='any',
                display_filter=display_filter,
                output_file=output_file_path if store_pcap else None)

            # Debug option for pyshark capture
            if is_verbose_mode():
                capture.set_debug()

            # Applied on every packet captured by pyshark LiveCapture
            capture.apply_on_packets(packet_callback, timeout=timeout)

        except get_timeout_error() as e:
            force_kill_tshark()
            # Catches the timeout error thrown by apply_on_packets
            insert_pcap_files_to_collection(
                FileArchive(output_file_path, generation_time,
                            timeout)) if store_pcap else e

        except KeyboardInterrupt as e:
            force_kill_tshark()
            insert_pcap_files_to_collection(
                FileArchive(output_file_path, generation_time,
                            timeout)) if store_pcap else e
            break

        except Exception as e:
            force_kill_tshark()
            insert_pcap_files_to_collection(
                FileArchive(output_file_path, generation_time,
                            timeout)) if store_pcap else e
            error(str(e))
            break

    return True
コード例 #15
0
def check_all_required(targets, targets_list, thread_number,
                       thread_number_host, log_in_file, scan_method,
                       exclude_method, users, users_list, passwds,
                       passwds_list, timeout_sec, ports, parser, module_names,
                       language, verbose_level, show_version, check_update,
                       socks_proxy, retries, graph_flag, help_menu_flag,
                       methods_args, method_args_list):
    # Checking Requirements
    # import libs
    from core.color import finish
    from core import compatible
    # Check Help Menu
    if help_menu_flag is True:
        parser.print_help()
        write('\n\n')
        write(messages(language, 3))
        finish()
        sys.exit(0)
    # Check if method args list called
    if method_args_list is True:
        from core.load_modules import load_all_method_args
        load_all_method_args(language)
        finish()
        sys.exit(0)
    # Check version
    if show_version is True:
        from core import color
        info(
            messages(language,
                     84).format(color.color('yellow'), compatible.__version__,
                                color.color('reset'), color.color('cyan'),
                                compatible.__code_name__, color.color('reset'),
                                color.color('green')))
        finish()
        sys.exit(0)
    # Check update
    if check_update is True:
        from core.update import _update
        _update(compatible.__version__, compatible.__code_name__, language)
        finish()
        sys.exit(0)
    # Check the target(s)
    if targets is None and targets_list is None:
        parser.print_help()
        write("\n")
        error(messages(language, 26))
        finish()
        sys.exit(1)
    else:
        if targets is not None:
            targets = list(set(targets.rsplit(",")))
        elif targets_list is not None:
            try:
                targets = list(set(open(targets_list, "rb").read().rsplit()))
            except:
                error(messages(language, 27).format(targets_list))
                finish()
                sys.exit(1)
    # Check thread number
    if thread_number > 100 or thread_number_host > 100:
        warn(messages(language, 28))
    # Check timeout number
    if timeout_sec is not None and timeout_sec >= 15:
        warn(messages(language, 29).format(timeout_sec))
    # Check scanning method
    if scan_method is not None and scan_method == "all":
        scan_method = module_names
        scan_method.remove("all")
    elif scan_method is not None and scan_method not in module_names:
        if "," in scan_method:
            scan_method = scan_method.rsplit(",")
            for sm in scan_method:
                if sm not in module_names:
                    error(messages(language, 30).format(sm))
                    finish()
                    sys.exit(1)
                if sm == "all":
                    scan_method = module_names
                    scan_method.remove("all")
                    break
        else:
            error(messages(language, 31).format(scan_method))
            finish()
            sys.exit(1)
    elif scan_method is None:
        error(messages(language, 41))
        finish()
        sys.exit(1)
    else:
        scan_method = scan_method.rsplit()
    if exclude_method is not None:
        exclude_method = exclude_method.rsplit(",")
        for exm in exclude_method:
            if exm in scan_method:
                if "all" == exm:
                    messages(language, 32)
                    finish()
                    sys.exit(1)
                else:
                    scan_method.remove(exm)
                    if len(scan_method) is 0:
                        messages(language, 33)
                        finish()
                        sys.exit(1)
            else:
                messages(language, 34).format(exm)
                finish()
                sys.exit(1)
    # Check port(s)
    if type(ports) is not list and ports is not None and "-" in ports:
        ports = ports.rsplit("-")
        ports = range(int(ports[0]), int(ports[1]) + 1)
    elif type(ports) is not list and ports is not None:
        ports = ports.rsplit(",")
    # Check user list
    if users is not None:
        users = list(set(users.rsplit(",")))
    elif users_list is not None:
        try:
            users = list(set(
                open(users_list).read().rsplit("\n")))  # fix later
        except:
            error(messages(language, 37).format(targets_list))
            finish()
            sys.exit(1)
    # Check password list
    if passwds is not None:
        passwds = list(set(passwds.rsplit(",")))
    if passwds_list is not None:
        try:
            passwds = list(set(
                open(passwds_list).read().rsplit("\n")))  # fix later
        except:
            error(messages(language, 39).format(targets_list))
            finish()
            sys.exit(1)
    # Check output file
    try:
        tmpfile = open(log_in_file, "w")
    except:
        error(messages(language, 40).format(log_in_file))
        finish()
        sys.exit(1)
    # Check Graph
    if graph_flag is not None:
        if graph_flag not in load_all_graphs():
            error(messages(language, 97).format(graph_flag))
            finish()
            sys.exit(1)
        if not (log_in_file.endswith('.html') or log_in_file.endswith('.htm')):
            warn(messages(language, 87))
            graph_flag = None
    # Check Socks
    if socks_proxy is not None:
        e = False
        try:
            if '://' in socks_proxy:
                socks_proxy = socks_proxy.rsplit('://')[1].rsplit('/')[0]
            if len(socks_proxy.rsplit(':')) is not 2 or socks_proxy.rsplit(
                    ':')[1] == '':
                e = True
        except:
            e = True
        if e:
            error(messages(language, 63))
            finish()
            sys.exit(1)
    # Check Methods ARGS
    if methods_args is not None:
        new_methods_args = {}
        methods_args = methods_args.rsplit('&')
        for imethod_args in methods_args:
            if len(imethod_args.rsplit('=')) is 2:
                if imethod_args.rsplit('=')[1].startswith('read_from_file:'):
                    try:
                        read_data = list(
                            set(
                                open(
                                    imethod_args.rsplit('=read_from_file:')
                                    [1]).read().rsplit('\n')))
                    except:
                        error(messages(language, 36))
                        finish()
                        sys.exit(1)
                    new_methods_args[imethod_args.rsplit('=')[0]] = read_data
                else:
                    new_methods_args[imethod_args.rsplit(
                        '=')[0]] = imethod_args.rsplit('=')[1].rsplit(',')
            else:
                new_methods_args[imethod_args.rsplit('=')[0]] = ""
        methods_args = new_methods_args
    # Return the values
    return [
        targets, targets_list, thread_number, thread_number_host, log_in_file,
        scan_method, exclude_method, users, users_list, passwds, passwds_list,
        timeout_sec, ports, parser, module_names, language, verbose_level,
        show_version, check_update, socks_proxy, retries, graph_flag,
        help_menu_flag, methods_args, method_args_list
    ]
コード例 #16
0
def load_all_args(module_names, graph_names):
    # Language Options
    # import libs
    from core.color import finish
    default_config = _builder(get_config())
    language_list = [lang for lang in messages(-1, 0)]
    if "-L" in sys.argv or "--language" in sys.argv:
        try:
            index = sys.argv.index("-L") + 1
        except:
            index = sys.argv.index("--language") + 1
    else:
        index = -1
    if index is -1:
        language = "en"
    else:
        _error_flag = False
        try:
            language = sys.argv[index]
        except:
            _error_flag = True
        if _error_flag or language not in language_list:
            error("Please select one of these languages {0}".format(
                language_list))
            finish()
            sys.exit(1)

    # Check if compatible
    check(language)
    finish()
    # Start Parser
    parser = argparse.ArgumentParser(prog="Nettacker", add_help=False)

    # parser = OptionParser(usage=messages(language, 1),
    #                      description=messages(language, 2),
    #                      epilog=messages(language, 3))

    # Engine Options
    engineOpt = parser.add_argument_group(messages(language, 4),
                                          messages(language, 5))
    engineOpt.add_argument("-L",
                           "--language",
                           action="store",
                           dest="language",
                           default=default_config["language"],
                           help=messages(language, 6).format(language_list))
    engineOpt.add_argument("-v",
                           "--verbose",
                           action="store",
                           dest="verbose_level",
                           default=default_config["verbose_level"],
                           help=messages(language, 59))
    engineOpt.add_argument("-V",
                           "--version",
                           action="store_true",
                           default=default_config["show_version"],
                           dest="show_version",
                           help=messages(language, 60))
    engineOpt.add_argument("-c",
                           "--update",
                           action="store_true",
                           default=default_config["check_update"],
                           dest="check_update",
                           help=messages(language, 61))
    engineOpt.add_argument("-o",
                           "--output",
                           action="store",
                           default=default_config["log_in_file"],
                           dest="log_in_file",
                           help=messages(language, 11))
    engineOpt.add_argument("--graph",
                           action="store",
                           default=default_config["graph_flag"],
                           dest="graph_flag",
                           help=messages(language, 86).format(graph_names))
    engineOpt.add_argument("-h",
                           "--help",
                           action="store_true",
                           default=default_config["help_menu_flag"],
                           dest="help_menu_flag",
                           help=messages(language, 2))

    # Target Options
    target = parser.add_argument_group(messages(language, 12),
                                       messages(language, 13))
    target.add_argument("-i",
                        "--targets",
                        action="store",
                        dest="targets",
                        default=default_config["targets"],
                        help=messages(language, 14))
    target.add_argument("-l",
                        "--targets-list",
                        action="store",
                        dest="targets_list",
                        default=default_config["targets_list"],
                        help=messages(language, 15))

    # Exclude Module Name
    exclude_names = module_names[:]
    exclude_names.remove('all')

    # Methods Options
    method = parser.add_argument_group("Method", messages(language, 16))
    method.add_argument("-m",
                        "--method",
                        action="store",
                        dest="scan_method",
                        default=default_config["scan_method"],
                        help=messages(language, 17).format(module_names))
    method.add_argument("-x",
                        "--exclude",
                        action="store",
                        dest="exclude_method",
                        default=default_config["exclude_method"],
                        help=messages(language, 18).format(exclude_names))
    method.add_argument("-u",
                        "--usernames",
                        action="store",
                        dest="users",
                        default=default_config["users"],
                        help=messages(language, 19))
    method.add_argument("-U",
                        "--users-list",
                        action="store",
                        dest="users_list",
                        default=default_config["users_list"],
                        help=messages(language, 20))
    method.add_argument("-p",
                        "--passwords",
                        action="store",
                        dest="passwds",
                        default=default_config["passwds"],
                        help=messages(language, 21))
    method.add_argument("-P",
                        "--passwords-list",
                        action="store",
                        dest="passwds_list",
                        default=default_config["passwds_list"],
                        help=messages(language, 22))
    method.add_argument("-g",
                        "--ports",
                        action="store",
                        dest="ports",
                        default=default_config["ports"],
                        help=messages(language, 23))
    method.add_argument("-T",
                        "--timeout",
                        action="store",
                        dest="timeout_sec",
                        default=default_config["timeout_sec"],
                        type=float,
                        help=messages(language, 24))
    method.add_argument("-w",
                        "--time-sleep",
                        action="store",
                        dest="time_sleep",
                        default=default_config["time_sleep"],
                        type=float,
                        help=messages(language, 25))
    method.add_argument("-r",
                        "--range",
                        action="store_true",
                        default=default_config["check_ranges"],
                        dest="check_ranges",
                        help=messages(language, 7))
    method.add_argument("-s",
                        "--sub-domains",
                        action="store_true",
                        default=default_config["check_subdomains"],
                        dest="check_subdomains",
                        help=messages(language, 8))
    method.add_argument("-t",
                        "--thread-connection",
                        action="store",
                        default=default_config["thread_number"],
                        type=int,
                        dest="thread_number",
                        help=messages(language, 9))
    method.add_argument("-M",
                        "--thread-hostscan",
                        action="store",
                        default=default_config["thread_number_host"],
                        type=int,
                        dest="thread_number_host",
                        help=messages(language, 10))
    method.add_argument("-R",
                        "--socks-proxy",
                        action="store",
                        dest="proxies",
                        default=default_config["socks_proxy"],
                        help=messages(language, 62))
    method.add_argument("--retries",
                        action="store",
                        dest="retries",
                        type=int,
                        default=default_config["retries"],
                        help=messages(language, 64))
    method.add_argument('--ping-before-scan',
                        action="store_true",
                        dest='ping_flag',
                        default=default_config["ping_flag"],
                        help=messages(language, 99))
    method.add_argument('--method-args',
                        action="store",
                        dest="methods_args",
                        default=default_config["methods_args"],
                        help=messages(language, 35))
    method.add_argument('--method-args-list',
                        action='store_true',
                        dest='method_args_list',
                        default=default_config["method_args_list"],
                        help=messages(language, 111))
    # Return Options
    return [
        parser,
        parser.parse_args(), default_config["startup_check_for_update"]
    ]
コード例 #17
0
def check_all_required(targets, targets_list, thread_number,
                       thread_number_host, log_in_file, scan_method,
                       exclude_method, users, users_list, passwds,
                       passwds_list, timeout_sec, ports, parser, module_names,
                       language, verbose_level, show_version, check_update,
                       proxies, retries):
    # Checking Requirements
    # Check the target(s)
    if targets is None and targets_list is None:
        parser.print_help()
        write("\n")
        sys.exit(error(messages(language, 26)))
    else:
        if targets is not None:
            targets = list(set(targets.rsplit(",")))
        elif targets_list is not None:
            try:
                targets = list(set(open(targets_list, "rb").read().rsplit()))
            except:
                sys.exit(error(messages(language, 27).format(targets_list)))
    # Check thread number
    if thread_number > 100 or thread_number_host > 100:
        warn(messages(language, 28))
    # Check timeout number
    if timeout_sec is not None and timeout_sec >= 15:
        warn(messages(language, 29).format(timeout_sec))
    # Check scanning method
    if scan_method is not None and scan_method == "all":
        scan_method = module_names
        scan_method.remove("all")
    elif scan_method is not None and scan_method not in module_names:
        if "," in scan_method:
            scan_method = scan_method.rsplit(",")
            for sm in scan_method:
                if sm not in module_names:
                    sys.exit(error(messages(language, 30).format(sm)))
                if sm == "all":
                    scan_method = module_names
                    scan_method.remove("all")
                    break
        else:
            sys.exit(error(messages(language, 31).format(scan_method)))
    elif scan_method is None:
        sys.exit(error(messages(language, 41)))
    else:
        scan_method = scan_method.rsplit()
    if exclude_method is not None:
        exclude_method = exclude_method.rsplit(",")
        for exm in exclude_method:
            if exm in scan_method:
                if "all" == exm:
                    sys.exit(messages(language, 32))
                else:
                    scan_method.remove(exm)
                    if len(scan_method) is 0:
                        sys.exit(messages(language, 33))
            else:
                sys.exit(messages(language, 34).format(exm))
    # Check port(s)
    if ports is None:
        sys.exit(error(messages(language, 35)))
    if type(ports) is not list and "-" in ports:
        ports = ports.rsplit("-")
        ports = range(int(ports[0]), int(ports[1]) + 1)
    elif type(ports) is not list:
        ports = ports.rsplit(",")
    # Check user list
    if users is None and users_list is None and scan_method is not None:
        for imethod in scan_method:
            if "_brute" in imethod:
                sys.exit(error(messages(language, 36)))
    else:
        if users is not None:
            users = list(set(users.rsplit(",")))
        if users_list is not None:
            try:
                users = list(set(
                    open(users_list).read().rsplit("\n")))  # fix later
            except:
                sys.exit(error(messages(language, 37).format(targets_list)))
    # Check password list
    if passwds is None and passwds_list is None and scan_method is not None:
        for imethod in scan_method:
            if "_brute" in imethod:
                sys.exit(error(messages(language, 38)))
    else:
        if passwds is not None:
            passwds = list(set(passwds.rsplit(",")))
        if passwds_list is not None:
            try:
                passwds = list(set(
                    open(passwds_list).read().rsplit("\n")))  # fix later
            except:
                sys.exit(error(messages(language, 39).format(targets_list)))
    # Check output file
    try:
        tmpfile = open(log_in_file, "a")
    except:
        sys.exit(error(messages(language, 40).format(log_in_file)))

    # Return the values
    return [
        targets, targets_list, thread_number, thread_number_host, log_in_file,
        scan_method, exclude_method, users, users_list, passwds, passwds_list,
        timeout_sec, ports, parser, module_names, language, verbose_level,
        show_version, check_update, proxies, retries
    ]