feat(go): port memory-map detector tranche
This commit is contained in:
parent
c6f7219de8
commit
6a27e6e770
13 changed files with 377 additions and 41 deletions
|
|
@ -22,6 +22,9 @@ 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, "maps"), []byte("7f00-8000 rwxp 00000000 00:00 0 /memfd:stage (deleted)\n"), 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)
|
||||
}
|
||||
|
|
@ -56,11 +59,23 @@ func TestCaptureUsesInjectableProcRoot(t *testing.T) {
|
|||
if got.Environ["LD_PRELOAD"] != "/tmp/x.so" || got.FDTargets["7"] != "/dev/input/event3" {
|
||||
t.Fatalf("missing environment or fd state: %#v", got)
|
||||
}
|
||||
if len(got.MemoryMaps) != 1 || got.MemoryMaps[0].Start != 0x7f00 ||
|
||||
got.MemoryMaps[0].Path != "/memfd:stage (deleted)" {
|
||||
t.Fatalf("missing memory-map state: %#v", got.MemoryMaps)
|
||||
}
|
||||
if state.LDPreload != "/tmp/global.so" {
|
||||
t.Fatalf("unexpected global preload: %q", state.LDPreload)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseMemoryMapsPreservesPathSpaces(t *testing.T) {
|
||||
maps := parseMemoryMaps("7f00-8000 r-xp 00000000 00:00 0 /tmp/a path.so\n")
|
||||
if len(maps) != 1 || maps[0].Start != 0x7f00 || maps[0].End != 0x8000 ||
|
||||
maps[0].Perms != "r-xp" || maps[0].Path != "/tmp/a path.so" {
|
||||
t.Fatalf("unexpected maps: %#v", maps)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSSMatchesPythonShapes(t *testing.T) {
|
||||
text := "tcp ESTAB 0 0 10.0.0.2:5555 8.8.8.8:443 users:((\"bash\",pid=42,fd=3)) ino:999\n"
|
||||
sockets := parseSS(text, "tcp")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue