Skip to content

Commit

Permalink
πŸ—“ Oct 6, 2023 10:54:15 PM
Browse files Browse the repository at this point in the history
✨ cut method
πŸ™ update search method for better matches
πŸ§ͺ tests added/updated
  • Loading branch information
securisec committed Oct 7, 2023
1 parent b745601 commit f2c8844
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 10 deletions.
5 changes: 3 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ New ideas:
☐ πŸ™ diff show results only
☐ ✨ brainfuck encoder/decoder
☐ ✨ spoon encoder/decoder
base62

Bug:

Expand All @@ -48,7 +47,6 @@ Plugins:

Methods:
☐ magic method from cyberchef
☐ base 62
☐ base 92

Github Actions:
Expand All @@ -61,6 +59,9 @@ Misc:
☐ cyberchef recipe to chepy recipe converter

Archive:
βœ” πŸ™ update ascii in xor function to documentation
βœ” πŸ› search with bytes is erroring
βœ” ✨ base62
βœ” ✨ callback function that can take a python function and run it over state. handle recipes for this
βœ” ✨ automatic delimiter detect
βœ” ✨ rabbit encryption
Expand Down
15 changes: 15 additions & 0 deletions chepy/modules/dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1966,3 +1966,18 @@ def from_base62(

self.state = decoded_data
return self

@ChepyDecorators.call_stack
def cut(self, start: int, end: int) -> DataFormatT:
"""Convert the state to bytes and cut x:y data from it
Args:
start (int): Starting position
end (int): End position
Returns:
Chepy: The Chepy object.
"""
data = self._convert_to_bytes()
self.state = data[start:end]
return self
1 change: 1 addition & 0 deletions chepy/modules/dataformat.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ class DataFormat(ChepyCore):
def rotate_left(self: DataFormatT, radix: int=1, carry: bool=False) -> DataFormatT: ...
def to_base62(self: DataFormatT, alphabet: str="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") -> DataFormatT: ...
def from_base62(self: DataFormatT, alphabet: str="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") -> DataFormatT: ...
def cut(self: DataFormatT, start: int, end: int) -> DataFormatT: ...
2 changes: 1 addition & 1 deletion chepy/modules/encryptionencoding.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EncryptionEncoding(ChepyCore):
def rot_47(self: EncryptionEncodingT, amount: int=...) -> EncryptionEncodingT: ...
def rot_47_bruteforce(self: EncryptionEncodingT) -> EncryptionEncodingT: ...
def rot_8000(self: EncryptionEncodingT) -> EncryptionEncodingT: ...
def xor(self: EncryptionEncodingT, key: Union[str, bytearray], key_type: Literal['hex', 'utf', 'base64', 'decimal']=..., ascii: bool=...) -> EncryptionEncodingT: ...
def xor(self: EncryptionEncodingT, key: Union[str, bytearray], key_type: Literal['hex', 'utf', 'base64', 'decimal']=...) -> EncryptionEncodingT: ...
def xor_bruteforce(self: EncryptionEncodingT, length: int=..., crib: Union[str, bytes, None]=...) -> EncryptionEncodingT: ...
def jwt_decode(self: EncryptionEncodingT) -> EncryptionEncodingT: ...
def jwt_verify(self: EncryptionEncodingT, secret: str, algorithm: list=...) -> EncryptionEncodingT: ...
Expand Down
7 changes: 4 additions & 3 deletions chepy/modules/search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TypeVar
from typing import TypeVar, Union

import regex as re

Expand All @@ -17,7 +17,7 @@ def __init__(self, *data):
"""

@ChepyDecorators.call_stack
def search(self, pattern: str) -> SearchT:
def search(self, pattern: Union[str, bytes]) -> SearchT:
"""Search. Group matches are returned as tuples.
Args:
Expand All @@ -30,7 +30,8 @@ def search(self, pattern: str) -> SearchT:
>>> Chepy("abcdefg123 and again abcdefg123").search("abc(de)fg(12)(3)").o
[('abcdefg123', 'de', '12', '3'), ('abcdefg123', 'de', '12', '3')]
"""
self.state = re.findall("({})".format(pattern), self._convert_to_str())
pattern = self._str_to_bytes(pattern)
self.state = re.findall(pattern, self._convert_to_bytes())
return self

@ChepyDecorators.call_stack
Expand Down
4 changes: 2 additions & 2 deletions chepy/modules/search.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from ..core import ChepyCore
from typing import Any, TypeVar
from typing import Any, TypeVar, Union

SearchT = TypeVar('SearchT', bound='Search')

class Search(ChepyCore):
def __init__(self, *data: Any) -> None: ...
state: Any = ...
def search(self: SearchT, pattern: str) -> SearchT: ...
def search(self: SearchT, pattern: Union[str, bytes]) -> SearchT: ...
def search_ctf_flags(self: SearchT, prefix: str, postfix: str=...) -> SearchT: ...
def search_slack_tokens(self: SearchT) -> SearchT: ...
def search_slack_webhook(self: SearchT) -> SearchT: ...
Expand Down
32 changes: 32 additions & 0 deletions tests/test_ctf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,35 @@ def test_bsides_c5():
.o
== b"th3_cak3_is_a_li3"
)

c = (
Chepy("MjBfcDAweF9ycm1hdV9ta3ozdmsza2ZqM19tcHlpX3B5aTN2")
.from_base64()
.vigenere_decode("key")
.o
== b"20_f00t_thick_imp3rm3abl3_clay_lay3r"
)

c = (
Chepy(
"ZXlKaGJHY2lPaUpJVXpJMU5pSXNJblI1Y0NJNklrcFhWQ0o5LmV5SnpkV0lpT2lJeE1qTTBOVFkzT0Rrd0lpd2libUZ0WlNJNklscHFSbnBoUmpsNllVZEdkMDB5VW1aWk0wcG9XVEp6ZW1OcVZTSXNJbWxoZENJNk1UVXhOakl6T1RBeU1uMC5QUkFfMlVfUHVZWEZHb1BWdGxEc2JnaHhvWDA1czNnTGVoVFJEdC1VeUgw"
)
.from_base64()
.jwt_decode()
.get_by_key("payload")
.get_by_key("name")
.from_base64()
.o
== b"f1sh_shap3d_crack3r5"
)

assert (
Chepy(
"e6 96 37 33 27 f5 27 33 47 37 56 97 c6 f6 07 f5 46 33 47 16 27 57 47 16 37 e6 57"
)
.reverse()
.remove_whitespace()
.from_hex()
.o
== b"unsaturat3d_polyest3r_r3sin"
)
7 changes: 7 additions & 0 deletions tests/test_dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,3 +630,10 @@ def test_base62():
== b"EtWxGEdLPmwchEzFHWNyyyI3p1w"
)
assert Chepy("3bfP0XZgTym6SsUKeZS5Z6qoKa").from_base62().o == b"hello !!123!! world"


def test_cut():
assert Chepy("abcd").cut(1, 2).o == b"b"
assert Chepy("abcd").cut(1, 3).o == b"bc"
assert Chepy({"a": 1}).cut(1, 3).o == b"'a"
assert Chepy({"a": None}).cut(6, 9).o == b"Non"
4 changes: 2 additions & 2 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

def test_search():
assert Chepy("abcdefg123 and again abcdefg123").search(r"abc(de)fg(12)(3)").o == [
("abcdefg123", "de", "12", "3"),
("abcdefg123", "de", "12", "3"),
(b"de", b"12", b"3"),
(b"de", b"12", b"3"),
]


Expand Down

0 comments on commit f2c8844

Please sign in to comment.