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/modules/post/multi/manage/open.rb
Views: 11784
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
)
21
)
22
23
register_options(
24
[
25
OptString.new('URI', [true, 'URI path to open'])
26
]
27
)
28
end
29
30
#
31
# The OSX version simply uses 'open'
32
#
33
def osx_open(uri)
34
begin
35
cmd_exec("open #{uri}")
36
rescue EOFError
37
return false
38
end
39
40
true
41
end
42
43
#
44
# The Linux version relies on 'xdg-open'
45
#
46
def linux_open(uri)
47
begin
48
cmd_exec("xdg-open #{uri}")
49
rescue EOFError
50
return false
51
end
52
53
true
54
end
55
56
def win_open(uri)
57
begin
58
cmd_exec("cmd.exe /c start #{uri}")
59
rescue EOFError
60
return false
61
end
62
63
true
64
end
65
66
def open(uri)
67
case session.platform
68
when 'osx'
69
return osx_open(uri)
70
when 'linux'
71
return linux_open(uri)
72
when 'windows'
73
return win_open(uri)
74
end
75
end
76
77
def run
78
uri = datastore['URI']
79
80
print_status("Opening #{uri}")
81
if open(uri)
82
print_good('Success')
83
else
84
print_error('Command failed')
85
end
86
end
87
end
88
89