Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/util/exe/osx/app.rb
57477 views
1
# -*- coding: binary -*-
2
module Msf::Util::EXE::OSX::App
3
include Msf::Util::EXE::Common
4
include Msf::Util::EXE::OSX::Common
5
6
def self.included(base)
7
base.extend(ClassMethods)
8
end
9
10
module ClassMethods
11
12
# Create an OSX .app bundle containing the Mach-O executable provided in +exe+
13
# to_osx_app
14
#
15
# @param opts [Hash] The options hash
16
# @option opts [Hash] :exe_name (random) the name of the macho exe file (never seen by the user)
17
# @option opts [Hash] :app_name (random) the name of the OSX app
18
# @option opts [Hash] :hidden (true) hide the app when it is running
19
# @option opts [Hash] :plist_extra ('') some extra data to shove inside the Info.plist file
20
# @return [String] zip archive containing an OSX .app directory
21
def to_osx_app(exe, opts = {})
22
exe_name = opts.fetch(:exe_name) { Rex::Text.rand_text_alpha(8) }
23
app_name = opts.fetch(:app_name) { Rex::Text.rand_text_alpha(8) }
24
hidden = opts.fetch(:hidden, true)
25
plist_extra = opts.fetch(:plist_extra, '')
26
27
app_name.chomp!(".app")
28
app_name += ".app"
29
30
visible_plist = if hidden
31
%Q|
32
<key>LSBackgroundOnly</key>
33
<string>1</string>
34
|
35
else
36
''
37
end
38
39
info_plist = %Q|
40
<?xml version="1.0" encoding="UTF-8"?>
41
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
42
<plist version="1.0">
43
<dict>
44
<key>CFBundleExecutable</key>
45
<string>#{exe_name}</string>
46
<key>CFBundleIdentifier</key>
47
<string>com.#{exe_name}.app</string>
48
<key>CFBundleName</key>
49
<string>#{exe_name}</string>#{visible_plist}
50
<key>CFBundlePackageType</key>
51
<string>APPL</string>
52
#{plist_extra}
53
</dict>
54
</plist>
55
|
56
57
zip = Rex::Zip::Archive.new
58
zip.add_file("#{app_name}/", '')
59
zip.add_file("#{app_name}/Contents/", '')
60
zip.add_file("#{app_name}/Contents/Resources/", '')
61
zip.add_file("#{app_name}/Contents/MacOS/", '')
62
# Add the macho and mark it as executable
63
zip.add_file("#{app_name}/Contents/MacOS/#{exe_name}", exe).last.attrs = 0o777
64
zip.add_file("#{app_name}/Contents/Info.plist", info_plist)
65
zip.add_file("#{app_name}/Contents/PkgInfo", 'APPLaplt')
66
zip.pack
67
end
68
end
69
70
class << self
71
include ClassMethods
72
end
73
74
end
75
76