Create macho2app.rb
parent
ce7b967a13
commit
9b7049610a
|
@ -0,0 +1,105 @@
|
|||
#!/usr/bin/env ruby
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# This script converts a macho file to a macOS .app
|
||||
#
|
||||
# $Revision$
|
||||
#
|
||||
|
||||
require 'optparse'
|
||||
|
||||
msfbase = __FILE__
|
||||
while File.symlink?(msfbase)
|
||||
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
|
||||
end
|
||||
|
||||
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))
|
||||
require 'msfenv'
|
||||
|
||||
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
|
||||
|
||||
class MachoToApp
|
||||
|
||||
macho_path = nil
|
||||
app_name = nil
|
||||
|
||||
def get_opts
|
||||
|
||||
ARGV.options do |opt|
|
||||
opt.separator ''
|
||||
|
||||
opt.on('-f', String, 'The macho file produced by msfvenom') do |x|
|
||||
macho_path = x
|
||||
end
|
||||
|
||||
opt.on('-o', String, 'The output app name (without .app)') do |x|
|
||||
app_name = x
|
||||
end
|
||||
|
||||
opt.on_tail('-h', '--help', 'Show this message') do
|
||||
$stderr.puts opt
|
||||
exit
|
||||
end
|
||||
|
||||
opt.parse!
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
def initialize
|
||||
@args = get_opts
|
||||
rescue OptionParser::MissingArgument => e
|
||||
$stderr.puts e.message
|
||||
exit
|
||||
end
|
||||
|
||||
def main
|
||||
if @args.empty?
|
||||
fail OptionParser::MissingArgument, 'No options set, try -h for usage'
|
||||
elsif @args[0].nil?
|
||||
fail OptionParser::MissingArgument, '-f is required'
|
||||
elsif @args[1].nil?
|
||||
fail OptionParser::MissingArgument, '-o is required'
|
||||
end
|
||||
orig_macho = File.expand_path(@args[0])
|
||||
warn orig_macho
|
||||
plist_outline = "<?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>CFBundleName</key>
|
||||
<string>#{@args[1]}</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>#{@args[0]}</string>
|
||||
</dict>
|
||||
</plist>"
|
||||
|
||||
# A .app file is essentially a specialy treated directory on macOS,
|
||||
# so we will treat it as such
|
||||
system("chmod 777 #{@args[0]}") # This is the only way macOS will execute the macho
|
||||
Dir.mkdir("#{@args[1]}.app")
|
||||
Dir.chdir("#{@args[1]}.app")
|
||||
Dir.mkdir('Contents')
|
||||
Dir.chdir('Contents')
|
||||
Dir.mkdir('MacOS')
|
||||
File.open('Info.plist', 'w') do |f|
|
||||
f.write plist_outline
|
||||
end
|
||||
Dir.chdir('MacOS')
|
||||
system("mv #{orig_macho.inspect} ./#{@args[0]}")
|
||||
system("chmod 777 #{@args[0]}")
|
||||
Dir.chdir('../../..')
|
||||
puts "Final app produced: #{Dir.pwd}/#{@args[1]}.app"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if __FILE__ == $PROGRAM_NAME
|
||||
bin = MachoToApp.new
|
||||
bin.main
|
||||
end
|
Loading…
Reference in New Issue