CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/core/exploit/jsobfu.rb
Views: 11784
1
# -*- coding: binary -*-
2
3
require 'rex/exploitation/jsobfu'
4
5
module Msf
6
module Exploit::JSObfu
7
8
def initialize(info={})
9
super
10
register_advanced_options([
11
OptInt.new('JsObfuscate', [false, "Number of times to obfuscate JavaScript", 0]),
12
OptString.new('JsIdentifiers', [false, "Identifiers to preserve for JsObfu"])
13
], Exploit::JSObfu)
14
end
15
16
#
17
# Returns an JSObfu object. A wrapper of ::Rex::Exploitation::JSObfu.new(js).obfuscate
18
#
19
# @param js [String] JavaScript code
20
# @param opts [Hash] obfuscation options
21
# * :iterations [FixNum] Number of times to obfuscate
22
# * :preserved_identifiers [Array] An array of identifiers to preserve during obfuscation
23
# @return [::Rex::Exploitation::JSObfu]
24
#
25
def js_obfuscate(js, opts={})
26
iterations = (opts[:iterations] || datastore['JsObfuscate']).to_i
27
identifiers = opts[:preserved_identifiers].blank? ? (datastore['JsIdentifiers'] || '').split(',') : opts[:preserved_identifiers]
28
obfu = ::Rex::Exploitation::JSObfu.new(js)
29
obfu_opts = {}
30
obfu_opts.merge!(iterations: iterations)
31
obfu_opts.merge!(preserved_identifiers: identifiers)
32
33
obfu.obfuscate(obfu_opts)
34
obfu
35
end
36
37
end
38
end
39
40