Skip to content

integration of attackmate in external projects#144

Merged
whotwagner merged 24 commits intoait-testbed:developmentfrom
thorinaboenke:112_return_result_in_run_method
Feb 7, 2025
Merged

integration of attackmate in external projects#144
whotwagner merged 24 commits intoait-testbed:developmentfrom
thorinaboenke:112_return_result_in_run_method

Conversation

@thorinaboenke
Copy link
Contributor

@thorinaboenke thorinaboenke commented Dec 11, 2024

This PR relates to issue #112

  • ensure all commands return a Result object
  • overload __repr__() method of Result object for string representation
  • add Command class whose create() method returns a command class instance depending on the argument type
  • add run_command() method to AttackMate to run single command from within an external project

config and varstore can be passed as optional constructor arguments to AttackMate() in the external script, otherwise Varstore is empty and Config uses the defaults.

example integration in external script:

from attackmate.attackmate import AttackMate
from attackmate.command import Command
from attackmate.schemas.config import Config

def main():
    ### Optional:  define configs
    config = Config(
    sliver_config={"config_file": "path/to/config/file"},
    msf_config={"password": "your_password", "ssl": True, "port": 55553},
    cmd_config={"loop_sleep": 10}
    )
    
    ### varstore can be passed as a dictionary
    varstore = {"TEST": "test"}

    attackmate = AttackMate(config = config, varstore = varstore)

    command1 = Command.create(type="sleep", cmd="sleep", seconds = "1")
    command2 = Command.create(type="debug", cmd="$TEST", varstore = True)

    result1 = attackmate.run_command(command1)
    result2 = attackmate.run_command(command2)

    print(result1)
    print(result2)

if __name__ == "__main__":
    main()  

Console Output of the above script:
image

@thorinaboenke thorinaboenke marked this pull request as draft December 11, 2024 13:17
@thorinaboenke thorinaboenke changed the base branch from main to development December 11, 2024 13:18
@thorinaboenke
Copy link
Contributor Author

when Attackmate is instantiated in another project, i.e. attack_mate = Attackmate() one should not neccessarily have to bother with configs and be able to use the defaults if nothing is passed. Ok to use those defined in config.py?

@thorinaboenke
Copy link
Contributor Author

@whotwagner on the topic of variables. Should there be an equivalent to the vars section of the playbook that can be passed as a dict to the Attackmate instance?

@thorinaboenke thorinaboenke linked an issue Feb 5, 2025 that may be closed by this pull request
@thorinaboenke thorinaboenke self-assigned this Feb 5, 2025
@thorinaboenke thorinaboenke marked this pull request as ready for review February 5, 2025 13:49
@thorinaboenke thorinaboenke changed the title 112 return result in run method integration of attackmate in external projects Feb 5, 2025
@annaerdi
Copy link
Contributor

annaerdi commented Feb 7, 2025

Does it work with the loop executor too?

@whotwagner whotwagner merged commit 7659fbd into ait-testbed:development Feb 7, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return result in run method of executors

4 participants