-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added set_fs_pwd event * Added test for set_fs_pwd * Run make fix-fmt * Added doc for set_fs_pwd event * Added test to PR workflow * Fix test for systems without bpf_probe_read_user_str The bpf_probe_read_user_str helper was added in kernel 5.5, and before that reads from user space were not guaranteed to work if the architecture doesn't support it. In practice, ARM systems couldn't read from user space before this helper was introduced. The test now doesn't expect the unresolved_path (which comes from a userspace read) to conatin anything if the helper doesn't exist.
- Loading branch information
Showing
12 changed files
with
202 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# set_fs_pwd | ||
|
||
## Intro | ||
|
||
set_fs_pwd - An event capturing changes to the current working directory. | ||
|
||
## Description | ||
|
||
This event captures any changes to the current working directory (typically by using the `chdir` and `fchdir` syscalls). | ||
|
||
## Arguments | ||
|
||
* `unresolved_pathname`:`const char*`[K,TOCTOU,OPT] - unresolved, user-supplied path which the current working directory is being changed to (only relevant to directory changes using the `chdir` syscall). | ||
* `resolved_pathname`:`const char*`[K] - the fully resolved filesystem path which the current working directory is being changed to. | ||
|
||
## Hooks | ||
|
||
### set_fs_pwd | ||
|
||
#### Type | ||
|
||
kprobe | ||
|
||
#### Purpose | ||
|
||
Catch changes to the current working directory. | ||
|
||
## Example Use Case | ||
|
||
## Issues | ||
|
||
## Related Events | ||
|
||
`chdir`, `fchdir` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
libbfgo "github.com/aquasecurity/libbpfgo/helpers" | ||
|
||
"github.com/aquasecurity/tracee/signatures/helpers" | ||
"github.com/aquasecurity/tracee/types/detect" | ||
"github.com/aquasecurity/tracee/types/protocol" | ||
"github.com/aquasecurity/tracee/types/trace" | ||
) | ||
|
||
type e2eSetFsPwd struct { | ||
cb detect.SignatureHandler | ||
hasReadUser bool | ||
} | ||
|
||
func (sig *e2eSetFsPwd) Init(ctx detect.SignatureContext) error { | ||
sig.cb = ctx.Callback | ||
|
||
// Find if this system has the bpf_probe_read_user_str helper. | ||
// If it doesn't we won't expect the unresolved path to contain anything | ||
ksyms, err := libbfgo.NewKernelSymbolTable() | ||
if err != nil { | ||
return err | ||
} | ||
_, err = ksyms.GetSymbolByName("bpf_probe_read_user_str") | ||
if err != nil { | ||
sig.hasReadUser = false | ||
} else { | ||
sig.hasReadUser = true | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (sig *e2eSetFsPwd) GetMetadata() (detect.SignatureMetadata, error) { | ||
return detect.SignatureMetadata{ | ||
ID: "SET_FS_PWD", | ||
EventName: "SET_FS_PWD", | ||
Version: "0.1.0", | ||
Name: "set_fs_pwd Test", | ||
Description: "Instrumentation events E2E Tests: set_fs_pwd", | ||
Tags: []string{"e2e", "instrumentation"}, | ||
}, nil | ||
} | ||
|
||
func (sig *e2eSetFsPwd) GetSelectedEvents() ([]detect.SignatureEventSelector, error) { | ||
return []detect.SignatureEventSelector{ | ||
{Source: "tracee", Name: "set_fs_pwd"}, | ||
}, nil | ||
} | ||
|
||
func (sig *e2eSetFsPwd) OnEvent(event protocol.Event) error { | ||
eventObj, ok := event.Payload.(trace.Event) | ||
if !ok { | ||
return fmt.Errorf("failed to cast event's payload") | ||
} | ||
|
||
switch eventObj.EventName { | ||
case "set_fs_pwd": | ||
unresolvedPath, err := helpers.GetTraceeStringArgumentByName(eventObj, "unresolved_path") | ||
if sig.hasReadUser && err != nil { | ||
return err | ||
} | ||
|
||
resolvedPath, err := helpers.GetTraceeStringArgumentByName(eventObj, "resolved_path") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// check expected values from test for detection | ||
|
||
if (sig.hasReadUser && !strings.HasSuffix(unresolvedPath, "/test_link")) || !strings.HasSuffix(resolvedPath, "/test_dir") { | ||
return nil | ||
} | ||
|
||
m, _ := sig.GetMetadata() | ||
|
||
sig.cb(&detect.Finding{ | ||
SigMetadata: m, | ||
Event: event, | ||
Data: map[string]interface{}{}, | ||
}) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (sig *e2eSetFsPwd) OnSignal(s detect.Signal) error { | ||
return nil | ||
} | ||
|
||
func (sig *e2eSetFsPwd) Close() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
exit_err() { | ||
echo -n "ERROR: " | ||
echo "$@" | ||
exit 1 | ||
} | ||
|
||
mkdir test_dir || exit_err "failed creating dir" | ||
ln -s test_dir test_link || exit_err "failed creating link" | ||
cd test_link || exit_err "failed changing directory" | ||
cd .. || exit_err "failed changing directory back" | ||
rm test_link || exit_err "failed removing link" | ||
rm -r test_dir || exit_err "failed removing dir" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters