Skip to content

[New Rule] PE via Container Misconfiguration #2983

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

Merged
merged 6 commits into from
Aug 4, 2023
Merged

Conversation

Aegrah
Copy link
Contributor

@Aegrah Aegrah commented Jul 31, 2023

Summary

This rule monitors for the execution of processes that interact with Linux containers through an interactive shell without root permissions. Utilities such as runc and ctr are universal command-line utilities leveraged to interact with containers via root permissions. On systems where the access to these utilities are misconfigured, attackers might be able to create and run a container that mounts the root folder or spawn a privileged container vulnerable to a container escape attack, which might allow them to escalate privileges and gain further access onto the host file system.

Detection

The Docker utility leverages runc and ctr under-the-hood as well, for log writing and other administrative tasks. In order to minimize FPs of runc and ctr spawns by Docker, the and process.interactive == "true" and process.parent.interactive == "true" filter has been added. When docker spawns these processes, they will run in a non-interactive state. This query has 0 hits in RedSector over the last 365 days, while the query without this filter has 8 hits.

process where host.os.type == "linux" and event.action == "exec" and event.type == "start" and (
  (process.name == "runc" and process.args : "run") or
  (process.name == "ctr" and process.args : "run" and process.args : ("--privileged", "--mount"))
) and not user.Ext.real.id : "0" and not group.Ext.real.id : "0" and 
process.interactive == true and process.parent.interactive == true
image

@Aegrah Aegrah added Rule: New Proposal for new rule Rule: Tuning tweaking or tuning an existing rule Domain: Endpoint backport: auto labels Jul 31, 2023
@Aegrah Aegrah self-assigned this Jul 31, 2023
@botelastic botelastic bot added the OS: Linux label Jul 31, 2023
process where host.os.type == "linux" and event.action == "exec" and event.type == "start" and (
(process.name == "runc" and process.args : "run") or
(process.name == "ctr" and process.args : "run" and process.args : ("--privileged", "--mount"))
) and not user.Ext.real.id : "0" and not group.Ext.real.id : "0" and
Copy link
Contributor

Choose a reason for hiding this comment

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

in this case, wouldn't we want to check that user.effective.id != "0" and user.effective.group.id != "0", otherwise sudo perms will FP?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brokensound77 The only pitfall of using user.effective.id here, is that this field is only ingested in Linux through auditbeat, and mostly present in non-interactive process events. I just checked, and in the events from this DR this field does not exist.

This one would work with user.id, process.user.id, process.real_user.id, user.Ext.real.id, user.effective.id, as long as the field would be present. I picked user.Ext.real.id because this field always exists, and to make sure that when a normal user runs sudo, it doesn't FP, because then user.Ext.real.id will never be 0.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you are right about the field availability, good call.

(process.name == "runc" and process.args : "run") or
(process.name == "ctr" and process.args : "run" and process.args : ("--privileged", "--mount"))
) and not user.Ext.real.id : "0" and not group.Ext.real.id : "0" and
process.interactive == true and process.parent.interactive == true
Copy link
Contributor

Choose a reason for hiding this comment

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

are these fields dependent on session data? If so, we may want to add it in setup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, totally forgot about that. Added a small setup guide to the rule!

@Aegrah Aegrah requested a review from brokensound77 August 3, 2023 08:46
Copy link
Contributor

@DefSecSentinel DefSecSentinel left a comment

Choose a reason for hiding this comment

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

LGTM

@Aegrah Aegrah requested a review from brokensound77 August 3, 2023 21:12
@Aegrah Aegrah merged commit e904ebb into main Aug 4, 2023
@Aegrah Aegrah deleted the new-rule-docker-privesc branch August 4, 2023 14:39
protectionsmachine pushed a commit that referenced this pull request Aug 4, 2023
* [New Rule] PE via Container Misconfiguration

* fixed boolean comparison unit test error

* Update privilege_escalation_container_util_misconfiguration.toml

* Update rules/linux/privilege_escalation_container_util_misconfiguration.toml

Co-authored-by: Justin Ibarra <[email protected]>

---------

Co-authored-by: Colson Wilhoit <[email protected]>
Co-authored-by: Justin Ibarra <[email protected]>

(cherry picked from commit e904ebb)
protectionsmachine pushed a commit that referenced this pull request Aug 4, 2023
* [New Rule] PE via Container Misconfiguration

* fixed boolean comparison unit test error

* Update privilege_escalation_container_util_misconfiguration.toml

* Update rules/linux/privilege_escalation_container_util_misconfiguration.toml

Co-authored-by: Justin Ibarra <[email protected]>

---------

Co-authored-by: Colson Wilhoit <[email protected]>
Co-authored-by: Justin Ibarra <[email protected]>

(cherry picked from commit e904ebb)
protectionsmachine pushed a commit that referenced this pull request Aug 4, 2023
* [New Rule] PE via Container Misconfiguration

* fixed boolean comparison unit test error

* Update privilege_escalation_container_util_misconfiguration.toml

* Update rules/linux/privilege_escalation_container_util_misconfiguration.toml

Co-authored-by: Justin Ibarra <[email protected]>

---------

Co-authored-by: Colson Wilhoit <[email protected]>
Co-authored-by: Justin Ibarra <[email protected]>

(cherry picked from commit e904ebb)
protectionsmachine pushed a commit that referenced this pull request Aug 4, 2023
* [New Rule] PE via Container Misconfiguration

* fixed boolean comparison unit test error

* Update privilege_escalation_container_util_misconfiguration.toml

* Update rules/linux/privilege_escalation_container_util_misconfiguration.toml

Co-authored-by: Justin Ibarra <[email protected]>

---------

Co-authored-by: Colson Wilhoit <[email protected]>
Co-authored-by: Justin Ibarra <[email protected]>

(cherry picked from commit e904ebb)
protectionsmachine pushed a commit that referenced this pull request Aug 4, 2023
* [New Rule] PE via Container Misconfiguration

* fixed boolean comparison unit test error

* Update privilege_escalation_container_util_misconfiguration.toml

* Update rules/linux/privilege_escalation_container_util_misconfiguration.toml

Co-authored-by: Justin Ibarra <[email protected]>

---------

Co-authored-by: Colson Wilhoit <[email protected]>
Co-authored-by: Justin Ibarra <[email protected]>

(cherry picked from commit e904ebb)
protectionsmachine pushed a commit that referenced this pull request Aug 4, 2023
* [New Rule] PE via Container Misconfiguration

* fixed boolean comparison unit test error

* Update privilege_escalation_container_util_misconfiguration.toml

* Update rules/linux/privilege_escalation_container_util_misconfiguration.toml

Co-authored-by: Justin Ibarra <[email protected]>

---------

Co-authored-by: Colson Wilhoit <[email protected]>
Co-authored-by: Justin Ibarra <[email protected]>

(cherry picked from commit e904ebb)
protectionsmachine pushed a commit that referenced this pull request Aug 4, 2023
* [New Rule] PE via Container Misconfiguration

* fixed boolean comparison unit test error

* Update privilege_escalation_container_util_misconfiguration.toml

* Update rules/linux/privilege_escalation_container_util_misconfiguration.toml

Co-authored-by: Justin Ibarra <[email protected]>

---------

Co-authored-by: Colson Wilhoit <[email protected]>
Co-authored-by: Justin Ibarra <[email protected]>

(cherry picked from commit e904ebb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport: auto Domain: Endpoint OS: Linux Rule: New Proposal for new rule Rule: Tuning tweaking or tuning an existing rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants