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

tracee: skip golang plugin for static binaries #3244

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions pkg/signatures/signature/signature.go
Expand Up @@ -2,6 +2,7 @@ package signature

import (
"bytes"
"debug/elf"
"fmt"
"io/fs"
"os"
Expand Down Expand Up @@ -58,6 +59,11 @@ func Find(target string, partialEval bool, signaturesDir string, signatures []st
func findGoSigs(dir string) ([]detect.Signature, error) {
var res []detect.Signature

if isBinaryStatic() {
logger.Warnw("The tracee static can't load golang signatures. Skipping ...")
return res, nil
}

errWD := filepath.WalkDir(dir,
func(path string, d fs.DirEntry, err error) error {
if err != nil {
Expand Down Expand Up @@ -188,3 +194,27 @@ func isRegoFile(name string) bool {
func isHelper(name string) bool {
return strings.HasSuffix(name, "helpers.rego")
}

func isBinaryStatic() bool {
exePath, err := os.Executable()
if err != nil {
logger.Errorw("Error getting tracee executable path", "error", err)
return false
}

loadedObject, err := elf.Open(exePath)
if err != nil {
logger.Errorw("Error opening tracee executable", "error", err)
return false
}

defer func() {
if err = loadedObject.Close(); err != nil {
logger.Errorw("Error closing file", "error", err)
}
}()

_, err = loadedObject.DynamicSymbols()

return err != nil
}