Skip to content

Commit

Permalink
🗓 Oct 15, 2023 12:31:40 PM
Browse files Browse the repository at this point in the history
🐙 plugins updated
🐙 allow raw key and iv for en/decryption methods
🧪 tests added/updated
  • Loading branch information
securisec committed Oct 15, 2023
1 parent eb31bdd commit 66780f6
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion chepy/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "6.3.0" # pragma: no cover
__version__ = "6.4.0" # pragma: no cover
__author__ = "@securisec" # pragma: no cover
2 changes: 1 addition & 1 deletion chepy/chepy_plugins
8 changes: 6 additions & 2 deletions chepy/modules/encryptionencoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def _convert_key(
key = key.decode().encode("utf-8")
if key_format == "latin-1":
key = key.decode().encode("latin-1")
if key_format == "raw":
key = key

# modify iv according to mode
iv = self._str_to_bytes(iv)
Expand All @@ -82,9 +84,11 @@ def _convert_key(
if iv_format == "base64" or iv_format == "b64":
iv = base64.b64decode(iv)
if iv_format == "utf-8" or iv_format == "utf8":
key = key.decode().encode("utf-8")
iv = key.decode().encode("utf-8")
if iv_format == "latin-1":
key = key.decode().encode("latin-1")
iv = key.decode().encode("latin-1")
if iv_format == "raw":
iv = iv
else:
iv = binascii.unhexlify(binascii.hexlify(iv))
return key, iv
Expand Down
6 changes: 3 additions & 3 deletions chepy/modules/encryptionencoding.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DES: Any
DES3: Any
Blowfish: Any
EncryptionEncodingT = TypeVar('EncryptionEncodingT', bound='EncryptionEncoding')
FORMAT = Literal['hex', 'base64', 'utf-8', 'latin-1']
FORMAT = Literal['hex', 'base64', 'utf-8', 'latin-1', 'raw']
RC4_FORMAT = Literal['hex', 'base64', 'utf8', 'utf-16-be', 'utf-16-le']

class EncryptionEncoding(ChepyCore):
Expand All @@ -35,8 +35,8 @@ class EncryptionEncoding(ChepyCore):
def chacha_decrypt(self: EncryptionEncodingT, key: str, nonce: str=..., key_format: FORMAT=..., nonce_format: FORMAT=...) -> EncryptionEncodingT: ...
def triple_des_encrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "OFB", "CTR", "ECB"]=..., key_format: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def triple_des_decrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "OFB", "CTR", "ECB"]=..., key_format: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def aes_encrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "CFB", "OFB", "CTR", "ECB", "GCM"]=..., key_format: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def aes_decrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "CFB", "OFB", "CTR", "ECB", "GCM"]=..., key_format: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def aes_encrypt(self: EncryptionEncodingT, key: Union[bytes, str], iv: str=..., mode: Literal["CBC", "CFB", "OFB", "CTR", "ECB", "GCM"]=..., key_format: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def aes_decrypt(self: EncryptionEncodingT, key: Union[bytes, str], iv: str=..., mode: Literal["CBC", "CFB", "OFB", "CTR", "ECB", "GCM"]=..., key_format: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def blowfish_encrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "OFB", "CTR", "ECB"]=..., key_format: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def blowfish_decrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "OFB", "CTR", "ECB"]=..., key_format: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def vigenere_encode(self: EncryptionEncodingT, key: str) -> EncryptionEncodingT: ...
Expand Down
10 changes: 10 additions & 0 deletions tests/test_encryptionencoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,16 @@ def test_aes_encrypt():
.o
== b"4ab2b4f72e9d92960b"
)
raw_key = (
raw_iv
) = b'\xe1p\x07\x01R\xee\xde)\xa0gx\xb6\xc2\xcb\x18\x9e\x80\xe5\x9eu\xf2"0PVvE\xdb\x08\x93\xa0\x93'
assert (
Chepy("hello")
.aes_encrypt(key=raw_key, iv=raw_iv[:16], key_format="raw", iv_format="raw")
.aes_decrypt(key=raw_key, iv=raw_iv[:16], key_format="raw", iv_format="raw")
.o
== b"hello"
)


def test_aes_decrypt():
Expand Down
22 changes: 14 additions & 8 deletions tests_plugins/test_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ def test_ml_detect():
assert (
Chepy("https%3A%2F%2Fwww.pennington.com%2Fcategories%2Fwp-content")
.ml_detect()
.o.get("to_url_encode")
.o.get("from_url_encode")
!= None
)
data = "5ZXN4aSn4N2ZVzGA6Q7NbqCRJa2XBt2CEKAvgDUoQj8x9vBJqcrk5fBKZh5XqdAoKnyXMeNmE21QQAqZcKZPamT8he6s8nYRU1unmSb2eAmnnBv8NWSs9f6BgsJ3DGPpdbPm8b9kDSMDTLfZ1"
assert Chepy(data).ml_detect().o.get("to_base58") != None
assert Chepy(data).from_base58().ml_detect().o.get("to_hex") != None
assert Chepy(data).ml_detect().o.get("from_base58") != None
assert Chepy(data).from_base58().ml_detect().o.get("from_hex") != None
assert (
Chepy(data).from_base58().from_hex().ml_detect().o.get("lzma_compress") != None
Chepy(data).from_base58().from_hex().ml_detect().o.get("lzma_decompress")
!= None
)
# assert (
# Chepy(data).from_base58().from_hex().lzma_decompress().o
# == b"some data with an encoded flag"
# )


# def test_ml_magic():
# assert (
# Chepy("Ca6wMuk9H4Y3rYb8uMQordMrH6JbvsaWx2Ua7dNQvF1tujWPvi2AEijEKsD6Mpe7Ld37T1y")
# .ml_magic()
# .o[-1]["out"]
# == b"hello world"
# )

0 comments on commit 66780f6

Please sign in to comment.