Exemple #1
0
def test_get_clear_cache():
    ArgHandler.parse_arguments(["-T", "127.0.0.1", "--clear-cache"])
    assert ArgHandler.get_clear_cache()
Exemple #2
0
def test_get_clear_cache_none():
    ArgHandler.parse_arguments(["-T", "127.0.0.1"])
    assert ArgHandler.get_clear_cache() is False
Exemple #3
0
def init():
    """
        Initialise all of the needed prerequisites for Lancer. This should:

        - Register the signal handler for Ctrl+C
        - Load the config file
        - Parse command line arguments
        - Show the header
        - Check that we're on a supported Python version
        - Show an option to update the VirtualTerminal registry key if on Win 10
        - Show a warning that localisation support is not yet implemented if there is a non-default -l parameter
        - Display a legal disclaimer about using Lancer for illegal use
        - Warn if the cache is over 500mb in size
        - Clear the cache if we want to
    """
    # Register the signal handler for a more graceful Ctrl+C
    signal.signal(signal.SIGINT, utils.signal_handler)

    # Load the config file
    config.load_config()

    # Parse the arguments
    ArgHandler.parse_arguments(sys.argv[1:])

    # Display the header
    utils.display_header()
    time.sleep(1.25)

    # Check we're on a supported Python version
    utils.python_version()

    # Update the Windows virtual terminal if necessary
    # If we're on Windows 10, import winutils
    if platform.system().lower() == "windows" and platform.release() == "10":
        from core.winutils import update_windows_virtual_terminal
        update_windows_virtual_terminal()

    # Language warning - not yet implemented
    if ArgHandler.get_language_code() != 'en':
        print(utils.error_message(), "Multi-language support is not yet implemented...")

    # Show a legal disclaimer
    disclaimer = utils.terminal_width_string(
        "Legal Disclaimer: Usage of Lancer for attacking targets without prior mutual"
        " authorisation is illegal. It is the end user's responsibility to adhere to all local"
        " and international laws. The developers of this tool assume no liability and are not"
        " responsible for any misuse or damage caused by the use of this program."
    )
    print(utils.error_message(), disclaimer)
    print()

    # Cache warning
    # If it is more than 1GB, we display an error-style warning
    root_directory = Path(config.get_cache_path())
    size = sum(f.stat().st_size for f in root_directory.glob('**/*') if f.is_file()) / 1048576  # Bytes -> MB
    if size >= 2048:
        print(utils.error_message(), "Cache is {SIZE}gb in size. It is recommended to clear it with --clear-cache."
              .format(SIZE="{:.1f}".format(size/1024)))
    # If it is more than 500, we display a warning
    elif size >= 512:
        print(utils.warning_message(), "Cache is {SIZE}mb in size. You can clear it with --clear-cache."
              .format(SIZE="{:.1f}".format(size)))

    # Clear the cache
    if ArgHandler.get_clear_cache():
        files = os.listdir(config.get_cache_path())
        for filename in files:
            file_path = os.path.join(config.get_cache_path(), filename)

            if os.path.isfile(file_path) or os.path.islink(file_path):
                os.unlink(file_path)
            elif os.path.isdir(file_path) and file_path != config.get_current_cache_path():
                shutil.rmtree(file_path)
        print(utils.normal_message(), "Removed {NUM} items from the cache".format(NUM=len(files)))

    # Check if we are admin, display a relevant message
    if utils.is_user_admin():
        print(utils.normal_message(), "Lancer running with elevated permissions")
    else:
        non_admin_warning = utils.terminal_width_string("Lancer doesn't appear to being run with elevated"
                                                        " permissions. Some functionality may not work"
                                                        " correctly")
        print(utils.warning_message(), non_admin_warning)

    # Display warning about your IP address
    ip_address = utils.terminal_width_string(
        "Your IP Address has been detected as {IP}. This can be changed with -a [IP]"
    )
    print(utils.normal_message(), ip_address.format(IP=get_ip()))
    print()

    # Preload all of the modules
    ModuleProvider.load()