@@ -227,12 +227,17 @@ public List<ActiveDirectoryUser> GetAllDomainUsers(IEnumerable<string> userSamAc
227227 if ( lastBadPwdTime == null )
228228 {
229229 var intEntry = entry . Attributes . GetIfExists < int ? > ( "badPasswordTime" ) ;
230- if ( intEntry == 0 )
230+ if ( intEntry == 0 || intEntry == null )
231231 {
232232 lastBadPwdTime = entry . Attributes . GetIfExists < DateTime ? > ( "createTimeStamp" ) ?? DateTime . MinValue ;
233233 }
234234 }
235235
236+ if ( badPwdCount == null )
237+ {
238+ badPwdCount = 0 ;
239+ }
240+
236241 if ( badPwdCount == null || lastBadPwdTime == null )
237242 {
238243 var sam = entry . Attributes . GetIfExists ( "sAMAccountName" ) ;
@@ -369,11 +374,15 @@ public async void SprayPasswords(
369374 var cancellationTokenSource = new CancellationTokenSource ( ) ;
370375 var saveTask = Task . Run ( async ( ) =>
371376 {
372- while ( ! cancellationTokenSource . Token . IsCancellationRequested )
377+ try
373378 {
374- await Task . Delay ( TimeSpan . FromSeconds ( 10 ) ) ;
375- SaveUnsavedAttempts ( unsavedAttempts , noDb ) ;
379+ while ( ! cancellationTokenSource . Token . IsCancellationRequested )
380+ {
381+ await Task . Delay ( TimeSpan . FromSeconds ( 10 ) , cancellationTokenSource . Token ) ;
382+ SaveUnsavedAttempts ( unsavedAttempts , noDb ) ;
383+ }
376384 }
385+ catch ( OperationCanceledException ) { }
377386 } , cancellationTokenSource . Token ) ;
378387
379388 try
@@ -516,7 +525,7 @@ public async void SprayPasswords(
516525 finally
517526 {
518527 cancellationTokenSource . Cancel ( ) ;
519- saveTask . Wait ( ) ;
528+ try { saveTask . Wait ( ) ; } catch ( AggregateException ) { }
520529 SaveUnsavedAttempts ( unsavedAttempts , noDb ) ;
521530 }
522531 }
0 commit comments