Skip to content

Commit 9191af6

Browse files
committed
Update js_obfuscate
1 parent a9420be commit 9191af6

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

lib/msf/core/exploit/remote/browser_exploit_server.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,10 @@ def get_payload(cli, browser_info)
561561
# @param iteration [FixNum] number of times to obfuscate
562562
# @return [::Rex::Exploitation::JSObfu]
563563
#
564-
def js_obfuscate(js, iteration)
564+
def js_obfuscate(js, opts={})
565+
iterations = (opts[:iterations] || datastore['JsObfuscate']).to_i
565566
obfu = ::Rex::Exploitation::JSObfu.new(js)
566-
obfu.obfuscate(:iterations=>iteration)
567+
obfu.obfuscate(:iterations=>iterations)
567568
obfu
568569
end
569570

spec/lib/msf/core/exploit/remote/browser_exploit_server_spec.rb

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,38 +303,46 @@
303303
%Q|alert("hello, world");|
304304
end
305305

306+
let(:default_jsobfuscate) do
307+
0
308+
end
309+
310+
before do
311+
subject.datastore['JsObfuscate'] = default_jsobfuscate
312+
end
313+
306314
context 'when iteration is set' do
307315
it 'returns a ::Rex::Exploitation::JSObfu object' do
308-
iteration = 1
309-
obj = server.js_obfuscate(js, iteration)
316+
opts = {:iterations=>0}
317+
obj = server.js_obfuscate(js, opts)
310318
expect(obj).to be_kind_of(::Rex::Exploitation::JSObfu)
311319
end
312320

313321
it 'does not obfuscate if iteration is 0' do
314-
iteration = 0
315-
obj = server.js_obfuscate(js, iteration)
322+
opts = {:iterations=>0}
323+
obj = server.js_obfuscate(js, opts)
316324
expect(obj.to_s).to include js
317325
end
318326

319327
it 'obfuscates if iteration is 1' do
320-
iteration = 1
321-
obj = server.js_obfuscate(js, iteration)
328+
opts = {:iterations=>1}
329+
obj = server.js_obfuscate(js, opts)
322330
expect(obj.to_s).not_to include js
323331
end
324332
end
325333

326334
context 'when iteration is nil' do
327-
let (:iteration) do
328-
nil
335+
let (:opts) do
336+
{:iterations=>nil}
329337
end
330338

331339
it 'should return a ::Rex::Exploitation::JSObfu object' do
332-
obj = server.js_obfuscate(js, iteration)
340+
obj = server.js_obfuscate(js, opts)
333341
expect(obj).to be_kind_of(::Rex::Exploitation::JSObfu)
334342
end
335343

336344
it 'should not obfuscate' do
337-
obj = server.js_obfuscate(js, iteration)
345+
obj = server.js_obfuscate(js, opts)
338346
expect(obj.to_s).to include(js)
339347
end
340348
end

0 commit comments

Comments
 (0)