Skip to content

Commit

Permalink
Implement mask-based password recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
kimci86 committed Aug 18, 2024
1 parent ee77b9b commit d897fd8
Show file tree
Hide file tree
Showing 4 changed files with 496 additions and 8 deletions.
15 changes: 15 additions & 0 deletions include/password.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,19 @@ auto recoverPassword(const Keys& keys, const std::vector<std::uint8_t>& charset,
std::size_t maxLength, std::string& start, int jobs, bool exhaustive, Progress& progress)
-> std::vector<std::string>;

/// \brief Try to recover the password associated with the given keys
/// \param keys Internal keys for which a password is wanted
/// \param mask A sequence of character sets, each corresponding to the successive characters of password candidates
/// \param start Starting point in the password search space.
/// Also used as an output parameter to tell where to restart.
/// \param jobs Number of threads to use
/// \param exhaustive True to try and find all valid passwords,
/// false to stop searching after the first one is found
/// \param progress Object to report progress
/// \return A vector of passwords associated with the given keys.
/// A vector is needed instead of a single string because there can be
/// collisions (i.e. several passwords for the same keys).
auto recoverPassword(const Keys& keys, const std::vector<std::vector<std::uint8_t>>& mask, std::string& start, int jobs,
bool exhaustive, Progress& progress) -> std::vector<std::string>;

#endif // BKCRACK_PASSWORD_HPP
25 changes: 17 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,30 @@ try
}

// recover password
if (args.bruteforce)
if (args.bruteforce || args.mask)
{
std::cout << "[" << put_time << "] Recovering password" << std::endl;

auto passwords = std::vector<std::string>{};

const auto [state, restart] = [&]() -> std::pair<Progress::State, std::string>
{
const auto& charset = *args.bruteforce;
const auto& [minLength, maxLength] = args.length.value_or(Arguments::LengthInterval{});
auto start = args.recoveryStart;
auto progress = ConsoleProgress{std::cout};
const auto sigintHandler = SigintHandler{progress.state};
passwords = recoverPassword(keysvec.front(), charset, minLength, maxLength, start, args.jobs,
args.exhaustive, progress);
auto start = args.recoveryStart;
auto progress = ConsoleProgress{std::cout};
const auto sigintHandler = SigintHandler{progress.state};

if (args.bruteforce)
{
const auto& charset = *args.bruteforce;
const auto& [minLength, maxLength] = args.length.value_or(Arguments::LengthInterval{});
passwords = recoverPassword(keysvec.front(), charset, minLength, maxLength, start, args.jobs,
args.exhaustive, progress);
}
else
{
passwords = recoverPassword(keysvec.front(), *args.mask, start, args.jobs, args.exhaustive, progress);
}

return {progress.state, start};
}();

Expand Down
Loading

0 comments on commit d897fd8

Please sign in to comment.