Add in ability for dynamic commands (like Msf) to cache target settings for easy tree display

git-svn-id: https://beef.googlecode.com/svn/trunk@677 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
This commit is contained in:
sussurro@happypacket.net
2011-01-06 16:14:40 +00:00
parent 437db63c82
commit f04a86337f
4 changed files with 74 additions and 9 deletions

View File

@@ -52,6 +52,27 @@ module Constants
end
def self.match_browser(browserstring)
matches = []
browserstring.split(" ").each do |chunk|
case chunk
when /Firefox/ , /FF/
matches << FF
when /Mozilla/
matches << M
when /Internet Explorer/, /IE/
matches << IE
when /Safari/
matches << S
when /Konqueror/
matches << K
when /Chrome/
matches << C
end
end
matches.uniq
end
end
# The User Agent strings for browser detection
@@ -85,6 +106,21 @@ module Constants
OS_MAC_IMG = 'mac.png'
OS_IPHONE_UA_STR = 'iPhone'
OS_IPHONE_IMG = 'iphone.png'
def self.match_os(name)
case name.downcase
when /win/
OS_WINDOWS_UA_STR
when /lin/
OS_LINUX_UA_STR
when /os x/, /osx/, /mac/
OS_MAC_UA_STR
when /iphone/
OS_IPHONE_UA_STR
else
'ALL'
end
end
end

View File

@@ -1,4 +1,3 @@
require 'pp'
module BeEF
#
@@ -50,9 +49,25 @@ class Migration
mod.save
if mod.dynamic_command_info == nil
msfi = msf.get_exploit_info(sploit)
st = sploit.split('/').first
targets = []
os_name = BeEF::Constants::Os::match_os(st)
browsers = BeEF::Constants::Browsers::match_browser(msfi['name'] + msfi['targets'].to_json)
targets << {'os_name' => os_name, 'browser_name' => 'ALL', 'verified_status' => 2} if browsers.count == 0
browsers.each do |bn|
targets << {'os_name' => os_name, 'browser_name' => bn, 'verified_status' => 2}
end
msfci = BeEF::Models::DynamicCommandInfo.new(
:name => msfi['name'],
:description => msfi['description'])
:description => msfi['description'],
:targets => targets.to_json)
mod.dynamic_command_info = msfci
mod.save
end
@@ -98,6 +113,7 @@ class Migration
end
end
end
end

View File

@@ -10,6 +10,7 @@ class DynamicCommandInfo
property :id, Serial
property :name, Text, :lazy => false
property :description, Text, :lazy => false
property :targets, Text, :lazy => false
belongs_to :command_module
end

View File

@@ -1,4 +1,3 @@
require 'pp'
module BeEF
module Modules
module Commands
@@ -20,10 +19,6 @@ class Msf < BeEF::Command
'File' => __FILE__,
})
set_target({
'browser_name' => ALL
})
use 'beef.dom'
use_template!
end
@@ -35,21 +30,39 @@ class Msf < BeEF::Command
def update_info(id)
mod = BeEF::Models::CommandModule.first(:id => id)
msfinfo = nil
targets = []
if mod.dynamic_command_info == nil
msf = BeEF::MsfClient.new
msf.login()
msfinfo = msf.get_exploit_info(mod.name)
st = mod.name.split('/').first
os_name = BeEF::Constants::Os::match_os(st)
browsers = BeEF::Constants::Browsers::match_browser(msfi['name'] + msfi['targets'].to_json)
targets << {'os_name' => os_name, 'browser_name' => 'ALL'} if browsers.count == 0
browsers.each do |bn|
targets << {'os_name' => os_name, 'browser_name' => bn}
end
mod.dynamic_command_info = BeEF::Models::DynamicCommandInfo.new(
:name => msfinfo['name'],
:description => msfinfo['description']);
:description => msfinfo['description'],
:targets => targets.to_json);
mod.save
else
msfinfo = mod.dynamic_command_info
targets = JSON.parse(msfinfo['targets'])
end
@info['Name'] = msfinfo['name']
@info['Description'] = msfinfo['description']
@info['MsfModName'] = mod.name
@target = targets
end
def update_data()
@@ -73,7 +86,6 @@ class Msf < BeEF::Command
else
print "K => #{k}\n"
print "Status => #{msfoptions[k]['advanced']}\n"
p msfoptions[k]
end
}