Git Product home page Git Product logo

passfiltex's Introduction

GitHub all releases

PassFiltEx.c

PassFiltEx by Joseph Ryan Ries

Author: Joseph Ryan Ries 2019-2023 [email protected] [email protected]

A password filter for Active Directory that uses a blacklist of bad passwords/character sequences.

Reference: https://msdn.microsoft.com/en-us/library/windows/desktop/ms721882(v=vs.85).aspx


READ ME

This is a personal project and is NOT endorsed or supported by Microsoft in any way.

Use at your own risk. This code is not guaranteed to be free of errors, and comes

with no guarantees, liability, warranties or support.


I wrote this just to join the club of people who can say that they've done it. Programming is fun.

Installation:

  • Copy PassFiltEx.dll into the C:\Windows\System32 (or %SystemRoot%\System32) directory.

  • Copy the PassFiltExBlacklist.txt file into the C:\Windows\System32 (or %SystemRoot%\System32) directory.

  • (Or replace the text file with a list of your own. You are free to edit the blacklist file if you want.)

  • IMPORTANT: You MUST go find your own blacklist file. The blacklist file that comes with this project is not sufficient to meet your needs on its own. There are many example blacklists of known-bad passwords out there, many hosted right here on GitHub!

  • Edit the registry: HKLM\SYSTEM\CurrentControlSet\Control\Lsa => Notification Packages

  • Add PassFiltEx to the end of the list. (Do not include the file extension.) So the whole list of notification packages will read "rassfm scecli PassFiltEx" with newlines between each one.

  • Reboot the domain controller.

  • Repeat the above procedure on all domain controllers.

files

regedit

Operation:

  • Any time a user attempts to change his or her password, or any time an administrator attempts to set a user's password, the callback in this password filter will be invoked.

  • All password filters must say yes in order for the password change to be accepted. If any password filter says no, the password is not accepted. Therefore, this password filter does not need to check for password length, password complexity, password age, etc., because those things are already checked for using the in-box Windows password policy.

  • Optionally, you can set the following registry values:

    Subkey: HKLM\SOFTWARE\PassFiltEx

    BlacklistFileName, REG_SZ, Default: PassFiltExBlacklist.txt

    TokenPercentageOfPassword, REG_DWORD, Default: 60

    RequireEitherLowerOrUpper, REG_DWORD, Default: 0

    MinLower, REG_DWORD, Default: 0

    MinUpper, REG_DWORD, Default: 0

    MinDigit, REG_DWORD, Default: 0

    MinSpecial, REG_DWORD, Default: 0

    MinUnicode, REG_DWORD, Default: 0

regedit

BlacklistFileName allows you to specify a custom path to a blacklist file. By default if there is nothing specified, it is PassFiltExBlacklist.txt. The current working directory of the password filter is %SystemRoot%\System32, but you can specify a fully-qualified path name too. Even a UNC path (such as something in SYSVOL) if you want. WARNING: You are responsible for properly setting the permissions on the blacklist file so that it may only be edited and viewed by authorized users. You can store the blacklist file in SYSVOL if you want, but you must ask yourself whether you want all Authenticated Users to have the ability to read your blacklist file.

TokenPercentageOfPassword allows you specify how much of the entire password must consist of the blacklisted token before the password change is rejected. The default is 60% if nothing is specified. The registry value is REG_DWORD, with the value 60 decimal representing 60%, which is converted to float 0 - 1.0 at runtime. For example, if the character sequence starwars appeared in the blacklist file, and TokenPercentageOfPassword was set to 60, then the password Starwars1! would be rejected, because more than 60% of the proposed password is made up of the blacklisted term starwars. However, the password starwars1!DarthVader88 would be accepted, because even though it contains the blacklisted sequence starwars, more than 60% of the proposed password is NOT starwars.

MinLower/MinUpper/etc. allows you to specify if you require the user's password to contain multiple instances of any given character class. For example setting MinDigit to 2 will require passwords to contain at least 2 digits.

  • Comparisons are NOT case sensitive. (Though the final password will of course still be case sensitive.)

  • The blacklist is reloaded every 60 seconds, so feel free to edit the blacklist file at will. The password filter will read the new updates within a minute.

  • Registry settings are re-read every 60 seconds as well so you can change the registry settings without having to restart the whole machine.

  • All registry settings are optional. They do not need to exist. If a registry setting does not exist, the default is used.

  • Unicode support is not thoroughly tested or reliable at this time. Everything is ASCII/ANSI. (You can still use Unicode characters in your passwords, but Unicode characters will not match against anything in the blacklist.)

  • Either Windows or Unix line endings (either \r\n or \n) in the blacklist file should both work. (Notepad++ is a good editor for finding unprintable characters in your text file.)

  • For example, if the blacklist contains the token "abc", then the passwords abc and abc123 and AbC123 and 123Abc will all be rejected. But Abc123! will be accepted, because the token abc does not make up 60% or more of the full password.

  • Question: Can you/will you integrate with Troy Hunt's "haveibeenpwned" API? Answer: Probably not. First, I'm pretty sure that has already been done by someone else. And you are free to use multiple password filters simultaneously if you want. Second, haveibeenpwned is about matching password hashes to identify passwords that have already been owned. This password filter aims to solve a slightly different problem by preventing not just passwords that have already been owned, but also preventing the use of passwords that could easily be owned because they contain common patterns, even if those password hashes are not known yet.

  • NOTE: This binary is not signed with a code signing certificate, which means the DLL will not load if LSA Protection, aka RunAsPPL is enabled. Only by getting the module signed by Microsoft as outlined here will the password filter load into lsass if LSA Protection is enabled.

Debugging:

  • The RELEASE build of the password filter uses only ETW event logging. The DEBUG build logs to ETW, stdout console and also DebugOut. (You can use Sysinternal's DbgView to view DebugOut messages.) WARNING: Debug builds print the passwords out into the logging, which is a security risk. Release builds do not print passwords. This project also contains another program, PassFiltExTest.exe, which allows you to test the functionality of the password filter in a simple console program where you just type sample passwords, but it only works with the Debug build.

  • The password filter utilizes Event Tracing for Windows (ETW). ETW is fast, lightweight, and there is no concern over managing text-based log files which are slow and consume disk space.

  • The ETW provider for this password filter is 07d83223-7594-4852-babc-784803fdf6c5. So for example, you can enable tracing of the password filter on the next boot of the machine with: logman create trace autosession\PassFiltEx -o %SystemRoot%\Debug\PassFiltEx.etl -p "{07d83223-7594-4852-babc-784803fdf6c5}" 0xFFFFFFFF -ets

  • The trace will start when you reboot. To stop the trace, run: logman stop PassFiltEx -ets && logman delete autosession\PassFiltEx -ets

  • The StartTracingAtBoot.cmd and StopTracingAtBoot.cmd files provided contain these commands.

  • The other files, StartTracing.cmd and StopTracing.cmd will also enable the tracing, but the tracing will not persist across reboots.

  • Collect the *.etl file that is generated in the C:\Windows\debug directory. Then open the ETL file with a tool such as Microsoft Message Analyzer. (There are other tools that understand ETW as well. Use what you like.) Add the "payload" as a Column, and decode the payload column as Unicode. Then it should look like a normal, human-readable text log.

starttrace

etw1

etw2

etw1

  • In the trace log above, you see an administrator attempting to set the password for the user hunter2. If the user had been attempting to reset their own password, the log would say "CHANGE password" instead of "SET password". Notice that the password is rejected numerous times. I tried to set the password to starwars, starwars1, Starwars1!, etc., but they all were rejected because the blacklist contains the token starwars. However, I eventually attempted to set the password to Starwars1!DarthVader, and that password was accepted because even though it contains the token starwars, more than 50% of the password is NOT starwars.

Coding Guidelines:

  • Want to contribute? Cool! I'd like to stick to these rules:

  • C only. (No C++, at least not in the filter itself.)

  • Compile with All Warnings (/Wall). Project should compile with 0 warnings. You MAY temporarily disable warnings with #pragmas if the warnings are too pedantic (e.g. don't warn me about adding padding bytes to structs or that a function was inlined.)

  • MSVC 2017 was the IDE I used originally. You can use something else if you have a good reason to though.

  • Use a static analyzer. The MSVC IDE comes with Code Analysis. Put it on "All Rules". You shouldn't trigger any Code Analysis warnings.

  • Define UNICODE.

  • Prefix global symbols with a lower-case g, no underscore. (E.g. gGlobalVar, not g_GlobalVar)

  • Hungarian notation not necessary. Use descriptive variable names. We don't use 80-character terminals anymore; it's OK to type it out.

  • Comments are good but don't make a lot of comments about what the code does - instead write comments about why you're doing what you're doing.

  • This code ABSOLUTELY MUST NOT CRASH. If it crashes, it will crash the lsass process of the domain controller, which will in turn reboot the domain controller. It can even render a domain controller unbootable. You'd need to boot the machine from alternate media and edit the registry offline to remove the password filter from the registry. Therefore, this code must be immaculate and as reliable as you can possibly imagine. Avoid being "clever" and just write "boring" code.

passfiltex's People

Contributors

allquixotic avatar bobvul avatar ryanries avatar ryanriesmsft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

passfiltex's Issues

Can you show a custom message

Can you show a custom message on password bad password default windows message shows nothing at all user might not know why is the password bad
Ps:- just a suggestion your tool is awesome

.dll file

Thanks for this project! One of the people I follow on twitter posted a link to it. Your readme file states that we should copy the PassFiltEx.dll file to the System32 folder. I do not see the .dll file available to download. I should mention that I am not a programmer.

Thanks.

Applying RunAsPPL make PassFiltEx didn't work

Hi, I've been trying to implementing PassFiltEx as a password protection in my domain. In my LAB for fresh installed and basic AD configuration it runs perfectly without any issue. But when I enable LSA protection (RunAsPPL), PassFiltEx did not work. Is anyone ever encounter this? Is there any workaround for this?

Thanks.
P.S. I'm using Windows Server 2019 as a domain controller.

Password tolower() not converting the last character

I noticed that here by wcslen(PasswordCopy) - 1, the last character of the password seems to be left out without converting to lowercase on Windows 10 and make it possible to bypass the blacklist:

for (unsigned int Counter = 0; Counter < wcslen(PasswordCopy) - 1; Counter++)

I thought it should be ended with \0 so your code should be correct but with a quick console printing it seem to say otherwise.

Could you confirm it's the case (and if there're other places that may have the same logical error)?

Empty password shown as allowed

The PasswordIsOK = FALSE; seems missing from the above section, which will make empty password shown as "allowed":

EventWriteStringW2(L"[%s:%s@%d] Empty password! Cannot continue.", __FILENAMEW__, __FUNCTIONW__, __LINE__);

Or it's done this way so the Admin can actually set the password as empty on purpose?

Custom error message

Hi Ryan! Thanks for your amazing password filter. I was able to deploy it on my environment and works flawlessly.
I would like to customize the error message that DC server returns to the users. Would it be possible with PassFiltEx?

Best regards.

We can't reset krbtgt_xxxxx passwords for RODC

Hello Ryan,
Like previous closed case #11
we can't reset krbtgt_xxxxx passwords (KRBTGT accounts for RODCs).
Do you have a workaround except "disabling PassFiltEx" during reset process (which involves 2 DC reboots......) ?

no dll in v1.19

Hello,

There doesn't appear to be a .dll in the most recent release. It is present in previous releases.

Question: SecureZeroMemory

Hi there,

I'm new to Windows API. I read on the Microsoft Doc that password buffer should be securely zero out once used. I saw the related code were comment out.

Is there a particular reason not to have not enabled? (And I noticed that if they were in place, the Test program will quit on the end of every password attempt.)

Measured effectiveness of many filters, PassFiltEx is the best

I thought you might be interested to know that yours is the best password filter.
For the first part of my master thesis, I measured the effectiveness of the following:

OpenPasswordFilter
passfiltex
passwdqc
zxcvbn
libpwquality

For each, I fed in a large number of passwords that actually DID get cracked after the hashes were leaked.
I also fed in a large number of passwords chosen by users to represent the passwords people want to use.

I calculated the effectiveness of a password filter / meter by it's ability to:

A. Reject passwords that ended up getting cracked.
B. Reject a low percentage of passwords overall

Your software did the best at distinguishing passwords that get cracked.

passwdqc is made by Solar Designer - the same guy who makes John the Ripper.
So you beat Solar Designer.

With default settings, PassFiltEx blocked 17% of the crackedpasswords, and only 7% overall. That gives it a net score of +10%.
PassFiltEx has the best score of the tested systems.

That might not seem like an incredibly high score, but three of the five systems tested had NEGATIVE scores.
They were more likely to allow a password that ended up getting cracked than to allow a password generally.

It seems that what sets PassFiltEx apart is the "if 60% of the password consists of a known string" function.
Checking to see if the password is MOSTLY made up of a word in your dictionary works much better than other methods.

I hope it brings a smile to your face to know you've made the best password filter.
The second half of my thesis project is I will attempt to blow you out of the water with a much better system. :)

  • If I fail to make a much better system, I'll fall back to using yours and sending you some PRs with improvements.

Memory consumption and performance

We are using kwprocessor to generate key walk password combinations to blacklist. One of the higher level “routes” generates all QWERTY keyboard password combinations from 2 to 16 characters with up to four “direction changes” while walking. This creates a 187 MB password database.

This 187 MB file ends up consuming about 3.5 GB when loaded into PassFiltEx, or 18 times the raw file size. But for all that memory usage, it doesn’t appear to vastly improve search performance when doing a password reset. An allowable password takes on the order of 60-90 seconds to validate; blacklisted passwords take a bit less.

The problem is, they take so long to validate that threads in lsass and other processes start to get blocked and queues start filling up because PassFiltEx takes so long. This is not a great experience for a middling password database considering it uses so much memory.

The priority for me would be to improve password validation time. After that, memory consumption, but we can deal with 3.5GB heap in lsass if it’s performant.

For now we are using a much smaller and simpler key walk file using a simpler “route” algorithm, but it isn’t as comprehensive as we’d like. Also, if we decide to append other types of password blacklists to our key walk database (the smaller one is only 3.5 MB), the file size could grow again and the performance would possibly be poor again.

What exactly is the algorithm used that takes up so much RAM while apparently still requiring a linear search? Any ideas for a suitable improvement without completely changing the design goals or scope of PassFiltEx?

Sent with GitHawk

Character Class Requirement

Is there any interest to allow a code submission to enable a per-character class requirement in addition to the word blacklist? This is an unachievable policy requirement for a ton of organizations, mostly those who do contract work for various government entities and to date I have never found a solid solution to meet this requirement.

I personally do not have the skillset to do this, but if there is a willingness to allow a pull request to add these features I am willing to either compensate you directory (if you want) or look for a 3rd party to commit to this repo. Wanted to ensure I had your blessing before going down that route.

I will also build a admx/adml file to compliment the new functionality.

Users accounts gets locked out when accessing shared folder

Hi Ryanries,
I used your DLL as a password filter following the instructions from the readme in your repo, but some of the users within my local domain get locked out due to the Kerberos authentication service.
I changed their password into a complex one that respects the filter but it keeps getting locked out, I restarted the client machine after and before changing the password, and I restarted the AD but I still have the same issue. the issue occurs once the user connects to a shared folder.
Note: that the majority of users have their accounts working fine but I have this problem with some of them.
it would be helpful if you can help me figure it out & thanks

Format string: incorrect number of arguments?

At PassFiltEx.c:472 we have:

	EventWriteStringW2(L"[%s:%s@%d] ERROR: This blacklist token is 0 characters long. It will be skipped. Check your blacklist file for blank lines!", __FILENAMEW__, __FUNCTIONW__, __LINE__, CurrentNode->String);

If I am reading this correctly, we end up calling _vsnwprintf_s() with a format string that accepts three arguments (%s, %s, and %d) but passing four actual arguments: __FILENAMEW__, __FUNCTIONW__, __LINE__, and CurrentNode->String.

Found this while doing a quick audit on the code. Amazingly, I didn't find any other issues -- the code is extremely well-written and a huge relief after the nightmare of OpenPasswordFilter :-)

Note: HP Fortify complains about the unchecked path passed to CreateFileW() at PassFiltEx.c:541 possibly leading to directory traversal.

I don't view this Fortify finding as an issue, because the key being read is in HKLM, and only Administrators can write to HKLM. Still, I'm not sure if there's some built-in C function that will refuse to allow path traversal that you could use instead. Or maybe you want to allow path traversal, so you could stick the file in C:\, say, and give the path as ..\..\passwords.txt? Either way, this seems like a silly issue to me.

Thanks for the work on this!

Crash when resetting password while blacklist does not exist

Steps to repro:

  1. Deploy PassFiltEx normally, but don't install a dictionary; or, point the registry key to a path that does not point to an existing file.
  2. Try to reset a password.
  3. Observe that LSASS crashes.

Also reproducible using PassFiltExTest (which is in one of my PRs).

Fixed in PR #4.

If the blacklist reloading interval questions.

The blacklist is reloaded every 60 seconds, so feel free to edit the blacklist file at will. The password filter will read the new updates within a minute.

//

  1. If the blacklist reloading interval can be modified?
  2. If the blacklist file is not changed, will it be reloaded?

thank a lot.

Crash on a 0-byte blacklist file

The blacklist dictionary linked list apparently gets corrupted when switching back and forth between a 0-byte dictionary and a non-0-byte dictionary.

Steps to repro:

  • Create two dictionary files. File1.txt will be a valid dictionary with some passwords. File2.txt will be a file with zero bytes of data inside it.
  • Start up PassFiltEx or PassFiltExTest with the registry pointing to File1.txt.
  • Once File1.txt is finished parsing, change the registry to point to File2.txt.
  • Observe that LSASS (or PassFiltExTest) crashes.

I wasn't able to isolate where the memory corruption comes from, but it looks like it happens when trying to traverse the linked list to delete the old blacklist.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.