Skip to content

Commit

Permalink
πŸ”… πŸ“š ℹ️ 🧨 βœ…
Browse files Browse the repository at this point in the history
πŸ”… 2.6.0
🧨 renamed shell_output to load_command
πŸ”… added python-editor to requirements
ℹ️ positional args will now show help for cli if none is passed
βœ… cli_edit_state to edit state from cli
πŸ“š some new examples
  • Loading branch information
securisecctf committed May 4, 2020
1 parent 493058a commit bc2bc23
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 11 deletions.
8 changes: 3 additions & 5 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ Code:
New ideas:
☐ rubber ducky encode/decode
☐ save registers https://t.co/pBNRufibY8?amp=1
☐ different keyboard converters

Cli:
☐ use $EDITOR to open state in an editor https://github.com/fmoo/python-editor.
Problem is it ill not set the state because chepy runs from scratch everytime
☐ edit with editor and send back to buffer
☐ open vim or vi with buffer. data can be piped to bim vim can read stdin with -
☐ optionally show output window in a split screen window
☐ lower the chepy prompt lower. that empty space is not being used
☐ pyinstaller package as single file
☐ write to file with prompt toolkit path autocomplete
☐ pipe input to chepy

Enhance:

Expand All @@ -38,6 +34,8 @@ Misc:
☐ cyberchef recipe to chepy recipe converter

Archive:
βœ” use $EDITOR to open state in an editor https://github.com/fmoo/python-editor. @project(Cli)
βœ” run command method to save output to state @project(New ideas)
βœ” use lazy-import to increase performance @project(Code)
βœ” rotate bruteforce @project(New ideas)
βœ” derive pbkdf2 key @project(New ideas)
Expand Down
18 changes: 16 additions & 2 deletions chepy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,10 @@ def parse_args(args):
parse.add_argument(
"-v", "--version", action="version", version="%(prog)s " + __version__
)
parse.add_argument("-r", "--recipe", dest="recipe", help="Run a Chepy recipe and exit")
parse.add_argument("data", nargs="*")
parse.add_argument(
"-r", "--recipe", dest="recipe", help="Run a Chepy recipe and exit"
)
parse.add_argument("data", nargs="+")
return parse.parse_args(args)


Expand Down Expand Up @@ -277,13 +279,25 @@ def main():
elif re.search(r"^cli_.+", prompt):
cli_method = prompt.split()[0]
cli_args = re.search(r"--(\w+)\s([\w\W]+)", prompt)
# Show errors encountered
if cli_method == "cli_show_errors":
getattr(chepy_cli, "cli_show_errors")(errors)
# show the current plugin path
elif cli_method == "cli_plugin_path":
getattr(chepy_cli, "cli_plugin_path")(config)
# Edit the current state
elif cli_method == "cli_edit_state":
try:
getattr(chepy_cli, "cli_edit_state")(fire_obj, args_data)
args_data = args_data[0 : args_data.index("-")] + ["-"]
except:
e_type, e_msg, e_traceback = sys.exc_info()
print(red(e_type.__name__), yellow("Could not edit state"))
# Go back one step
elif cli_method == "cli_go_back":
args_data = args_data[: -len(last_command + ["-"])]
print(cyan("Go back: {}".format(last_command)))
# Delete the cli history file
elif cli_method == "cli_delete_history":
Path(config.history_path).unlink()
elif cli_args:
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__ = "2.5.0" # pragma: no cover
__version__ = "2.6.0" # pragma: no cover
__author__ = "Hapsida @securisec" # pragma: no cover
2 changes: 1 addition & 1 deletion chepy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ def reset(self):
return self

@ChepyDecorators.call_stack
def shell_output(self): # pragma: no cover
def load_command(self): # pragma: no cover
"""Run the command in state and get the output
Returns:
Expand Down
22 changes: 20 additions & 2 deletions chepy/modules/internal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import regex as re
from pprint import pformat, pprint

import editor
from docstring_parser import parse as _parse_doc
from prompt_toolkit.completion import Completer, Completion
from prompt_toolkit import print_formatted_text
Expand Down Expand Up @@ -77,6 +78,17 @@ def get_doc(method: str):
print(red(pformat("Could not find docs...")))


def cli_edit_state(fire: object, args: list):
"""Edit the current state
Args:
args (object): Cli args
"""
current_index = fire._current_index
hold = editor.edit(contents=str(fire.states[current_index])).decode()
args[current_index] = hold


def cli_highlight(fire: object, highlight: str):
"""Highlight regex match for cli
Expand All @@ -87,9 +99,15 @@ def cli_highlight(fire: object, highlight: str):
current_state = fire.states[fire._current_index]
if fire is not None and isinstance(fire, Chepy):
try:
print(re.sub('({})'.format(highlight), yellow_background(r'\1'), str(current_state)))
print(
re.sub(
"({})".format(highlight),
yellow_background(r"\1"),
str(current_state),
)
)
except:
red('Could not highlight because state is not a string')
red("Could not highlight because state is not a string")
# elif type(current_state) == bytes or type(current_state) == bytearray:
# print(re.sub('({})'.format(highlight).encode(), red(r'\1').encode(), current_state).decode())
else:
Expand Down
8 changes: 8 additions & 0 deletions chepy/modules/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def search_ctf_flags(self, prefix: str, postfix: str = ".+?\{*\}"):
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy("tests/files/flags").read_file().search_ctf_flags("pico").get_by_index(0)
picoCTF{r3source_pag3_f1ag}
"""
self.state = re.findall(prefix + postfix, self._convert_to_str(), re.IGNORECASE)
return self
Expand All @@ -50,6 +54,10 @@ def search_slack_tokens(self):
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy("tests/files/flags").read_file().search_slack_tokens().get_by_index(0)
xoxp...859
"""
self.state = re.findall(
"(xox[p|b|o|a]-[0-9]{12}-[0-9]{12}-[0-9]{12}-[a-z0-9]{32})",
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pydash
pyjwt
pyOpenSSL
pyperclip
python-editor
PyYAML
regex
typing_extensions
Expand Down

0 comments on commit bc2bc23

Please sign in to comment.