Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/core/main/autorun_engine/parser.rb
1154 views
1
#
2
# Copyright (c) 2006-2025 Wade Alcorn - [email protected]
3
# Browser Exploitation Framework (BeEF) - https://beefproject.com
4
# See the file 'doc/COPYING' for copying permission
5
#
6
module BeEF
7
module Core
8
module AutorunEngine
9
class Parser
10
include Singleton
11
12
def initialize
13
@config = BeEF::Core::Configuration.instance
14
end
15
16
BROWSER = %w[FF C IE S O ALL]
17
OS = %w[Linux Windows OSX Android iOS BlackBerry ALL]
18
VERSION = ['<', '<=', '==', '>=', '>', 'ALL', 'Vista', 'XP']
19
CHAIN_MODE = %w[sequential nested-forward]
20
MAX_VER_LEN = 15
21
22
def parse(name, author, browser, browser_version, os, os_version, modules, execution_order, execution_delay, chain_mode)
23
raise ArgumentError, "Invalid rule name: #{name}" unless BeEF::Filters.is_non_empty_string?(name)
24
raise ArgumentError, "Invalid author name: #{author}" unless BeEF::Filters.is_non_empty_string?(author)
25
raise ArgumentError, "Invalid chain_mode definition: #{chain_mode}" unless CHAIN_MODE.include?(chain_mode)
26
raise ArgumentError, "Invalid os definition: #{os}" unless OS.include?(os)
27
28
unless modules.size == execution_delay.size
29
raise ArgumentError, "Number of execution_delay values (#{execution_delay.size}) must be consistent with number of modules (#{modules.size})"
30
end
31
execution_delay.each { |delay| raise TypeError, "Invalid execution_delay value: #{delay}. Values must be Integers." unless delay.is_a?(Integer) }
32
33
unless modules.size == execution_order.size
34
raise ArgumentError, "Number of execution_order values (#{execution_order.size}) must be consistent with number of modules (#{modules.size})"
35
end
36
execution_order.each { |order| raise TypeError, "Invalid execution_order value: #{order}. Values must be Integers." unless order.is_a?(Integer) }
37
38
# if multiple browsers were specified, check each browser
39
if browser.is_a?(Array)
40
browser.each do |b|
41
raise ArgumentError, "Invalid browser definition: #{browser}" unless BROWSER.include?(b)
42
end
43
# else, if only one browser was specified, check browser and browser version
44
else
45
raise ArgumentError, "Invalid browser definition: #{browser}" unless BROWSER.include?(browser)
46
47
if browser_version != 'ALL' && !(VERSION.include?(browser_version[0, 2].gsub(/\s+/, '')) &&
48
BeEF::Filters.is_valid_browserversion?(browser_version[2..-1].gsub(/\s+/, '')) && browser_version.length < MAX_VER_LEN)
49
raise ArgumentError, "Invalid browser_version definition: #{browser_version}"
50
end
51
end
52
53
if os_version != 'ALL' && !(VERSION.include?(os_version[0, 2].gsub(/\s+/, '')) &&
54
BeEF::Filters.is_valid_osversion?(os_version[2..-1].gsub(/\s+/, '')) && os_version.length < MAX_VER_LEN)
55
return ArgumentError, "Invalid os_version definition: #{os_version}"
56
end
57
58
# check if module names, conditions and options are ok
59
modules.each do |cmd_mod|
60
mod = BeEF::Core::Models::CommandModule.where(name: cmd_mod['name']).first
61
62
raise "The specified module name (#{cmd_mod['name']}) does not exist" if mod.nil?
63
64
modk = BeEF::Module.get_key_by_database_id(mod.id)
65
mod_options = BeEF::Module.get_options(modk)
66
67
opt_count = 0
68
mod_options.each do |opt|
69
if opt['name'] != cmd_mod['options'].keys[opt_count]
70
raise ArgumentError, "The specified option (#{cmd_mod['options'].keys[opt_count]}) for module (#{cmd_mod['name']}) was not specified"
71
end
72
73
opt_count += 1
74
end
75
end
76
77
true
78
end
79
end
80
end
81
end
82
end
83
84