Skip to content

Commit e1cfc74

Browse files
committed
Move jsobfu to a mixin
1 parent cd03746 commit e1cfc74

File tree

4 files changed

+95
-67
lines changed

4 files changed

+95
-67
lines changed

lib/msf/core/exploit/jsobfu.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
], Exploit::JSObfu)
13+
end
14+
15+
#
16+
# Returns an JSObfu object. A wrapper of ::Rex::Exploitation::JSObfu.new(js).obfuscate
17+
#
18+
# @param js [String] JavaScript code
19+
# @param opts [Hash] obfuscation options
20+
# * :iterations [FixNum] Number of times to obfuscate
21+
# @return [::Rex::Exploitation::JSObfu]
22+
#
23+
def js_obfuscate(js, opts={})
24+
iterations = (opts[:iterations] || datastore['JsObfuscate']).to_i
25+
obfu = ::Rex::Exploitation::JSObfu.new(js)
26+
obfu.obfuscate(:iterations=>iterations)
27+
obfu
28+
end
29+
30+
end
31+
end

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require 'cgi'
55
require 'date'
66
require 'rex/exploitation/js'
7+
require 'msf/core/exploit/jsobfu'
78

89
###
910
#
@@ -17,6 +18,7 @@ module Exploit::Remote::BrowserExploitServer
1718

1819
include Msf::Exploit::Remote::HttpServer::HTML
1920
include Msf::Exploit::RopDb
21+
include Msf::Exploit::JSObfu
2022

2123
# this must be static between runs, otherwise the older cookies will be ignored
2224
DEFAULT_COOKIE_NAME = '__ua'
@@ -82,8 +84,7 @@ def initialize(info={})
8284

8385
register_advanced_options([
8486
OptString.new('CookieName', [false, "The name of the tracking cookie", DEFAULT_COOKIE_NAME]),
85-
OptString.new('CookieExpiration', [false, "Cookie expiration in years (blank=expire on exit)"]),
86-
OptInt.new('JsObfuscate', [false, "Number of times to obfuscate JavaScript", 0])
87+
OptString.new('CookieExpiration', [false, "Cookie expiration in years (blank=expire on exit)"])
8788
], Exploit::Remote::BrowserExploitServer)
8889
end
8990

@@ -554,20 +555,5 @@ def get_payload(cli, browser_info)
554555
regenerate_payload(cli, platform, arch).encoded
555556
end
556557

557-
#
558-
# Returns an JSObfu object. A wrapper of ::Rex::Exploitation::JSObfu.new(js).obfuscate
559-
#
560-
# @param js [String] JavaScript code
561-
# @param opts [Hash] obfuscation options
562-
# * :iterations [FixNum] Number of times to obfuscate
563-
# @return [::Rex::Exploitation::JSObfu]
564-
#
565-
def js_obfuscate(js, opts={})
566-
iterations = (opts[:iterations] || datastore['JsObfuscate']).to_i
567-
obfu = ::Rex::Exploitation::JSObfu.new(js)
568-
obfu.obfuscate(:iterations=>iterations)
569-
obfu
570-
end
571-
572558
end
573559
end
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
require 'spec_helper'
2+
require 'msf/core'
3+
require 'msf/core/exploit/jsobfu'
4+
5+
6+
describe Msf::Exploit::JSObfu do
7+
subject(:jsobfu) do
8+
mod = ::Msf::Module.new
9+
mod.extend described_class
10+
mod.send(:initialize, {})
11+
mod
12+
end
13+
14+
let (:js) do
15+
%Q|alert("hello, world");|
16+
end
17+
18+
let(:default_jsobfuscate) do
19+
0
20+
end
21+
22+
before do
23+
subject.datastore['JsObfuscate'] = default_jsobfuscate
24+
end
25+
26+
context 'when iteration is set' do
27+
it 'returns a ::Rex::Exploitation::JSObfu object' do
28+
opts = {:iterations=>0}
29+
obj = jsobfu.js_obfuscate(js, opts)
30+
expect(obj).to be_kind_of(::Rex::Exploitation::JSObfu)
31+
end
32+
33+
it 'does not obfuscate if iteration is 0' do
34+
opts = {:iterations=>0}
35+
obj = jsobfu.js_obfuscate(js, opts)
36+
expect(obj.to_s).to include js
37+
end
38+
39+
it 'obfuscates if iteration is 1' do
40+
opts = {:iterations=>1}
41+
obj = jsobfu.js_obfuscate(js, opts)
42+
expect(obj.to_s).not_to include js
43+
end
44+
end
45+
46+
context 'when iteration is nil' do
47+
let (:opts) do
48+
{:iterations=>nil}
49+
end
50+
51+
it 'should return a ::Rex::Exploitation::JSObfu object' do
52+
obj = jsobfu.js_obfuscate(js, opts)
53+
expect(obj).to be_kind_of(::Rex::Exploitation::JSObfu)
54+
end
55+
56+
it 'should not obfuscate' do
57+
obj = jsobfu.js_obfuscate(js, opts)
58+
expect(obj.to_s).to include(js)
59+
end
60+
end
61+
end

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

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -298,54 +298,4 @@
298298
end
299299
end
300300

301-
describe '#js_obfuscate' do
302-
let (:js) do
303-
%Q|alert("hello, world");|
304-
end
305-
306-
let(:default_jsobfuscate) do
307-
0
308-
end
309-
310-
before do
311-
subject.datastore['JsObfuscate'] = default_jsobfuscate
312-
end
313-
314-
context 'when iteration is set' do
315-
it 'returns a ::Rex::Exploitation::JSObfu object' do
316-
opts = {:iterations=>0}
317-
obj = server.js_obfuscate(js, opts)
318-
expect(obj).to be_kind_of(::Rex::Exploitation::JSObfu)
319-
end
320-
321-
it 'does not obfuscate if iteration is 0' do
322-
opts = {:iterations=>0}
323-
obj = server.js_obfuscate(js, opts)
324-
expect(obj.to_s).to include js
325-
end
326-
327-
it 'obfuscates if iteration is 1' do
328-
opts = {:iterations=>1}
329-
obj = server.js_obfuscate(js, opts)
330-
expect(obj.to_s).not_to include js
331-
end
332-
end
333-
334-
context 'when iteration is nil' do
335-
let (:opts) do
336-
{:iterations=>nil}
337-
end
338-
339-
it 'should return a ::Rex::Exploitation::JSObfu object' do
340-
obj = server.js_obfuscate(js, opts)
341-
expect(obj).to be_kind_of(::Rex::Exploitation::JSObfu)
342-
end
343-
344-
it 'should not obfuscate' do
345-
obj = server.js_obfuscate(js, opts)
346-
expect(obj.to_s).to include(js)
347-
end
348-
end
349-
end
350-
351301
end

0 commit comments

Comments
 (0)