Skip to content

Commit 8bf9e98

Browse files
committed
PingCastle 2.10.0.0
1 parent c99d964 commit 8bf9e98

File tree

199 files changed

+3980
-729
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+3980
-729
lines changed

ADWS/ADConnection.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public static string EncodeSidToString(string sid)
5353
{
5454
try
5555
{
56+
Trace.WriteLine("Encoding sid: " + sid);
5657
var realsid = new System.Security.Principal.SecurityIdentifier(sid);
5758
var bytesid = new byte[realsid.BinaryLength];
5859
realsid.GetBinaryForm(bytesid, 0);
@@ -71,5 +72,8 @@ public static string EncodeSidToString(string sid)
7172

7273
public abstract IFileConnection FileConnection {get;}
7374

75+
76+
77+
public abstract void ThreadInitialization();
7478
}
7579
}

ADWS/ADItem.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ static ADItem()
131131
public string AttributeID { get; set; }
132132
[ADAttributeAttribute("cACertificate", ADAttributeValueKind.CertificateStore)]
133133
public X509Certificate2Collection CACertificate { get; set; }
134+
[ADAttributeAttribute("certificateTemplates", ADAttributeValueKind.StringArrayValue)]
135+
public string[] CertificateTemplates { get; set; }
134136
[ADAttributeAttribute("description", ADAttributeValueKind.StringValue)]
135137
public string Description { get; set; }
136138
[ADAttributeAttribute("displayName", ADAttributeValueKind.StringValue)]
@@ -171,8 +173,12 @@ static ADItem()
171173
public ActiveDirectorySecurity msDSAllowedToActOnBehalfOfOtherIdentity { get; set; }
172174
[ADAttributeAttribute("msDS-AllowedToDelegateTo", ADAttributeValueKind.StringArrayValue)]
173175
public string[] msDSAllowedToDelegateTo { get; set; }
176+
[ADAttributeAttribute("mS-DS-CreatorSID", ADAttributeValueKind.SIDValue)]
177+
public SecurityIdentifier msDSCreatorSID { get; set; }
174178
[ADAttributeAttribute("msDS-EnabledFeature", ADAttributeValueKind.StringArrayValue)]
175179
public string[] msDSEnabledFeature { get; set; }
180+
[ADAttributeAttribute("msDS-IntId", ADAttributeValueKind.IntValue)]
181+
public int msDSIntId { get; set; }
176182
[ADAttributeAttribute("msDS-SupportedEncryptionTypes", ADAttributeValueKind.IntValue)]
177183
public int msDSSupportedEncryptionTypes { get; set; }
178184
[ADAttributeAttribute("msDS-MinimumPasswordAge", ADAttributeValueKind.LongValue)]
@@ -203,6 +209,18 @@ static ADItem()
203209
public string[] msDSNeverRevealGroup { get; set; }
204210
[ADAttributeAttribute("msDS-TrustForestTrustInfo", ADAttributeValueKind.ForestInfoValue)]
205211
public List<HealthCheckTrustDomainInfoData> msDSTrustForestTrustInfo { get; set; }
212+
[ADAttributeAttribute("msPKI-Certificate-Name-Flag", ADAttributeValueKind.IntValue)]
213+
public int msPKICertificateNameFlag { get; set; }
214+
[ADAttributeAttribute("msPKI-Cert-Template-OID", ADAttributeValueKind.StringValue)]
215+
public string msPKICertTemplateOID { get; set; }
216+
[ADAttributeAttribute("msPKI-Enrollment-Flag", ADAttributeValueKind.IntValue)]
217+
public int msPKIEnrollmentFlag { get; set; }
218+
[ADAttributeAttribute("msPKI-Private-Key-Flag", ADAttributeValueKind.IntValue)]
219+
public int msPKIPrivateKeyFlag { get; set; }
220+
[ADAttributeAttribute("msPKI-RA-Application-Policies", ADAttributeValueKind.StringValue)]
221+
public string msPKIRAApplicationPolicies { get; set; }
222+
[ADAttributeAttribute("msPKI-Template-Schema-Version", ADAttributeValueKind.IntValue)]
223+
public int msPKITemplateSchemaVersion { get; set; }
206224
[ADAttributeAttribute("msiFileList", ADAttributeValueKind.StringArrayValue)]
207225
public string[] msiFileList { get; set; }
208226
[ADAttributeAttribute("name", ADAttributeValueKind.StringValue)]
@@ -217,6 +235,12 @@ static ADItem()
217235
public int ObjectVersion { get; set; }
218236
[ADAttributeAttribute("operatingSystem", ADAttributeValueKind.StringValue)]
219237
public string OperatingSystem { get; set; }
238+
[ADAttributeAttribute("operatingSystemVersion", ADAttributeValueKind.StringValue)]
239+
public string OperatingSystemVersion { get; set; }
240+
[ADAttributeAttribute("pKIExtendedKeyUsage", ADAttributeValueKind.StringArrayValue)]
241+
public string[] pKIExtendedKeyUsage { get; set; }
242+
[ADAttributeAttribute("possSuperiors", ADAttributeValueKind.StringArrayValue)]
243+
public string[] possSuperiors { get; set; }
220244
[ADAttributeAttribute("primaryGroupID", ADAttributeValueKind.IntValue)]
221245
public int PrimaryGroupID { get; set; }
222246
[ADAttributeAttribute("pwdLastSet", ADAttributeValueKind.DateValue)]
@@ -239,6 +263,8 @@ static ADItem()
239263
public string SiteObject { get; set; }
240264
[ADAttributeAttribute("siteObjectBL", ADAttributeValueKind.StringArrayValue)]
241265
public string[] SiteObjectBL { get; set; }
266+
[ADAttributeAttribute("subClassOf", ADAttributeValueKind.StringValue)]
267+
public string subClassOf { get; set; }
242268
[ADAttributeAttribute("trustAttributes", ADAttributeValueKind.IntValue)]
243269
public int TrustAttributes { get; set; }
244270
[ADAttributeAttribute("trustDirection", ADAttributeValueKind.IntValue)]

ADWS/ADWSConnection.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ private void EnumerateInternalWithADWS(string distinguishedName, string filter,
351351
Trace.WriteLine("[" + DateTime.Now.ToLongTimeString() + "]Getting Enumerate page " + pagenum);
352352
Pull pull = new Pull();
353353
pull.EnumerationContext = enumerateResponse.EnumerationContext;
354-
pull.MaxElements = "500";
354+
pull.MaxElements = LDAPConnection.PageSize.ToString();
355355
if (nTSecurityDescriptor || DomainScope)
356356
{
357357

@@ -451,11 +451,16 @@ public override IFileConnection FileConnection
451451
get
452452
{
453453
if (fileConnection == null)
454-
fileConnection = new WindowsFileConnection(this.Credential);
454+
fileConnection = new WindowsFileConnection(this.Credential, Server);
455455
return fileConnection;
456456
}
457457
}
458458

459+
public override void ThreadInitialization()
460+
{
461+
FileConnection.ThreadInitialization();
462+
}
463+
459464
void CleanConnection<TChannel>(ClientBase<TChannel> c) where TChannel : class
460465
{
461466
if (c != null)

ADWS/ADWebService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ public IFileConnection FileConnection
330330
}
331331
}
332332

333+
public void ThreadInitialization()
334+
{
335+
connection.ThreadInitialization();
336+
}
337+
333338
#region IDispose
334339
public void Dispose()
335340
{
@@ -370,6 +375,5 @@ protected virtual void Dispose(bool disposing)
370375
Dispose(false);
371376
}
372377
#endregion IDispose
373-
374378
}
375379
}

ADWS/IADConnection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ public interface IADConnection
1414

1515
IFileConnection FileConnection { get; }
1616

17+
void ThreadInitialization();
18+
1719
}
1820
}

ADWS/LDAPConnection.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public LDAPConnection(string server, int port, NetworkCredential credential)
2121
Port = port;
2222
Credential = credential;
2323
}
24+
public static int PageSize = 500;
2425

2526
public override void Enumerate(string distinguishedName, string filter, string[] properties, WorkOnReturnedObjectByADWS callback, string scope)
2627
{
@@ -49,7 +50,7 @@ private void EnumerateInternalWithLDAP(string distinguishedName, string filter,
4950
DirectorySearcher clsDS = new DirectorySearcher(entry);
5051
clsDS.SearchRoot = entry;
5152
clsDS.Filter = filter;
52-
clsDS.PageSize = 500;
53+
clsDS.PageSize = PageSize;
5354
switch (scope)
5455
{
5556
case "OneLevel":
@@ -77,8 +78,37 @@ private void EnumerateInternalWithLDAP(string distinguishedName, string filter,
7778
}
7879
}
7980
Trace.WriteLine("[" + DateTime.Now.ToLongTimeString() + "]Calling FindAll");
80-
foreach (SearchResult sr in clsDS.FindAll())
81+
var iterator = clsDS.FindAll().GetEnumerator();
82+
while(true)
8183
{
84+
try
85+
{
86+
if (!iterator.MoveNext())
87+
break;
88+
}
89+
catch (DirectoryServicesCOMException ex)
90+
{
91+
if (ex.ErrorCode == -2147024662 && ex.ExtendedError == 234)
92+
{
93+
Console.ForegroundColor = ConsoleColor.Yellow;
94+
Console.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] Warning: received \"Calling GetNextRow can potentially return more results\"");
95+
Trace.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] Warning: received \"Calling GetNextRow can potentially return more results\"");
96+
Console.ResetColor();
97+
if (!iterator.MoveNext())
98+
{
99+
Console.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] No more results");
100+
Trace.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] No more results");
101+
break;
102+
}
103+
Console.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] More results found");
104+
Trace.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] More results found");
105+
}
106+
else
107+
{
108+
throw;
109+
}
110+
}
111+
var sr = (SearchResult) iterator.Current;
82112
ADItem aditem = null;
83113
try
84114
{
@@ -229,9 +259,14 @@ public override IFileConnection FileConnection
229259
get
230260
{
231261
if (fileConnection == null)
232-
fileConnection = new WindowsFileConnection(this.Credential);
262+
fileConnection = new WindowsFileConnection(this.Credential, Server);
233263
return fileConnection;
234264
}
235265
}
266+
267+
public override void ThreadInitialization()
268+
{
269+
FileConnection.ThreadInitialization();
270+
}
236271
}
237272
}

ADWS/LinuxConnection.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,11 @@ protected override ADDomainInfo GetDomainInfoInternal()
181181
Trace.WriteLine(control);
182182
}
183183
}
184-
Trace.WriteLine("supportedLDAPVersion: ");
184+
Trace.WriteLine("namingContexts: ");
185185
info.NamingContexts = new List<string>();
186186
foreach (var nc in GetValues(result, "namingContexts"))
187187
{
188+
Trace.WriteLine(nc);
188189
info.NamingContexts.Add(nc);
189190
}
190191
return info;
@@ -412,6 +413,11 @@ public LDAPException(int code)
412413
}
413414
}
414415

416+
417+
public override void ThreadInitialization()
418+
{
419+
420+
}
415421
}
416422

417423

ADWS/LinuxFileConnection.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ static private void SetString(IntPtr dest, string str, int maxLen)
338338
Marshal.Copy(buffer, 0, dest, buffer.Length);
339339
}
340340

341+
public void ThreadInitialization()
342+
{
343+
}
344+
341345
#region pinvoke
342346
internal const string SmbLibrary = "libPingCastlesmb";
343347

@@ -463,6 +467,8 @@ protected virtual void Dispose(bool disposing)
463467
Dispose(false);
464468
}
465469
#endregion IDispose
470+
471+
466472
}
467473

468474
internal class LinuxFileStream : Stream
@@ -478,6 +484,7 @@ public override int Read(byte[] buffer, int offset, int count)
478484
IntPtr mem = Marshal.AllocHGlobal(count);
479485
var result = smbc_read(descriptor, mem, count);
480486
Marshal.Copy(mem, buffer, offset, count);
487+
Marshal.FreeHGlobal(mem);
481488
return result;
482489
}
483490

ADWS/WindowsFileConnection.cs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public interface IFileConnection : IDisposable
2626
string PathCombine(string path1, string path2);
2727
List<string> GetAllSubDirectories(string path);
2828
List<string> GetAllSubFiles(string path);
29+
30+
void ThreadInitialization();
2931
}
3032

3133
internal class WindowsFileConnection : IFileConnection
@@ -78,11 +80,11 @@ public bool DirectoryExists(string path)
7880
WindowsIdentity identity;
7981
WindowsImpersonationContext context;
8082

81-
public WindowsFileConnection(NetworkCredential credential)
83+
public WindowsFileConnection(NetworkCredential credential, string server)
8284
{
8385
if (credential != null)
8486
{
85-
identity = GetWindowsIdentityForUser(credential);
87+
identity = GetWindowsIdentityForUser(credential, server);
8688
context = identity.Impersonate();
8789
}
8890
}
@@ -101,25 +103,36 @@ private void Unmount()
101103
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
102104
private static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
103105

106+
[DllImport("kernel32.dll", SetLastError = true)]
107+
private static extern bool CloseHandle(IntPtr hObject);
108+
104109
// logon types
105110
const int LOGON32_LOGON_NEW_CREDENTIALS = 9;
106111

107112
// logon providers
108113
const int LOGON32_PROVIDER_DEFAULT = 0;
109114

110-
public static WindowsIdentity GetWindowsIdentityForUser(NetworkCredential credential, string optionalRemoteserver = null)
115+
public static WindowsIdentity GetWindowsIdentityForUser(NetworkCredential credential, string remoteserver)
111116
{
112117
IntPtr token = IntPtr.Zero;
113-
string domain = credential.Domain;
114-
if (String.IsNullOrEmpty(domain))
115-
domain = optionalRemoteserver;
116-
Trace.WriteLine("Preparing to login with login = " + credential.UserName + " domain = " + domain);
117-
bool isSuccess = LogonUser(credential.UserName, (credential.UserName.Contains("@") ? null : domain), credential.Password, LOGON32_LOGON_NEW_CREDENTIALS, LOGON32_PROVIDER_DEFAULT, ref token);
118+
Trace.WriteLine("Preparing to login with login = " + credential.UserName + " remoteserver = " + remoteserver);
119+
var szDomain = credential.Domain;
120+
if (string.IsNullOrEmpty(szDomain))
121+
{
122+
if (!credential.UserName.Contains("@"))
123+
{
124+
szDomain = remoteserver;
125+
}
126+
}
127+
128+
bool isSuccess = LogonUser(credential.UserName, szDomain, credential.Password, LOGON32_LOGON_NEW_CREDENTIALS, LOGON32_PROVIDER_DEFAULT, ref token);
118129
if (!isSuccess)
119130
{
120131
throw new Win32Exception();
121132
}
122-
return new WindowsIdentity(token);
133+
var output = new WindowsIdentity(token);
134+
CloseHandle(token);
135+
return output;
123136
}
124137

125138
#region IDispose
@@ -201,5 +214,12 @@ public List<string> GetAllSubFiles(string path)
201214
{
202215
return new List<string>(Directory.GetFiles(path, "*.*", SearchOption.AllDirectories));
203216
}
217+
218+
219+
public void ThreadInitialization()
220+
{
221+
if (identity != null)
222+
identity.Impersonate();
223+
}
204224
}
205225
}

0 commit comments

Comments
 (0)