Skip to content

Commit

Permalink
πŸ—“ Jul 18, 2023 8:55:25 PM
Browse files Browse the repository at this point in the history
✨ password hashing for various algos
πŸ§ͺ tests added/updateds
βž• deps added/updated
  • Loading branch information
securisec committed Jul 19, 2023
1 parent a757326 commit cab4871
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 5 deletions.
4 changes: 2 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ New ideas:
☐ ✨ shuffle
☐ ✨ cetacean encode/decode
☐ ✨ ls47 enc/dec
☐ ✨ lm hash
☐ ✨ nt hash

Bug:

Expand Down Expand Up @@ -68,6 +66,8 @@ Misc:
☐ cyberchef recipe to chepy recipe converter

Archive:
βœ” ✨ nt hash
βœ” ✨ lm hash
βœ” ✨ lz4 compression/decompression
βœ” πŸš€ improve aes ctr enc/dec to handle iv
βœ” stringify method using json.dumps
Expand Down
16 changes: 15 additions & 1 deletion chepy/modules/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import lazy_import

from typing import TypeVar, Union
from typing import TypeVar, Union, Any

from crccheck.crc import Crc8, Crc32, CrcArc
from typing_extensions import Literal
Expand All @@ -23,6 +23,7 @@
RIPEMD = lazy_import.lazy_module("Crypto.Hash.RIPEMD")
BLAKE2s = lazy_import.lazy_module("Crypto.Hash.BLAKE2s")
BLAKE2b = lazy_import.lazy_module("Crypto.Hash.BLAKE2b")
import passlib.hash

# from Crypto.Protocol.KDF import PBKDF2
KDF = lazy_import.lazy_module("Crypto.Protocol.KDF")
Expand Down Expand Up @@ -557,3 +558,16 @@ def scrypt_hash(
self._convert_to_bytes(), salt=salt, key_len=key_length, N=2**N, r=r, p=p
).hex()
return self

@ChepyDecorators.call_stack
def password_hashing(self, format: str, **kwargs: Any) -> HashingT:
"""Hash the state with various password hashing algorithems
Args:
format (str): Hash state with password algorithems
Returns:
Chepy: The Chepy object.
"""
self.state = getattr(passlib.hash, format).hash(self._convert_to_bytes(), **kwargs)
return self
58 changes: 57 additions & 1 deletion chepy/modules/hashing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,61 @@ from ..core import ChepyCore
from typing import Any, TypeVar, Union
from typing_extensions import Literal as Literal

type_password_hashes = Literal[
"apr_md5_crypt",
"argon2",
"atlassian_pbkdf2_sha1",
"bcrypt",
"bcrypt_sha256",
"bigcrypt",
"bsd_nthash",
"bsdi_crypt",
"cisco_asa",
"cisco_pix",
"cisco_type7",
"crypt16",
"cta_pbkdf2_sha1",
"des_crypt",
"django_digest",
"dlitz_pbkdf2_sha1",
"fshp",
"grub_pbkdf2_sha512",
"hex_digest",
"ldap_crypt",
"ldap_hex_md5",
"ldap_hex_sha1",
"ldap_md5",
"ldap_pbkdf2_digest",
"ldap_plaintext",
"ldap_salted_md5",
"ldap_salted_sha1",
"ldap_salted_sha256",
"ldap_salted_sha512",
"ldap_sha1",
"lmhash",
"md5_crypt",
"msdcc",
"msdcc2",
"mssql2000",
"mssql2005",
"mysql323",
"mysql41",
"nthash",
"oracle10",
"oracle11",
"pbkdf2_digest",
"phpass",
"postgres_md5",
"roundup_plaintext",
"scram",
"scrypt",
"sha1_crypt",
"sha256_crypt",
"sha512_crypt",
"sun_md5_crypt",
"unix_disabled",
]

HashingT = TypeVar('HashingT', bound='Hashing')
hmac: Any
MD2: Any
Expand Down Expand Up @@ -50,4 +105,5 @@ class Hashing(ChepyCore):
def derive_pbkdf2_key(self: HashingT, password: Union[str, bytes], salt: Union[str, bytes], key_size: int=..., iterations: int=..., hash_type: Literal['md5', 'sha1', 'sha256', 'sha512']=..., hex_salt: bool=..., show_full_key: bool=...) -> Any: ...
def bcrypt_hash(self: HashingT, rounds: int=...) -> HashingT: ...
def bcrypt_compare(self: HashingT, hash: str) -> HashingT: ...
def scrypt_hash(self: HashingT, salt: str=..., key_length: int=..., N: int=..., r: int=..., p: int=...) -> Any: ...
def scrypt_hash(self: HashingT, salt: str=..., key_length: int=..., N: int=..., r: int=..., p: int=...) -> HashingT: ...
def password_hashing(self: HashingT, format: type_password_hashes, **kwargs) -> HashingT: ...
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ PyYAML
regex
typing_extensions
pretty-errors==1.2.25
lz4==4.3.2
lz4==4.3.2
passlib==1.7.4
12 changes: 12 additions & 0 deletions tests/test_hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,15 @@ def test_derive_pbkdf2_key():
.o[:10]
== b"6d2a9c4b24"
)


def test_password_hashing():
password = "lol"
assert (
Chepy(password).password_hashing("lmhash").o
== b"7d0fbaebf878e771aad3b435b51404ee"
)
assert (
Chepy(password).password_hashing("msdcc", user="lol").o
== b"5a487b0cda9a56e7e25464d81da162a2"
)

0 comments on commit cab4871

Please sign in to comment.