Skip to content

Add Tracee eBPF threat detection for Linux Dynamic Analysis #2235

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 5 commits into from
Jul 17, 2024

Conversation

theoleecj2
Copy link
Contributor

@theoleecj2 theoleecj2 commented Jul 17, 2024

Tracee Pull Request

This pull request integrates Aqua Security Tracee, an eBPF-based threat detection engine with built-in signatures, into CAPEv2 for Linux dynamic analysis to complement the existing strace implementation. The log streaming implementation is similar to @winson0123's strace streaming to prevent ransomware's encryption of the logs.

Please comment if you see any issues.

Screenshots and demo

Screenshot of the Tracee Behaviour UI
image

Demonstration of a captured kernel module (which was encrypted and stored only in memory)
image

Rationale

In no order of importance:

  • Tracee has functionality to capture artifacts such as loaded kernel modules, suspicious memory regions and eBPF programs in their run-time state, allowing their easy extraction even from packed and encrypted malwares, aiding in dynamic analysis
  • Powerful filtering UI based on datatables JavaScript library
    • Opted for client-side data filtering for performance reasons and to ease server load
    • Compressed (gzipped) data format for storage in CAPE report (~10x compression and bandwidth savings due to JSON log format)
    • Able to store uncompressed fields if required, e.g. for integration into CAPE signatures (future work)
  • Tracee has advanced built-in signatures for many suspicious behaviours such as:
    • Dynamic Code Loading
    • Fileless Execution
    • Hidden File Created
    • Syscall Table Hooking
    • kallsyms_lookup_name - it could be used in some rootkits, likely until recently... (it's an interesting story)
    • Illegitimate Shell - detect instances where a web server program spawns a shell
    • Kernel Module Loading - new kernel module loaded (possible kernel rookits)
    • Loader Preload - identifies manipulation of LD_PRELOAD and LD_LIBRARY_PATH environment variables, or similar methods which can potentially be leveraged for code injection
    • Process VM Write - detect potential code injection attacks using the process_vm_writev syscall
    • Scheduled Task Modification - like cron
    • Standard I/O Over Socket - potential remote shell
    • Many more...
  • Built-in signatures make it easier for users to identify and narrow down suspicious behaviours compared to sifting through many syscalls
  • Tracee operates at the eBPF level, making it harder (but not impossible) to detect than strace by malware.

Trying it out

To get started, use the branch theoleecj2/CAPEv2 -> tracee.

Run docker pull docker.io/aquasec/tracee:0.20.0 in a Ubuntu VM which already has the CAPE agent running. For best results, use Ubuntu 20.04.

Side Note: Some rootkits and malware you may find online may require kallsyms_lookup_name which is affected in Linux kernel versions > 5.7. See here for more information.

Then docker image tag aquasec/tracee:0.20.0 aquasec/tracee:latest to record v0.20.0 as the latest.

Add tracee_linux = yes to the auxiliary.conf's [auxiliary_modules] section and

[tracee]
enabled = yes

into processing.conf.

You can obtain a live malware sample for Linux to load into CAPEv2 from https://bazaar.abuse.ch/sample/bd0141e88a0d56b508bc52db4dab68a49b6027a486e4d9514ec0db006fe71eed/. Please be careful with this file as it's an actual malware. We do not take responsibility for anything that goes wrong.

For further demonstration, you can try https://github.com/citronneur/pamspy which loads an eBPF program to steal credentials. The eBPF should be captured by Tracee in 'Dropped Files'.

Limitations

Tracee sometimes does not de-reference pointers while strace can capture the contents. The Tracee implementation here is not 100% reliable, and we are working on improving it (for instance, we have added a health check).

Common Issues

You need to have the strace auxiliary module enabled. Processing for strace need not be enabled, but you can enable it to observe the Tracee module's weaknesses and strengths compared to it.

The event capturing is not 100% reliable. If a task's Tracee output looks incorrect, please try again.

Check that you have /opt/CAPEv2/data/linux/linux-syscalls.json. If not, you can obtain it from https://raw.githubusercontent.com/mebeim/linux-syscalls/master/db/x86/64/x64/v6.5/table.json.

@kevoreilly
Copy link
Owner

Thank you ❤️

Andriy Brukhovetskyy added 3 commits July 17, 2024 09:48
@doomedraven
Copy link
Collaborator

hello, thank you for such a great contribution, i will merge it , but some parts will be moved to community repo to clarify that is not done by core devs

@doomedraven doomedraven merged commit 79df868 into kevoreilly:master Jul 17, 2024
5 checks passed
@theoleecj2 theoleecj2 deleted the tracee branch July 17, 2024 09:16
@Dasher-zdh
Copy link

log
2025-04-28 09:50:56,040 [root] DEBUG: Starting analyzer from: /tmphhcukjcn
2025-04-28 09:50:56,041 [root] DEBUG: Storing results at: /tmp/TLzwjbKO
2025-04-28 09:50:56,050 [root] DEBUG: Importing auxiliary module "modules.auxiliary.filecollector"...
2025-04-28 09:50:56,149 [root] DEBUG: Importing auxiliary module "modules.auxiliary.human"...
2025-04-28 09:50:56,639 [root] DEBUG: Importing auxiliary module "modules.auxiliary.screenshots"...
2025-04-28 09:50:56,936 [lib.api.screenshot] DEBUG: Importing 'PIL.ImageChops'
2025-04-28 09:50:56,937 [lib.api.screenshot] DEBUG: Importing 'PIL.ImageDraw'
2025-04-28 09:50:56,937 [lib.api.screenshot] INFO: Please upgrade Pillow to >= 5.4.1 for best performance
2025-04-28 09:50:57,074 [modules.auxiliary.filecollector] INFO: FileCollector run started
2025-04-28 09:50:57,135 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir srv
2025-04-28 09:50:57,136 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir lost+found
2025-04-28 09:50:57,141 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir snap
2025-04-28 09:51:01,382 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir tmpjz1jkxdc
2025-04-28 09:51:01,387 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir libx32
2025-04-28 09:51:01,388 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir bin
2025-04-28 09:51:01,388 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir opt
2025-04-28 09:51:01,389 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir home
2025-04-28 09:51:01,508 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir .Library
2025-04-28 09:51:01,509 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir cdrom
2025-04-28 09:51:01,509 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir lib32
2025-04-28 09:51:01,510 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir media
2025-04-28 09:51:01,510 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir sbin
2025-04-28 09:51:01,511 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir boot
2025-04-28 09:51:01,513 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir tmphhcukjcn
2025-04-28 09:51:01,514 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir etc
2025-04-28 09:51:01,607 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir tmp
2025-04-28 09:51:01,610 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir root
2025-04-28 09:51:01,673 [modules.auxiliary.filecollector] INFO: FileCollector trying to watch dir mnt
2025-04-28 09:51:01,673 [modules.auxiliary.filecollector] INFO: FileCollector setup complete
2025-04-28 09:51:02,076 [root] DEBUG: Initialized auxiliary module "FileCollector"
2025-04-28 09:51:02,077 [root] DEBUG: Trying to start auxiliary module "FileCollector"...
2025-04-28 09:51:02,078 [root] DEBUG: Started auxiliary module "FileCollector"
2025-04-28 09:51:02,080 [modules.auxiliary.human] DEBUG: Human init complete
2025-04-28 09:51:02,081 [root] DEBUG: Initialized auxiliary module "Human"
2025-04-28 09:51:02,081 [root] DEBUG: Trying to start auxiliary module "Human"...
2025-04-28 09:51:02,082 [root] DEBUG: Started auxiliary module "Human"
2025-04-28 09:51:02,083 [root] DEBUG: Initialized auxiliary module "Screenshots"
2025-04-28 09:51:02,084 [root] DEBUG: Trying to start auxiliary module "Screenshots"...
2025-04-28 09:51:02,084 [asyncio] DEBUG: Using selector: EpollSelector
2025-04-28 09:51:02,085 [root] DEBUG: Started auxiliary module "Screenshots"
2025-04-28 09:51:02,092 [lib.core.packages] INFO: sh -c
2025-04-28 09:51:02,092 [lib.core.packages] INFO: sudo strace -o /dev/stderr -s 800 -ttf sh -c /tmp/bd0141e88a0d56b508bc.elf
2025-04-28 09:51:02,095 [lib.core.packages] INFO: Process started with strace
2025-04-28 09:51:02,096 [root] INFO: Added new process to list with pid: 2274
2025-04-28 09:51:02,348 [root] INFO: New child process detected: 2280
2025-04-28 09:51:02,769 [lib.common.results] INFO: File /.Library/SystemServices/updateSystem size is 40960, Max size: 100000000
2025-04-28 09:51:02,786 [lib.common.results] INFO: File /.Library/SystemServices/updateSystem size is 865144, Max size: 100000000
2025-04-28 09:54:22,430 [root] INFO: Analysis timeout hit, terminating analysis
2025-04-28 09:54:22,431 [root] INFO: Stopping auxiliary modules
2025-04-28 09:54:22,433 [root] INFO: Stopping auxiliary module: FileCollector
2025-04-28 09:54:23,201 [lib.core.packages] INFO: Strace streaming connection has been closed
2025-04-28 09:54:29,436 [root] INFO: Stopping auxiliary module: Human
2025-04-28 09:54:29,437 [root] INFO: Stopping auxiliary module: Screenshots
2025-04-28 09:54:29,437 [root] INFO: Finishing auxiliary modules
2025-04-28 09:54:29,438 [lib.common.results] WARNING: File /sslkeylog.log doesn't exist anymore
2025-04-28 09:54:29,438 [root] INFO: Analysis completed

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.

4 participants