swuforce

[워게임]BISC Safe 풀이

범호야 2025. 9. 30. 23:20

문제 서버에 들어가보면 해당 금고만 보인다.

 

    const start = async () => {
    if(window.ethereum !== "undefined") {
            const accounts = await ethereum.request({method: "eth_requestAccounts"});
            account = accounts[0];
            console.log(`my contract: ${account}`);
    }
      const ABI = [
{
"inputs": [
{
"internalType": "address",
"name": "_owner",
"type": "address"
}
],
"name": "changeOwner",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "opensafe",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
}
];
      const ADDRESS = "0x5e992854Bd912ae170b7b5b8a64323e4e5E0feAF";
      window.web3 = await new Web3(window.ethereum);
      window.contract = new web3.eth.Contract(ABI, ADDRESS);
      console.log(`safe contract: ${window.contract.options.address}`);
  }
  start();
  async function openSafe() {
    try {
      const result = await window.contract.methods.opensafe().call({from: account});
  
      if (result === "Your not owner!!") {
        document.getElementById('result').innerText = result;
      } else {
        document.getElementById('result').innerText = result;
        var door = document.getElementById('door');
        door.style.transform = 'rotateY(-90deg)';
      }
    } catch (error) {
      console.error(error);
    }
  }


  -> 위의코드는 개발자 도구로 열어서 확인해본 코드이다. 여기서 더 힌트를 얻지는 못 할 것 같아 문제 파일을 확인해본다. 

safe.sol이라는 파일만 있다. 

오 별도의 에디터 없이 VSCode에서 열린다

코드를 확인해보면 owner 는 msg.sender여야만 금고가 열리는 것 같다. 

콘솔 창에서 my contrack와 safe contract를 확인할 수 있다. 신기방구

그러면 이제 owner == msg.sender이므로 owner의 주소를 알아내고 그 주소를 opensafe()함수를 사용하여 열면 열리겠다.