Class: Rex::Exploitation::VBSObfuscate
- Inherits:
-
Object
- Object
- Rex::Exploitation::VBSObfuscate
- Defined in:
- lib/rex/exploitation/vbsobfuscate.rb
Overview
VBScript obfuscation library
Instance Attribute Summary collapse
-
#code ⇒ Object
The VBScript code that this obfuscator will transform.
Instance Method Summary collapse
-
#<<(str) ⇒ Object
Append
strto the (possibly obfuscated) code. -
#initialize(code = nil, _opts = {}) ⇒ VBSObfuscate
constructor
Saves
codefor later obfuscation with #obfuscate!. -
#obfuscate!(iterations: 1, normalize_whitespace: true, dynamic_execution: true) ⇒ self
Obfuscate VBScript code.
-
#to_s ⇒ String
The (possibly obfuscated) code.
Constructor Details
#initialize(code = nil, _opts = {}) ⇒ VBSObfuscate
Saves code for later obfuscation with #obfuscate!
16 17 18 |
# File 'lib/rex/exploitation/vbsobfuscate.rb', line 16 def initialize(code = nil, _opts = {}) self.code = code end |
Instance Attribute Details
#code ⇒ Object
The VBScript code that this obfuscator will transform
10 11 12 |
# File 'lib/rex/exploitation/vbsobfuscate.rb', line 10 def code @code end |
Instance Method Details
#<<(str) ⇒ Object
Append str to the (possibly obfuscated) code
26 27 28 |
# File 'lib/rex/exploitation/vbsobfuscate.rb', line 26 def <<(str) @code << str end |
#obfuscate!(iterations: 1, normalize_whitespace: true, dynamic_execution: true) ⇒ self
Obfuscate VBScript code.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rex/exploitation/vbsobfuscate.rb', line 37 def obfuscate!(iterations: 1, normalize_whitespace: true, dynamic_execution: true) raise(ArgumentError, 'code must be present') if @code.nil? raise(ArgumentError, 'iterations must be a positive integer') unless iterations.integer? && iterations.positive? = @code.dup iterations.times do # Normalize line endings and strip leading/trailing whitespace if normalize_whitespace .gsub!(/\r\n/, "\n") = .lines.map(&:strip).reject(&:empty?).join("\n") end # Convert all VBScript to a string to be dynamically executed with Execute() if dynamic_execution = 'Execute ' + vbscript_string_for_execute() end # Obfuscate strings = chunk_vbscript_strings() .gsub!(/"((?:[^"]|"")*)"/) do raw = ::Regexp.last_match(1).gsub('""', '"') raw.chars.map { |c| "chr(#{generate_number_expression(c.ord)})" }.join('&') end # Obfuscate integers .gsub!(/\b\d+\b/) do |num| generate_number_expression(num.to_i) end end @code = self end |
#to_s ⇒ String
Returns the (possibly obfuscated) code.
21 22 23 |
# File 'lib/rex/exploitation/vbsobfuscate.rb', line 21 def to_s @code end |