mirror of
https://github.com/aljazceru/ctfd-bitcoin-rewards-challenge.git
synced 2025-12-16 15:14:27 +01:00
main
Bitcoin Challenges Plugin for CTFd
A CTFd plugin that enables Bitcoin rewards for challenge completions, with Lightning Network support for instant withdrawals.
Features
- Real Bitcoin rewards for solving challenges
- Instant withdrawal to Lightning address on solve
- Persistent balance system with transaction history
- Lightning Network withdrawals via LNURL
- Admin wallet management dashboard
- User profile integration with balance display
- Auto-withdraw option for users with saved Lightning address
Installation
- Copy the plugin to CTFd plugins directory:
CTFd/plugins/bitcoin_challenges/
- Install dependencies:
pip install breez-sdk qrcode[pil] lnurl
- Set environment variables:
export BREEZ_API_KEY=your_api_key
export WALLET_MNEMONIC="your twelve word seed phrase"
export BITCOIN_DATA_DIR=./data/bitcoin_wallet
- Restart CTFd
Usage
For Administrators
- Create a new challenge and select "Bitcoin" as the challenge type
- Set the standard point value (for scoreboard)
- Set the Bitcoin reward amount in satoshis
- Enable/disable Bitcoin rewards as needed
Access the admin wallet dashboard at /admin/bitcoin to:
- View wallet balance
- Fund the wallet
- Monitor withdrawals
- View transaction history
For Users
- Solve Bitcoin challenges to earn sats
- On successful solve, enter Lightning address to withdraw instantly
- Or save Lightning address in Settings for quick withdrawals
- View balance and history in Settings > Bitcoin tab
Configuration
Required Environment Variables
BREEZ_API_KEY: Your Breez SDK API keyWALLET_MNEMONIC: 12-word seed phrase for the wallet
Optional Environment Variables
BITCOIN_DATA_DIR: Directory for wallet data (default:./data/bitcoin_wallet)BITCOIN_MAX_WITHDRAWAL_PER_DAY: Daily withdrawal limit per user (default: 10)BITCOIN_MAX_WITHDRAWAL_PER_HOUR: Hourly withdrawal limit per user (default: 5)
File Structure
CTFd/plugins/bitcoin_challenges/
├── __init__.py # Main plugin, challenge class, API routes
├── models.py # Database models (Balance, Reward, Withdrawal)
├── balances.py # Balance management functions
├── payments.py # Breez SDK integration
├── errors.py # Error handling
├── logging_config.py # Logging configuration
├── assets/
│ ├── create.html # Challenge creation template
│ ├── update.html # Challenge edit template
│ ├── view.html # Challenge view template
│ ├── bitcoin-challenge-success.js # Withdrawal UI on solve
│ └── settings_bitcoin_tab.js # User settings tab
└── admin/
├── routes.py # Admin API routes
└── templates/ # Admin dashboard templates
Security
- Wallet mnemonic stored only in environment variables
- Rate limiting on withdrawals
- Input validation on all endpoints
- CSRF protection on all forms
- Comprehensive audit logging
Description
Languages
Python
56.5%
JavaScript
32.4%
HTML
10.3%
CSS
0.8%