Beispiel #1
0
 def take_action(self, parsed_args):
     if (parsed_args.transport_key):
         system_id = get_user_id('system')
         api_key = create_api_key(user_id=system_id,
                                  owner_id=system_id,
                                  type="Transport")
         print_output(
             "Transport API Key Created.\n\nKey Name: {0}\nSecret: {1}".
             format(api_key["Name"], api_key["Token"]))
Beispiel #2
0
    def take_action(self, parsed_args):
        print_output("Setup started..")
        generate_config_file(
            admin_username=parsed_args.admin_username,
            admin_password=parsed_args.admin_password,
            api_upload_dir=parsed_args.api_upload_dir,
            build=parsed_args.build,
            console_port=parsed_args.console_port,
            containers=parsed_args.container_names,
            docker_network_name=parsed_args.docker_network_name,
            external_address=parsed_args.external_address,
            faction_path=parsed_args.faction_path,
            flask_secret=parsed_args.flask_secret,
            postgres_host=parsed_args.postgres_host,
            postgres_database=parsed_args.postgres_database,
            postgres_username=parsed_args.postgres_username,
            postgres_password=parsed_args.postgres_password,
            rabbit_host=parsed_args.rabbit_host,
            rabbit_username=parsed_args.rabbit_username,
            rabbit_password=parsed_args.rabbit_password,
            system_username=parsed_args.system_username,
            system_password=parsed_args.system_password)

        if parsed_args.external_address:
            if not parsed_args.external_address.startswtih(
                    'http://') or not parsed_args.external_address.startswtih(
                        'https://'):
                error_out(
                    'Setup failed. --external-address argument must begin with http:// or https://'
                )

        if parsed_args.build:
            for component in parsed_args.components:
                download_github_repo(
                    "FactionC2/{0}".format(component),
                    "{0}/source/{1}".format(parsed_args.faction_path,
                                            component), parsed_args.github_pat)
            write_build_compose_file()
        elif parsed_args.dev:
            write_dev_compose_file()
        else:
            write_hub_compose_file()

        clone_github_repo(
            "FactionC2/Modules-Dotnet",
            "{0}/modules/dotnet".format(parsed_args.faction_path))
        clone_github_repo(
            "maraudershell/Marauder",
            "{0}/agents/Marauder".format(parsed_args.faction_path))

        build_faction()

        if parsed_args.dev:
            print_output("Pausing setup, you need to do stuff.")
            print("Add the following to your hosts file: ")
            print("127.0.0.1 api")
            print("127.0.0.1 db")
            print("127.0.0.1 mq\n")
            print(
                "Run the following commands from the Faction Core directory: ")
            print(
                "1.  dotnet ef migration add 'Initial' (You only have to do this once, unless you change the db schema)"
            )
            print("2.  dotnet ef database update\n")
            input("Press enter to continue setup..")
        else:
            print_output("Waiting 30 seconds for Core to come up..")
            core_down = True
            sleep(30)
            while core_down:
                status = get_container_status('faction_core_1')
                self.log.debug("Got status: {0}".format(status))
                if status:
                    if status.status.lower() == 'running':
                        print_output("Core is up, continuing..")
                        core_down = False
                else:
                    print_output(
                        "Core is not up yet. Waiting 15 more seconds..")
                    sleep(15)

            create_database_migration("Initial")
            update_database()

        create_faction_roles()
        create_system_user()
        create_admin_user()

        system_id = get_user_id('system')
        api_key = create_api_key(user_id=system_id,
                                 owner_id=system_id,
                                 type="Transport")
        create_direct_transport(api_key=api_key)

        if parsed_args.dev == None or parsed_args.dev == False:
            print_output("Restarting Core for database changes..")
            core = get_container("faction_core_1")
            restart_container(core)
        config = get_config()
        print_output(
            "Setup complete! Get to hacking!!\n\nURL: {0}\nUsername: {1}\nPassword: {2}"
            .format(config["EXTERNAL_ADDRESS"], config["ADMIN_USERNAME"],
                    config["ADMIN_PASSWORD"]))