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

Added rule to detect LKM module injects using insmod used by rootkits for kernel hooking #1401

Closed
wants to merge 18 commits into from
Closed

Conversation

josehelps
Copy link
Contributor

@josehelps josehelps commented Sep 14, 2020

What type of PR is this?

/kind rule-create

Any specific area of the project related to this PR?

/area rules

What this PR does / why we need it:

This PR adds a new falco rule that looks for when insmod is called as part of a execve event. Injecting LKM modules on (post build) running production instances should be rare and is a common way for rootkits that employ kernel hooking to obfuscate themselves.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

This is a rehashed of PR#1389 just cleaned up DCO

Does this PR introduce a user-facing change?:

Yes new rule in falco_rules.yml

rule(Linux Kernel Module injection detected): adds a new rule that detects when a LKM module is inject using insmod typically used by rookits looking to obfuscate their behavior via kernel hooking. 

@josehelps
Copy link
Contributor Author

/assign @Kaizhe

@leogr
Copy link
Member

leogr commented Sep 15, 2020

Thanks @d1vious !

PS: I have just edited the PR description to fix the release note block syntax.

@josehelps
Copy link
Contributor Author

Thank you 😊

@krisnova krisnova added this to the 0.27.0 milestone Sep 24, 2020
Copy link
Member

@leodido leodido left a comment

Choose a reason for hiding this comment

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

Thanks @d1vious!

Waiting for @Kaizhe review but just a comment: shouldn't this new macro exclude the Falco kernel module ?

@josehelps
Copy link
Contributor Author

@leodido we can add exclusion for a bunch of commonly used modules, if you like we can collage a list and tack it to the end of the query. Otherwise I suspect a customer would have to do some tuning.

Copy link
Member

@leogr leogr left a comment

Choose a reason for hiding this comment

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

Thank you for this PR 👍

The rule seems good to me, but I believe it worth adding an exclusion list for known modules.
IMHO, the list should at least include the Falco kernel module, then users can extend it.

@@ -3010,6 +3010,12 @@
output: Drift detected (open+create), new executable created in a container (user=%user.name user_loginuid=%user.loginuid command=%proc.cmdline filename=%evt.arg.filename name=%evt.arg.name mode=%evt.arg.mode event=%evt.type)
priority: ERROR

# find when a new kernel module is injected
- rule: Linux Kernel Module injection detected
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please capitalized the beginning letter of every word?

@@ -3010,6 +3010,12 @@
output: Drift detected (open+create), new executable created in a container (user=%user.name user_loginuid=%user.loginuid command=%proc.cmdline filename=%evt.arg.filename name=%evt.arg.name mode=%evt.arg.mode event=%evt.type)
priority: ERROR

# find when a new kernel module is injected
- rule: Linux Kernel Module injection detected
desc: It is very uncommon for kernel modules to be injected in running production instances, used rookits to obfuscate their behavior via kernel hooking
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you rephrase a little bit of the description to something as simple as

Detect kernel module was injected (from container).

# find when a new kernel module is injected
- rule: Linux Kernel Module injection detected
desc: It is very uncommon for kernel modules to be injected in running production instances, used rookits to obfuscate their behavior via kernel hooking
condition: evt.type=execve and proc.name=insmod
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest to limit to activities happen from inside a container. So the condition would be something like:
spawned_process and container and proc.name=insmod

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed with @leogr , need to have a whitelisted images/containers that perform kernel module injection like falco.

desc: It is very uncommon for kernel modules to be injected in running production instances, used rookits to obfuscate their behavior via kernel hooking
condition: evt.type=execve and proc.name=insmod
output: Linux Kernel Module injection using insmod detected (user=%user.name user_loginuid=%user.loginuid parent_process=%proc.pname module=%proc.args)
priority: WARNING
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add tags fields with process

@leogr
Copy link
Member

leogr commented Oct 16, 2020

Hey @d1vious

Could you also rebase this PR, please?

leogr and others added 9 commits October 26, 2020 11:21
On previously modified files.

Signed-off-by: Leonardo Grasso <[email protected]>
Reviewed-by: Spencer Krum <[email protected]>
Reviewed-by: Leonardo Grasso <[email protected]>
Reviewed-by: Leonardo Di Donato <[email protected]>
Signed-off-by: Lorenzo Fontana <[email protected]>
Previously, formatters were freed by LUA code when re-opening outputs.
Since now, outputs are not controlling anymore the falco_formats class (see #1412), we just free formatters only if were already initialized.

That is needed when the engine restarts (see #1446).

By doing so, we also ensure that correct inspector instance is set to the formatter cache.

Signed-off-by: Leonardo Grasso <[email protected]>
leogr and others added 6 commits October 27, 2020 15:12
Co-Authored-By: Leonardo Di Donato <[email protected]>
Signed-off-by: Leonardo Grasso <[email protected]>
Use the right list name in the rule Full K8s Administrative Access--it
was using the nonexistent list admin_k8s_users, so it was just using the
string "admin_k8s_users".

Signed-off-by: Mark Stemm <[email protected]>
…cts storage proposals

Co-authored-by: Lorenzo Fontana <[email protected]>
Signed-off-by: Leonardo Di Donato <[email protected]>
Co-authored-by: Lorenzo Fontana <[email protected]>
Signed-off-by: Leonardo Di Donato <[email protected]>
@poiana
Copy link
Contributor

poiana commented Nov 3, 2020

@d1vious: Adding label do-not-merge/contains-merge-commits because PR contains merge commits, which are not allowed in this repository.
Use git rebase to reapply your commits on top of the target branch. Detailed instructions for doing so can be found here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@poiana
Copy link
Contributor

poiana commented Nov 3, 2020

Thanks for your pull request. Before we can look at it, you'll need to add a 'DCO signoff' to your commits.

📝 Please follow instructions in the contributing guide to update your commits with the DCO

Full details of the Developer Certificate of Origin can be found at developercertificate.org.

The list of commits missing DCO signoff:

  • b963dda fixed merge conflix
  • b3630ce Merge branch 'add_lkm_inject_rule' of github.com:d1vious/falco into add_lkm_inject_rule

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@poiana
Copy link
Contributor

poiana commented Nov 3, 2020

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign fntlnz
You can assign the PR to them by writing /assign @fntlnz in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana added size/L and removed size/S labels Nov 3, 2020
@josehelps
Copy link
Contributor Author

josehelps commented Nov 3, 2020

@leogr rebased as requested. Also added the changes you asked for @Kaizhe. Let me know what else I can help with 👍

@leogr
Copy link
Member

leogr commented Nov 3, 2020

@leogr rebased as requested. Also added the changes you asked for @Kaizhe. Let me know what else I can help with

Hey @d1vious

Thank you, but unfortunately, I see some issues now. There're merge commits in this PR and commits missing the sign-off that are both not allowed in this repo (please check out the comments from our bot). Moreover, integration tests are failing. :(

Thus, I'd suggest reverting the merge then use git rebase -i master please. If you need any help, feel free to contact me via DM on Slack.

@josehelps
Copy link
Contributor Author

@leogr This literally has been more work than is worth IMHO, if you want to rebase and include the changes feel free. I was hoping to contribute back to the project this detection which I found useful in my production environment at Splunk, but contributing here has been extremely cumbersome due to all the steps/hoops required and will likely not contribute again unfortunately. My advice is make this process easier for contributors if you really want the community to be part of the project. Feel free to close the PR if you did not find it useful, otherwise enjoy the free detection 😄


- rule: Linux Kernel Module Injection Detected
desc: Detect kernel module was injected (from container).
condition: spawned_process and container and evt.type=execve and proc.name=insmod
Copy link
Contributor

Choose a reason for hiding this comment

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

evt.type=execve is redundant. Can you please remove it?

@leogr
Copy link
Member

leogr commented Nov 5, 2020

@leogr This literally has been more work than is worth IMHO, if you want to rebase and include the changes feel free. I was hoping to contribute back to the project this detection which I found useful in my production environment at Splunk, but contributing here has been extremely cumbersome due to all the steps/hoops required and will likely not contribute again unfortunately. My advice is make this process easier for contributors if you really want the community to be part of the project. Feel free to close the PR if you did not find it useful, otherwise enjoy the free detection

Hey @d1vious

I'm sorry you felt unhappy with the process we have in place. Your contribution is valuable, and we appreciate it. We never thought it was unuseful.

However, I'm here to help with this PR. So let's try to solve the issue.
We actually just need to rebase it, then @Kaizhe's suggestions can be applied easily.

Unfortunately, GitHub does not allow us to force push on your branch, so I cannot rebase this PR by myself atm. I can propose two solutions (almost effortless for you):

  • giving me collaborator access to your fork so that I can rebase your branch
  • or, I can create a new PR if that's ok for you

In both cases, I will cherry-pick and keep your two commits (that have been signed-off by you, so it's perfectly fine) then we will also be able to include our suggestions on top of that.

WDYT?

@josehelps josehelps mentioned this pull request Nov 6, 2020
@josehelps
Copy link
Contributor Author

cleaned up, added the fixes and DCO signature on #1478, closing this one

@josehelps josehelps closed this Nov 6, 2020
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.

8 participants