/usr/lib/python2.7/dist-packages/rekall/plugins/linux/pslist.py is in python-rekall-core 1.6.0+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | # Rekall Memory Forensics
#
# Copyright 2013 Google Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
@author: Andrew Case
@license: GNU General Public License 2.0 or later
@contact: atcuno@gmail.com
@organization: Digital Forensics Solutions
"""
from rekall import utils
from rekall import testlib
from rekall.plugins.common import memmap
from rekall.plugins.linux import common
class LinuxPsList(common.LinProcessFilter):
"""Gathers active tasks by walking the task_struct->task list.
It does not display the swapper process. If the DTB column is blank, the
item is likely a kernel thread.
"""
__name = "pslist"
table_header = [
dict(name="proc", width=40, type="task_struct"),
dict(name="ppid", align="r", width=6),
dict(name="uid", align="r", width=6),
dict(name="gid", align="r", width=6),
dict(name="dtb", style="address"),
dict(name="start_time", align="r", width=24),
dict(name="binary")
]
def column_types(self):
task = self.session.profile.task_struct()
return dict(
proc=task,
ppid=0,
uid=utils.HexInteger(0),
gid=utils.HexInteger(0),
dtb=utils.HexInteger(0),
start_time=task.task_start_time,
binary="")
def collect(self):
for task in self.filter_processes():
dtb = self.kernel_address_space.vtop(task.mm.pgd)
path = task.get_path(task.mm.m("exe_file"))
yield (task,
task.parent.pid,
task.uid,
task.gid,
dtb, task.task_start_time,
path)
class LinMemMap(memmap.MemmapMixIn, common.LinProcessFilter):
"""Dumps the memory map for linux tasks."""
__name = "memmap"
class LinMemDump(memmap.MemDumpMixin, common.LinProcessFilter):
"""Dump the addressable memory for a process."""
class TestLinMemDump(testlib.HashChecker):
mode = "mode_linux_memory"
PARAMETERS = dict(
commandline="memdump --proc_regex %(proc_name)s --dump_dir %(tempdir)s",
proc_name="bash",
)
# We only care about PIDTYPE_PID here.
# http://lxr.free-electrons.com/source/include/linux/pid.h?v=3.8#L6
# enum pid_type
# {
# PIDTYPE_PID,
# };
PIDTYPE_PID = 0
class PidHashTable(LinuxPsList):
"""List processes by enumerating the pid hash tables."""
__name = "pidhashtable"
def list_tasks(self):
# According to
# http://lxr.free-electrons.com/source/kernel/pid.c?v=3.8#L566, the
# pid_hash table is a pointer to a dynamically allocated array of
# hlist_head.
pidhash_shift = self.profile.get_constant_object(
"pidhash_shift", "unsigned int")
pidhash = self.profile.get_constant_object(
"pid_hash",
target="Pointer",
target_args=dict(
target="Array",
target_args=dict(
count=1 << pidhash_shift,
target="hlist_head"
)
)
)
seen = set()
# Now we iterate over all the hash slots in the hash table to retrieve
# their struct upid entries.
for hash_slot in pidhash:
for upid in hash_slot.list_of_type("upid", "pid_chain"):
# upid structures are contained inside pid structures:
# http://lxr.free-electrons.com/source/kernel/pid.c?v=3.8#L351
# container_of(pnr, struct pid, numbers[ns->level]);
level = upid.ns.level
pid = self.profile.pid(
upid.obj_offset -
self.profile.get_obj_offset("pid", "numbers") -
level * self.profile.get_obj_size("pid"))
# Here we only care about regular PIDs.
for task in pid.tasks[PIDTYPE_PID].list_of_type(
"task_struct", "pids"):
if task not in seen:
yield task
seen.add(task)
|