Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/post/multi/manage/open.rb
19812 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Post
7
def initialize(info = {})
8
super(
9
update_info(
10
info,
11
'Name' => 'Open a file or URL on the target computer',
12
'Description' => %q{
13
This module will open any file or URL specified with the URI format on the
14
target computer via the embedded commands such as 'open' or 'xdg-open'.
15
},
16
'License' => MSF_LICENSE,
17
'Author' => [ 'Eliott Teissonniere'],
18
'Platform' => [ 'osx', 'linux', 'win' ],
19
'SessionTypes' => [ 'shell', 'meterpreter' ],
20
'Notes' => {
21
'Stability' => [CRASH_SAFE],
22
'SideEffects' => [SCREEN_EFFECTS],
23
'Reliability' => []
24
}
25
)
26
)
27
28
register_options(
29
[
30
OptString.new('URI', [true, 'URI path to open'])
31
]
32
)
33
end
34
35
#
36
# Open a file on OSX using 'open'
37
#
38
def osx_open(uri)
39
cmd_exec("open #{uri}")
40
return true
41
rescue EOFError
42
return false
43
end
44
45
#
46
# Open a file on Linux using 'xdg-open'
47
#
48
def linux_open(uri)
49
cmd_exec("xdg-open #{uri}")
50
return true
51
rescue EOFError
52
return false
53
end
54
55
#
56
# Open a file on Windows using 'start'
57
#
58
def win_open(uri)
59
cmd_exec("cmd.exe /c start #{uri}")
60
return true
61
rescue EOFError
62
return false
63
end
64
65
def open_uri(uri)
66
case session.platform
67
when 'osx'
68
return osx_open(uri)
69
when 'linux'
70
return linux_open(uri)
71
when 'windows'
72
return win_open(uri)
73
end
74
end
75
76
def run
77
uri = datastore['URI']
78
79
print_status("Opening #{uri}")
80
if open_uri(uri)
81
print_good('Success')
82
else
83
print_error('Command failed')
84
end
85
end
86
end
87
88