Fixes issue in the implant where `ps` command leads to infinite loop on Darwin under certain conditions.
This commit is contained in:
lip234
2024-07-08 13:35:30 -06:00
parent 7676fc6c37
commit 8bf4f8ef02
+4 -7
View File
@@ -227,12 +227,9 @@ func getArgvFromPid(pid int) ([]string, error) {
errStr := unix.ErrnoName(errno)
return []string{""}, fmt.Errorf("%s", errStr)
}
buffer := bytes.NewBuffer(processArgs)
numberOfArgs, err := binary.ReadUvarint(buffer)
if err != nil {
return []string{""}, err
}
buffer.Next(3) // skip sizeof(int32), the number of args
buffer := bytes.NewBuffer(processArgs[0:size])
numberOfArgsBytes := buffer.Next(4)
numberOfArgs := binary.LittleEndian.Uint32(numberOfArgsBytes)
argv := make([]string, numberOfArgs+1) // executable name is present twice
// There's probably a way to optimize that loop.
@@ -248,7 +245,7 @@ func getArgvFromPid(pid int) ([]string, error) {
for {
arg, err := buffer.ReadString(0x00)
if err != nil {
continue
break
}
if strings.ReplaceAll(arg, "\x00", "") != "" {
argv[i] = arg