Skip to content

Commit

Permalink
πŸ—“ Apr 4, 2022 7:32:27 PM
Browse files Browse the repository at this point in the history
4.0.0
πŸ”₯ move some extractors and codetidy to plugins
πŸ”₯ move multimedia to plugins
βž• deps removed from core
πŸ§ͺ tests added/updated
  • Loading branch information
securisecctf committed Apr 4, 2022
1 parent cd9ab3e commit 2498b58
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 806 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ omit =


[report]
fail_under = 90
fail_under = 100
2 changes: 0 additions & 2 deletions chepy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from .modules.hashing import Hashing
from .modules.language import Language
from .modules.links import Links
from .modules.multimedia import Multimedia
from .modules.networking import Networking
from .modules.other import Other
from .modules.publickey import Publickey
Expand All @@ -34,7 +33,6 @@ class Chepy(
Hashing,
Language,
Links,
Multimedia,
Networking,
Other,
Publickey,
Expand Down
2 changes: 1 addition & 1 deletion chepy/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "3.5.1" # pragma: no cover
__version__ = "4.0.0" # pragma: no cover
__author__ = "Hapsida @securisec" # pragma: no cover
2 changes: 1 addition & 1 deletion chepy/chepy_plugins
4 changes: 2 additions & 2 deletions chepy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def for_each(self, methods: List[Tuple[Union[str, object], dict]]):
>>> c = Chepy(['41', '42'])
>>> c.for_each([("from_hex",), ("to_hex",)])
>>> # this is how to use fork methods with a string
>>> c.for([(c.from_hex,), (c.to_hex,)])
>>> c.for_each([(c.from_hex,), (c.to_hex,)])
>>> # This is how to use fork using methods
>>> print(c)
['41', '42']
Expand Down Expand Up @@ -539,7 +539,7 @@ def _convert_to_str(self) -> str:
return str(self.state)
elif isinstance(self.state, bytearray):
return bytearray(self.state).decode()
elif isinstance(self.state, float):
elif isinstance(self.state, float): # pragma: no cover
return format(self.state, "f")
else: # pragma: no cover
# todo check more types here
Expand Down
59 changes: 4 additions & 55 deletions chepy/modules/codetidy.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from typing import TypeVar
import lazy_import

import json

pydash = lazy_import.lazy_module("pydash")
import phpserialize
import pydash
import regex as re
from lxml import etree
from ..core import ChepyCore, ChepyDecorators

CodeTidyT = TypeVar("CodeTidyT", bound="CodeTidy")
Expand All @@ -27,7 +24,9 @@ def minify_json(self) -> CodeTidyT:
>>> c = Chepy("/path/to/file.json").load_file()
>>> print(c.minify_json())
"""
self.state = json.dumps(json.loads(self._convert_to_str()), separators=(',', ':'))
self.state = json.dumps(
json.loads(self._convert_to_str()), separators=(",", ":")
)
return self

@ChepyDecorators.call_stack
Expand All @@ -47,56 +46,6 @@ def beautify_json(self, indent: int = 2) -> CodeTidyT:
self.state = json.dumps(json.loads(self._convert_to_str()), indent=indent)
return self

@ChepyDecorators.call_stack
def minify_xml(self) -> CodeTidyT:
"""Minify XML string
Returns:
Chepy: The Chepy object.
Examples:
>>> c = Chepy("/path/to/file.xml").load_file()
>>> print(c.minify_xml())
"""
parser = etree.XMLParser(remove_blank_text=True)
self.state = etree.tostring(
etree.fromstring(self._convert_to_bytes(), parser=parser)
)
return self

@ChepyDecorators.call_stack
def beautify_xml(self) -> CodeTidyT:
"""Beautify compressed XML
Returns:
Chepy: The Chepy object.
Examples:
>>> c = Chepy("/path/to/file.xml").load_file()
>>> print(c.beautify_json())
"""
self.state = etree.tostring(
etree.fromstring(self._convert_to_bytes()), pretty_print=True
)
return self

@ChepyDecorators.call_stack
def php_deserialize(self) -> CodeTidyT:
"""Deserialize php to dict
Deserializes PHP serialized data, outputting keyed arrays as a python dict.
Returns:
Chepy: The Chepy object.
Examples:
>>> c = Chepy('a:3:{i:1;s:6:"elem 1";i:2;s:6:"elem 2";i:3;s:7:" elem 3";}')
>>> c.php_deserialize()
{1: b'elem 1', 2: b'elem 2', 3: b' elem 3'}
"""
self.state = phpserialize.loads(self._convert_to_bytes())
return self

@ChepyDecorators.call_stack
def to_upper_case(self, by: str = "all") -> CodeTidyT:
"""Convert string to uppercase
Expand Down
3 changes: 0 additions & 3 deletions chepy/modules/codetidy.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ class CodeTidy(ChepyCore):
state: Any = ...
def minify_json(self: CodeTidyT) -> CodeTidyT: ...
def beautify_json(self: CodeTidyT, indent: int=...) -> CodeTidyT: ...
def minify_xml(self: CodeTidyT) -> CodeTidyT: ...
def beautify_xml(self: CodeTidyT) -> CodeTidyT: ...
def php_deserialize(self: CodeTidyT) -> CodeTidyT: ...
def to_upper_case(self: CodeTidyT, by: Literal['all', 'word', 'sentence']=...) -> CodeTidyT: ...
def to_lower_case(self: CodeTidyT) -> CodeTidyT: ...
def to_snake_case(self: CodeTidyT) -> CodeTidyT: ...
Expand Down
2 changes: 1 addition & 1 deletion chepy/modules/encryptionencoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
jwt = lazy_import.lazy_module("jwt")
import pathlib

import pycipher
import regex as re
import json

Expand All @@ -24,6 +23,7 @@
PKCS1_OAEP = lazy_import.lazy_module("Crypto.Cipher.PKCS1_OAEP")
Blowfish = lazy_import.lazy_module("Crypto.Cipher.Blowfish")
Padding = lazy_import.lazy_module("Crypto.Util.Padding")
pycipher = lazy_import.lazy_module("pycipher")

from ..core import ChepyCore, ChepyDecorators
from ..extras.combinatons import hex_chars
Expand Down
81 changes: 0 additions & 81 deletions chepy/modules/extractors.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from typing import TypeVar
from urllib.parse import urlparse as _pyurlparse

import jsonpath_rw
import lazy_import
import regex as re
import json

parsel = lazy_import.lazy_module("parsel")
from ..core import ChepyCore, ChepyDecorators

ExtractorsT = TypeVar("ExtractorsT", bound="Extractors")
Expand All @@ -16,10 +12,6 @@ class Extractors(ChepyCore):
def __init__(self, *data):
super().__init__(*data)

def _parsel_obj(self):
"""Returns a parsel.Selector object"""
return parsel.Selector(self._convert_to_str())

@ChepyDecorators.call_stack
def extract_hashes(self) -> ExtractorsT:
"""Extract md5, sha1, sha256 and sha512 hashes
Expand Down Expand Up @@ -207,79 +199,6 @@ def extract_domains(self, is_binary: bool = False) -> ExtractorsT:
self.state = matched
return self

@ChepyDecorators.call_stack
def xpath_selector(self, query: str, namespaces: str = None) -> ExtractorsT:
"""Extract data using valid xpath selectors
Args:
query (str): Required. Xpath query
namespaces (str, optional): Namespace. Applies for XML data. Defaults to None.
Returns:
Chepy: The Chepy object.
Examples:
>>> c = Chepy("http://example.com")
>>> c.http_request()
>>> c.xpath_selector("//title/text()")
>>> c.get_by_index(0)
>>> c.o
"Example Domain"
"""
self.state = (
parsel.Selector(self._convert_to_str(), namespaces=namespaces)
.xpath(query)
.getall()
)
return self

@ChepyDecorators.call_stack
def css_selector(self, query: str) -> ExtractorsT:
"""Extract data using valid CSS selectors
Args:
query (str): Required. CSS query
Returns:
Chepy: The Chepy object.
Examples:
>>> c = Chepy("http://example.com")
>>> c.http_request()
>>> c.css_selector("title")
>>> c.get_by_index(0)
>>> c.o
"<title>Example Domain</title>"
"""
self.state = self._parsel_obj().css(query).getall()
return self

@ChepyDecorators.call_stack
def jpath_selector(self, query: str) -> ExtractorsT:
"""Query JSON with jpath query
`Reference <https://goessner.net/articles/JsonPath/index.html#e2>`__
Args:
query (str): Required. Query. For reference, see the help
Returns:
Chepy: The Chepy object.
Examples:
>>> c = Chepy("tests/files/test.json")
>>> c.load_file()
>>> c.jpath_selector("[*].name.first")
>>> c.get_by_index(2)
>>> c.o
"Long"
"""
self.state = list(
j.value
for j in jsonpath_rw.parse(query).find(json.loads(self._convert_to_str()))
)
return self

@ChepyDecorators.call_stack
def html_comments(self) -> ExtractorsT:
"""Extract html comments
Expand Down
4 changes: 0 additions & 4 deletions chepy/modules/extractors.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from ..core import ChepyCore
from typing import Any, TypeVar

parsel: Any
ExtractorsT = TypeVar('ExtractorsT', bound='Extractors')

class Extractors(ChepyCore):
Expand All @@ -14,9 +13,6 @@ class Extractors(ChepyCore):
def extract_mac_address(self: ExtractorsT, is_binary: bool=...) -> ExtractorsT: ...
def extract_urls(self: ExtractorsT, is_binary: bool=...) -> ExtractorsT: ...
def extract_domains(self: ExtractorsT, is_binary: bool=...) -> ExtractorsT: ...
def xpath_selector(self: ExtractorsT, query: str, namespaces: str=...) -> ExtractorsT: ...
def css_selector(self: ExtractorsT, query: str) -> ExtractorsT: ...
def jpath_selector(self: ExtractorsT, query: str) -> ExtractorsT: ...
def html_comments(self: ExtractorsT) -> ExtractorsT: ...
def javascript_comments(self: ExtractorsT) -> ExtractorsT: ...
def html_tags(self: ExtractorsT, tag: str) -> ExtractorsT: ...
Expand Down

0 comments on commit 2498b58

Please sign in to comment.