Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions analyzer/linux/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ def dump_memory(pid):
output_file = open(f"{MEM_PATH}/{pid}.dmp", "wb")

for line in maps_file.readlines():
m = re.match(r"([0-9A-Fa-f]+)-([0-9A-Fa-f]+) ([-r])(\S+)\s+\d+\s+\S+\s+\d+\s*(.*)?", line)
if m and m.group(3) == "r":
# Reference: https://man7.org/linux/man-pages/man5/proc_pid_maps.5.html
m = re.match(r"^([0-9a-f]+)-([0-9a-f]+) ([-rwxsp]{4}) ([0-9a-f]+) (\d\d:\d\d) (\d+) *(.*)$", line)
if not m:
log.error("Could not parse memory map line for pid %s: %s", pid, line)
continue
perms = m.group(3)
pathname = m.group(7)
if "r" in perms:
# Testing: Uncomment to skip memory regions associated with dynamic libraries
# pathname = m.group(5)
# if pathname and (pathname.endswith('.so') or 'lib' in pathname or '[' in pathname):
# continue
start = int(m.group(1), 16)
Expand All @@ -118,7 +123,7 @@ def dump_memory(pid):
chunk = mem_file.read(end - start)
output_file.write(chunk)
except (OSError, ValueError) as e:
log.error("Could not read memory range %s: {e}", f"{start:x}-{end:x}", str(e))
log.error("Could not read memory range %x-%x (%s) (%s): %s", start, end, perms, pathname, e)
maps_file.close()
mem_file.close()
output_file.close()
Expand Down
6 changes: 3 additions & 3 deletions analyzer/linux/lib/api/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ def is_alive(self):
status = self.get_proc_status()
if not status:
return False
if "zombie" in status.get("State:", ""):
if "zombie" in status.get("State", ""):
return False
return True

def get_parent_pid(self):
return self.get_proc_status().get("PPid")
return int(self.get_proc_status().get("PPid"))

def get_proc_status(self):
try:
with open(f"/proc/{self.pid}/status") as f:
status = f.readlines()
status_values = dict([j.strip().split(maxsplit=1) for j in status])
status_values = dict([tuple(map(str.strip, j.split(':',1))) for j in status])
return status_values
except Exception:
log.critical("Could not get process status for pid %s", self.pid)
Expand Down
2 changes: 1 addition & 1 deletion lib/cuckoo/common/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ def _prot_to_str(self, prot):
if prot & PAGE_GUARD:
return "G"
prot &= 0xFF
return self.protmap[prot]
return self.protmap.get(prot, "UNKNOWN")

def pretty_print(self):
new_addr_space = copy.deepcopy(self.address_space)
Expand Down