Skip to content

Commit 0253e11

Browse files
author
maxime.peim
committed
Added README, and better project structure
1 parent 3dfc03f commit 0253e11

11 files changed

+176
-12
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) [year] [fullname]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# CryptoHack Requester Package
2+
3+
This is a simple python package to ease interaction with CryptoHack's challenges over Netcat and Web API.
4+
5+
## Installing / Getting started
6+
7+
The project has been tested with python >= 3.6.9. It may works with previous version, but nothing sure.
8+
9+
To install the package simply use `pip`:
10+
```shell
11+
python3 -m pip install CHRequester
12+
```
13+
14+
## Features
15+
16+
CryptoHack has some challenges working with a Web API ([Block Cipher Mode challenges](https://cryptohack.org/challenges/aes/)), and some through server comunication. They generaly need automation so it is recommanded in the [FAQ](https://cryptohack.org/faq/) to use the [Requets](https://requests.readthedocs.io/en/master/) package for web challenges and [Pwntools](http://docs.pwntools.com/en/stable/) to communicate to a challenge on a server.
17+
This package offer a more user-firendly and less time-consuming way to communicate with these challenges.
18+
19+
### Example of usage with the Web API:
20+
```python
21+
from ch_requester import URLRequester
22+
23+
if __name__ == "__main__":
24+
BASE_URL = "http://aes.cryptohack.org/oh_snap/"
25+
26+
R = URLRequester(BASE_URL)
27+
# adding actions to the requester
28+
# first give the name of the action
29+
# then specify a tuple of inputs that are needed for this action
30+
# then specify a tuple of outputs that can given in return
31+
32+
# 'error' can be specified as an output if the challenge returns
33+
# useful information through an error message
34+
# else, an Exception will be raised if an error is returned
35+
# and the user does not specify it as a desired output.
36+
# inputs must be in the order of the url, e.g.
37+
# http://aes.cryptohack.org/oh_snap/ciphertext/nonce/
38+
R.add_action('send_cmd', ('ciphertext', 'nonce'), ('msg', 'error'))
39+
40+
# we can then execute an action, by giving its name as first parameters.
41+
# The following ordered arguments are the wanted outputs from this action.
42+
# Even if we specified multiple possible outputs for this actions ('error')
43+
# and 'msg', it is possible to retrieve a subset. If only one output is
44+
# asked, then its value is returned by the function. Else a dictionnary
45+
# is returned.
46+
# Then inputs are specified through unordered arguments. There must always
47+
# be given as bytes, the requester is in charge to send it as hex to the web
48+
# server. If some day the Web API changes, and some arguments are not expected
49+
# to be in hexadecimal, changes will be needed.
50+
error_message = req.do_action('send_cmd', 'error', ciphertext=b'\xff', nonce=b'\xff')
51+
52+
# do awesome things to find the flag
53+
```
54+
55+
### Example of usage with server communication using 'option' parameters:
56+
```python
57+
from ch_requester import NCRequester
58+
59+
if __name__ == "__main__":
60+
61+
R = NCRequester(13397)
62+
# adding actions to the requester
63+
# first give the name of the action, and must match the option
64+
# paramete of the server-side.
65+
# then specify a tuple of inputs that are needed for this action
66+
# then specify a tuple of outputs that can given in return.
67+
# No particular ordering is needed here.
68+
R.add_action("insert_key", ("key",), ("msg"))
69+
R.add_action("unlock", (), ("msg",))
70+
71+
# we then open the connection (using pwntools)
72+
R.open()
73+
# some challenges print a line to welcome the challenger
74+
# we can skip it
75+
R.flush_line()
76+
77+
# As for the Web API, we can execute action, except this time
78+
# the user is responsible to put input data into the correct
79+
# format used by the server-side.
80+
msg = req.do_action("insert_key", "msg", key=(b"\x00" * 16).hex())
81+
82+
print(msg)
83+
84+
flag = req.do_action("unlock", "msg")
85+
86+
# do awesome things to find the flag
87+
88+
R.close()
89+
```
90+
91+
### Example of usage with server communication without 'option' parameters:
92+
```python
93+
from ch_requester import NCRequester
94+
from base64 import b64decode
95+
96+
if __name__ == "__main__":
97+
98+
R = NCRequester(13370)
99+
# some challenges don't use the 'option' parameters
100+
# so you can send your own dictionnary payload to the server
101+
102+
# we then open the connection (using pwntools)
103+
R.open()
104+
# some challenges print a line to welcome the challenger
105+
# we can skip it
106+
R.flush_line()
107+
108+
PAYLOAD = {'msg': 'request'}
109+
ciphertext = b64decode(req.send_recv_raw_payload(PAYLOAD, 'ciphertext'))
110+
111+
# do awesome things to find the flag
112+
113+
R.close()
114+
```
115+
116+
## Contributing
117+
118+
If you'd like to contribute, please fork the repository and use a feature
119+
branch. Pull requests are warmly welcome.
120+
121+
## Licensing
122+
123+
The code in this project is licensed under MIT license.
5.03 KB
Binary file not shown.
5.04 KB
Binary file not shown.
6.17 KB
Binary file not shown.
6.17 KB
Binary file not shown.

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[build-system]
2+
requires = [
3+
"setuptools>=42",
4+
"wheel"
5+
]
6+
build-backend = "setuptools.build_meta"

setup.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
from setuptools import setup
2-
setup(
3-
name='CHRequester',
4-
version='0.1',
5-
description='Cryptohack URL/NetCat request maker.',
6-
url='#',
1+
import setuptools
2+
3+
with open("README.md", "r", encoding="utf-8") as fh:
4+
long_description = fh.read()
5+
6+
setuptools.setup(
7+
name='CHRequester-Maxou',
8+
version='0.0.4',
79
author='Maxime Peim',
810
author_email='[email protected]',
9-
license='MIT',
10-
packages=['ch_requester'],
11-
zip_safe=False,
11+
description='Cryptohack URL/NetCat request maker.',
12+
long_description=long_description,
13+
long_description_content_type="text/markdown",
14+
url='https://github.com/maxime-peim/cryptohack-requester',
15+
project_urls={
16+
'Bug Tracker': 'https://github.com/maxime-peim/cryptohack-requester/issues',
17+
},
18+
classifiers=[
19+
"Programming Language :: Python :: 3",
20+
"License :: OSI Approved :: MIT License",
21+
"Operating System :: OS Independent",
22+
],
23+
package_dir={"": "src"},
24+
packages=setuptools.find_packages(where="src"),
1225
install_requires=[
13-
"requests >= 2.26"
26+
'requests >= 2.26',
27+
'pwntools >= 4.6.0'
1428
],
1529
)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .url_requester import URLRequester
22
from .nc_requester import NCRequester
33

4-
__all__ = ['URLRequester', 'NCRequester']
4+
__all__ = ['URLRequester', 'NCRequester']
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class NCRequester:
77

8-
def __init__(self, hostname: str, port: int, actions: Optional[dict] = None) -> None:
8+
def __init__(self, port: int, hostname: str = "socket.cryptohack.org", actions: Optional[dict] = None) -> None:
99
self._hostname: str = hostname
1010
self._port: int = port
1111
self._actions: dict = {} if not actions else actions

0 commit comments

Comments
 (0)