Skip to content

Add --processes flag to scan active process commands#469

Merged
egibs merged 6 commits intochainguard-dev:mainfrom
egibs:scan-processes
Sep 25, 2024
Merged

Add --processes flag to scan active process commands#469
egibs merged 6 commits intochainguard-dev:mainfrom
egibs:scan-processes

Conversation

@egibs
Copy link
Member

@egibs egibs commented Sep 25, 2024

This PR adds the ability to scan the [unique] commands of running processes if the command is a valid, absolute path.

go-yara provides a ScanProc method; however, it was proving difficult to use (at least on MacOS where SIP may be a contributing factor), so this implementation focuses on the binaries of running processes which is actually easier to fit into our current scan pattern (loading file descriptors).

To support the scanning of several hundred process paths, I had to track down and address a bug with the scanPathFindings sync.Map. We were not removing keys as they were used so we'd endlessly iterate through them as the Map elements grew. This wasn't originally apparent because we would provide a single scan path (even if it was a directory).

Finally, I also fixed the brief terminal output and made it a bit easier to read when accounting for multiple lines:
CleanShot 2024-09-24 at 17 48 09@2x

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
@egibs egibs requested a review from tstromberg September 25, 2024 12:30
@egibs egibs changed the base branch from scan-processes to main September 25, 2024 12:39
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
@egibs egibs force-pushed the scan-processes branch 2 times, most recently from bc7fa9d to 709b6a9 Compare September 25, 2024 13:24
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
@egibs egibs force-pushed the scan-processes branch 3 times, most recently from fa9829a to ca38615 Compare September 25, 2024 15:14
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
@egibs egibs merged commit 473356a into chainguard-dev:main Sep 25, 2024
@egibs egibs deleted the scan-processes branch September 25, 2024 16:59
egibs added a commit to egibs/malcontent that referenced this pull request Sep 25, 2024
)

* Add --processes flag to scan active process commands

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>

* Fix Linux ps command

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>

* Avoid generating a report for malcontent when running a scan

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>

* Use gopsutil instead of parsing ps

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>

* Appease the linter

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>

* Re-add unique path functionality

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>

---------

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
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.

2 participants