1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import math
20
21 from rekall.plugins.linux import common
22 from rekall.plugins.overlays.linux import vfs
23
24
26 """A simple container."""
27
28
29 -class Mount(common.LinuxPlugin):
30 """Lists the mount points."""
31 __name = "mount"
32
33 table_header = [
34 dict(name="Device", width=50),
35 dict(name="Path", width=50),
36 dict(name="Type", width=14),
37 dict(name="flags", width=20),
38 ]
39
41 if self.profile.get_constant("set_mphash_entries"):
42
43 mnttype = "mount"
44 mount_hashtable_target_type = "hlist_head"
45 elif self.profile.has_type("mount"):
46
47 mnttype = "mount"
48 mount_hashtable_target_type = "list_head"
49 else:
50 mnttype = "vfsmount"
51 mount_hashtable_target_type = "list_head"
52
53 if mount_hashtable_target_type == "list_head":
54
55
56 hashtable_head_len = self.profile.get_obj_size(
57 mount_hashtable_target_type)
58 page_size = self.kernel_address_space.PAGE_SIZE
59 hash_size = 1 << int(math.log(page_size/hashtable_head_len, 2))
60 numentries = hash_size
61
62 else:
63
64
65
66
67
68
69
70 numentries = self.profile.get_constant_object(
71 "mhash_entries",
72 vm=self.kernel_address_space,
73 target="unsigned long").value
74
75
76
77 if not numentries:
78 nr_kernel_pages = self.profile.get_constant_object(
79 "nr_kernel_pages",
80 vm=self.kernel_address_space,
81 target="unsigned long")
82
83 numentries = 65536
84
85 self.session.logging.debug("numentries: %d", numentries)
86
87 mount_hashtable = self.profile.get_constant_object(
88 "mount_hashtable",
89 vm=self.kernel_address_space,
90 target="Pointer",
91 target_args=dict(
92 target="Array",
93 target_args=dict(
94 count=numentries,
95 target=mount_hashtable_target_type
96 )))
97
98 init_task = self.session.profile.get_constant_object(
99 "init_task", "task_struct", vm=self.kernel_address_space)
100 if not init_task:
101 self.session.logging.debug(
102 "Unable to obtain the init task. Mounted paths may be incorrect.")
103
104
105 for hash in mount_hashtable:
106 for mnt in hash.list_of_type(mnttype, "mnt_hash"):
107
108
109
110 vfsmount = mnt.mnt
111
112
113
114
115
116
117 devname = mnt.mnt_devname.deref()
118
119
120 sb = vfsmount.mnt_sb
121
122 fs_type = sb.s_type.name.deref()
123
124 if (not devname.is_valid() or len(str(devname)) == 0 or
125 not fs_type.is_valid() or len(str(fs_type)) == 0):
126 continue
127
128
129
130
131
132
133
134
135
136
137 path_struct = Container()
138 path_struct.dentry = mnt.mnt_root
139 path_struct.mnt = vfsmount
140 path = vfs.Linux3VFS(self.session.profile).prepend_path(
141 path_struct, init_task.fs.root)
142
143 yield vfs.MountPoint(device=devname,
144 mount_path=path,
145 superblock=sb,
146 flags=vfsmount.mnt_flags,
147 session=self.session)
148
150 for mountpoint in self.get_mount_points():
151 flags_string = str(mountpoint.flags)
152
153
154 if not mountpoint.flags.ro:
155 if mountpoint.sb.s_flags & 0x01:
156 additional_flag = "ro"
157 else:
158 additional_flag = "rw"
159 flags_string = ', '.join([additional_flag, flags_string])
160
161 yield dict(Device=mountpoint.device,
162 Path=mountpoint.name,
163 Type=mountpoint.fstype,
164 flags=flags_string)
165