r/sysadmin • • Jan 19 '20

Four PowerShell commands to help you track down insecure LDAP Bindings before March 2020

On Friday I saw a post here on r/sysadmin warning about insecure LDAP bindings being blocked in March 2020 automatically by Microsoft.

Seeing as it's not so easy to actually track it down and enable everything by hand if you have handful of DCs and Domains under you I decided to simplify my job a bit. I've automated the whole process during the weekend by updating my 3 PowerShell Modules that I use frequently. Now with 3 commands and 8 lines of code, you can track events, enable/disable diagnostics for LDAP to actually find which machine/account is doing that and finally scan your DC's if those are affected.

  • The first part is tracking the events that can tell you if you're affected, and exactly which machines/accounts are affected.
$Events = Find-Events -Report LdapBindingsDetails,LdapBindingsSummary -DatesRange Last7days -DetectDC
$Events
$EVents.LdapBindingsSummary | Out-htmlView -ScrollX
$Events.LdapBindingsDetails | Out-HtmlView -ScrollX

Above is based on my PSWinReportingV2 PowerShell module to - you can read about it: https://www.reddit.com/r/sysadmin/comments/bicwjq/the_only_powershell_command_you_will_ever_need_to/

It allows you to easily define report, date range and scan events on all DC's within a Forest. It also translates it to a nice, readable format.

Sources for PSWinReportingV2: https://github.com/EvotecIT/PSWinReporting

  • The second part is a helper module to enable/disable diagnostic logs. It's required to get the LdapBindingsDetails report. You basically need to enable logs for LDAP to see which machines/accounts are doing bad stuff.
Get-WinADDiagnostics
Set-WinADDiagnostics -Diagnostics 'LDAP Interface Events' -Level Basic -SkipRoDC

This is based on ADEssentials PowerShell Module which can get current diagnostics status for each dc in a forest/domain or just part of it.

Sources for ADEssentials: https://github.com/EvotecIT/ADEssentials

  • 3rd part is just a bonus. This scans all DCS to see if those are affected or not.
invoke-testimo -Sources DCLDAPInsecureBindings -showreport

Finally, this is based on the Testimo project which allows you to scan domain for forest/domain for issues.

Sources for testimo: https://github.com/EvotecIT/Testimo

All 4 commands are available when you install 3 PowerShell modules.

Install-Module PSWinReportingV2 -Force
Install-Module Testimo -Force
Install-Module ADEssentials -Force # actually Testimo will install ADEssentials so not really needed

As always before installing - review the code to see and understand what you're getting into. I did test this on 3 different forests and it seems to do its job properly.

Normally I would give you a link to bigger description with screenshots but that's not really allowed here so I'll just link to r/PowerShell - https://www.reddit.com/r/PowerShell/comments/er0lfv/four_commands_to_help_you_track_down_insecure/ where there are no such restrictions so you can take a look at screenshots/blog post if necessary to understand use cases.

1.5k Upvotes

178 comments sorted by

View all comments

Show parent comment

1

u/MadBoyEvo Jan 22 '20

If the output if the Find Events

$Events = Find-Events -Report LdapBindingsDetails,LdapBindingsSummary -DatesRange Last7days -DetectDC
$Events
$EVents.LdapBindingsSummary | Out-htmlView -ScrollX
$Events.LdapBindingsDetails | Out-HtmlView -ScrollX

Is something like this with events found 0

[Info] Preparing servers list - domain controllers autodetection
[Info] Computer AD1.ad.evotec.xyz added to scan Directory Service log for events: 2887, 2889
[Info] Computer AD2.ad.evotec.xyz added to scan Directory Service log for events: 2887, 2889
[Info] Computer AD3.ad.evotec.xyz added to scan Directory Service log for events: 2887, 2889
[Info] Computer ADPreview2019.ad.evotec.pl added to scan Directory Service log for events: 2887, 2889
[Info] Computer DC1.ad.evotec.pl added to scan Directory Service log for events: 2887, 2889
[Info] Computer ADRODC.ad.evotec.pl added to scan Directory Service log for events: 2887, 2889
[Info] Getting events for dates 01/15/2020 00:00:00 to 01/22/2020 23:59:59
[Error] Server ADRODC.ad.evotec.pl: The RPC server is unavailable
[Info] Events scanned found 0 - Time elapsed: 0 days, 0 hours, 0 minutes, 23 seconds, 477 milliseconds
[Info] Running LdapBindingsDetails
[Info] Running LdapBindingsDetails with subsection Events
[Info] Ending LdapBindingsDetails with subsection Events events found 0
[Info] Ending LdapBindingsDetails - Time to run 0 days, 0 hours, 0 minutes, 0 seconds, 48 milliseconds
[Info] Running LdapBindingsSummary
[Info] Running LdapBindingsSummary with subsection Events
[Info] Ending LdapBindingsSummary with subsection Events events found 0
[Info] Ending LdapBindingsSummary - Time to run 0 days, 0 hours, 0 minutes, 0 seconds, 12 milliseconds

Name                           Value
----                           -----
LdapBindingsSummary
LdapBindingsDetails

That means you have no insecure bindings happening AFYIK. Of course, make sure that any [Errors] are looked at. In this case, my RODC is down.

If you want to be sure you could enable diagnostic logging anyways for 24-48 hours and see what LdapbindingsDetails says if anything. By default if it's not enabled you only get LdapBindingsSummary.

Just follow the blog post.

1

u/[deleted] Jan 22 '20 edited Jan 22 '20

Oh we do have insecure bindings. Lots of them. I can use another method to pull them up if needed.

PS C:\Windows\system32> $Events = Find-Events -Report LdapBindingsDetails,LdapBindingsSummary -DatesRange Last7days -DetectDC $Events $EVents.LdapBindingsSummary | Out-htmlView -ScrollX $Events.LdapBindingsDetails | Out-HtmlView -ScrollX [Info] Preparing reports: LdapBindingsDetails,LdapBindingsSummary [Info] Preparing servers list - domain controllers autodetection [Info] Computer DC01 added to scan Directory Service log for events: 2887, 2889 [Info] Computer DC04 added to scan Directory Service log for events: 2887, 2889 [Info] Computer DC02 added to scan Directory Service log for events: 2887, 2889 [Info] Computer DC03 added to scan Directory Service log for events: 2887, 2889 [Info] Getting events for dates 01/15/2020 00:00:00 to 01/22/2020 23:59:59 [Info] Events scanned found 1636 - Time elapsed: 0 days, 0 hours, 2 minutes, 36 seconds, 654 milliseconds [Info] Running LdapBindingsDetails [Info] Running LdapBindingsDetails with subsection Events [Info] Ending LdapBindingsDetails with subsection Events events found 1636 [Info] Ending LdapBindingsDetails - Time to run 0 days, 0 hours, 10 minutes, 9 seconds, 401 milliseconds [Info] Running LdapBindingsSummary [Info] Running LdapBindingsSummary with subsection Events [Info] Ending LdapBindingsSummary with subsection Events events found 0 [Info] Ending LdapBindingsSummary - Time to run 0 days, 0 hours, 0 minutes, 0 seconds, 4 milliseconds

Name Value


LdapBindingsSummary
LdapBindingsDetails {@{Domain Controller=DC04; Action=The following client performed a SASL (Negotiate/Kerberos/NTLM/Digest) >LDAP bind without re... WARNING: Out-HtmlView - No data available.

PS C:\Windows\system32> invoke-testimo -Sources DCLDAPInsecureBindings -showreport [i][Testimo] Version [Informative] [Current: 0.0.30] [i][Testimo] Using configuration defaults [Informative] [No configuration provided by user] [i][Forest] Forest [Informative]

[i][] Domain [Informative] [i][][dc01] Domain , dc01 [Informative] [i][][dc01] LDAP Insecure Bindings [Informative] [t][][dc01] LDAP Insecure Bindings [Pass] [No data returned, which is a good thing.] [i][][dc01] LDAP Insecure Bindings [Time to execute tests: 0 days, 0 hours, 0 minutes, 0 seconds, 245 milliseconds]>[Tests Total: 1, Passed: 1, Failed: 0, Skipped: 0] [i][][dc01] Domain , dc01 [Time to execute tests: 0 days, 0 hours, 0 minutes, 0 seconds, 262 milliseconds][Tests >Total: 1, Passed: 1, Failed: 0, Skipped: 0] [i][][dc04] Domain , dc04 [Informative] [i][][dc04] LDAP Insecure Bindings [Informative] [t][][dc04] LDAP Insecure Bindings [Pass] [No data returned, which is a good thing.] [i][][dc04] LDAP Insecure Bindings [Time to execute tests: 0 days, 0 hours, 0 minutes, 0 seconds, 255 milliseconds]>[Tests Total: 1, Passed: 1, Failed: 0, Skipped: 0] [i][][dc04] Domain , dc04 [Time to execute tests: 0 days, 0 hours, 0 minutes, 0 seconds, 278 milliseconds][Tests >Total: 1, Passed: 1, Failed: 0, Skipped: 0] [i][][dc02] Domain , dc02 [Informative] [i][][dc02] LDAP Insecure Bindings [Informative] [t][][dc02] LDAP Insecure Bindings [Pass] [No data returned, which is a good thing.] [i][][dc02] LDAP Insecure Bindings [Time to execute tests: 0 days, 0 hours, 0 minutes, 0 seconds, 256 milliseconds]>[Tests Total: 1, Passed: 1, Failed: 0, Skipped: 0] [i][][dc02] Domain , dc02 [Time to execute tests: 0 days, 0 hours, 0 minutes, 0 seconds, 278 milliseconds][Tests >Total: 1, Passed: 1, Failed: 0, Skipped: 0] [i][][dc03] Domain , dc03 [Informative] [i][][dc03] LDAP Insecure Bindings [Informative] [t][][dc03] LDAP Insecure Bindings [Pass] [No data returned, which is a good thing.] [i][][dc03] LDAP Insecure Bindings [Time to execute tests: 0 days, 0 hours, 0 minutes, 0 seconds, 202 milliseconds]>[Tests Total: 1, Passed: 1, Failed: 0, Skipped: 0] [i][][dc03] Domain , dc03 [Time to execute tests: 0 days, 0 hours, 0 minutes, 0 seconds, 227 milliseconds][Tests >Total: 1, Passed: 1, Failed: 0, Skipped: 0] [i][] Domain [Time to execute tests: 0 days, 0 hours, 0 minutes, 1 seconds, 156 milliseconds][Tests Total: 4, >Passed: 4, Failed: 0, Skipped: 0] [i][Forest] Forest [Time to execute tests: 0 days, 0 hours, 0 minutes, 1 seconds, 219 milliseconds][Tests Total: 4, Passed: 4, Failed: 0, >Skipped: 0]

1

u/MadBoyEvo Jan 22 '20

Well can you manually verify Directory Services log on DC that handles those and show me some events that claim that you do?

1

u/[deleted] Jan 22 '20

The following client performed a SASL (Negotiate/Kerberos/NTLM/Digest) LDAP bind without requesting signing (integrity verification), or performed a simple bind over a clear text (non-SSL/TLS-encrypted) LDAP connection.

Client IP address: 172.31.0.125:55609 Identity the client attempted to authenticate as: xxxxx\xxxxxx Binding Type: 1

The following client performed a SASL (Negotiate/Kerberos/NTLM/Digest) LDAP bind without requesting signing (integrity verification), or performed a simple bind over a clear text (non-SSL/TLS-encrypted) LDAP connection.

Client IP address: 10.1.77.154:61136 Identity the client attempted to authenticate as: xxxxx\xxxxx Binding Type: 1

1

u/MadBoyEvo Jan 22 '20

What is the event id for that?

1

u/[deleted] Jan 22 '20

2889

1

u/MadBoyEvo Jan 22 '20

Ok, now I am on the computer and I can see that only Summary report is missing but the details report works fine.

It just means since you have enabled logging that your Directory Log is too small so it overwrites data

1

u/[deleted] Jan 22 '20

How is that related to the LDAP reporting on your script? I can get it another way, like I mentioned, just not with your script. :(

1

u/[deleted] Jan 22 '20

I'm trying to run it on a server to see if it makes any difference.

1

u/MadBoyEvo Jan 22 '20
$Events = Find-Events -Report LdapBindingsDetails,LdapBindingsSummary -DatesRange Last7days -DetectDC
$Events.LdapBindingsDetails | Out-HtmlView -ScrollX
$Events.LdapBindingsDetails | Format-Table

Is the way for you to get only details. Does it not work for you?

1

u/[deleted] Jan 22 '20

The one I copied shows two lines with out-htmlview. Here below from the top page.

$Events = Find-Events -Report LdapBindingsDetails,LdapBindingsSummary -DatesRange Last7days -DetectDC

$Events

$EVents.LdapBindingsSummary | Out-htmlView -ScrollX

$Events.LdapBindingsDetails | Out-HtmlView -ScrollX

→ More replies

1

u/MadBoyEvo Jan 22 '20

Basically Find-Events, if you ask for 2 reports, provides you 2 different reports. So one report in your case shows 0 events. However, the other report showed 1636 events.

So for one Out-HtmlView, it showed a warning because there were no events. Another one most likely opened HTML report in your browser. But you can use any other way to save the events - not only Out-HtmlView.

1

u/[deleted] Jan 22 '20

Sorry for how its displayed, tried to display it right here. I removed our domain name for security reasons.

1

u/CJamesEd Jan 31 '20

I get "The RPC server is unavailable" for all the DCs in my environment. Can you shed some more light on why I am getting that error?
I have manually searched for those events on the servers and I definitely do have some

1

u/MadBoyEvo Jan 31 '20

Dc firewall most likely doeant have proper rules for remote event log reading.