Skip to content

Commit 311cc5b

Browse files
committed
Land rapid7#3668 - Add specs for Rex::Exploitation::HeapLib
2 parents 7bf6377 + f812d26 commit 311cc5b

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

lib/rex/exploitation/heaplib.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ def load_js(custom_js, opts = {})
8888

8989
if opts[:newobfu]
9090
# Obfuscate the javascript using the new lexer method
91-
@js = JSObfu.new(@js)
92-
return @js.obfuscate
91+
js_obfu = JSObfu.new(@js)
92+
js_obfu.obfuscate
93+
@js = js_obfu.to_s
94+
return @js
9395
elsif opts[:noobfu]
9496
# Do not obfuscate, let the exploit do the work (useful to avoid double obfuscation)
9597
return @js
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# -*- coding:binary -*-
2+
require 'spec_helper'
3+
4+
require 'rex/exploitation/heaplib'
5+
6+
describe Rex::Exploitation::HeapLib do
7+
8+
let(:custom_code) { "var test = 'metasploit';" }
9+
let(:plain_signature) { 'JavaScript Heap Exploitation library' }
10+
let(:signature) { 'function(maxAlloc, heapBase)' }
11+
let(:methods) {
12+
[
13+
'lookasideAddr',
14+
'lookaside',
15+
'flushOleaut32',
16+
'freeOleaut32',
17+
'allocOleaut32',
18+
'paddingStr',
19+
'debugBreak',
20+
'debugHeap'
21+
]
22+
}
23+
24+
subject(:heap_lib_class) do
25+
described_class.allocate
26+
end
27+
28+
subject(:heap_lib) do
29+
described_class.new
30+
end
31+
32+
describe "#initialize" do
33+
it "returns an String" do
34+
expect(heap_lib_class.send(:initialize)).to be_a(String)
35+
end
36+
37+
it "returns the heap lib code" do
38+
expect(heap_lib_class.send(:initialize)).to include(signature)
39+
end
40+
41+
it "obfuscates with ObfuscateJS by default" do
42+
methods.each do |m|
43+
expect(heap_lib_class.send(:initialize)).to_not include(m)
44+
end
45+
end
46+
47+
it "allows to provide custom JS code as argument" do
48+
expect(heap_lib_class.send(:initialize, custom_code)).to include(custom_code)
49+
end
50+
51+
it "allows to disable obfuscation" do
52+
expect(heap_lib_class.send(:initialize, '', {:noobfu => true})).to include(plain_signature)
53+
end
54+
55+
it "allows to use JSObfu for obfuscation" do
56+
expect(heap_lib_class.send(:initialize, '', {:newobfu => true})).to_not include(plain_signature)
57+
end
58+
end
59+
60+
describe "#to_s" do
61+
it "returns the heap lib js code" do
62+
expect(heap_lib.to_s).to include(signature)
63+
end
64+
end
65+
66+
end

0 commit comments

Comments
 (0)