Module: Msf::Util::EXE::OSX::App::ClassMethods

Included in:
Msf::Util::EXE::OSX::App
Defined in:
lib/msf/util/exe/osx/app.rb

Instance Method Summary collapse

Instance Method Details

#to_osx_app(exe, opts = {}) ⇒ String

Create an OSX .app bundle containing the Mach-O executable provided in exe to_osx_app

Parameters:

  • opts (Hash) (defaults to: {})

    The options hash

Options Hash (opts):

  • :exe_name (Hash) — default: random

    the name of the macho exe file (never seen by the user)

  • :app_name (Hash) — default: random

    the name of the OSX app

  • :hidden (Hash) — default: true

    hide the app when it is running

  • :plist_extra (Hash) — default: ''

    some extra data to shove inside the Info.plist file

Returns:

  • (String)

    zip archive containing an OSX .app directory



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/msf/util/exe/osx/app.rb', line 20

def to_osx_app(exe, opts = {})
  exe_name    = opts.fetch(:exe_name) { Rex::Text.rand_text_alpha(8) }
  app_name    = opts.fetch(:app_name) { Rex::Text.rand_text_alpha(8) }
  hidden      = opts.fetch(:hidden, true)
  plist_extra = opts.fetch(:plist_extra, '')

  app_name.chomp!(".app")
  app_name += ".app"

  visible_plist = if hidden
    %Q|
    <key>LSBackgroundOnly</key>
    <string>1</string>
    |
  else
    ''
  end

  info_plist = %Q|
    <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
  <dict>
<key>CFBundleExecutable</key>
<string>#{exe_name}</string>
<key>CFBundleIdentifier</key>
<string>com.#{exe_name}.app</string>
<key>CFBundleName</key>
<string>#{exe_name}</string>#{visible_plist}
<key>CFBundlePackageType</key>
<string>APPL</string>
#{plist_extra}
  </dict>
  </plist>
  |

  zip = Rex::Zip::Archive.new
  zip.add_file("#{app_name}/", '')
  zip.add_file("#{app_name}/Contents/", '')
  zip.add_file("#{app_name}/Contents/Resources/", '')
  zip.add_file("#{app_name}/Contents/MacOS/", '')
  # Add the macho and mark it as executable
  zip.add_file("#{app_name}/Contents/MacOS/#{exe_name}", exe).last.attrs = 0o777
  zip.add_file("#{app_name}/Contents/Info.plist", info_plist)
  zip.add_file("#{app_name}/Contents/PkgInfo", 'APPLaplt')
  zip.pack
end