feat(go): port process access detectors
This commit is contained in:
parent
f02509aab5
commit
fc9b5f0448
22 changed files with 554 additions and 40 deletions
|
|
@ -20,10 +20,24 @@ func TestCaptureUsesInjectableProcRoot(t *testing.T) {
|
|||
if err := os.WriteFile(filepath.Join(proc, "cmdline"), []byte("bash\x00-i\x00"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(proc, "environ"), []byte("LD_PRELOAD=/tmp/x.so\x00A=B\x00"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Symlink("/tmp/x (deleted)", filepath.Join(proc, "exe")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
state, err := Capture(root)
|
||||
fdDir := filepath.Join(proc, "fd")
|
||||
if err := os.Mkdir(fdDir, 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Symlink("/dev/input/event3", filepath.Join(fdDir, "7")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
preload := filepath.Join(root, "ld.so.preload")
|
||||
if err := os.WriteFile(preload, []byte("/tmp/global.so\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
state, err := CaptureWithPaths(Paths{ProcRoot: root, LDPreloadPath: preload})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -34,4 +48,10 @@ func TestCaptureUsesInjectableProcRoot(t *testing.T) {
|
|||
if got.PID != 42 || got.Comm != "bash" || got.Cmdline != "bash -i" || got.Exe != "/tmp/x (deleted)" {
|
||||
t.Fatalf("unexpected process: %#v", got)
|
||||
}
|
||||
if got.Environ["LD_PRELOAD"] != "/tmp/x.so" || got.FDTargets["7"] != "/dev/input/event3" {
|
||||
t.Fatalf("missing environment or fd state: %#v", got)
|
||||
}
|
||||
if state.LDPreload != "/tmp/global.so" {
|
||||
t.Fatalf("unexpected global preload: %q", state.LDPreload)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue