This repository contains comprehensive solutions and detailed writeups for HackTheBox Blockchain challenges. Each solution includes:
- β Working exploit code (Python + Solidity)
- π Detailed README documenting the problem-solving journey
- π Failed attempts and why they didn't work
- π‘ Breakthrough moments and key insights
- π‘οΈ Defense mechanisms and security best practices
- π― Automatic flag extraction from HTB endpoints
All solutions are tested and verified to work against live HTB instances.
| Challenge | Vulnerability Type | Key Concepts | Status |
|---|---|---|---|
| Survival of the Fittest | Direct Combat | Basic contract interaction, function calls | β Solved |
| Distract and Destroy | Access Control | tx.origin vs msg.sender, proxy contracts |
β Solved |
| Challenge | Vulnerability Type | Key Concepts | Status |
|---|---|---|---|
| Honor Among Thieves | Event Analysis | XOR encryption, transaction forensics, event logs | β Solved |
| Magic Vault | Storage Reading | Private storage variables, password extraction | β Solved |
| Token to Wonderland | Integer Underflow | ERC20 vulnerabilities, unchecked arithmetic | β Solved |
| Challenge | Vulnerability Type | Key Concepts | Status |
|---|---|---|---|
| False Bidding | Integer Overflow | uint32 overflow, time manipulation, helper contracts | β Solved |
| Portal Noncense | Address Prediction | Deterministic addresses, RLP encoding, nonce burning | β Solved |
| Locked and Loaded | Reentrancy | CEI pattern violation, recursive external calls | β Solved |
Difficulty: Very Easy | Category: Combat Mechanics
π Challenge Details
Description: Face your first monster on a mysterious island. Learn basic smart contract interaction by attacking a creature and claiming its loot.
Win Condition: Drain the Creature contract's balance to 0 by reducing its life points.
Key Vulnerability:
- Simple combat system with no access controls
attack()function reduces life pointsloot()function withdraws funds when creature is defeated
Concepts Learned:
- Basic contract interaction
- Reading contract state
- Function calls and transactions
- Balance manipulation
Flag: HTB{...}
Files:
solve.py- Automated exploit scriptCreature.sol- Vulnerable combat contractSetup.sol- Challenge setup and win conditionREADME.md- Detailed writeup
Difficulty: Very Easy | Category: Access Control
π Challenge Details
Description: Face a stronger monster with defense mechanisms. Learn to bypass tx.origin checks using intermediate contracts.
Win Condition: Drain the Creature contract despite the tx.origin defense check.
Key Vulnerability:
- Uses
tx.origin == msg.sendercheck inattack() - This check fails when called through a contract
- Solution: Deploy a proxy contract to call
attack()
Concepts Learned:
tx.originvsmsg.senderdifferences- Proxy contract patterns
- Access control vulnerabilities
- Contract-to-contract calls
Flag: HTB{...}
Files:
solution.py- Automated exploit with proxy contractCreature.sol- Contract with tx.origin checkSetup.sol- Challenge setupREADME.md- Detailed writeup
Difficulty: Easy | Category: Cryptography + Blockchain
π Challenge Details
Description: Spy on a rival group and steal their key. Extract the flag by analyzing blockchain events and reversing XOR encryption.
Win Condition: Call talk() with the correct key to become the solver.
Key Vulnerability:
- Previous successful transaction emitted
Voice(5)event - Transaction data reveals the correct
_keyparameter - Flag can be extracted from event logs without solving XOR
Concepts Learned:
- Blockchain forensics and event analysis
- Reading past transactions
- Event log extraction
- XOR encryption properties
- Transaction replay analysis
Flag: HTB{d0n7_741k_11573n_70_3v3n75!}
Files:
solve.py- Event analysis exploit (145 lines)Rivals.sol- XOR challenge contractSetup.sol- Challenge initializationREADME.md- Complete writeup with 5 failed attempts (476 lines)
Difficulty: Easy | Category: Storage Manipulation
π Challenge Details
Description: Unlock a magic vault protected by complex password validation. Learn to read private storage variables from the blockchain.
Win Condition: Call openVault() with the correct password to become the map holder.
Key Vulnerability:
- Password stored in "private" storage variable
- Blockchain storage is always readable
- Can extract password using
web3.eth.get_storage_at()
Concepts Learned:
- Storage slot calculation
- Reading private variables
- Complex password validation logic
- Storage layout in Solidity
- Keccak256 hashing
Flag: HTB{...}
Files:
solve.py- Storage reading exploitVault.sol- Password-protected vaultVaultExploit.sol- Optional exploit contractSetup.sol- Challenge setupREADME.md- Detailed writeup (426 lines)
Difficulty: Easy | Category: ERC20 Security
π Challenge Details
Description: Buy a golden key from a shop using silver coins. Exploit integer underflow to generate unlimited tokens and purchase the key.
Win Condition: Own item #2 (the Golden Key) by accumulating enough SilverCoins.
Key Vulnerability:
SilverCoin.transfer()uses unchecked arithmetic- Transferring more than your balance causes underflow
- Balance wraps around to 2^256 - 1 (unlimited coins)
Concepts Learned:
- Integer underflow vulnerabilities
- ERC20 token mechanics
- Unchecked arithmetic blocks
- Balance manipulation
- Safe math patterns
Flag: HTB{...}
Files:
main.py- Underflow exploit scriptShop.sol- Item shop contractSilverCoin.sol- Vulnerable ERC20 tokenSetup.sol- Challenge initializationREADME.md- Complete writeup (405 lines)
Difficulty: Medium | Category: Integer Overflow
π Challenge Details
Description: Win a secret auction for the Phoenix Key. Exploit uint32 overflow in the timeout mechanism to claim the prize instantly.
Win Condition: Become the owner of the Phoenix Key by claiming it before timeout expires normally.
Key Vulnerability:
timeoutisuint32(max: 4,294,967,295 seconds = ~136 years)- Each bid adds 1 year (31,556,926 seconds)
- 136 bids cause overflow β timeout wraps to small value
- Can claim prize immediately after overflow
Exploitation Strategy:
- Bid 1 ETH to become top bidder
- Deploy 136 helper contracts
- Each helper bids then withdraws (increments timeout)
- Helper contracts have no
receive()β refund fails β blacklisted - After 136 cycles, timeout overflows
- Claim the Phoenix Key
Concepts Learned:
- Integer overflow in uint32
- Time-based vulnerabilities
- Helper contract patterns
- Blacklist bypass mechanics
- Nonce burning for contract deployment
Flag: HTB{0v32f10w_70_w1n_7h3_4uc710n}
Files:
solve.py- Complete overflow exploit (169 lines)AuctionHouse.sol- Vulnerable auction contractSetup.sol- Challenge setupREADME.md- Comprehensive writeup with 5 failed attempts (653 lines)
Difficulty: Medium | Category: Address Calculation
π Challenge Details
Description: Navigate the portal station to reach the Orc Kingdom. Calculate the exact nonce needed to deploy a contract at a predetermined address.
Win Condition: Activate the orcKingdom portal by deploying a contract at the hardcoded destination address.
Key Vulnerability:
- Portal destinations are hardcoded addresses
delegatecallto destination requires a contract withconnect()function- Contract addresses are deterministic:
keccak256(rlp([sender, nonce]))[12:] - Can calculate which nonce deploys to the target address
Exploitation Strategy:
- Read hardcoded address:
0xFC31cde4aCbF2b1d2996a2C7f695E850918e4007 - Burn nonces by deploying dummy contracts
- Calculate when next deployment matches target address
- Deploy exploit contract with
connect()function at exact nonce - Call
createPortal("orcKingdom")β delegatecall succeeds - Portal activated!
Concepts Learned:
- Deterministic contract address calculation
- RLP encoding in Python
- Keccak256 hashing
- Nonce manipulation
- Delegatecall mechanics
- CREATE opcode behavior
Flag: HTB{7h3_4dd2355_0f_4_c0n724c7_15_41m057_d3732m1n1571c}
Files:
solve.py- Dynamic nonce calculation exploit (173 lines)main.py- Original script with hardcoded noncePortal.sol- Portal station contractSetup.sol- Challenge setupREADME.md- Detailed writeup with clarifications (682 lines)
Important Clarification: The address 0xFC31cde4... IS hardcoded in the Lockers.sol constructor, but we CALCULATE which nonce from our account will deploy a contract to that exact address.
Difficulty: Medium | Category: Reentrancy
π Challenge Details
Description: Raid a wizard's locker system to steal the WizardsScepter and drain all funds. Exploit a classic reentrancy vulnerability in the payment mechanism.
Win Condition: Drain the Lockers contract completely (balance must be 0 ETH).
Key Vulnerability:
sellItem()sends payment via.call{value:}BEFORE deleting the item- External call triggers the receiver's
fallback()orreceive()function - Can call
sellItem()recursively before the item is deleted - Each call pays out 1 ETH until contract is drained
Exploitation Strategy:
- Deploy attack contract with reentrancy callback
- Register username = attack contract address (as string)
- Transfer WizardsScepter (Mythic, 1 ETH) to attack contract's username
- Call
start()β triggerssellItem() - Payment sent to attack contract β
receive()called receive()callssellItem()again (item not deleted yet!)- Recursive reentrancy drains all 2 ETH
- Contract balance = 0 β Challenge solved!
Concepts Learned:
- Reentrancy attack patterns
- Checks-Effects-Interactions pattern
- Memory vs storage modifications
- Fallback and receive functions
- Recursive external calls
- Address-to-string conversion
Flag: HTB{und32574nd1n9_7h3_s70rag3_47_7h3_m4x}
Files:
exploit.py- Complete reentrancy attack (168 lines)Attack.sol- Exploit contract with fallback reentrancyLockers.sol- Vulnerable locker systemSetup.sol- Challenge setupREADME.md- Comprehensive writeup with 5 failed attempts (717 lines)
- Solidity: 0.7.0, 0.8.13 (Smart contract development)
- Python: 3.10+ (Exploit scripts)
- Web3.py: Ethereum interaction library
web3 # Ethereum JSON-RPC interaction
eth_abi # ABI encoding/decoding
requests # HTTP requests for flag retrieval
solcx # Solidity compiler wrapper
rlp # Recursive Length Prefix encoding- Foundry/Forge: Smart contract testing
- Remix: Contract compilation and debugging
- Ganache: Local blockchain testing
- MetaMask: Wallet interaction
# Install Python dependencies
pip install web3 eth_abi requests py-solc-x rlp
# Or using the project's pyproject.toml
pip install -e .Each challenge directory contains a solve script. General usage:
# Navigate to challenge directory
cd "Challenge Name"
# Run the exploit
python solve.py
# or
python exploit.py
# or
python main.py
# or
python solution.pyMost scripts automatically:
- π Fetch connection info from HTB endpoint
- π Deploy necessary contracts
- π₯ Execute the exploit
- π Retrieve and display the flag
If automatic fetching fails, update the script with your instance details:
RPC_URL = "http://your-instance-ip:port"
PRIVATE_KEY = "0x..."
PLAYER_ADDRESS = "0x..."
SETUP_ADDRESS = "0x..."
TARGET_ADDRESS = "0x..."Recommended challenge order for learning:
- Survival of the Fittest - Basic contract interaction
- Distract and Destroy - Access control basics
- Honor Among Thieves - Event analysis and forensics
- Magic Vault - Storage reading techniques
- Token to Wonderland - Integer vulnerabilities
- False Bidding - Advanced overflow exploitation
- Portal Noncense - Deterministic address calculation
- Locked and Loaded - Reentrancy attacks
- Challenges: False Bidding, Token to Wonderland
- Concept: Arithmetic wrapping in fixed-size integers
- Defense: Use SafeMath or Solidity 0.8+ built-in checks
- Challenges: Locked and Loaded
- Concept: Recursive external calls before state updates
- Defense: Checks-Effects-Interactions pattern, ReentrancyGuard
- Challenges: Distract and Destroy
- Concept:
tx.originvsmsg.senderconfusion - Defense: Always use
msg.senderfor authorization
- Challenges: Magic Vault, Honor Among Thieves
- Concept: "Private" variables are publicly readable
- Defense: Never store secrets on-chain
- Challenges: Portal Noncense
- Concept: Deterministic contract address calculation
- Defense: Don't rely on address secrecy, validate deployed code
- Challenges: Honor Among Thieves
- Concept: Historical transactions reveal sensitive data
- Defense: Don't pass secrets as function parameters
Each challenge README follows a consistent structure:
- Challenge Description - Story and context
- Initial Reconnaissance - Contract analysis and win conditions
- Understanding the Mechanics - How the system works
- Failed Attempts - 5+ approaches that didn't work (with code)
- The Breakthrough - Discovery of the actual vulnerability
- Exploitation - Step-by-step attack execution
- Running the Solution - Usage instructions and expected output
- Key Takeaways - Lessons learned and defense mechanisms
- Real-World Implications - Similar vulnerabilities in production
- Resources - Additional reading and references
Smart Contract Security:
- Common vulnerability patterns (OWASP Top 10)
- Secure coding practices
- Audit techniques and red flags
Blockchain Fundamentals:
- EVM mechanics and opcodes
- Storage layout and memory management
- Gas optimization and transaction analysis
Exploitation Techniques:
- Contract-to-contract interactions
- State manipulation strategies
- Advanced attack patterns
Python + Web3:
- Contract compilation and deployment
- Transaction signing and broadcasting
- ABI encoding/decoding
β
Use Solidity 0.8+ for automatic overflow checks
β
Implement reentrancy guards on external calls
β
Follow Checks-Effects-Interactions pattern
β
Use msg.sender not tx.origin for authorization
β
Never store secrets in contract storage
β
Validate all inputs and state transitions
β
Use OpenZeppelin libraries for standards
β
Conduct professional audits before mainnet
β
Implement circuit breakers for emergency stops
β
Test extensively with fuzzing and formal verification
Total Challenges: 8
Difficulty Breakdown:
- Very Easy: 2
- Easy: 3
- Medium: 3
Lines of Code:
- Python Scripts: ~1,300 lines
- Solidity Contracts: ~800 lines
- Documentation: ~4,600 lines
Vulnerability Types:
- Reentrancy: 1
- Integer Overflow/Underflow: 2
- Access Control: 1
- Storage Reading: 1
- Address Prediction: 1
- Event Analysis: 1
- Direct Interaction: 2
While this is a personal solution repository, feedback and improvements are welcome:
- π Bug Reports: Found an issue? Open an issue!
- π‘ Alternative Solutions: Have a different approach? Share it!
- π Documentation: Improvements to writeups are appreciated
- π Security: Found a vulnerability? Please report responsibly
Educational Purpose Only
This repository is intended for:
- β Learning smart contract security
- β Understanding blockchain vulnerabilities
- β Practicing ethical hacking in controlled environments
- β Solving HackTheBox challenges
NOT intended for:
- β Attacking mainnet contracts
- β Unauthorized exploitation
- β Financial theft or fraud
- β Any illegal activities
Always obtain proper authorization before testing any system.
- π Platform: hackthebox.com
- π― Blockchain Track: app.hackthebox.com/tracks/Blockchain
- π Solidity Documentation
- π Smart Contract Best Practices
- π‘οΈ SWC Registry - Smart Contract Weakness Classification
- π Ethernaut - More blockchain CTF challenges
- π OpenZeppelin Docs
This project is provided for educational purposes. Each challenge is the intellectual property of HackTheBox. Solutions and writeups are original work.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β β
All 8 Blockchain Challenges Solved β
β β
β π― Flags Captured: 8/8 β
β π Writeups Completed: 8/8 β
β π§ Exploits Working: 8/8 β
β β
β π‘ Vulnerabilities Mastered: β
β β’ Reentrancy Attacks β
β β’ Integer Overflow/Underflow β
β β’ Access Control Bypasses β
β β’ Storage Manipulation β
β β’ Address Prediction β
β β’ Event Analysis β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β If you found this helpful, consider starring the repository! β
Made with π§ for blockchain security enthusiasts
Happy Hacking! π