无题
OnChain Transaction Debugging: 4. Write your own POC - MEV Bot
Author: Sun
手把手撰写 PoC - 以 MEV Bot (BNB48) 为例
前情提要
20220913 有一个 MEV Bot 被攻击者发现漏洞进而将合约上的资产都转走,共损失约 $140K.
攻击者透过 BNB48 验证节点发送隐私交易,类似于 Flashbot 不把交易放入公开 mempool 避免被抢跑攻击.
分析
攻击者发动攻击的 TXID,MEV Bot合约未开源,如何利用的?
透过 phalcon 来分析看看,从金流的部分可到这笔交易将 MEV bot 转移了 6 种资产到攻击者钱包上,如何利用的?
再来换看看 Function call 调用流程,看到刚好也调用了 6 次 pancakeCall 函式.
From: 0xee286554f8b315f0560a15b6f085ddad616d0601
攻击者合约: 0x5cb11ce550a2e6c24ebfc8df86c5757b596e69c1
MEV B ...
无题
OnChain Transaction Debugging: 5. Write Your Own PoC (Reentrancy)
Author: gbaleeee
在本次教学中,我们将带你实际分析一个重入攻击事件,并逐步带你利用 Foundry 测试框架撰写代码,完成 Reproduce PoC。
在学习撰写 Reproduce PoC 之前,会需要具备的知识
了解常见智能合约漏洞样态,可以参考 DeFiVulnLabs 进行练习。
了解 DeFi 基础建设如何运作,以及智能合约与智能合约之间如何互动。
重入攻击相关概念介绍
来自Consensys的一篇对重入攻击介绍的文章:Reentrancy
重入攻击是区块链世界中广泛存在一种攻击手法,在DeFiHackLabs库中搜索,你会发现几乎每月都会发生重入攻击的事件。同时有一个精彩的Github项目 reentrancy-attacks,专门收录现实中发生的重入攻击。
对于重入攻击的攻击模式简单概括:当一个函数对另一个不受信任的合约进行外部调用时,重入攻击就有可能发生。
目前可以将重入攻击分为三种类型
单函数重入 (Single ...
无题
OnChain Transaction Debugging: 4. Write your own POC - MEV Bot
Author: Sun
Write PoC step by step - Take MEV Bot (BNB48) as an example
Recap
On 20220913 A MEV Bot was exploited by an attacker and all the assets on the contract were transferred away, with a total loss of about $140K.
The attacker sends a private transaction through the BNB48 validator node, similar to Flashbot not putting the transaction into the public mempool to avoid being Front-running.
Analysis
Attacker’s TXID,We can se ...
无题
OnChain Transaction Debugging: 5. Write Your Own PoC (Reentrancy)
Author: gbaleeee
Translation: Spark
In this article, we will learn reentrancy by demonstrating a real-world attack and using Foundry to conduct tests and reproduce the attack.
Prerequisite
Understand common attack vectors in the smart contract. DeFiVulnLabs is a great resource to get started.
Know how the basic Defi model work and how smart contracts interact with others.
What Is Reentrancy Attack
Source from: Reentrancy by Cons ...
无题
WTF Solidity习题汇总
文件夹命名规则:
每一讲的随堂检验,以第一讲为例:Quiz_01_HelloWeb3
每5讲的小测,以第1-5讲小测为例:Exam_01_05
入门、进阶、应用的大测验,入门为Exam_Baic,进阶为Exam_Advanced、应用为Exam_Application
无题
OnChain Transaction Debugging: 2. Warm up
Author: Sun
链上交易数据包含从简单的单笔交易转帐、1 个 DeFi 合约交互、多个 DeFi 合约交互、闪电贷套利、治理提案、跨链交易等等,这一节我们先来热身一下,先从简单的开始。我将介绍通常使用区块链浏览器 Etherscan 哪些讯息是我们所在意的,再来我们会使用交易分析工具 Phalcon 看一下这些交易从简单的转帐、UniSWAP上 Swap、Curve 3pool 增加流动性、Compound 治理提案、闪电贷的调用差异。
开始进入热身篇
首先环境上需要先安装 Foundry,安装方法请参考 instructions.
测试主要会用到 Forge test,如果第一次使用 Foundry,可以参考 Foundry book、Foundry @EthCC、WTF Solidity - Foundry
每条链上都有专属的区块链浏览器,这节我们都会使用 Ethereum 主网来当案例所以可以透过 Etherscan 来分析.
通常我会特别想看的栏位包含:
Transaction ...
无题
OnChain Transaction Debugging: 1. Tools
Author: SunSec
Online resources were scarce when I started learning on-chain transaction analysis. Although slowly, l was able to piece together bits and pieces of information to perform tests and analysis.
From my studies, we will launch a series of Web3 security articles to entice more people to join Web3 security and create a secure network together.
In the first series, we will introduce how to conduct an on-chain analysis, and then we will reproduce o ...
无题
OnChain Transaction Debugging: 2. Warm up
Author: Sun
Translation: Helen
Community Discord
This article is published on XREX and WTF Academy
On-chain data can include simple one-time transfers, interactions with one DeFi contract or multiple DeFi contracts, flash loan arbitrage, governance proposals, cross-chain transactions, and more. In this section, let’s begin with a simple start.
I will introduce on BlockChain Explorer - Etherscan what we are interested in, and then use Phalcon to compare t ...
S17. "跨服"重入攻击
WTF Solidity 合约安全: S17. "跨服"重入攻击
我最近在重新学 Solidity,巩固一下细节,也写一个“WTF Solidity 合约安全”,供小白们使用(编程大佬可以另找教程),每周更新 1-3 讲。
推特:@0xAA_Science|@WTFAcademy_
社区:Discord|微信群|官网 wtf.academy
所有代码和教程开源在 github: github.com/AmazingAng/WTF-Solidity
在智能合约安全领域,重入攻击永远是一个备受关注的话题。在重入攻击这一讲中,0xAA生动展示了教科书级经典的重入攻击思路;而在生产环境中,常常有一些更加安排巧妙,复杂的实例一直在以各种新瓶装旧酒的面目不断地出现,并且成功地对很多项目造成了破坏。这些实例展示了攻击者如何利用智能合约中的漏洞来搭配组合出精心策划的攻击。这一讲,我们将介绍一些生产环境中真实发生的具有“跨服”属性的重入攻击案例。所谓“跨服”,是对这一类型的攻击目标的生动概括,因为它们共同的手段是从某一个函数开始入手,但是攻击对象却是其他函数/合约/项目等等。在本讲 ...
S16. NFT重入攻击
WTF Solidity 合约安全: S16. NFT重入攻击
我最近在重新学 Solidity,巩固一下细节,也写一个“WTF Solidity 合约安全”,供小白们使用(编程大佬可以另找教程),每周更新 1-3 讲。
推特:@0xAA_Science|@WTFAcademy_
社区:Discord|微信群|官网 wtf.academy
所有代码和教程开源在 github: github.com/AmazingAng/WTF-Solidity
这一讲,我们将介绍NFT合约的重入攻击漏洞,并攻击一个有漏洞的NFT合约,铸造10个NFT。
NFT重入风险
我们在S01 重入攻击中讲过,重入攻击是智能合约中最常见的一种攻击,攻击者通过合约漏洞(例如fallback函数)循环调用合约,将合约中资产转走或铸造大量代币。转账NFT时并不会触发合约的fallback或receive函数,为什么会有重入风险呢?
这是因为NFT标准(ERC721/ERC1155)为了防止用户误把资产转入黑洞而加入了安全转账:如果转入地址为合约,则会调用该地址相应的检查函数,确保它已准备好接收NFT资产。例如 ERC ...