Skip to content

Commit

Permalink
βœ… πŸ“š πŸ”… ℹ️
Browse files Browse the repository at this point in the history
πŸ”… secrets.txt added
ℹ️ test.html updated
βœ… _warning_logger method added
βœ… html_tags method added
βœ… secrets method added
βœ… get_ssl_cert method added
  • Loading branch information
securisecctf committed Dec 1, 2019
1 parent 0e1cb06 commit 44035da
Show file tree
Hide file tree
Showing 8 changed files with 1,721 additions and 1 deletion.
12 changes: 12 additions & 0 deletions chepy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ def _info_logger(self, data: str) -> None:
logging.info(data)
return None

def _warning_logger(self, data: str) -> None: # pragma: no cover
"""Just a binding for logger.warning
Args:
data (str): Message to log
Returns:
Chepy: The Chepy object.
"""
logging.warning(data)
return None

def fork(self, methods: List[Tuple[Union[str, object], dict]]):
"""Run multiple methods on all available states
Expand Down
54 changes: 54 additions & 0 deletions chepy/modules/extractors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pkg_resources

import ujson
import regex as re
import jsonpath_rw
Expand Down Expand Up @@ -267,3 +269,55 @@ def js_comments(self):
)
return self

@ChepyDecorators.call_stack
def html_tags(self, tag: str):
"""Extract tags from html along with their attributes
Args:
tag (str): A HTML tag
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy("http://example.com").http_request().html_tags('p').o
[
{'tag': 'p', 'attributes': {}},
{'tag': 'p', 'attributes': {}},
{'tag': 'p', 'attributes': {}}
]
"""
tags = []

for element in self._parsel_obj().xpath("//{}".format(tag)):
attributes = []
for index, attribute in enumerate(element.xpath("@*"), start=1):
attribute_name = element.xpath("name(@*[%d])" % index).extract_first()
attributes.append((attribute_name, attribute.extract()))
tags.append({"tag": tag, "attributes": dict(attributes)})

self.state = tags
return self

@ChepyDecorators.call_stack
def secrets(self): # pragma: no cover
"""Checks for secrets
Checks ~1500 different secrets patterns. Returns a dict of partial
pattern name as the key, and and array of found matches as the value.
This mostly checks for common variable names that contains secrets.
Returns:
Chepy: The Chepy object.
"""
found = {}
secrets_path = pkg_resources.resource_filename(
__name__, "internal/data/secrets.txt"
)
with open(secrets_path, "r") as f:
for pattern in f:
matches = re.findall(fr"{pattern}.*?".strip(), self.response.text)
if matches:
found[re.sub(r"[^a-zA-Z0-9_]", "", pattern[0:20])] = matches
self.state = found
return self
25 changes: 25 additions & 0 deletions chepy/modules/forensics.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def get_mime(self, set_state: bool = False):
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy("tests/files/hello").load_file().get_mime()
INFO - application/x-executable
"""
filename = self._temp_file()
parser = createParser(filename)
Expand All @@ -65,6 +69,20 @@ def get_metadata(self, set_state: bool = False):
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy("logo.png").load_file().get_metadata().o
{'Bits/pixel': '32',
'Compression': 'deflate',
'Compression rate': '138.6x',
'Creation date': '2019-11-30 21:40:30',
'Endianness': 'Big endian',
'Image DPI height': '3780 DPI',
'Image DPI width': '3780 DPI',
'Image height': '1080 pixels',
'Image width': '1920 pixels',
'MIME type': 'image/png',
'Pixel format': 'RGBA'}
"""
filename = self._temp_file()
filename, realname = filename, filename
Expand Down Expand Up @@ -94,6 +112,13 @@ def embedded_files(self, extract_path: str = None):
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy("/tmp/stego_50.jpg").load_file().embedded_files(extract_path="/tmp/embedded")
[+] Start search on 10757 bytes (10.5 KB)
[+] End of search -- offset=10757 (10.5 KB)
[+] File at 0 size=10541 (10.3 KB): JPEG picture: 430x425 pixels => /tmp/embedded/file-0001.jpg
[+] File at 10541 size=201 (201 bytes): ZIP archive => /tmp/embedded/file-0002.zip
"""
filename = self._temp_file()
inp = FileInputStream(filename)
Expand Down

0 comments on commit 44035da

Please sign in to comment.