Skip to content

Commit 829248f

Browse files
committed
Land rapid7#3840, @wchen-r7's tweaks to os.js and module addition.
2 parents d52236f + 2e96026 commit 829248f

File tree

8 files changed

+186
-91
lines changed

8 files changed

+186
-91
lines changed

data/js/detect/ie_addons.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
window.ie_addons_detect = { };
1+
var ie_addons_detect = { };
22

33
/**
44
* Returns true if this ActiveX is available, otherwise false.
55
* Grabbed this directly from browser_autopwn.rb
66
**/
7-
window.ie_addons_detect.hasActiveX = function (axo_name, method) {
7+
ie_addons_detect.hasActiveX = function (axo_name, method) {
88
var axobj = null;
99
if (axo_name.substring(0,1) == String.fromCharCode(123)) {
1010
axobj = document.createElement("object");
@@ -41,7 +41,7 @@ window.ie_addons_detect.hasActiveX = function (axo_name, method) {
4141
/**
4242
* Returns the version of Microsoft Office. If not found, returns null.
4343
**/
44-
window.ie_addons_detect.getMsOfficeVersion = function () {
44+
ie_addons_detect.getMsOfficeVersion = function () {
4545
var version;
4646
var types = new Array();
4747
for (var i=1; i <= 5; i++) {

data/js/detect/misc_addons.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
window.misc_addons_detect = { };
1+
var misc_addons_detect = { };
22

33

44
/**
55
* Detects whether the browser supports Silverlight or not
66
**/
7-
window.misc_addons_detect.hasSilverlight = function () {
7+
misc_addons_detect.hasSilverlight = function () {
88
var found = false;
99

1010
//
@@ -49,7 +49,7 @@ window.misc_addons_detect.hasSilverlight = function () {
4949
/**
5050
* Returns the Adobe Flash version
5151
**/
52-
window.misc_addons_detect.getFlashVersion = function () {
52+
misc_addons_detect.getFlashVersion = function () {
5353
var foundVersion = null;
5454

5555
//
@@ -96,7 +96,7 @@ window.misc_addons_detect.getFlashVersion = function () {
9696
/**
9797
* Returns the Java version
9898
**/
99-
window.misc_addons_detect.getJavaVersion = function () {
99+
misc_addons_detect.getJavaVersion = function () {
100100
var foundVersion = null;
101101

102102
//

data/js/detect/os.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11

22
// Case matters, see lib/msf/core/constants.rb
33
// All of these should match up with constants in ::Msf::HttpClients
4-
clients_opera = "Opera";
5-
clients_ie = "MSIE";
6-
clients_ff = "Firefox";
7-
clients_chrome= "Chrome";
8-
clients_safari= "Safari";
4+
var clients_opera = "Opera";
5+
var clients_ie = "MSIE";
6+
var clients_ff = "Firefox";
7+
var clients_chrome= "Chrome";
8+
var clients_safari= "Safari";
99

1010
// All of these should match up with constants in ::Msf::OperatingSystems
11-
oses_linux = "Linux";
12-
oses_windows = "Microsoft Windows";
13-
oses_mac_osx = "Mac OS X";
14-
oses_freebsd = "FreeBSD";
15-
oses_netbsd = "NetBSD";
16-
oses_openbsd = "OpenBSD";
11+
var oses_linux = "Linux";
12+
var oses_windows = "Microsoft Windows";
13+
var oses_mac_osx = "Mac OS X";
14+
var oses_freebsd = "FreeBSD";
15+
var oses_netbsd = "NetBSD";
16+
var oses_openbsd = "OpenBSD";
1717

1818
// All of these should match up with the ARCH_* constants
19-
arch_armle = "armle";
20-
arch_x86 = "x86";
21-
arch_x86_64 = "x86_64";
22-
arch_ppc = "ppc";
23-
arch_mipsle = "mipsle";
19+
var arch_armle = "armle";
20+
var arch_x86 = "x86";
21+
var arch_x86_64 = "x86_64";
22+
var arch_ppc = "ppc";
23+
var arch_mipsle = "mipsle";
2424

25-
window.os_detect = {};
25+
var os_detect = {};
2626

2727
/**
2828
* This can reliably detect browser versions for IE and Firefox even in the
2929
* presence of a spoofed User-Agent. OS detection is more fragile and
3030
* requires truthful navigator.appVersion and navigator.userAgent strings in
3131
* order to be accurate for more than just IE on Windows.
3232
**/
33-
window.os_detect.getVersion = function(){
33+
os_detect.getVersion = function(){
3434
//Default values:
3535
var os_name;
3636
var os_flavor;
@@ -1121,7 +1121,7 @@ window.os_detect.getVersion = function(){
11211121
return { os_name:os_name, os_flavor:os_flavor, os_sp:os_sp, os_lang:os_lang, arch:arch, ua_name:ua_name, ua_version:ua_version };
11221122
}; // function getVersion
11231123

1124-
window.os_detect.searchVersion = function(needle, haystack) {
1124+
os_detect.searchVersion = function(needle, haystack) {
11251125
var index = haystack.indexOf(needle);
11261126
var found_version;
11271127
if (index == -1) { return; }
@@ -1137,7 +1137,7 @@ window.os_detect.searchVersion = function(needle, haystack) {
11371137
/*
11381138
* Return -1 if a < b, 0 if a == b, 1 if a > b
11391139
*/
1140-
window.ua_ver_cmp = function(ver_a, ver_b) {
1140+
ua_ver_cmp = function(ver_a, ver_b) {
11411141
// shortcut the easy case
11421142
if (ver_a == ver_b) {
11431143
return 0;
@@ -1181,15 +1181,15 @@ window.ua_ver_cmp = function(ver_a, ver_b) {
11811181
return 0;
11821182
};
11831183

1184-
window.ua_ver_lt = function(a, b) {
1184+
ua_ver_lt = function(a, b) {
11851185
if (-1 == this.ua_ver_cmp(a,b)) { return true; }
11861186
return false;
11871187
};
1188-
window.ua_ver_gt = function(a, b) {
1188+
ua_ver_gt = function(a, b) {
11891189
if (1 == this.ua_ver_cmp(a,b)) { return true; }
11901190
return false;
11911191
};
1192-
window.ua_ver_eq = function(a, b) {
1192+
ua_ver_eq = function(a, b) {
11931193
if (0 == this.ua_ver_cmp(a,b)) { return true; }
11941194
return false;
11951195
};

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: 10 additions & 7 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'
@@ -371,27 +373,27 @@ def get_detection_html(user_agent)
371373
372374
373375
window.onload = function() {
374-
var osInfo = window.os_detect.getVersion();
376+
var osInfo = os_detect.getVersion();
375377
var d = {
376378
"<%=REQUIREMENT_KEY_SET[:os_name]%>" : osInfo.os_name,
377379
"<%=REQUIREMENT_KEY_SET[:os_flavor]%>" : osInfo.os_flavor,
378380
"<%=REQUIREMENT_KEY_SET[:ua_name]%>" : osInfo.ua_name,
379381
"<%=REQUIREMENT_KEY_SET[:ua_ver]%>" : osInfo.ua_version,
380382
"<%=REQUIREMENT_KEY_SET[:arch]%>" : osInfo.arch,
381-
"<%=REQUIREMENT_KEY_SET[:java]%>" : window.misc_addons_detect.getJavaVersion(),
382-
"<%=REQUIREMENT_KEY_SET[:silverlight]%>" : window.misc_addons_detect.hasSilverlight(),
383-
"<%=REQUIREMENT_KEY_SET[:flash]%>" : window.misc_addons_detect.getFlashVersion()
383+
"<%=REQUIREMENT_KEY_SET[:java]%>" : misc_addons_detect.getJavaVersion(),
384+
"<%=REQUIREMENT_KEY_SET[:silverlight]%>" : misc_addons_detect.hasSilverlight(),
385+
"<%=REQUIREMENT_KEY_SET[:flash]%>" : misc_addons_detect.getFlashVersion()
384386
};
385387
386388
<% if os == OperatingSystems::WINDOWS and client == HttpClients::IE %>
387-
d['<%=REQUIREMENT_KEY_SET[:office]%>'] = window.ie_addons_detect.getMsOfficeVersion();
389+
d['<%=REQUIREMENT_KEY_SET[:office]%>'] = ie_addons_detect.getMsOfficeVersion();
388390
d['<%=REQUIREMENT_KEY_SET[:mshtml_build]%>'] = ScriptEngineBuildVersion().toString();
389391
<%
390392
clsid = @requirements[:clsid]
391393
method = @requirements[:method]
392394
if clsid and method
393395
%>
394-
d['activex'] = window.ie_addons_detect.hasActiveX('<%=clsid%>', '<%=method%>');
396+
d['activex'] = ie_addons_detect.hasActiveX('<%=clsid%>', '<%=method%>');
395397
<% end %>
396398
<% end %>
397399
@@ -453,7 +455,8 @@ def on_request_uri(cli, request)
453455
ua = request.headers['User-Agent'] || ''
454456
init_profile(tag)
455457
print_status("Sending response HTML.")
456-
send_response(cli, get_detection_html(ua), {'Set-Cookie' => cookie_header(tag)})
458+
html = get_detection_html(ua)
459+
send_response(cli, html, {'Set-Cookie' => cookie_header(tag)})
457460

458461
when /#{@info_receiver_page}/
459462
#
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 'returns 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 'does not obfuscate' do
57+
obj = jsobfu.js_obfuscate(js, opts)
58+
expect(obj.to_s).to include(js)
59+
end
60+
end
61+
end

0 commit comments

Comments
 (0)