Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SSH module #77

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions acquire/acquire.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,7 @@
@register_module("--home")
class Home(Module):
SPEC = [
# TODO: Use from_user_home if supported for osx
("glob", "/root/.*[akz]sh*"),
("dir", "/root/.config"),
("glob", "/home/*/.*[akz]sh*"),
Expand All @@ -1338,6 +1339,7 @@
("glob", "/home/*/*/.config"),
# OS-X home (aka /Users)
("glob", "/Users/*/.*[akz]sh*"),
("glob", "/Users/*/.config"),
("glob", "/Users/*/.bash_sessions/*"),
("glob", "/Users/*/Library/LaunchAgents/*"),
("glob", "/Users/*/Library/Logs/*"),
Expand All @@ -1346,6 +1348,36 @@
]


@register_module("--ssh")
class SSH(Module):
@classmethod
def _run(cls, target: Target, collector):
user_pattern = ".ssh/*"

Check warning on line 1355 in acquire/acquire.py

View check run for this annotation

Codecov / codecov/patch

acquire/acquire.py#L1355

Added line #L1355 was not covered by tests

# Gather user paths
# TODO: Use from_user_home if supported for osx
if target._os.os == "osx":
iterator = [f"/Users/*/{user_pattern}"]

Check warning on line 1360 in acquire/acquire.py

View check run for this annotation

Codecov / codecov/patch

acquire/acquire.py#L1359-L1360

Added lines #L1359 - L1360 were not covered by tests
else:
iterator = list(from_user_home(target, user_pattern))

Check warning on line 1362 in acquire/acquire.py

View check run for this annotation

Codecov / codecov/patch

acquire/acquire.py#L1362

Added line #L1362 was not covered by tests

# Acquire SSH configuration in sshd directories
iterator += ["/etc/ssh/*", "sysvol/ProgramData/ssh/*"]

Check warning on line 1365 in acquire/acquire.py

View check run for this annotation

Codecov / codecov/patch

acquire/acquire.py#L1365

Added line #L1365 was not covered by tests

globbed_path = (path for pattern in iterator for path in target.fs.glob(pattern))
for path in globbed_path:
if target.fs.path(path).is_dir():
collector.collect_dir(path)
continue

Check warning on line 1371 in acquire/acquire.py

View check run for this annotation

Codecov / codecov/patch

acquire/acquire.py#L1367-L1371

Added lines #L1367 - L1371 were not covered by tests

with target.fs.path(path).open("rt") as file:
if "PRIVATE KEY" in file.readline():

Check warning on line 1374 in acquire/acquire.py

View check run for this annotation

Codecov / codecov/patch

acquire/acquire.py#L1373-L1374

Added lines #L1373 - L1374 were not covered by tests
# Detected a private key, skipping.
continue

Check warning on line 1376 in acquire/acquire.py

View check run for this annotation

Codecov / codecov/patch

acquire/acquire.py#L1376

Added line #L1376 was not covered by tests

collector.collect_file(path, outpath=path)

Check warning on line 1378 in acquire/acquire.py

View check run for this annotation

Codecov / codecov/patch

acquire/acquire.py#L1378

Added line #L1378 was not covered by tests


@register_module("--var")
class Var(Module):
SPEC = [
Expand Down Expand Up @@ -1919,17 +1951,20 @@
QuarantinedFiles,
RemoteAccess,
WindowsNotifications,
SSH,
],
"linux": [
Etc,
Boot,
Home,
History,
SSH,
Var,
],
"bsd": [
Etc,
Boot,
SSH,
Home,
Var,
BSD,
Expand All @@ -1938,13 +1973,15 @@
Bootbanks,
ESXi,
VMFS,
SSH,
],
"osx": [
Etc,
Home,
Var,
OSX,
History,
SSH,
],
},
"default": {
Expand Down Expand Up @@ -1975,19 +2012,22 @@
Etc,
Boot,
Home,
SSH,
Var,
],
"bsd": [
Etc,
Boot,
Home,
SSH,
Var,
BSD,
],
"esxi": [
Bootbanks,
ESXi,
VMFS,
SSH,
],
"osx": [
Etc,
Expand All @@ -2012,18 +2052,21 @@
Etc,
Boot,
Home,
SSH,
Var,
],
"bsd": [
Etc,
Boot,
Home,
SSH,
Var,
BSD,
],
"esxi": [
Bootbanks,
ESXi,
SSH,
],
"osx": [
Etc,
Expand Down