diff --git a/acquire/acquire.py b/acquire/acquire.py index 0be80276..af7ac9ae 100644 --- a/acquire/acquire.py +++ b/acquire/acquire.py @@ -2166,21 +2166,6 @@ def main() -> None: except ValueError as err: parser.exit(err) - if args.targetd: - from targetd.tools.targetd import start_client - - # Configure your targetd agent here - config = { - "function": "agent", - "topics": ["/host/a", "/host/*"], - "link": "pipe-server://tmp/b", - "address": "10.0.2.3", - "port": 1884, - "cacert": Path("targetd.crt"), - } - start_client(args, presets=config) - parser.exit("Done") - if args.log_to_dir: # When args.upload files are specified, only these files are uploaded # and no other action is done. Thus a log file specifically named @@ -2207,6 +2192,25 @@ def main() -> None: log.exception(err) parser.exit(1) + if args.targetd: + from targetd.tools.targetd import start_client + + # set @auto hostname to real hostname + if args.targetd_hostname == "@auto": + args.targetd_hostname = f"/host/{Target.open('local').hostname}" + + config = { + "function": args.targetd_func, + "topics": [args.targetd_hostname, args.targetd_groupname, args.targetd_globalname], + "link": args.targetd_link, + "address": args.targetd_ip, + "port": args.targetd_port, + "cacert_str": args.targetd_cacert, + "cacert": None, + } + start_client(args, presets=config) + return + if args.upload: try: upload_files(args.upload, args.upload_plugin, args.no_proxy) diff --git a/acquire/utils.py b/acquire/utils.py index f7384191..69b15699 100644 --- a/acquire/utils.py +++ b/acquire/utils.py @@ -17,6 +17,20 @@ from acquire.outputs import OUTPUTS from acquire.uploaders.plugin_registry import UploaderRegistry +# Acquire Configuration for CAgent and TargetD +CAGENT_TARGETD_ATTRS = { + "cagent_key", + "cagent_certificate", + "targetd_func", + "targetd_cacert", + "targetd_ip", + "targetd_port", + "targetd_hostname", + "targetd_groupname", + "targetd_globalname", + "targetd_link", +} + class StrEnum(str, Enum): """Sortable and serializible string-based enum""" @@ -288,9 +302,9 @@ def check_and_set_acquire_args( raise ValueError("No public key available (embedded or argument)") setattr(args, "public_key", public_key) - # set cagent related configuration - setattr(args, "cagent_key", args.config.get("cagent_key")) - setattr(args, "cagent_certificate", args.config.get("cagent_certificate")) + # set cagent/targetd related configuration + for attr in CAGENT_TARGETD_ATTRS: + setattr(args, attr, args.config.get(attr)) if not args.children and args.skip_parent: raise ValueError("--skip-parent can only be set with --children")