rapid7 / metasploit-framework

Metasploit Framework
https://www.metasploit.com/
Other
34.23k stars 14k forks source link

Fixing multiple bugs in credential generation + refactoring #19653

Open Mathiou04 opened 1 week ago

Mathiou04 commented 1 week ago

Draft PR linked to issue #19652

Summary

In this PR, I added various tests on the CredentialCollection class, all of them currently failing and illustrating what I think are bugs.

Issues can be grouped in two categories:

I added some comments on each test explaining what it is currently yielding (instead of the result I think should be expected - let me know if I misunderstood anything).

Refactoring opportunity

You will see that there are many bugs linked to the password_spray option.

It seems that this branch of the code has been copy/pasted from the original branch (that didn't handle password spraying) and adapted. There was not a lot of tests on this part of the code + the structure is difficult to maintain which probably explains those issues.

The original code branch (without spraying: #each_unfiltered_username_first) is also a bit complex with a lot of duplicated code.

I think there are some opportunities to simplify and clarify the code a lot with some refactoring.

Non-regression tests

For this, I created 2 additional "non-regression" tests that activate all options and show how the credentials should be yielded. There is one test with password spraying, one without.

I don't know if we want to keep them after the refactoring, but they will surely help.

Also, even if a part of the order in which the credentials are yielded should be "fixed", there are questions around others. For example:

Additional question

As a side note, the nil_passwords, blank_passwords and user_as_pass options do not apply to the userpass file. Is it expected behaviour or should we extend this behaviour to users yielded in the userpass file?

Next steps