Path: blob/master/lib/msf/util/exe/osx/app.rb
57477 views
# -*- coding: binary -*-1module Msf::Util::EXE::OSX::App2include Msf::Util::EXE::Common3include Msf::Util::EXE::OSX::Common45def self.included(base)6base.extend(ClassMethods)7end89module ClassMethods1011# Create an OSX .app bundle containing the Mach-O executable provided in +exe+12# to_osx_app13#14# @param opts [Hash] The options hash15# @option opts [Hash] :exe_name (random) the name of the macho exe file (never seen by the user)16# @option opts [Hash] :app_name (random) the name of the OSX app17# @option opts [Hash] :hidden (true) hide the app when it is running18# @option opts [Hash] :plist_extra ('') some extra data to shove inside the Info.plist file19# @return [String] zip archive containing an OSX .app directory20def to_osx_app(exe, opts = {})21exe_name = opts.fetch(:exe_name) { Rex::Text.rand_text_alpha(8) }22app_name = opts.fetch(:app_name) { Rex::Text.rand_text_alpha(8) }23hidden = opts.fetch(:hidden, true)24plist_extra = opts.fetch(:plist_extra, '')2526app_name.chomp!(".app")27app_name += ".app"2829visible_plist = if hidden30%Q|31<key>LSBackgroundOnly</key>32<string>1</string>33|34else35''36end3738info_plist = %Q|39<?xml version="1.0" encoding="UTF-8"?>40<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">41<plist version="1.0">42<dict>43<key>CFBundleExecutable</key>44<string>#{exe_name}</string>45<key>CFBundleIdentifier</key>46<string>com.#{exe_name}.app</string>47<key>CFBundleName</key>48<string>#{exe_name}</string>#{visible_plist}49<key>CFBundlePackageType</key>50<string>APPL</string>51#{plist_extra}52</dict>53</plist>54|5556zip = Rex::Zip::Archive.new57zip.add_file("#{app_name}/", '')58zip.add_file("#{app_name}/Contents/", '')59zip.add_file("#{app_name}/Contents/Resources/", '')60zip.add_file("#{app_name}/Contents/MacOS/", '')61# Add the macho and mark it as executable62zip.add_file("#{app_name}/Contents/MacOS/#{exe_name}", exe).last.attrs = 0o77763zip.add_file("#{app_name}/Contents/Info.plist", info_plist)64zip.add_file("#{app_name}/Contents/PkgInfo", 'APPLaplt')65zip.pack66end67end6869class << self70include ClassMethods71end7273end747576