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 rule for checking for presence of known GTFOBins on filesystems #315

Closed
wants to merge 4 commits into from
Closed

Add rule for checking for presence of known GTFOBins on filesystems #315

wants to merge 4 commits into from

Conversation

0xquark
Copy link

@0xquark 0xquark commented Feb 25, 2023

Fixes #310

Summary

The rule checks for the presence of known GTFOBins binaries on the file system. It uses a set of file paths for the binaries and checks if any of those paths match the file path of any file on the system. If a match is found, a violation is generated.

Test Cases

image

Comments

There are standard Unix binaries that are commonly installed on many systems, and they can be used for legitimate purposes as well so i wasn't sure if to include them or not. Please let me know what all gtfobins files would be a good standard for this rule. I've added the most common ones.

Signed-off-by: Karanjot Singh <drquark@duck.com>
Signed-off-by: Karanjot Singh <drquark@duck.com>
@0xquark
Copy link
Author

0xquark commented Feb 25, 2023

@alegrey91 Could you review this PR ?

@alegrey91 alegrey91 closed this Feb 25, 2023
@0xquark
Copy link
Author

0xquark commented Feb 25, 2023

@alegrey91 I think you closed this instead of merging?

@alegrey91
Copy link
Contributor

alegrey91 commented Feb 25, 2023

Hello @0xquark, and thanks a lot for your contribution! We really appreciate your effort :)
I'll try to review your PR asap!

@alegrey91 alegrey91 reopened this Feb 25, 2023
@alegrey91
Copy link
Contributor

@alegrey91 I think you closed this instead of merging?

Yes, sorry 😅

@alegrey91 alegrey91 self-requested a review February 25, 2023 11:56
Copy link
Contributor

@alegrey91 alegrey91 left a comment

Choose a reason for hiding this comment

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

Hi @0xquark and still thanks for your contribution!
I just checked the code that you submitted.
It looks good, but I realized that we don't have as much information available in order to have a deep overview about the GTFOBins present.
What I mean is that we should be able to extract for each container the whole list of binaries inside them and use this list to effectively check their presence.
In your implementation (the only possible at the moment), we can only have a limited knowledge about them, since we don't have enough data.
I'm going to schedule an internal call with the team in order to take a decision on how to provide these data and allow you to implement a better and more complete rule.
I'll keep you updated :)
If you have any doubt feel free to ask. I'll try to make you understand better the point.

@slashben
Copy link
Contributor

@0xquark , sorry for my confusion. Is this rule connected to a control?

Signed-off-by: Karanjot Singh <drquark@duck.com>
@slashben
Copy link
Contributor

Hi @0xquark and still thanks for your contribution! I just checked the code that you submitted. It looks good, but I realized that we don't have as much information available in order to have a deep overview about the GTFOBins present. What I mean is that we should be able to extract for each container the whole list of binaries inside them and use this list to effectively check their presence. In your implementation (the only possible at the moment), we can only have a limited knowledge about them, since we don't have enough data. I'm going to schedule an internal call with the team in order to take a decision on how to provide these data and allow you to implement a better and more complete rule. I'll keep you updated :) If you have any doubt feel free to ask. I'll try to make you understand better the point.

Adding to this, I think that we will have access to image SBOMs within a few weeks. This means we can look for packages containing these binaries in Kubescape API SBOM objects

@0xquark
Copy link
Author

0xquark commented Feb 27, 2023

Thanks for the review @alegrey91 and @slashben. I first thought of implementing it by iterating over all the present binaries in a container but i was not able to find a way to do that ( Is it possible if i use find on / and check perms to get the executables find / -type f -executable ). Kubescape API SBOM objects could be really helpful, will implement in the coming weeks then.
Would it be a good idea to have a similar rule that checks for the gtfobins binaries in the container commands?
I've modified the rule to iterate over each pod object in the input, then checks each container in the pod for the presence of GTFOBins binaries. It does this by defining a set of GTFOBin binaries, then checking if any of these binaries are present in the container's command field.
It could be possible that the user may be using some binaries in the command that has bigger risks while running the container, there may be an alternative present to that binary.

@0xquark
Copy link
Author

0xquark commented Feb 27, 2023

@0xquark , sorry for my confusion. Is this rule connected to a control?
Is it possible to make a control for this rule?

…tainer

Signed-off-by: Karanjot Singh <drquark@duck.com>
@0xquark
Copy link
Author

0xquark commented Feb 27, 2023

My Implementation of above rule using find : https://pastebin.com/1ef61nTP

@0xquark 0xquark closed this by deleting the head repository Mar 7, 2023
@0xquark 0xquark reopened this Mar 7, 2023
@yuleib
Copy link
Collaborator

yuleib commented Apr 3, 2023

@alegrey91 , @0xquark - hey guys, what is the status with this PR ?

@yuleib yuleib closed this Oct 2, 2023
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.

Add rego rule to check for GTFOBins files on the filesystem
4 participants