<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Mythril on Ash Tewari</title><link>https://www.tewari.info/tag/mythril/</link><description>Recent content in Mythril on Ash Tewari</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><lastBuildDate>Sun, 22 May 2022 23:32:20 +0000</lastBuildDate><atom:link href="https://www.tewari.info/tag/mythril/feed.xml" rel="self" type="application/rss+xml"/><item><title>Security Analysis of Etheruem Smart Contracts with Mythril</title><link>https://www.tewari.info/2022/05/22/security-analysis-of-etheruem-smart-contracts-with-mythril/</link><pubDate>Sun, 22 May 2022 23:32:20 +0000</pubDate><guid>https://www.tewari.info/2022/05/22/security-analysis-of-etheruem-smart-contracts-with-mythril/</guid><description>&lt;p&gt;&lt;a class="link" href="https://github.com/ConsenSys/mythril" target="_blank" rel="noopener"&#10; &gt;Mythril&lt;/a&gt; is an open-source security analysis tool for EVM bytecode, courtesy of &lt;a class="link" href="https://consensys.net/diligence/tools/" target="_blank" rel="noopener"&#10; &gt;ConsenSys&lt;/a&gt;. It is also a component of their Security Analysis Service - &lt;a class="link" href="https://mythx.io/" target="_blank" rel="noopener"&#10; &gt;Mythx&lt;/a&gt;. Mythril detects security vulnerabilities in smart contracts built for Ethereum and other EVM-compatible blockchains.&lt;/p&gt;&#10;&lt;p&gt;Vulnerabilities found by Mythril are reported with reference to the weaknesses listed on the Smart Contract Weakness Classification Registry (&lt;a class="link" href="https://swcregistry.io/" target="_blank" rel="noopener"&#10; &gt;SWC Registry&lt;/a&gt;). I will use two entries from SWC Registry for the examples in this article:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a class="link" href="https://swcregistry.io/docs/SWC-106#simple_suicidesol" target="_blank" rel="noopener"&#10; &gt;SWC-106&lt;/a&gt; - Due to missing or insufficient access controls, malicious parties can self-destruct the contract.&lt;/li&gt;&#10;&lt;li&gt;&lt;a class="link" href="https://swcregistry.io/docs/SWC-107#simple_daosol" target="_blank" rel="noopener"&#10; &gt;SWC-107&lt;/a&gt; - One of the major dangers of calling external contracts is that they can take over the control flow. In the reentrancy attack (a.k.a. recursive call attack), a malicious contract calls back into the calling contract before the first invocation of the function is finished.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h3 id="install-mythril-on-windows"&gt;Install Mythril on Windows&#10;&lt;/h3&gt;&#10; &lt;blockquote&gt;&#10; &lt;p&gt;&amp;gt; docker import mythril/myth&lt;/p&gt;&#10;&lt;p&gt;&lt;a class="link" href="https://mythril-classic.readthedocs.io/en/master/installation.html" target="_blank" rel="noopener"&#10; &gt;https://mythril-classic.readthedocs.io/en/master/installation.html&lt;/a&gt;&lt;/p&gt;&#10;&#10; &lt;/blockquote&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-16.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;h3 id="get-test-files-from-github"&gt;Get test files from github&#10;&lt;/h3&gt;&lt;p&gt;Source code for these tests is on github : &lt;a class="link" href="https://github.com/ashtewari/mythril-tests" target="_blank" rel="noopener"&#10; &gt;mythril-tests&lt;/a&gt;. Clone the repo locally and adjust the paths in the commands below to match your local environment.&lt;/p&gt;&#10;&lt;h3 id="analyze-a-local-smart-contract"&gt;Analyze a local smart contract&#10;&lt;/h3&gt;&lt;h5 id="analysis-of"&gt;&lt;strong&gt;Analysis of &lt;a class="link" href="https://github.com/ashtewari/mythril-tests/blob/master/mythx-tests/05222022-25/SelfDestructMultiTxFeasible.sol" target="_blank" rel="noopener"&#10; &gt;SelfDestructMultiTxFeasible.sol&lt;/a&gt;&lt;/strong&gt;&#10;&lt;/h5&gt;&#10; &lt;blockquote&gt;&#10; &lt;p&gt;&amp;gt; docker run -v E:\share\:/data mythril/myth -v4 analyze /data/mythx-tests\05222022-25/SelfDestructMultiTxFeasible.sol&lt;/p&gt;&#10;&#10; &lt;/blockquote&gt;&#10;&lt;p&gt;Mythril reports an instance of SWC-106 vulnerability:&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-17.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;h5 id=""&gt;&#10;&lt;/h5&gt;&lt;p&gt;&lt;strong&gt;Analysis of &lt;a class="link" href="https://github.com/ashtewari/mythril-tests/blob/master/mythx-tests/05222022-25/SimpleDAO.sol" target="_blank" rel="noopener"&#10; &gt;SimpleDAO.sol&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&#10;&#10; &lt;blockquote&gt;&#10; &lt;p&gt;&amp;gt; docker run -v E:\share\:/data mythril/myth -v4 analyze /data/mythx-tests\05222022-25/SimpleDAO.sol&lt;/p&gt;&#10;&#10; &lt;/blockquote&gt;&#10;&lt;p&gt;Mythril reports three instances of SWC-107 and one instance of SWC-105:&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-18.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;h5 id="analysis-of-a"&gt;&lt;strong&gt;Analysis of a &lt;a class="link" href="https://github.com/ashtewari/mythril-tests/blob/master/mythx-tests/05222022-25/flatenned-01.sol" target="_blank" rel="noopener"&#10; &gt;flatenned contract file&lt;/a&gt;&lt;/strong&gt;&#10;&lt;/h5&gt;&lt;p&gt;File containing the two test contracts returns five instances of vulnerabilities of both contracts:&lt;/p&gt;&#10;&#10; &lt;blockquote&gt;&#10; &lt;p&gt;&amp;gt; docker run -v E:\share\:/data mythril/myth -v4 analyze /data/mythx-tests\05222022-25/flatenned-01.sol&lt;/p&gt;&#10;&#10; &lt;/blockquote&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-19.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;h5 id="analyze-a-contract-with-imported-contract"&gt;&lt;strong&gt;Analyze a contract with imported contract&lt;/strong&gt;&#10;&lt;/h5&gt;&lt;p&gt;Most smart contracts import other contracts to reuse functionality. You do not have to flatten the contracts into one file. Mythril can work with contracts with imports specified in them : &lt;a class="link" href="https://github.com/ashtewari/mythril-tests/blob/master/mythx-tests/05222022-26/SimpleDAOWithImport.sol" target="_blank" rel="noopener"&#10; &gt;SimpleDAOWithImport.sol&lt;/a&gt;&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-20.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&#10; &lt;blockquote&gt;&#10; &lt;p&gt;&amp;gt; docker run -v E:\share\:/data mythril/myth -v4 analyze /data/mythx-tests\05222022-26/SimpleDAOWithImport.sol&lt;/p&gt;&#10;&#10; &lt;/blockquote&gt;&#10;&lt;h5 id="analyze-a-contract-with-openzeppelin-style-import"&gt;&lt;strong&gt;Analyze a contract with @OpenZeppelin style import&lt;/strong&gt;&#10;&lt;/h5&gt;&lt;p&gt;Mythril relies on &lt;a class="link" href="https://github.com/ethereum/solc-js" target="_blank" rel="noopener"&#10; &gt;solc&lt;/a&gt; for compiling contract source code. For @OpenZeppelin style imports, you have to specify &amp;ndash;solc-json file containing remapping for solc to locate the referenced files : &lt;a class="link" href="https://github.com/ashtewari/mythril-tests/blob/master/mythx-tests/05222022-26/SimpleDAOWith-OzImport.sol" target="_blank" rel="noopener"&#10; &gt;SimpleDAOWith-OzImport.sol&lt;/a&gt;&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-22.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&#10; &lt;blockquote&gt;&#10; &lt;p&gt;&amp;gt; docker run -v E:\share\:/data mythril/myth -v4 analyze /data/mythx-tests\05222022-26/SimpleDAOWith-OzImport.sol &amp;ndash;solc-json=/data/solc-args.json&lt;/p&gt;&#10;&#10; &lt;/blockquote&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-21.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;h3 id="analyzing-on-chain-contracts"&gt;Analyzing On-Chain Contracts&#10;&lt;/h3&gt;&lt;p&gt;Mythril can &lt;a class="link" href="https://mythril-classic.readthedocs.io/en/master/security-analysis.html#analyzing-on-chain-contracts" target="_blank" rel="noopener"&#10; &gt;analyze contracts deployed on the blockchain&lt;/a&gt; directly. You do not need source code of the contract. Support for &lt;a class="link" href="https://infura.io/" target="_blank" rel="noopener"&#10; &gt;infura&lt;/a&gt; is built-in, you can also use custom RPC endpoint. Replace INFURA_ID with your Infura project id and CONTACT_ADDRESS with the address of your contract on the blockchain :&lt;/p&gt;&#10;&#10; &lt;blockquote&gt;&#10; &lt;p&gt;&amp;gt; docker run mythril/myth -v4 analyze &amp;ndash;rpc infura-rinkeby &amp;ndash;infura-id INFURA_ID -a CONTACT_ADDRESS&lt;/p&gt;&#10;&#10; &lt;/blockquote&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-23.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;</description></item></channel></rss>