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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Hidden LaunchAgent/Daemon Discovery #8053

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

calhall
Copy link

@calhall calhall commented Jun 6, 2023

Please see the original PR for historical comments. Opening a clean PR to move away from some chaotic branch conflicts.

Hidden LaunchAgent/Daemon Discovery

Background

As per this issue -> #7703 <- this PR introduces the capability for osquery to identify LaunchAgents/Daemons that are defined in hidden .plist files.

The TL;DR from the issue linked above is ->

Malware commonly persists on macOS devices using LaunchAgents/Daemons. It has been observed that certain malware samples have been utilising hidden plist files i.e. /Library/LaunchDaemons/.com.apple.WindowServer.plist. This PR aims to cover off this blind spot within the current launchd table.

Changes

One file has been altered within this PR:

  • osquery/filesystem/filesystem.cpp - adding a consistent approach to discovering files and directories. This allows us to identify hidden files; which in this case enables us to identify hidden launch items.

Impact

This PR prevents malicious LaunchAgents/Daemons from evading detection by using a hidden plist files. As shown in the screenshot below, we can now identify these hidden plists:


image

Updates

Since the opening of the original PR, @marcosd4h made some great changes to directory listing (馃憦) - which I was able to replicate for file discovery to allow us to identify hidden files. Specifically in this case to target macOS launch items.

cc. @Smjert, @directionless from the previous PR.

@calhall calhall requested review from a team as code owners June 6, 2023 22:36
return Status(1, "Target directory is invalid");
}

if (recursive) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know these libraries very well -- if there's a symlink loop here, what happens?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is I believe that risks already exists as a result of this PR... #7974 (comment)

I'm reusing the code that was introduced for directory listing to list files here. So I'm also uncertain as to whether there is a potential symlink loop... but if there is I believe it'll already exist 馃憖

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symlinks should not be a problem because recursion for those is by default disabled; it's documented here https://www.boost.org/doc/libs/1_77_0/libs/filesystem/doc/reference.html#Class-recursive_directory_iterator

[Note: By default, recursive_directory_iterator does not follow directory symlinks. To follow directory symlinks, specify directory_options::follow_directory_symlink in opts. 鈥攅nd note]

But I think the directory PR (and this PR) might still have issues with hardlinks, junctions and the directory PR it's incorrectly returning all symlinks as if they were directories.

I think it's important to test this situations on at least Linux and Windows.

@directionless directionless added this to the 5.10.0 milestone Jun 8, 2023
@mike-myers-tob mike-myers-tob added virtual tables macOS ready for review Pull requests that are ready to be reviewed by a maintainer and removed ready for review Pull requests that are ready to be reviewed by a maintainer labels Jun 20, 2023
@Smjert
Copy link
Member

Smjert commented Oct 3, 2023

Closing and reopening to kick the CI

@Smjert Smjert closed this Oct 3, 2023
@Smjert Smjert reopened this Oct 3, 2023
Copy link
Member

@Smjert Smjert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a comment about recursion, I think this needs further tests to verify its functionality (and also CI tests that can be run to verify the behavior).

Finally, the CI is currently failing because there's a test that it's "importing" via extern the removed alternative that was called here; since it's the last place where it was directly used (and it's not a public function) the linker is dropping it.

Long story short, all the references and implementation of listInAbsoluteDirectory should be removed.

@Smjert Smjert modified the milestones: 5.10.0, 5.11.0 Oct 6, 2023
@directionless directionless modified the milestones: 5.11.0, 5.12.0 Dec 27, 2023
@directionless directionless modified the milestones: 5.12.0, 5.13 Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants