1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from rekall.plugins.overlays.windows import tcpip_vtypes
24 from rekall.plugins.windows import common
25
26
27
28 -class Connections(tcpip_vtypes.TcpipPluginMixin,
29 common.WindowsCommandPlugin):
30 """
31 Print list of open connections [Windows XP Only]
32 ---------------------------------------------
33
34 This module enumerates the active connections from tcpip.sys.
35
36 Note that if you are using a hibernated image this might not work
37 because Windows closes all sockets before hibernating. You might
38 find it more effective to do conscan instead.
39
40 Active TCP connections are found in a hash table. The Hash table is given by
41 the _TCBTable symbol. The size of the hash table is found in the
42 _MaxHashTableSize variable.
43 """
44
45 __name = "connections"
46
47 mode = "mode_xp"
48
49 table_header = [
50 dict(name="offset_v", style="address"),
51 dict(name="local_net_address", width=25),
52 dict(name="remote_net_address", width=25),
53 dict(name="pid", width=6)
54 ]
55
57
58 TCBTable = self.tcpip_profile.get_constant_object(
59 "TCBTable",
60 target="Pointer",
61 vm=self.kernel_address_space,
62 target_args=dict(
63 target="Array",
64 target_args=dict(
65 count=int(self.tcpip_profile.get_constant_object(
66 "MaxHashTableSize", "unsigned int")),
67
68 target="Pointer",
69 target_args=dict(
70 target="_TCPT_OBJECT"
71 )
72 )
73 )
74 )
75
76
77 for slot in TCBTable.deref():
78 for conn in slot.walk_list("Next"):
79 offset = conn.obj_offset
80 local = "{0}:{1}".format(conn.LocalIpAddress, conn.LocalPort)
81 remote = "{0}:{1}".format(conn.RemoteIpAddress, conn.RemotePort)
82 yield (offset, local, remote, conn.Pid)
83
84
85 -class Sockets(tcpip_vtypes.TcpipPluginMixin,
86 common.WindowsCommandPlugin):
87 """
88 Print list of open sockets. [Windows xp only]
89 ---------------------------------------------
90
91 This module enumerates the active sockets from tcpip.sys
92
93 Note that if you are using a hibernated image this might not work
94 because Windows closes all sockets before hibernating.
95
96 _ADDRESS_OBJECT are arranged in a hash table found by the _AddrObjTable
97 symbol. The hash table has a size found by the _AddrObjTableSize symbol.
98 """
99
100 name = "sockets"
101 mode = "mode_xp"
102
103 table_header = [
104 dict(name="offset_v", style="address"),
105 dict(name="pid", width=6, align="r"),
106 dict(name="port", width=6, align="r"),
107 dict(name="proto", width=6, align="r"),
108 dict(name="protocol", width=10),
109 dict(name="address", width=15),
110 dict(name="create_time")
111 ]
112
114 sock = self.tcpip_profile._ADDRESS_OBJECT()
115 return dict(offset_v=sock,
116 pid=sock.Pid,
117 port=sock.LocalPort,
118 proto=int(sock.Protocol),
119 protocol=sock.Protocol,
120 address=sock.LocalIpAddress,
121 create_time=sock.CreateTime)
122
124 AddrObjTable = self.tcpip_profile.get_constant_object(
125 "AddrObjTable",
126 target="Pointer",
127 vm=self.kernel_address_space,
128 target_args=dict(
129 target="Array",
130 target_args=dict(
131 count=int(self.tcpip_profile.get_constant_object(
132 "AddrObjTableSize", "unsigned int")),
133
134 target="Pointer",
135 target_args=dict(
136 target="_ADDRESS_OBJECT"
137 )
138 )
139 )
140 )
141
142 for slot in AddrObjTable.deref():
143 for sock in slot.walk_list("Next"):
144 yield dict(offset_v=sock,
145 pid=sock.Pid,
146 port=sock.LocalPort,
147 proto=int(sock.Protocol),
148 protocol=sock.Protocol,
149 address=sock.LocalIpAddress,
150 create_time=sock.CreateTime)
151