2007-04-03 07:35:54 +00:00
|
|
|
require 'rex/text'
|
|
|
|
require 'rex/exploitation/obfuscatejs'
|
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Exploitation
|
|
|
|
|
2007-04-03 07:36:33 +00:00
|
|
|
#
|
|
|
|
# Encapsulates the generation of the Alexander Sotirov's HeapLib javascript
|
|
|
|
# stub
|
|
|
|
#
|
2007-04-03 07:35:54 +00:00
|
|
|
class HeapLib
|
|
|
|
|
|
|
|
#
|
|
|
|
# The source file to load the javascript from
|
|
|
|
#
|
2008-01-25 03:15:26 +00:00
|
|
|
JavascriptFile = File.join(File.dirname(__FILE__), "heaplib.js.b64")
|
2007-04-03 07:35:54 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# The list of symbols found in the file. This is used to dynamically
|
|
|
|
# replace contents.
|
|
|
|
#
|
|
|
|
SymbolNames =
|
|
|
|
{
|
|
|
|
"Methods" =>
|
|
|
|
[
|
|
|
|
"vtable",
|
|
|
|
"lookasideAddr",
|
|
|
|
"lookaside",
|
|
|
|
"freeList",
|
|
|
|
"gc",
|
|
|
|
"flushOleaut32",
|
|
|
|
"freeOleaut32",
|
|
|
|
"allocOleaut32",
|
|
|
|
"free",
|
|
|
|
"alloc",
|
|
|
|
"addr",
|
|
|
|
"hex",
|
|
|
|
"round",
|
|
|
|
"paddingStr",
|
|
|
|
"padding",
|
|
|
|
"debugBreak",
|
|
|
|
"debugHeap",
|
|
|
|
"debug",
|
|
|
|
],
|
|
|
|
"Classes" =>
|
|
|
|
[
|
|
|
|
{ 'Namespace' => "heapLib", 'Class' => "ie" }
|
|
|
|
],
|
|
|
|
"Namespaces" =>
|
|
|
|
[
|
|
|
|
"heapLib"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Initializes the heap library javascript
|
|
|
|
#
|
|
|
|
def initialize(custom_js = '')
|
|
|
|
load_js(custom_js)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the replaced version of the javascript
|
|
|
|
#
|
|
|
|
def to_s
|
|
|
|
@js
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
#
|
|
|
|
# Loads the raw javascript from the source file and strips out comments
|
|
|
|
#
|
|
|
|
def load_js(custom_js)
|
2008-01-25 03:15:26 +00:00
|
|
|
|
2007-04-03 07:35:54 +00:00
|
|
|
# Grab the complete javascript
|
|
|
|
File.open(JavascriptFile) { |f|
|
|
|
|
@js = f.read
|
|
|
|
}
|
2008-01-25 03:15:26 +00:00
|
|
|
|
|
|
|
# Decode the text
|
|
|
|
@js = Rex::Text.decode_base64(@js)
|
|
|
|
|
|
|
|
# Append the real code
|
2007-04-03 07:35:54 +00:00
|
|
|
@js += "\n" + custom_js
|
|
|
|
|
|
|
|
# Obfuscate the javascript
|
|
|
|
@js = ObfuscateJS.obfuscate(@js, 'Symbols' => SymbolNames)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2008-10-19 21:03:39 +00:00
|
|
|
end
|