Ethernaut, a CTF-like smart contract security challenge writeup
1. Ethernaut0 - Hello Ethernaut
// SPDX-License-Identifier: MIT
pragma solidity^0.8.0;
contractInstance {
stringpublic password;
uint8public infoNum =42;
stringpublic theMethodName ='The method name is method7123949.';
boolprivate cleared =false;
// constructor
constructor(stringmemory _password) {
password = _password;
}
functioninfo() publicpurereturns (stringmemory) {
return'You will find what you need in info1().';
}
functioninfo1() publicpurereturns (stringmemory) {
return'Try info2(), but with "hello" as a parameter.';
}
functioninfo2(stringmemory param) publicpurereturns (stringmemory) {
if(keccak256(abi.encodePacked(param)) == keccak256(abi.encodePacked('hello'))) {
return'The property infoNum holds the number of the next info method to call.';
}
return'Wrong parameter.';
}
functioninfo42() publicpurereturns (stringmemory) {
return'theMethodName is the name of the next method.';
}
functionmethod7123949() publicpurereturns (stringmemory) {
return'If you know the password, submit it to authenticate().';
}
functionauthenticate(stringmemory passkey) public {
if(keccak256(abi.encodePacked(passkey)) == keccak256(abi.encodePacked(password))) {
cleared =true;
}
}
functiongetCleared() publicviewreturns (bool) {
return cleared;
}
}
1.1 Solution
Starting from contract.info() which redirecting me to a function that change “cleared” to true;