diff --git a/lib/msf/core/exploit/remote/browser_exploit_server.rb b/lib/msf/core/exploit/remote/browser_exploit_server.rb index 5fe6914203..8a574e88d5 100644 --- a/lib/msf/core/exploit/remote/browser_exploit_server.rb +++ b/lib/msf/core/exploit/remote/browser_exploit_server.rb @@ -561,9 +561,10 @@ module Msf # @param iteration [FixNum] number of times to obfuscate # @return [::Rex::Exploitation::JSObfu] # - def js_obfuscate(js, iteration) + def js_obfuscate(js, opts={}) + iterations = (opts[:iterations] || datastore['JsObfuscate']).to_i obfu = ::Rex::Exploitation::JSObfu.new(js) - obfu.obfuscate(:iterations=>iteration) + obfu.obfuscate(:iterations=>iterations) obfu end diff --git a/spec/lib/msf/core/exploit/remote/browser_exploit_server_spec.rb b/spec/lib/msf/core/exploit/remote/browser_exploit_server_spec.rb index d553e1ee54..af4ed22eae 100644 --- a/spec/lib/msf/core/exploit/remote/browser_exploit_server_spec.rb +++ b/spec/lib/msf/core/exploit/remote/browser_exploit_server_spec.rb @@ -303,38 +303,46 @@ describe Msf::Exploit::Remote::BrowserExploitServer do %Q|alert("hello, world");| end + let(:default_jsobfuscate) do + 0 + end + + before do + subject.datastore['JsObfuscate'] = default_jsobfuscate + end + context 'when iteration is set' do it 'returns a ::Rex::Exploitation::JSObfu object' do - iteration = 1 - obj = server.js_obfuscate(js, iteration) + opts = {:iterations=>0} + obj = server.js_obfuscate(js, opts) expect(obj).to be_kind_of(::Rex::Exploitation::JSObfu) end it 'does not obfuscate if iteration is 0' do - iteration = 0 - obj = server.js_obfuscate(js, iteration) + opts = {:iterations=>0} + obj = server.js_obfuscate(js, opts) expect(obj.to_s).to include js end it 'obfuscates if iteration is 1' do - iteration = 1 - obj = server.js_obfuscate(js, iteration) + opts = {:iterations=>1} + obj = server.js_obfuscate(js, opts) expect(obj.to_s).not_to include js end end context 'when iteration is nil' do - let (:iteration) do - nil + let (:opts) do + {:iterations=>nil} end it 'should return a ::Rex::Exploitation::JSObfu object' do - obj = server.js_obfuscate(js, iteration) + obj = server.js_obfuscate(js, opts) expect(obj).to be_kind_of(::Rex::Exploitation::JSObfu) end it 'should not obfuscate' do - obj = server.js_obfuscate(js, iteration) + obj = server.js_obfuscate(js, opts) expect(obj.to_s).to include(js) end end