securisec / chepy Goto Github PK
View Code? Open in Web Editor NEWChepy is a python lib/cli equivalent of the awesome CyberChef tool.
License: GNU General Public License v3.0
Chepy is a python lib/cli equivalent of the awesome CyberChef tool.
License: GNU General Public License v3.0
I'd like to be able to provide a custom location for the plugins. It would be great if we could provide a custom location for the chepy.conf location too. In addition, I think it would be an idea to search the current location for chepy.conf, both the users cwd and the .py file
Describe the bug
A clear and concise description of what the bug is. Do keep in mind that Chepy is attempting to provide functionality that a web app does, which makes it difficult at times to work with certain types of user input.
I was trying to load a recipe but when i ran the script it gave me error : File "C:\Users\[REDACTED]\AppData\Local\Programs\Python\Python310\lib\site-packages\chepy\core.py", line 980, in load_recipe function = recipe["function"] KeyError: 'function
To Reproduce
my script:
import chepy
from chepy import Chepy
print (
Chepy("Hello World")
.load_recipe("C:\Users\[REDACTED]\test.recipe")
.o
)
Expected behavior
it to print the encrypted "Hello world"
Desktop (please complete the following information):
Additional context
I am using a recipe from the cyberchef website so that might be the issue?
Describe the bug
No pcap command available.
To Reproduce
:~/tmp/analisis/pcap$ chepy p.pcap
read_pcap
ERROR: Could not consume arg: read_pcap
read_pcap is not a valid Chepy method
Desktop (please complete the following information):
Hi, I have tried to install Chepy on Windows Subsystem for Linux (Ubuntu), but pip3 installation has failed with the following error:
$ sudo -H pip3 install chepy
Collecting chepy
Downloading https://files.pythonhosted.org/packages/b9/1a/1b1a406c6e343018b21d820323897327c56991f17eb383c56ff2c8d347dd/chepy-1.5.0.tar.gz (60kB)
100% |################################| 61kB 1.3MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-quz04m03/chepy/setup.py", line 18, in <module>
requirements = read_requirements()
File "/tmp/pip-build-quz04m03/chepy/setup.py", line 14, in read_requirements
with open("requirements.txt") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-quz04m03/chepy/
$
Module escape_string() provides an example for unescape_string()
Line 353 in bc4c2be
Hi, I have tried to install Chepy on Windows, but pip3 installation has failed with the following error:
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [7 lines of output]
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "C:\Users\lipu\AppData\Local\Temp\pip-install-9s51y_zs\lazy-import_33141cce3c0c4752a7b368e8515ea1a2\setup.py", line 6, in <module>
readme = infile.read()
^^^^^^^^^^^^^
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa5 in position 623: illegal multibyte sequence
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
Describe the bug
pip can not install chepy , and here is the error stack
Preparing metadata (setup.py) ... done
Collecting base58
Using cached base58-2.1.1-py3-none-any.whl (5.6 kB)
Collecting colorama
Using cached colorama-0.4.4-py2.py3-none-any.whl (16 kB)
Collecting crccheck
Using cached crccheck-1.1-py3-none-any.whl (29 kB)
Collecting decorator
Using cached decorator-5.1.1-py3-none-any.whl (9.1 kB)
Collecting docstring-parser
Using cached docstring_parser-0.13.tar.gz (23 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Collecting emoji
Using cached emoji-1.6.3.tar.gz (174 kB)
Preparing metadata (setup.py) ... done
Collecting exrex
Using cached exrex-0.10.5.tar.gz (4.8 kB)
Preparing metadata (setup.py) ... done
Collecting fire==0.4.0
Using cached fire-0.4.0.tar.gz (87 kB)
Preparing metadata (setup.py) ... done
Collecting lazy-import
Using cached lazy_import-0.2.2.tar.gz (15 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [6 lines of output]
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "C:\Users\Ryan\AppData\Local\Temp\pip-install-n3w9cm9y\lazy-import_b016669906f64b6b8754dec0e34c1709\setup.py", line 6, in <module>
readme = infile.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa5 in position 623: illegal multibyte sequence
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
To Reproduce
just run
pip install chepy
Expected behavior
successfully installed
Desktop (please complete the following information):
Additional context
I have tried to execute Chepy CLI after installation, but it has exited with the following error message:
$ chepy
Traceback (most recent call last):
File "/usr/local/bin/chepy", line 11, in <module>
load_entry_point('chepy==1.5.1', 'console_scripts', 'chepy')()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 480, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2693, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2324, in load
return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2330, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python3.6/dist-packages/chepy/__init__.py", line 22, in <module>
_plugins = ChepyConfig().load_plugins()
File "/usr/local/lib/python3.6/dist-packages/chepy/config.py", line 43, in __init__
self.plugin_path = self.config["Plugin"]["PluginPath"]
File "/usr/lib/python3.6/configparser.py", line 959, in __getitem__
raise KeyError(key)
KeyError: 'Plugin'
$
So I have created ~/.chepy/chepy.conf like this based on the error message and the Chepy document:
[Plugin]
pluginpath = None
Then the error message has been slightly changed:
Traceback (most recent call last):
File "/usr/local/bin/chepy", line 11, in <module>
load_entry_point('chepy==1.5.1', 'console_scripts', 'chepy')()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 480, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2693, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2324, in load
return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2330, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python3.6/dist-packages/chepy/__init__.py", line 22, in <module>
_plugins = ChepyConfig().load_plugins()
File "/usr/local/lib/python3.6/dist-packages/chepy/config.py", line 45, in __init__
self.history_path = self.config["Cli"]["history_path"]
File "/usr/lib/python3.6/configparser.py", line 959, in __getitem__
raise KeyError(key)
KeyError: 'Cli'
It seems that Chepy does not work unless I create chepy.conf with proper settings.
That's a fancy interactive Python shell in the demo GIF. What is it?
Describe the bug
$ chepy
File "/usr/local/bin/chepy", line 5, in <module>
from chepy.__main__ import main
File "/usr/local/lib/python3.7/site-packages/chepy/__main__.py", line 9, in <module>
from prompt_toolkit.completion import (
ImportError: cannot import name 'FuzzyCompleter' from 'prompt_toolkit.completion' (/usr/local/lib/python3.7/site-packages/prompt_toolkit/completion/__init__.py)
To Reproduce
macOS 10.14.6
python 3.7.6 brew
pip3 install chepy
as admin user
got error on install
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/data'
Consider using the `--user` option or check the permissions.
(is this a dependency issue ? the directory /usr/local/data/
does not exist, isn't found in chepy codebase)
Updated pip and reran, installed successfully
Ran $ chepy
Expected behavior
chepy runs
Desktop (please complete the following information):
Describe the bug
Running chepy
from python 3.12 causes an import error on distutil which was deprecated in 3.10 and removed in 3.10:
https://docs.python.org/3.10/library/distutils.html#module-distutils
To Reproduce
With python 3.12:
> chepy -h
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
chepy 5 <module>
from chepy.__main__ import main
__main__.py 23 <module>
import chepy.modules.internal.cli as chepy_cli
cli.py 6 <module>
import editor
editor.py 11 <module>
from distutils.spawn import find_executable
ModuleNotFoundError:
No module named 'distutils'
Expected behavior
No error:
> chepy -h
usage: chepy [-h] [-v] [-r RECIPE] data [data ...]
positional arguments:
data
options:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-r RECIPE, --recipe RECIPE
Run a Chepy recipe and exit
Screenshots
See output above.
Desktop (please complete the following information):
Additional context
N/A
Any chance to expose choosing the cyberchef URL? Maybe thought the .conf file?
Also, if "url" could be defined in core.py within ChepyCore.init this would allow us to change the URL at runtime.
Describe the bug
In the command line mode, I used the divide
functionality to divide the number 292262389274690408548006301899589727852083546444257944699387424801240942764492032200007955762912227603275746735031016712863733064563879094464059741610108500835368376220623485884465561854806354636144062794412193277435369414718402609 by 178
I tested this again with 103 by 5 and 10 by 2
Here is the error:
>>> ...
292262389274690408548006301899589727852083546444257944699387424801240942764492032200007955762912227603275746735031016712863733064563879094464059741610108500835368376220623485884465561854806354636144062794412193277435369414718402609
>>> divide --n 185
ERROR:root:
Cannot print current state. Either chain with another method, or use one of the output methods Example: .o, .output, .state or .out()
Traceback (most recent call last):
File "C:\Python39\lib\site-packages\chepy\core.py", line 111, in __str__
return self._convert_to_str()
File "C:\Python39\lib\site-packages\chepy\core.py", line 541, in _convert_to_str
raise NotImplementedError
NotImplementedError
To Reproduce
Use the command line to get the number 292262389274690408548006301899589727852083546444257944699387424801240942764492032200007955762912227603275746735031016712863733064563879094464059741610108500835368376220623485884465561854806354636144062794412193277435369414718402609 then divide it by 178 (Should work with any other denominator and or numerator)
Expected behavior
Expected Chepy to correctly divide the numbers, instead it raised an error.
Desktop:
I have seen that if I load a text file, text decoding is happening automatically. I believe this is due to the lack of the binary mode ("rb") being used to load the file:
Line 747 in af26c01
This causes issues when the exact bytes are required to be manipulated.
For example given the file below, it is loaded successfully by the first open
statement (line 747), which automatically decodes it's contents. Obviously, this is ok in most cases, however, this changes the loaded contents, instead, it should have been loaded by line 750.
$ xxd file.bin
00000000: 6865 6c6c 6f24 653d 3133 0d0a hello$e=13..
The above file has the md5 hash b2d3abb022e881225d9b1fc1b7cff2ae. However when loaded (as a file using .load_file()
, and passed through .md5()
, the hash comes out as 33f3ba396fa287739afefa64a715630d, which is incorrect.
This can be fixed by always loading files with open mode of "rb".
To recreate:
$ echo "00000000: 6865 6c6c 6f24 653d 3133 0d0a hello$e=13.." | xxd -r > test.bin
Chepy('test.bin').load_file().md5().o
Line 747 in af26c01
I propose that all files should be opened in "rb" mode (perferred option) or that an argument be provided by the user to load the file as bytes (a second option, if the first option breaks existing methods!)
As .load_file
is, chepy is making assumptions to what the user wants (in this case decoding automatically). This causes issues when the file contents should be loaded as is (byte-for-byte).
I caught this as I use chepy to load a file and then send it to a local service which returns the md5 hash of the provided data.
hi,
I can't change the state
when I use the Chepy CLI :
$ chepy --version
chepy 6.4.0
$ chepy state1 state2
>>> Type of current state
state1
>>> cli_show_states Chepy
{0: 'state1', 1: 'state2'}
>>> cli_get_state Chepy
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
chepy 8 <module>
sys.exit(main())
__main__.py 308 main
getattr(chepy_cli, cli_method)(fire_obj)
TypeError:
cli_get_state() missing 1 required positional argument: 'index'
$ chepy state1 state2
>>> cli_get_state(1) Type of current state
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
chepy 8 <module>
sys.exit(main())
__main__.py 308 main
getattr(chepy_cli, cli_method)(fire_obj)
AttributeError:
module 'chepy.modules.internal.cli' has no attribute 'cli_get_state(1)'
$ chepy state1 state2
>>> cli_get_state --1 Type of current state
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
chepy 8 <module>
sys.exit(main())
__main__.py 308 main
getattr(chepy_cli, cli_method)(fire_obj)
TypeError:
cli_get_state() missing 1 required positional argument: 'index'
$ chepy state1 state2
>>> cli_get_state --index=1 Type of current state
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
chepy 8 <module>
sys.exit(main())
__main__.py 308 main
getattr(chepy_cli, cli_method)(fire_obj)
TypeError:
cli_get_state() missing 1 required positional argument: 'index'
$ chepy state1 state2
>>> cli_get_state --index 1 Type of current state
<class 'NoneType'>
>>> Type of current state
state1
>>> Chepy
OKBye
(I have to restart Chepy every time because the error ejects me from the CLI)
and the subject is not addressed in the documentation : how to do it ?
regards, lacsaP.
from chepy import Chepy
print(Chepy('80').from_hex().to_binary().o)
UnicodeDecodeError Traceback (most recent call last)
Cell In[48], line 2
1 from chepy import Chepy
----> 2 print(Chepy('80').from_hex().to_binary().o)
File d:\codebase\CTF\tools\binary_recon.venv\lib\site-packages\decorator.py:232, in decorate..fun(*args, **kw)
230 if not kwsyntax:
231 args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)
File d:\codebase\CTF\tools\binary_recon.venv\lib\site-packages\chepy\core.py:51, in ChepyDecorators.call_stack(func, *args, **kwargs)
48 func_sig["args"] = func_arguments
49 func_self._stack.append(func_sig)
---> 51 return func(*args, **kwargs)
File d:\codebase\CTF\tools\binary_recon.venv\lib\site-packages\chepy\modules\dataformat.py:935, in DataFormat.to_binary(self, join_by)
920 @ChepyDecorators.call_stack
921 def to_binary(self, join_by: str = " ") -> DataFormatT:
922 """Convert string characters to binary
923
924 Args:
(...)
932 "01100001 01100010 01100011"
933 """
934 self.state = join_by.join(
--> 935 list(format(ord(s), "08b") for s in list(self._convert_to_str()))
936 )
937 return self
File d:\codebase\CTF\tools\binary_recon.venv\lib\site-packages\chepy\core.py:583, in ChepyCore._convert_to_str(self)
573 """This method is used to coerce the curret object in
574 the state variable into bytes. The method should be
575 called inside any method that operates on a bytes object
(...)
580 for the current state type.
581 """
582 if isinstance(self.state, bytes):
--> 583 return self.state.decode()
584 elif isinstance(self.state, str):
585 return self.state
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte
Lines 87 and 89:
iv = key.decode()...
Describe the bug
When remove_whitespace() is used a list of replacement characters is printed to the terminal:
[' ', '\r', '\n', '\t', '\x0c']
To Reproduce
$ python -V
Python 3.7.5
$ python
Python 3.7.5 (default, Nov 1 2019, 02:16:32)
[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from chepy import Chepy
>>> c = (
... Chepy("lots of white space s")
... .remove_whitespace()
... )
[' ', '\r', '\n', '\t', '\x0c']
>>> print(c.o)
lotsofwhitespaces
Hello, I would like to know if chepy's dependencies can be a range instead of a strict version. I know I'm not using venv, but probably not a lot of people uses venv for this kind of global tool.
I often update my global dependencies and chepy is one of the most problematic regarding conflicts. I recommend using major version range i.e. >1,<2
.
Thanks for this project :)
You may already have this, but I couldn't find a reference. The ability to do something like this in one shot would be amazing. This command wouldn't drop to the chepy cli, but the output would be the shell (bash etc.) terminal.
So this would string the modules together, acting on 'data_to_be_transformed'.
This would allow shell scripts to be built against this really, really quickly - or run from the command line and use other commands against it. Only trouble is outputting python objects to the command line (lists, dict etc.)
The source code to the Magic function used by CyberChef is here: https://github.com/gchq/CyberChef/blob/master/src/core/operations/Magic.mjs
It doesn't seem very complicated. I would try implementing it here and contributing, but I'm wondering if anyone has tried and struggled for some reason related to how this project implements things.
To create a full automatic recipe with the use of http_request, it would be great to be able to utilise state data in the request itself. This should mainly be available in Request payload, params etc.
An option for this maybe to have special characters which are replaced by the state values at runtime. i.e.:
>>> c = Chepy("https://en4qpftrmznwq.x.pipedream.net")
>>> c.http_request(
>>> method="POST",
>>> headers={"My-header": "some header"},
>>> json={"some": "$state"}
>>> )
Suggestion is, to be able to replace $state with the current state, and $state[1] with the first state index etc...
Just an idea to make it more flexible. My use case at the moment is that I have a bunch of simple APIs that I want to POST the state data to but I have to create a new plugin for each one...! This would also make it more versatile on the command line!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.