Skip to content

Commit

Permalink
πŸ”… ℹ️ πŸ“š
Browse files Browse the repository at this point in the history
πŸ”… version 1.0.2
ℹ️ updated tests
πŸ”… added shell command from cli
πŸ”… added Dockerfile
πŸ”… bake method alias for o, output, out
πŸ”… cyberchef method alias for web
πŸ“š more docs
  • Loading branch information
securisecctf committed Nov 26, 2019
1 parent d23a84b commit 185af99
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests_multi_os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Test with bandit
run: |
pip install bandit
bandit --recursive chepy/ --ignore-nosec --skip B101,B413,B303,B310,B112,B304,B320,B410
bandit --recursive chepy/ --ignore-nosec --skip B101,B413,B303,B310,B112,B304,B320,B410,B404
- name: Test docs
run: |
pip install sphinx recommonmark
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Test with bandit
run: |
pip install bandit
bandit --recursive chepy/ --ignore-nosec --skip B101,B413,B303,B310,B112,B304,B320,B410
bandit --recursive chepy/ --ignore-nosec --skip B101,B413,B303,B310,B112,B304,B320,B410,B404
- name: Test docs
run: |
pip install sphinx recommonmark
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
- name: Test with bandit
run: |
pip install bandit
bandit --recursive chepy/ --ignore-nosec --skip B101,B413,B303,B310,B112,B304,B320,B410
bandit --recursive chepy/ --ignore-nosec --skip B101,B413,B303,B310,B112,B304,B320,B410,B404
- name: Test docs
run: |
pip install sphinx recommonmark
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ script:
- pytest --disable-pytest-warnings --cov-report=xml --cov=chepy --cov-config=.coveragerc
tests/
- coverage report -m
- bandit --recursive chepy/ --ignore-nosec --skip B101,B413,B303,B310,B112,B304,B320,B410
- bandit --recursive chepy/ --ignore-nosec --skip B101,B413,B303,B310,B112,B304,B320,B410,B404
- make -C docs/ clean html
deploy:
provider: pypi
Expand Down
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.8.0

COPY . /app/chepy/
RUN pip install /app/chepy/

WORKDIR /data
VOLUME ["/data"]

ENTRYPOINT ["chepy"]
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

[![](https://img.shields.io/badge/code%20style-black-000000.svg?label=Style)](https://github.com/securisec/chepy)
![](https://img.shields.io/github/license/securisec/chepy?label=License)
[![](https://badges.gitter.im/chepy_/community.svg)](https://gitter.im/chepy_/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)


# Chepy
Expand All @@ -22,6 +23,32 @@ There is still a long way to go for Chepy as it does not offer every single abil
## Docs
[Refer to the docs for full usage information](http://chepy.readthedocs.io/en/latest/)

## Example
[For all usage and examples, see the docs.](http://chepy.readthedocs.io/en/latest/)

Chepy has a stacking mechanism similar to Cyberchef. For example, this in Cyberchef:
![](https://raw.githubusercontent.com/securisec/chepy/master/logo.png)

This is equivalent to

```python
from chepy import Chepy

file_path = "/tmp/demo/encoding"

print(
Chepy(file_path)
.load_file()
.reverse()
.rot_13()
.base64_decode()
.base32_decode()
.hexdump_to_str()
.o
)

```

## Installation
Chepy can be installed in a few ways.

Expand All @@ -45,6 +72,11 @@ cd chepy
pipenv install
```

#### Docker
```bash
docker run --rm -ti -v $PWD:/data securisec/chepy "some string" [somefile, "another string"]
```

## Chepy vs Cyberchef

#### Advantages
Expand Down
2 changes: 1 addition & 1 deletion all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function check_test {
check_test pytest --disable-pytest-warnings --cov=chepy --cov-config=.coveragerc tests/

# bandit
check_test bandit --recursive chepy/ --ignore-nosec --skip B101,B413,B303,B310,B112,B304,B320,B410
check_test bandit --recursive chepy/ --ignore-nosec --skip B101,B413,B303,B310,B112,B304,B320,B410,B404

# docs
check_test make -C docs/ clean html
12 changes: 8 additions & 4 deletions chepy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import inspect
import fire
import regex as re
from pathlib import Path
import argparse
from pathlib import Path
from docstring_parser import parse as _parse_doc
from prompt_toolkit.completion import (
Completer,
Expand Down Expand Up @@ -131,7 +131,9 @@ def bottom_toolbar(fire_obj):
class CustomValidator(Validator):
def validate(self, document):
text = document.text.split()
if len(text) > 1:
if document.text.startswith("!"):
pass
elif len(text) > 1:
if not text[-2].startswith("--"):
if (
not re.search(r"\"|'", text[-1])
Expand Down Expand Up @@ -236,14 +238,16 @@ def main():
)

# check and output any commands that start with cli_
if re.search(r"^cli_.+", prompt):
if re.match(r"^\!", prompt):
getattr(chepy_cli, "cli_shell")(re.sub(r"^\!\s?", "", prompt))
elif re.search(r"^cli_.+", prompt):
cli_method = prompt.split()[0]
cli_args = re.search(r"--(\w+)\s(\w+)", prompt)
if cli_method == "cli_show_errors":
getattr(chepy_cli, "cli_show_errors")(errors)
elif cli_method == "cli_go_back":
args_data = args_data[: -len(last_command + ["-"])]
elif cli_method == 'cli_delete_history':
elif cli_method == "cli_delete_history":
Path(config.history_path).unlink()
elif cli_args:
getattr(chepy_cli, cli_method)(
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__ = "1.0.1" # pragma: no cover
__version__ = "1.0.2" # pragma: no cover
__author__ = "Hapsida @securisec" # pragma: no cover
4 changes: 4 additions & 0 deletions chepy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def __init__(self, *data):
self.buffers = dict()
#: Alias for `write_to_file`
self.write = self.write_to_file
#: Alias for `out`
self.bake = self.out
#: Alias for `web`
self.cyberchef = self.web

@property
def state(self):
Expand Down
14 changes: 14 additions & 0 deletions chepy/modules/internal/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
import inspect
from pprint import pformat, pprint
from subprocess import getoutput

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 @@ -189,11 +191,23 @@ def cli_show_errors(errors):
"""
pprint(errors)


def cli_shell(command: str):
"""Execute a system command in the cli
Args:
command (str): Command to execute
"""
out = getoutput(command)
print(out)


def cli_go_back():
"""Go back one step
"""
pass


def cli_delete_history():
"""Delete local history file
"""
Expand Down
Binary file added docs/assets/cc_encoding.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ This same behavior is replicated in the Chepy cli.
### Cli only methods
For completeness sake everything is document here, but the only functions that are callable from the CLI are functions that start with `cli_`.

### Cli shell commands
It is possible to run shell commands from the cli py starting the command with a `!`.

```bash
>>> !ls -la | grep py
```
This will run the following command inside the Chepy cli

```eval_rst
.. automodule:: chepy.modules.internal.cli
:members:
Expand Down

0 comments on commit 185af99

Please sign in to comment.