1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 from rekall import obj
21 from rekall.plugins.windows import common
22 from rekall.plugins.windows.gui import win32k_core
23 from rekall.plugins.windows.gui import constants
24
25
26
27 -class Clipboard(win32k_core.Win32kPluginMixin,
28 common.WinProcessFilter):
29 """Extract the contents of the windows clipboard"""
30
31 __name = "clipboard"
32
33 table_header = [
34 dict(name="session", width=10),
35 dict(name="window_station", width=12),
36 dict(name="format", width=18),
37 dict(name="handle", style="address"),
38 dict(name="object", style="address"),
39 dict(name="data", width=50),
40 dict(name="hexdump", hidden=True),
41 ]
42
44 session_plugin = self.session.plugins.sessions()
45
46
47 sessions = dict((int(session.SessionId), session)
48 for session in session_plugin.session_spaces())
49
50
51 session_handles = {}
52
53
54
55 e0 = obj.NoneObject("Unknown tagCLIPDATA")
56 e1 = obj.NoneObject("Unknown tagWINDOWSTATION")
57 e2 = obj.NoneObject("Unknown tagCLIP")
58
59
60 for sid, session in sessions.items():
61 handles = {}
62 shared_info = self.win32k_profile.get_constant_object(
63 "gSharedInfo",
64 target="tagSHAREDINFO",
65 vm=session.obj_vm)
66 if not shared_info:
67 self.session.logging.debug(
68 "No shared info for session {0}".format(sid))
69 continue
70
71 for handle in shared_info.aheList:
72 if handle.bType != "TYPE_CLIPDATA":
73 continue
74
75 handles[int(handle.phead.h)] = handle
76
77 session_handles[sid] = handles
78
79
80 windowstations_plugin = self.session.plugins.wndscan()
81
82 for wndsta, station_as in windowstations_plugin.generate_hits():
83 session = sessions.get(int(wndsta.dwSessionId), None)
84
85 if not session:
86 continue
87
88 handles = session_handles.get(int(session.SessionId), None)
89
90 if not handles:
91 continue
92
93 clip_array = wndsta.pClipBase.dereference(vm=station_as)
94
95 if not clip_array:
96 continue
97
98
99 for clip in clip_array:
100 handle = handles.get(int(clip.hData), e0)
101
102 if handle:
103 handles.pop(int(clip.hData))
104
105 yield session, wndsta, clip, handle
106
107
108
109
110 for sid in sessions.keys():
111 handles = session_handles.get(sid, None)
112
113 if not handles:
114 continue
115
116 for handle in handles.values():
117 yield sessions[sid], e1, e2, handle
118
120 for session, wndsta, clip, handle in self.calculate():
121
122 if not clip:
123 fmt = obj.NoneObject("Format unknown")
124 else:
125
126
127 if clip.fmt.v() in constants.CLIPBOARD_FORMAT_ENUM:
128 fmt = str(clip.fmt)
129 else:
130 fmt = hex(clip.fmt.v())
131
132
133
134
135 handle_value = clip.hData or handle.phead.h
136
137 clip_data = ""
138 if handle and "TEXT" in fmt:
139 clip_data = handle.reference_object().as_string(fmt)
140
141 print handle
142
143 yield dict(session=session.SessionId,
144 window_station=wndsta.Name,
145 format=fmt,
146 handle=handle_value,
147 object=handle.phead.v(),
148 data=clip_data,
149 hexdump=handle.reference_object().as_hex())
150