CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/post/meterpreter/extensions/extapi/window/window.rb
Views: 11797
1
# -*- coding: binary -*-
2
3
module Rex
4
module Post
5
module Meterpreter
6
module Extensions
7
module Extapi
8
module Window
9
10
###
11
#
12
# This meterpreter extension contains extended API functions for
13
# querying and managing desktop windows.
14
#
15
###
16
class Window
17
18
def initialize(client)
19
@client = client
20
end
21
22
# Enumerate all the windows on the target.
23
# If the specified parent window is nil, then all top-level windows
24
# are enumerated. Otherwise, all child windows of the specified
25
# parent window are enumerated.
26
def enumerate(include_unknown = false, parent_window = nil)
27
request = Packet.create_request(COMMAND_ID_EXTAPI_WINDOW_ENUM)
28
29
if include_unknown
30
request.add_tlv(TLV_TYPE_EXT_WINDOW_ENUM_INCLUDEUNKNOWN, true)
31
end
32
33
if !parent_window.nil?
34
request.add_tlv(TLV_TYPE_EXT_WINDOW_ENUM_HANDLE, parent_window)
35
end
36
37
response = client.send_request(request)
38
39
windows = []
40
41
response.each(TLV_TYPE_EXT_WINDOW_ENUM_GROUP) do |w|
42
windows << {
43
pid: w.get_tlv_value(TLV_TYPE_EXT_WINDOW_ENUM_PID),
44
handle: w.get_tlv_value(TLV_TYPE_EXT_WINDOW_ENUM_HANDLE),
45
title: w.get_tlv_value(TLV_TYPE_EXT_WINDOW_ENUM_TITLE),
46
class_name: w.get_tlv_value(TLV_TYPE_EXT_WINDOW_ENUM_CLASSNAME)
47
}
48
end
49
50
windows.sort_by { |w| w[:pid] }
51
end
52
53
attr_accessor :client
54
55
end
56
end
57
end
58
end
59
end
60
end
61
end
62
63