Skip to content

Commit 14ed79a

Browse files
committed
Add volatile profiles
1 parent b4307da commit 14ed79a

File tree

2 files changed

+69
-14
lines changed

2 files changed

+69
-14
lines changed

acquire/acquire.py

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,21 @@ def acquire_target_targetd(target: Target, args: argparse.Namespace, output_ts:
18131813
return files
18141814

18151815

1816+
def _add_modules_for_profile(choice: str, operating_system: str, profile: dict, msg: str):
1817+
modules_selected = dict()
1818+
1819+
if choice and choice != "none":
1820+
profile_dict = profile[choice]
1821+
if operating_system not in profile_dict:
1822+
log.error(msg, operating_system, choice)
1823+
return {}
1824+
1825+
for mod in profile_dict[operating_system]:
1826+
modules_selected[mod.__modname__] = mod
1827+
1828+
return modules_selected
1829+
1830+
18161831
def acquire_target_regular(target: Target, args: argparse.Namespace, output_ts: Optional[str] = None) -> list[str]:
18171832
files = []
18181833
output_ts = output_ts or get_utc_now_str()
@@ -1880,13 +1895,18 @@ def acquire_target_regular(target: Target, args: argparse.Namespace, output_ts:
18801895
profile = "default"
18811896
log.info("")
18821897

1883-
if profile and profile != "none":
1884-
if target.os not in PROFILES[profile]:
1885-
log.error("No collection set for OS %s with profile %s", target.os, profile)
1886-
return files
1898+
profile_modules = _add_modules_for_profile(
1899+
profile, target.os, PROFILES, "No collection set for OS %s with profile %s"
1900+
)
1901+
volatile_modules = _add_modules_for_profile(
1902+
args.volatile, target.os, VOLATILE, "No collection set for OS %s with volatile profile %s"
1903+
)
18871904

1888-
for mod in PROFILES[profile][target.os]:
1889-
modules_selected[mod.__modname__] = mod
1905+
modules_selected.update(profile_modules)
1906+
modules_selected.update(volatile_modules)
1907+
1908+
if not (profile_modules or volatile_modules):
1909+
return files
18901910

18911911
log.info("Modules selected: %s", ", ".join(sorted(modules_selected)))
18921912

@@ -2144,8 +2164,35 @@ class OSXProfile:
21442164
}
21452165

21462166

2167+
class VolatileProfile:
2168+
DEFAULT = [
2169+
Netstat,
2170+
WinProcesses,
2171+
WinProcEnv,
2172+
WinArpCache,
2173+
WinRDPSessions,
2174+
WinDnsClientCache,
2175+
]
2176+
EXTENSIVE = [
2177+
Proc,
2178+
Sys,
2179+
]
2180+
2181+
2182+
VOLATILE = {
2183+
"default": {"windows": VolatileProfile.DEFAULT},
2184+
"extensive": {
2185+
"windows": VolatileProfile.DEFAULT,
2186+
"linux": VolatileProfile.EXTENSIVE,
2187+
"bsd": VolatileProfile.EXTENSIVE,
2188+
"esxi": VolatileProfile.EXTENSIVE,
2189+
},
2190+
"none": None,
2191+
}
2192+
2193+
21472194
def main() -> None:
2148-
parser = create_argument_parser(PROFILES, MODULES)
2195+
parser = create_argument_parser(PROFILES, VOLATILE, MODULES)
21492196
args = parse_acquire_args(parser, config=CONFIG)
21502197

21512198
try:

acquire/utils.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,33 @@ class StrEnum(str, Enum):
3636
"""Sortable and serializible string-based enum"""
3737

3838

39-
def create_argument_parser(profiles: dict, modules: dict) -> argparse.ArgumentParser:
39+
def _create_profile_information(profiles: dict):
4040
desc = ""
4141

4242
profile_names = (name for name in profiles.keys() if name != "none")
43-
4443
for name in profile_names:
44+
profile_dict = profiles[name]
4545
desc += f"{name} profile:\n"
46-
minindent = max([len(os_) for os_ in profiles[name].keys()])
46+
47+
minindent = max([len(os_) for os_ in profile_dict.keys()])
4748
descfmt = f" {{:{minindent}s}}: {{}}\n"
48-
for os_ in profiles[name].keys():
49-
indent = 4 + len(os_)
50-
modlist = textwrap.wrap(", ".join([mod.__modname__ for mod in profiles[name][os_]]), 50)
5149

50+
for os_, modlist in profile_dict.items():
51+
indent = 4 + len(os_)
52+
modlist = textwrap.wrap(", ".join([mod.__modname__ for mod in modlist]), 50)
5253
moddesc = modlist.pop(0)
5354
for ml in modlist:
5455
moddesc += "\n" + (" " * indent) + ml
55-
5656
desc += descfmt.format(os_, moddesc)
5757
desc += "\n"
5858

59+
return desc
60+
61+
62+
def create_argument_parser(profiles: dict, volatile: dict, modules: dict) -> argparse.ArgumentParser:
63+
desc = _create_profile_information(profiles)
64+
desc += _create_profile_information(volatile)
65+
5966
parser = argparse.ArgumentParser(
6067
prog="acquire",
6168
description=desc,
@@ -101,6 +108,7 @@ def create_argument_parser(profiles: dict, modules: dict) -> argparse.ArgumentPa
101108
parser.add_argument("-l", "--log", type=Path, help="log directory location")
102109
parser.add_argument("--no-log", action="store_true", help=argparse.SUPPRESS)
103110
parser.add_argument("-p", "--profile", choices=profiles.keys(), help="collection profile")
111+
parser.add_argument("--volatile", choices=volatile.keys(), help="volatile profile")
104112

105113
parser.add_argument("-f", "--file", action="append", help="acquire file")
106114
parser.add_argument("-d", "--directory", action="append", help="acquire directory recursively")

0 commit comments

Comments
 (0)