Files
beef/extensions/metasploit/dbmigration.rb
scotty.b.brown@gmail.com 5c3e6f1575 Adding Apache Licence Header to all files (except VERSION file)
git-svn-id: https://beef.googlecode.com/svn/trunk@1046 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
2011-07-02 23:08:28 +00:00

97 lines
3.4 KiB
Ruby

#
# Copyright 2011 Wade Alcorn wade@bindshell.net
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module BeEF
module Extension
module Metasploit
module DbMigration
extend BeEF::API::Migration
def self.migrate_commands!
msf = BeEF::Extension::Metasploit::RpcClient.instance
# verify that metasploit is enabled and we are logged in.
if(msf.is_enabled && msf.login())
Thread.new() {
begin
sploits = msf.browser_exploits()
sploits.each do |sploit|
if not BeEF::Core::Models::CommandModule.first(:name => sploit)
mod = BeEF::Core::Models::CommandModule.new(:path => "Dynamic/Msf", :name => sploit)
mod.save
if mod.dynamic_command_info == nil
msfi = msf.get_exploit_info(sploit)
st = sploit.split('/').first
targets = []
os_name = BeEF::Core::Constants::Os::match_os(st)
browsers = BeEF::Core::Constants::Browsers::match_browser(msfi['name'] + msfi['targets'].to_json)
targets << {'os_name' => os_name, 'browser_name' => 'ALL', 'verified_status' =>
BeEF::Core::Constants::CommandModule::VERIFIED_UNKNOWN} if browsers.count == 0
browsers.each do |bn|
targets << {'os_name' => os_name, 'browser_name' => bn, 'verified_status' =>
BeEF::Core::Constants::CommandModule::VERIFIED_WORKING
}
end
targets << {'os_name' => "ALL", 'verified_status' => BeEF::Core::Constants::CommandModule::VERIFIED_NOT_WORKING}
msfci = BeEF::Core::Models::DynamicCommandInfo.new(
:name => msfi['name'],
:description => msfi['description'],
:targets => targets.to_json)
mod.dynamic_command_info = msfci
mod.save
end
end
end
payloads = msf.payloads()
payloads.each do |payload|
if not BeEF::Core::Models::DynamicPayloads.first( :name => payload)
pl = BeEF::Core::Models::DynamicPayloads.new( :name => payload)
pl.save
opts = msf.payload_options(payload)
opts.keys.each do |opt|
next if opts[opt]['advanced'] or opts[opt]['evasion']
pl.dynamic_payload_info.new(:name => opt, :description => opts[opt]['desc'], :required => opts[opt]['required'], :value => opts[opt]['default'])
end
pl.save
end
end
# Catching and printing exceptions in regards to migration
# of Metasploit exploits into BeEF
rescue Exception => e
puts e.message
puts e.backtrace
end
msf.launch_autopwn()
}#thread end
end
end
end
end
end
end