Path: blob/master/lib/msf/util/exe/osx/app.rb
36043 views
module Msf::Util::EXE::OSX::App1include Msf::Util::EXE::Common2include Msf::Util::EXE::OSX::Common34def self.included(base)5base.extend(ClassMethods)6end78module ClassMethods910# Create an OSX .app bundle containing the Mach-O executable provided in +exe+11# to_osx_app12#13# @param opts [Hash] The options hash14# @option opts [Hash] :exe_name (random) the name of the macho exe file (never seen by the user)15# @option opts [Hash] :app_name (random) the name of the OSX app16# @option opts [Hash] :hidden (true) hide the app when it is running17# @option opts [Hash] :plist_extra ('') some extra data to shove inside the Info.plist file18# @return [String] zip archive containing an OSX .app directory19def to_osx_app(exe, opts = {})20exe_name = opts.fetch(:exe_name) { Rex::Text.rand_text_alpha(8) }21app_name = opts.fetch(:app_name) { Rex::Text.rand_text_alpha(8) }22hidden = opts.fetch(:hidden, true)23plist_extra = opts.fetch(:plist_extra, '')2425app_name.chomp!(".app")26app_name += ".app"2728visible_plist = if hidden29%Q|30<key>LSBackgroundOnly</key>31<string>1</string>32|33else34''35end3637info_plist = %Q|38<?xml version="1.0" encoding="UTF-8"?>39<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">40<plist version="1.0">41<dict>42<key>CFBundleExecutable</key>43<string>#{exe_name}</string>44<key>CFBundleIdentifier</key>45<string>com.#{exe_name}.app</string>46<key>CFBundleName</key>47<string>#{exe_name}</string>#{visible_plist}48<key>CFBundlePackageType</key>49<string>APPL</string>50#{plist_extra}51</dict>52</plist>53|5455zip = Rex::Zip::Archive.new56zip.add_file("#{app_name}/", '')57zip.add_file("#{app_name}/Contents/", '')58zip.add_file("#{app_name}/Contents/Resources/", '')59zip.add_file("#{app_name}/Contents/MacOS/", '')60# Add the macho and mark it as executable61zip.add_file("#{app_name}/Contents/MacOS/#{exe_name}", exe).last.attrs = 0o77762zip.add_file("#{app_name}/Contents/Info.plist", info_plist)63zip.add_file("#{app_name}/Contents/PkgInfo", 'APPLaplt')64zip.pack65end66end6768class << self69include ClassMethods70end7172end737475