<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jonghyuk Song on Medium]]></title>
        <description><![CDATA[Stories by Jonghyuk Song on Medium]]></description>
        <link>https://medium.com/@jonghyk.song?source=rss-8218b7b42412------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*82g6owIHKpt2yAmc.</url>
            <title>Stories by Jonghyuk Song on Medium</title>
            <link>https://medium.com/@jonghyk.song?source=rss-8218b7b42412------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 00:02:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jonghyk.song/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[To be a winner of Ethereum gambling game, All For One, by breaking PRNG (CVE-2018–12056)]]></title>
            <link>https://medium.com/coinmonks/to-be-a-winner-of-ethereum-gambling-game-all-for-one-by-breaking-prng-1ab011163d40?source=rss-8218b7b42412------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ab011163d40</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Jonghyuk Song]]></dc:creator>
            <pubDate>Fri, 10 Aug 2018 00:08:58 GMT</pubDate>
            <atom:updated>2018-08-24T11:12:32.108Z</atom:updated>
            <content:encoded><![CDATA[<h3>Abstract</h3><p>I found a vulnerability in smart contract of ‘<a href="https://all-for-one.club/"><strong>All For One</strong></a>’ which is a Ethereum gambling game. This game generates random numbers using keccak256() function with 4 parameters, such as a private variable _seed, blockhash(block.number-1), block.coinbase, and block.difficulty. They are all publicly readable to anyone, so attackers can get rewards by predicting the random number.</p><h3>Details</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*m5WHUgugwX0a9AcJ690ZHw.png" /><figcaption>Figure 1. play() function</figcaption></figure><p>‘<strong>All For One</strong>’ is a Ethereum gambling game. If you want to participate this game, you first bet 0.1 Ether on this contract through play() function(See Figure 1). Players who bet on the smart contract are pushed in the array. After an amount of time, a winner is decided by draw() function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j8weSudfmp57z5wgunfzpw.png" /><figcaption>Figure 2. draw() function. A winner is decided by a random value.</figcaption></figure><p>In draw() function, a winner is decided by a random number. A red box in Figure 2 produceRandom() function generates a random number and return it. The random number is a index of a players array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wjxYmwn5LvJYBHCkWvUm7Q.png" /><figcaption>Figure 3. maxRandom() function generates a random value using keccak256() function with 4 parameters.</figcaption></figure><p>produceRandom() function calls random()<em> </em>function at line 80, so finally maxRandom() function is called(See Figure 3). In maxRandom() function, it generates random numbers using keccak256() function with 4 parameters. However, all the 4 parameters are publicly readable to anyone. Therefore, attackers can predict the random numbers and can be a winner.</p><h3>Exploit</h3><p>I already explained several times how to exploit these vulnerability in my previous articles. If you want to know the way to exploit it, I recommend reading my articles, especially “<a href="https://medium.com/@jonghyk.song/attack-on-pseudo-random-number-generator-prng-used-in-1000-guess-an-ethereum-lottery-game-7b76655f953d">Attack on Pseudo-random number generator (PRNG) used in 1000 Guess, an Ethereum lottery game (CVE-2018–12454)</a>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j3wLkqAyDC3fF2yiM6tw7A.png" /><figcaption>Figure 4. exploit contract</figcaption></figure><p>Figure 4 shows the exploit contract. Attackers bet 0.1 Ether on All For One site and then can be a winner by using the exploit contract.</p><h3>Report</h3><p>I reported it to admin and they patched it. They changed draw() function as private and generate random numbers by using <a href="https://docs.oraclize.it/#ethereum">Oraclize </a>library.</p><h3>Conclusion</h3><p>When you generate random numbers in the smart contract, you must not use private variables and variables of past and current blocks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ab011163d40" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/to-be-a-winner-of-ethereum-gambling-game-all-for-one-by-breaking-prng-1ab011163d40">To be a winner of Ethereum gambling game, All For One, by breaking PRNG (CVE-2018–12056)</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get legendary items by breaking PNRG of MyCyptoChamp, an Ethereum online game (CVE-2018–12885)]]></title>
            <link>https://medium.com/coinmonks/get-legendary-items-by-breaking-pnrg-of-mycyptochamp-an-ethereum-online-game-cve-2018-12855-6e6beb41b8df?source=rss-8218b7b42412------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e6beb41b8df</guid>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[Jonghyuk Song]]></dc:creator>
            <pubDate>Tue, 31 Jul 2018 03:17:03 GMT</pubDate>
            <atom:updated>2020-09-01T19:15:21.082Z</atom:updated>
            <content:encoded><![CDATA[<h3>Abstract</h3><p>An Ethereum online game, <a href="https://mycryptochamp.io/">MyCryptoChamp</a>, has a vulnerability that it generates predictable random numbers. In this game, users can create champs and items by paying some Ether. At this time, the power of the champs and items are decided by the random numbers. The random numbers are generated using by keccak256() function with a private variable and a blockhash of block.number-1. However, they are all public, so attackers can easily access them and precompute the random number. This case is so similar with 1000 Guess<strong><em>’</em></strong>s vulnerability that I described before[1]. I exploited MyCryptoChamp<strong> </strong>using the internal transactions in the way I exploited 1000 Guess. You can find more detail explanation in this article: “<a href="https://medium.com/coinmonks/attack-on-pseudo-random-number-generator-prng-used-in-1000-guess-an-ethereum-lottery-game-7b76655f953d"><em>Attack on Pseudo-random number generator (PRNG) used in 1000 Guess, an Ethereum lottery game. (CVE-2018–12454)</em></a>”. After the exploitation, I got a powerful champ with three legendary items.</p><h3>Details</h3><p>As I mentioned before, this vulnerability is similar to 1000 Guess’s vulnerability. If you don’t know how to read private variables and how to exploit using internal transactions, I recommend you reading my <a href="https://medium.com/coinmonks/attack-on-pseudo-random-number-generator-prng-used-in-1000-guess-an-ethereum-lottery-game-7b76655f953d">previous article[1]</a>. There are more details.</p><h4>Vulnerable codes</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NhJcJta38ZmtaokBuc2WWA.png" /><figcaption>Figure 1. MyCryptoChamp generates random numbers with a private variable and a blockhash</figcaption></figure><p>randMod function is the vulnerable function of MyCryptoChamp’s smart contract. It generates random numbers using keccak256 with a private variable randNonce and blockhash(block.number-1). Both are public, so anyone can access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kuf3W7_kPSkHXgdxEkJRbQ.png" /><figcaption>Figure 2. Part of createChamp() function which generates new champs</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ttn5EVekQtUF6mkdyj_qSg.png" /><figcaption>Figure 3. Part of openLootbox() function which generates new items</figcaption></figure><p>Figure 2 and Figure 3 show that MyCryptoChamp generates champs and items using random numbers. Power of champs/items depends on the random numbers. Therefore, if an attacker can predict the random number, he can create most powerful champs and items.</p><h4>Exploits</h4><p>The way to exploit MyCryptoChamp is simple. Attackers precompute the random number by using randNonce and blockhash(block.number-1). When the desired random number is generated, attackers send transactions to MyCryptoChamp and get champs/items.</p><p>First, let’s find out how to get randNonce. we can read private variables like this[2]:</p><pre>web3.eth.getStorageAt(contractAddress, position)</pre><p>position is index position of a variable. We can retrieve all storage variables in smart contract using the above way. In MyCryptoChamp, randNonce is located at slot 11. Therefore, we can get randNonce when contractAddress is the address of MyCryptoChamp’s smart contract and position is 11.</p><p>Now, all we have to do is finding out blockhash(block.number-1). To know it accurately, we should know the block including the transaction that we sent. If I send a transaction at block number N, the transaction will be executed at block number N+a because it takes some time that miners select and execute transactions. However, nobody exactly knows the a. Therefore, before we send transactions, we cannot know the block number of the block executing our transactions.</p><p>Then, how we get blockhash(block.number-1) and precompute the random number?. We can know the block number of the block executing our transactions only in the smart contract. Therefore, we should deploy a smart contract and precompute the random number in that contract. This smart contract should satisfy the following conditions:</p><ol><li>generate random numbers in the same way as target contract</li><li>send internal transactions to the target contract if it generates the random number that attackers want</li><li>revert if it generates the random numbers that attackers don’t want</li></ol><p>To attack MyCryptoChamp, attackers need the contract that satisfying the above conditions. Because of 3 condition, attackers should continuously send transactions until they get the random numbers they want. Therefore, some gas costs are consumed. However, in most cases, it is a tiny compared to the benefits that they will get when their attack is success.</p><p>To exploit MyCryptoChamp, I deployed the following contract:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*faAtl9u_T-TFFRTYlYki6A.png" /><figcaption>Figure 4. The smart contract to exploit MyCryptoChamp</figcaption></figure><p>In createChp function, the first random number is for the attack power and the second is for the defense power. In createItm function, the first random number is for the rarity of the item and the second is for the item type. Both functions call MyCryptoChamp’s function when they generates the random numbers that attackers want. The random numbers generated in the attack contract is same with the random numbers generated in the contract of MyCryptoChamp because both are generated at the same block.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*AkBt1PBhvtsKIgomqlSdGQ.png" /><figcaption>Figure 5. Champ and items that I created by exploiting the vulnerability</figcaption></figure><p>Figure 5. shows the champs and items that I created by exploiting this vulnerability. I created powerful champ and three legendary items.</p><h3>Report</h3><p>I reported it to the developers at end of June. Surprisingly, they returned back to me the gas cost that I spent on the exploit.</p><p>Now MyCryptoChamp is patched.</p><ul><li>Old smart contract: <a href="https://etherscan.io/address/0xa44e464b13280340904ffef0a65b8a0033460430">https://etherscan.io/address/0xa44e464b13280340904ffef0a65b8a0033460430</a></li><li>New smart contract: <a href="https://etherscan.io/address/0x689FB61845488297dfE7586E5f7956475955d2Dc">https://etherscan.io/address/0x689FB61845488297dfE7586E5f7956475955d2Dc</a></li></ul><p>They removed my champ and three legendary items. Actually, I cannot find the source code of the new smart contract, so I’m not sure it is safe now.</p><h3>Conclusion</h3><p>Generating random numbers in Ethereum smart contract is not easy. It is not safe using private variables and block variables of past blocks. I recommend to you read my previous article if you want to know more details[1]. If there are smart contracts generating random numbers, you should check it is completely random.</p><h3>Reference</h3><p>[1] <a href="https://medium.com/coinmonks/attack-on-pseudo-random-number-generator-prng-used-in-1000-guess-an-ethereum-lottery-game-7b76655f953d">https://medium.com/coinmonks/attack-on-pseudo-random-number-generator-prng-used-in-1000-guess-an-ethereum-lottery-game-7b76655f953d</a></p><p>[2] <a href="https://web3js.readthedocs.io/en/1.0/web3-eth.html#getstorageat">https://web3js.readthedocs.io/en/1.0/web3-eth.html#getstorageat</a></p><blockquote><a href="https://coincodecap.com/?utm_source=coinmonks">Get Best Software Deals Directly In Your Inbox</a></blockquote><figure><a href="https://coincodecap.com/?utm_source=coinmonks"><img alt="" src="https://cdn-images-1.medium.com/max/584/0*OJ-qb5G6i863msBB.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e6beb41b8df" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/get-legendary-items-by-breaking-pnrg-of-mycyptochamp-an-ethereum-online-game-cve-2018-12855-6e6beb41b8df">Get legendary items by breaking PNRG of MyCyptoChamp, an Ethereum online game (CVE-2018–12885)</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Attack on Pseudo-random number generator(PRNG) used in Cryptogs, an Ethereum (CVE-2018–14715)]]></title>
            <link>https://medium.com/coinmonks/attack-on-pseudo-random-number-generator-prng-used-in-cryptogs-an-ethereum-cve-2018-14715-f63a51ac2eb9?source=rss-8218b7b42412------2</link>
            <guid isPermaLink="false">https://medium.com/p/f63a51ac2eb9</guid>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[vulner]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Jonghyuk Song]]></dc:creator>
            <pubDate>Mon, 30 Jul 2018 12:35:00 GMT</pubDate>
            <atom:updated>2020-09-01T19:16:59.977Z</atom:updated>
            <content:encoded><![CDATA[<h3>Abstract</h3><p><a href="https://cryptogs.io/">Cryptogs</a> is the game of pogs on the Ethereum blockchain[1]. It is a kind of game of slap-match. This game generates random numbers using blockhash(uint blockNumber) to decide the winner. In Solidity, blockhash(uint blockNumber) function returns ‘0’ when blockNumber is older than 256 blocks from the current block(block.number)<a href="https://solidity.readthedocs.io/en/latest/units-and-global-variables.html">[2]</a>. Cryptogs doesn’t check the blockNumber whether it is too old or not, so attackers can predict the random numbers and always win.</p><h3>Details</h3><p>There are two functions generating random numbers: endCoinFlip() and throwSlammer(). Both functions required preliminary functions: startCoinFlip() and raiseSlammer().</p><p>First, let’s check startCoinFlip() and endCoinFlip(). The two functions decide who goes first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cxzRGREs_sbHVr8IqClHTw.png" /><figcaption>Figure 1. startCoinFlip()</figcaption></figure><p>In startCoinFlip(), it stores the current block number block.number into commitBlock[_stack].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u-V_Exo9qRfgy7qglczKQw.png" /><figcaption>Figure 2. endCoinFlip()</figcaption></figure><p>After calling startCoinFlip(), players should call endCoinFlip(). In endCoinFlip(), it generates random numbers using keccak256() with _reveal and blockhash of commitBlock[_stack]. As you can see in Figure 2, at line 464, uint32(block.number) &gt; commitBlock[_stack] is the only condition for commitBlock[_stack]. Therefore, players can call endCoinFlip() after long periods of time. In Solidity, however, blockhash(uint blockNumber) is only works for 256 most recent blocks<a href="https://solidity.readthedocs.io/en/latest/units-and-global-variables.html">[2]</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*34tAwRV8uqfXqyVW-30Gkw.png" /></figure><p>blockhash(uint blockNumber) returns ‘0’ if blockNumber is older than 256 blocks from the current block. Therefore, if a player calls endCoinFlip() after 256 blocks from calling startCoinFlip(), the pseudoRandomHash is same with keccak256(_reveal, 0) because block.blockhash(commitBlock[_stack]) is ‘0’. _reveal is an argument of endCoinFlip(), so players can put anything they want. Therefore, attackers can generate random numbers and get the first order.</p><p>Next, raiseSlammer() and throwSlammer() have the same vulnerability. In raiseSlammer(), the current block number block.number is stored into commitBlock[_stack].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Un9-DSb3bNAaS-RPKbd0Q.png" /><figcaption>Figure 3. raiseSlammer()</figcaption></figure><p>Then, pseudoRandomHash is computed the same way as endCoinFlip() at line 554.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*73LX_XSl9d1-ehmYiUKAkA.png" /><figcaption>Figure 4. a part of throwSlammer()</figcaption></figure><p>At line 573, one byte of pseudoRandomHash is selected as thisFlipper. At line 575, thisFlipper is checked whether it is under 80 or not. If it is under 80, one pog is flipped and the player in that turn gets the pog.</p><p>Just like endCoinFlip(), if an attacker call throwSlammer() after 256 blocks from calling raiseSlammer(), keccak256(_reveal, block.blockhash(commitBlock[_stack]) is same with keccak256(_reveal, 0). So, attacker can generate pseudoRandomNumber as they want and get the all pogs.</p><h3>Exploit</h3><p>So, the attack scenario is as follows:</p><ol><li>Create a new game and wait until a victim join the game.</li><li>Call startCoinFlip() and wait until 256 blocks are generated</li><li>After 256 blocks, call endCoinFlip() and get the first order</li><li>Call raiseSlammer() and wait until 256 blocks are generated</li><li>After 256 blocks, call throwSlammer() and get all pogs at the first turn</li></ol><p>If we want to proceed as the above scenario, we should compute the proper pseudoRandomNumber that satisfying the following conditions:</p><ol><li>even → get the first order</li><li>all 10 bytes of most significant bytes are under 80 → get all 10 pogs at the first turn</li></ol><p>Because of the vulnerability, pseudoRandomNumber is computed as keccak256(_reveal, 0).So, I found when _reveal is ‘<strong>0x20182</strong>’, pseudoRandomNumber is ‘<strong>0x262f33140b273901193bc3cc78c5c7f6abf498af8cc1faafc5d5454dd63e3dec</strong>’ which is satisfying the above two conditions.</p><p>I exploited Cryptogs in Ropsten test network<a href="https://ropsten.etherscan.io/tx/0xed84edc7644eb4da5f91182b8bb638e9e7ad8cb2f17ebfec9d14ecca542a3a9c">[3]</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eg3GPfSQl6BAe1Wt6tpXnQ.gif" /><figcaption>Figure 5. exploit result</figcaption></figure><p>Figure 5 shows the exploit result that I recorded. As you can see, I can get all 10 pogs at the first turn.</p><h3>Report</h3><p>I reported it to the developer and he replied to me very quickly. He said that he probably will not fix the vulnerability because there are no players in Cryptogs. So, I do not recommend playing Cryptogs. But, he said he will check his new game, <a href="https://austingriffith.com/portfolio/galleass/">Galleass</a>, whether there is the same vulnerability.</p><p>Surprisingly, he gave me some bug bounty. At first I refused the bounty but he kept trying to give the bounty to me, so I finally received the bounty. I found several vulnerable smart contracts so far, but he is the first developer who give the bounty. As a security researcher, I think there should be more people like the developer of Cryptogs. So, I hope that bug hunters get the proper compensation.</p><h3>Conclusion</h3><p>When you generates random numbers using blockhash, you should remind that blockhash(uint blockNumber) is only works for 256 most recent blocks. If you try to use blockhash with too old block, it will return ‘0’.</p><h3>References</h3><p>[1] <a href="https://cryptogs.io/">https://cryptogs.io</a></p><p>[2] <a href="https://solidity.readthedocs.io/en/latest/units-and-global-variables.html">https://solidity.readthedocs.io/en/latest/units-and-global-variables.html</a></p><p>[3] <a href="https://ropsten.etherscan.io/tx/0xed84edc7644eb4da5f91182b8bb638e9e7ad8cb2f17ebfec9d14ecca542a3a9c">https://ropsten.etherscan.io/tx/0xed84edc7644eb4da5f91182b8bb638e9e7ad8cb2f17ebfec9d14ecca542a3a9c</a></p><blockquote><a href="https://coincodecap.com/?utm_source=coinmonks">Get Best Software Deals Directly In Your Inbox</a></blockquote><figure><a href="https://coincodecap.com/?utm_source=coinmonks"><img alt="" src="https://cdn-images-1.medium.com/max/584/0*OJ-qb5G6i863msBB.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f63a51ac2eb9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/attack-on-pseudo-random-number-generator-prng-used-in-cryptogs-an-ethereum-cve-2018-14715-f63a51ac2eb9">Attack on Pseudo-random number generator(PRNG) used in Cryptogs, an Ethereum (CVE-2018–14715)</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Attack on Pseudo-random number generator (PRNG) used in 1000 Guess, an Ethereum lottery game…]]></title>
            <link>https://medium.com/coinmonks/attack-on-pseudo-random-number-generator-prng-used-in-1000-guess-an-ethereum-lottery-game-7b76655f953d?source=rss-8218b7b42412------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b76655f953d</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Jonghyuk Song]]></dc:creator>
            <pubDate>Sun, 17 Jun 2018 07:12:37 GMT</pubDate>
            <atom:updated>2018-08-03T00:48:45.967Z</atom:updated>
            <content:encoded><![CDATA[<h3>Attack on Pseudo-random number generator (PRNG) used in 1000 Guess, an Ethereum lottery game (CVE-2018–12454)</h3><h3>Abstract</h3><p>An Ethereum lottery game, 1000 Guess, has a vulnerability that it generates predictable random numbers. This game decides a winner by a random number when the number of players who bet on the contract reaches to the predetermined number. The contract generates the random number using sha256() function with a private variable and the current block variables, such as block.timestamp<em>, </em>block.coinbase<em> </em>and<em> </em>block.difficulty. However, they are easily readable. First, a private variable is easily accessible by using web3.eth.getStorageAt. Second, it is well known that block variables can be easily manipulated by malicious miners. However, it will be also dangerous even though attackers are not miners. In this article, I will explain how to attack PRNG by using internal transactions.</p><h3>Details</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*elmQ0F3N5xE45gZuBAEujA.png" /><figcaption>Figure 1. 1000 guess generates a random number with block variables and a private variable</figcaption></figure><p>1000 Guess generates a random number using sha256() function with block.timestamp, block.coinbase, block.difficulty and a private variable curhash. These are all accessible to anyone, so anyone can precompute the random number and can be a winner.</p><h4>How to access a private variable?</h4><p>First, how can we access to a private variable? Before that, let’s find out how to access a public variable. Accessing a public variable is very easy and intuitive. If there is a public variable uint data, we can access it in web3js like this:</p><pre>contractInstance.methods.data().call()</pre><p>Or, we can call a function that returns data, if exists,</p><pre>function getData() public returns (uint){<br>    return data;<br>}</pre><p>In web3js, we call getData() to get data like this</p><pre>contractInstance.methods.getData().call()</pre><p>However, we cannot use the above methods to access a private variable. For this reason, some people think that a private variable is hidden. In Solidity documents, however, it said that everything is visible to all observers even though it is private <a href="http://solidity.readthedocs.io/en/v0.4.24/contracts.html">[1]</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*a_IIDWb2HVDzKaDtvXFhZQ.png" /><figcaption>Figure 2. In a contract, everything is visible to all external observers</figcaption></figure><p>Then, how to can we access to a private variable? In web3js, we can access a private variable like this <a href="https://web3js.readthedocs.io/en/1.0/web3-eth.html#getstorageat">[2]</a>:</p><pre>web3.eth.getStorageAt(contractAddress, position);</pre><p>We can retrieve all variables in smart contracts using the above way. In a smart contract, variables are sequentially located at storage slot. For example, the first declared variable is located at slot 0, the second variable is located at slot 1. Therefore, if we want to read curhash, we should know the position of curhash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*DzLQ40W8mMC9RpGTVV0bjg.png" /><figcaption>Figure 3. variables declaration in the smart contract of 1000 Guess</figcaption></figure><p>The first variable is state, so curhash is located at slot 1004. constant variable is not stored in storage slot, so uint constant maxguess is excluded. Therefore, we can read curhash as follows:</p><pre>web3.eth.getStorageAt(contractAddress, 1004);</pre><p>When I write this post, I tried to read curhash and other variables using the following code. I tested on <a href="https://etherscan.io/address/0x386771ba5705da638d889381471ec1025a824f53#readContract">0x386771ba5705da638d889381471ec1025a824f53</a> among several versions of 1000 Guess.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aydE2TtGG8_5qS3zjEJDQQ.png" /><figcaption>Figure 4. Example code of accessing variables</figcaption></figure><p>The result is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vd7ErqfMRarEkoLlgGc3wA.png" /><figcaption>Figure 5. State of variables</figcaption></figure><p>From the results, we can know the current state of numguesses, curhash, _gameindex and _starttime. You can confirm the above results using getBettingStatus() function.</p><h4>Generating random numbers with same block variables</h4><p>Now, we know how to read the private variable, so we just compute curhash using the current block variables. It is clear that the current block variables are accessible. However, you cannot know the block number what your transaction is executed. For example, there is a smart contract that you can be a winner when you send a transaction at the block number is even. Simply thinking, you continuously observe the current block number, and then send a transaction to the contract when the block number is even. However, it can not be success always because your transaction is not executed at the block what you send a transaction. Therefore, if you want that your transaction is executed at a specific block, you should use another way.</p><p>Internal transaction can be a solution. First, you compute new curhash in your contract, and then calls 1000 Guess contract via an internal transaction in your contract. Then, the same curhash is calculated because the two computations are executed at the same block.</p><h3>Exploit</h3><p>I exploited one of 1000 Guess contracts: <a href="https://etherscan.io/address/0x386771ba5705da638d889381471ec1025a824f53#readContract">https://etherscan.io/address/0x386771ba5705da638d889381471ec1025a824f53</a>. In this contract, bettingprice is 0.01 Ether and arraysize is 10. I prepared two accounts: a victim and an attacker.</p><p>First, the victim account continuously bet 0.01 Ether on 1000 Guess contract until numguesses is 9 which is arraysize-1. In this state, if someone bet on this contract, _finish() will be executed and then _winner will be decided by new curhash.</p><p>Second, the attack account deployed an attack contract as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*omZsDcfb-nGiBPeVOz7RUw.png" /><figcaption>Figure 6. Attacker’s contract</figcaption></figure><p>attack() function needs 4 parameters:</p><ul><li>address target: the address of 1000 Guess contract.</li><li>curhash: the current curhash in 1000 Guess contract</li><li>arraysize: the current arraysize</li><li>attackeridx: index of attacker address in guessess array</li></ul><p>In the attack contract, it computes curhash in the same way with 1000 Guess contract. The attack account sent transactions to the attack contract continuously until the contract computes curhash that makes the attacker as a winner. After several trials, finally an internal transaction was transmitted and the attack account got the rewards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AHnSINND37_RgkqytArHMA.png" /><figcaption>Figure 7. Internal transactions executed on the target contract</figcaption></figure><p>I tested two times and I succeeded two times. Figure 7 shows the internal transactions. ‘0x48e9c58bb66d0…‘ is the attack contract and ‘0x1973f023e4c03ef…’ is the developer of 1000 Guess. When the attack was succeeded, 1000 Guess sent reward (0.099 Ether) to the attack contract and sent a fee (0.001 Ether) to the developer.</p><p>You can check the results on the followings:</p><ul><li>1000 Guess contract: <a href="https://etherscan.io/address/0x386771ba5705da638d889381471ec1025a824f53">https://etherscan.io/address/0x386771ba5705da638d889381471ec1025a824f53</a></li><li>Attack contract: <a href="https://etherscan.io/address/0x48e9c58bb66dd0b0f218cf0448a797096d585179#internaltx">https://etherscan.io/address/0x48e9c58bb66dd0b0f218cf0448a797096d585179</a></li><li>Victim account: <a href="https://etherscan.io/address/0x9dbea040fde74f9014c873401675ccd298d302ba">https://etherscan.io/address/0x9dbea040fde74f9014c873401675ccd298d302ba</a></li><li>Attacker Account: <a href="https://etherscan.io/address/0x28fb13eb570c23bf65f606431a6cc3ff34f41af0">https://etherscan.io/address/0x28fb13eb570c23bf65f606431a6cc3ff34f41af0</a></li></ul><p>You can see that there are several failed transactions because the attack contract executes revert() when curhash computed by the contract cannot make the attacker as a winner. However, if it sends an internal transaction to the target contract, it gets the reward without fails. Of course the attacker should pay some gases because he tried several times, but it is a tiny compared to the reward he will get.</p><p>When I exploited on the 1000 Guess contract, it contains only 0.01 Ether sent by the developer. So, after my exploit, I returned 0.01 Ether to the developer.</p><h3>Report</h3><p>I reported it to the developer. Then, he closed all 1000 Guess games immediately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I5d6_P2hTm6JA93YiM1kyg.png" /><figcaption>Figure 8. The developer closed the game</figcaption></figure><p>The site, <a href="http://www.1000guess.com/">http://www.1000guess.com</a>, is completely down now. Now, you can only check Twitter account of 1000 Guess: <a href="https://twitter.com/1000guess">https://twitter.com/1000guess</a>.</p><h3>Conclusion</h3><p>Generating a random number in Ethereum smart contract is not easy. As I know, there are two methods to generate the random number safely. First way is using future block’s variables, and the other one is getting random number from outside of Ethereum network using libraries like Oraclize[3]. Developers should study how to generate the random numbers safely. Also, users should check how the contract generates random numbers, if they want to use the contract.</p><h3>Reference</h3><p>[1] <a href="http://solidity.readthedocs.io/en/v0.4.24/contracts.html">http://solidity.readthedocs.io/en/v0.4.24/contracts.html</a></p><p>[2] <a href="https://web3js.readthedocs.io/en/1.0/web3-eth.html#getstorageat">https://web3js.readthedocs.io/en/1.0/web3-eth.html#getstorageat</a></p><p>[3] <a href="http://www.oraclize.it/">http://www.oraclize.it/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b76655f953d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/attack-on-pseudo-random-number-generator-prng-used-in-1000-guess-an-ethereum-lottery-game-7b76655f953d">Attack on Pseudo-random number generator (PRNG) used in 1000 Guess, an Ethereum lottery game…</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DimonCoin(FUD), ERC20 token, allows attackers to steal all victim’s balances (CVE-2018–11411)]]></title>
            <link>https://medium.com/coinmonks/dimoncoin-fud-erc20-token-allows-attackers-to-steal-all-victims-balances-cve-2018-11411-ba9a320604f9?source=rss-8218b7b42412------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba9a320604f9</guid>
            <category><![CDATA[erc20]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[vulnerability]]></category>
            <dc:creator><![CDATA[Jonghyuk Song]]></dc:creator>
            <pubDate>Thu, 24 May 2018 09:44:52 GMT</pubDate>
            <atom:updated>2018-06-27T05:33:47.575Z</atom:updated>
            <content:encoded><![CDATA[<h3>Abstract</h3><p>I found a vulnerability of a smart contract for DimonCoin(FUD), an Ethereum ERC20 token (<a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-11411">CVE-2018–11411</a>)[1]. This vulnerability is exactly same with the UselessEthereumToken’s vulnerability[2, 3]. DimonCoin token also has the same vulnerable function which is <em>transferFrom</em> in UET token. Therefore, attackers can steal all victim’s balances into their accounts by exploiting this function. After more investigation, I found that DimonCoin(FUD) is a scam. There are multiple smart contracts of FUD token, and one of them has been dumped. I found the vulnerability in the different contract which is not dumped yet. In this article, I will explain the details of the vulnerability and the FUD token.</p><h3>Details</h3><p>As mentioned above, this vulnerability is same with the vulnerability of UselessEthereumToken (<a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-10468">CVE-2018–10468</a>)[3]. If you read the article “<a href="https://medium.com/coinmonks/uselessethereumtoken-uet-erc20-token-allows-attackers-to-steal-all-victims-balances-543d42ac808e"><em>UselessEthereumToken(UET), ERC20 token, allows attackers to steal all victim’s balances (CVE-2018–10468)</em></a>”, it will be helpful to understand it[2].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ezgay3X7-79Rho7aZscq1g.png" /><figcaption>Figure 1. Code of transferFrom function in FUD smart contract</figcaption></figure><p>Figure 1. shows the vulnerable <em>transferFrom</em> function. The verification for ERC20 short address attack is moved to the modifier <em>onlyPayloadSize</em>. It is the only change and other part is exactly same with <em>transferFrom</em> function in UET token.</p><p>As you can see, the codes in the red box are wrong. By the code, a user can transfer balances more than address _from has, when balances[_to] + _value is overflowed. The correct code should be as follows:</p><pre>bool sufficientFunds = fromBalance <strong>&gt;=</strong> _value;<br>bool sufficientAllowance = allowance <strong>&gt;=</strong> _value;<br>bool overflowed = balances[_to] + _value &gt; balances[_to];</pre><pre>if (sufficientFunds &amp;&amp; sufficientAllowance &amp;&amp; <strong>overflowed</strong>) {</pre><h4>Exploit</h4><p>All attackers have to do is find a target account and a value to cause overflow. If balances of a target account is 0xaaaa, the value should be more than pow(2,260)-0xaaaa. If the value is exactly pow(2,260)-0xaaaa, then all the target’s balances are transferred to attackers account. A part of my exploit code is as follows:</p><pre>max = web3.utils.toBN(&#39;0x10000000000000000000000000000000000000000000000000000000000000000&#39;);<br>v_bal=web3.utils.toBN(await FUD.methods.balanceOf(victim).call());<br>FUD.methods.transferFrom(attacker, victim, max.sub(v_bal))<br>           .send({from:attacker, gas:1000000, gasPrice:1});</pre><h3>Scam</h3><p>DimonCoin(FUD) have been already regarded as a scam[4]. There are multiple FUD token’s smart contracts. I think the developers have created the several smart contracts to hide their cheats. Among the contracts, one is the vulnerable contract[5] that I found, and another one is a contract that is suspected to be dumped by the developers[6]. In the dumped contract, some accounts have the tokens more than total supply[7].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lfcqbruBc3W9OML6Q-FaoA.png" /><figcaption>Figure 2. All top 10 holders have tokens more than 1000000% of total supply</figcaption></figure><p>The developers have advertised FUD token in bitcointalk using the two contract addresses[8]. The advertising article is translated to several languages, and there are 6 translation copies have advertised the vulnerable contract.</p><blockquote>- Skandinavisk/Danish: <a href="https://bitcointalk.org/index.php?topic=2249616">https://bitcointalk.org/index.php?topic=2249616</a> <br>- German: <a href="https://bitcointalk.org/index.php?topic=2254901">https://bitcointalk.org/index.php?topic=2254901</a> <br>- Italian: <a href="https://bitcointalk.org/index.php?topic=2248634.0">https://bitcointalk.org/index.php?topic=2248634.0</a> <br>- Russian: <a href="https://bitcointalk.org/index.php?topic=2255885">https://bitcointalk.org/index.php?topic=2255885</a> <br>- Chinese: <a href="https://bitcointalk.org/index.php?topic=2250544">https://bitcointalk.org/index.php?topic=2250544</a> <br>- Korean: <a href="https://bitcointalk.org/index.php?topic=2292406">https://bitcointalk.org/index.php?topic=2292406</a></blockquote><p>The developers already have removed their evidences. The official site, Telegram, Twitter and Github pages are down[9–12]. Only Facebook page is remain[13].</p><h3>Conclusion</h3><p>I am sure that DimonCoin(FUD) is a scam. The developers have created multiple contracts without rational reasons, one is dumped and the other one has a vulnerability. Moreover, communication channels to developers have been removed. It has been already widely known to people that it is scam, but still some people make transactions to the contracts. So, it should be known to more people. Please be careful when you trade unverified coins.</p><h3>References</h3><ul><li>[1] <a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-11411">http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-11411</a></li><li>[2] <a href="https://medium.com/coinmonks/uselessethereumtoken-uet-erc20-token-allows-attackers-to-steal-all-victims-balances-543d42ac808e">https://medium.com/coinmonks/uselessethereumtoken-uet-erc20-token-allows-attackers-to-steal-all-victims-balances-543d42ac808e</a></li><li>[3] <a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-10468">http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-10468</a></li><li>[4] <a href="https://bitcointalk.org/index.php?topic=2722276.0">https://bitcointalk.org/index.php?topic=2722276.0</a></li><li>[5] <a href="https://etherscan.io/token/0xf084d5bc3e35e3d903260267ebd545c49c6013d0">https://etherscan.io/token/0xf084d5bc3e35e3d903260267ebd545c49c6013d0</a></li><li>[6] <a href="https://etherscan.io/token/0xDe39E5E5a1B0eEB3Afe717D6d011CaE88D19451e#balances">https://etherscan.io/token/0xDe39E5E5a1B0eEB3Afe717D6d011CaE88D19451e</a></li><li>[7] <a href="https://etherscan.io/token/0xDe39E5E5a1B0eEB3Afe717D6d011CaE88D19451e#balances">https://etherscan.io/token/0xDe39E5E5a1B0eEB3Afe717D6d011CaE88D19451e#balances</a></li><li>[8] <a href="https://bitcointalk.org/index.php?topic=2247833.0">https://bitcointalk.org/index.php?topic=2247833.0</a></li><li>[9] <a href="http://dimoncoin.org/cgi-sys/defaultwebpage.cgi">http://dimoncoin.org</a></li><li>[10] <a href="https://t.me/DimonCoinFUDD">https://t.me/DimonCoinFUDD</a></li><li>[11] <a href="https://twitter.com/DimonCoin">https://twitter.com/DimonCoin</a></li><li>[12] <a href="https://github.com/dimoncoin/DimonCoin">https://github.com/dimoncoin/DimonCoin</a></li><li>[13] <a href="https://www.facebook.com/DimonCoin-120112948666326/">https://www.facebook.com/DimonCoin-120112948666326/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba9a320604f9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/dimoncoin-fud-erc20-token-allows-attackers-to-steal-all-victims-balances-cve-2018-11411-ba9a320604f9">DimonCoin(FUD), ERC20 token, allows attackers to steal all victim’s balances (CVE-2018–11411)</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Attackers can steal all of Ether in ROC (Rasputin Online Coin) token smart contract…]]></title>
            <link>https://medium.com/coinmonks/attackers-can-steal-all-of-ether-in-roc-rasputin-online-coin-token-smart-contract-ae928b4a935a?source=rss-8218b7b42412------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae928b4a935a</guid>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[Jonghyuk Song]]></dc:creator>
            <pubDate>Mon, 14 May 2018 00:34:40 GMT</pubDate>
            <atom:updated>2018-05-25T12:03:46.990Z</atom:updated>
            <content:encoded><![CDATA[<h3>Attackers can steal all of Ether in ROC (Rasputin Online Coin) token smart contract (CVE-2018–10944)</h3><h3>Abstract</h3><p>I found a vulnerability of a smart contract for ROC (aka Rasputin Online Coin), an Ethereum ERC20 token (<a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-10944"><strong>CVE-2018–10944</strong></a>)<a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-10944">[1]</a>. The<em> request_dividend()</em> function has a critical bug similar to <strong>Reentrancy attack</strong>. Attackers can call the function in multiple times to steal Ether constantly until all of the contract’s Ether is drained.</p><h3>Details</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UNZP3CtxsyrjYCa-n7n1NA.png" /><figcaption>Figure 1. Source code of the request_dividend() function</figcaption></figure><p>Figure 1 shows the source code of the<em> request_dividend()</em> function <a href="https://etherscan.io/address/0x1bcbc54166f6ba149934870b60506199b6c9db6d#code">[2]</a>. First, this function computes holder_token_balance and holder_profit using balances of token_holder which is an argument of the function. Then, it sends Ether to token_holder as much as holder_profit. However, the balance of token_holder is not decreased after or before the transmission. It means that we can send the same amount of Ether to token_holder again and again until all of the contract’s Ether is drained. Moreover, <em>request_dividend()</em> function is declared as public and there is no permission check, so anyone can call this function and send the contract’s Ether to any address.</p><h4>What attackers can do?</h4><p>Attackers can get all of the contract’s Ether by calling <em>request_dividend() </em>function repeatedly. All they have to do is buy some ROC tokens and call <em>request_dividend() </em>function with their account addresses. Attackers can get all of the contract’s Ether by calling the function infinitely.</p><h4>Why it happened?</h4><p>I am not sure why they implement the <em>request_dividend()</em> function like this. In my opinion, there are two mistakes in here.</p><p>First, the <em>request_dividend() </em>function does not check how much Ether have been transferred to specific address before. Therefore, the request_dividend() functions send same amount of Ether even though it is called with same address in multiple times. It is similar with <strong>Reentrancy attack </strong>that it became widely known because of <a href="https://blog.ethereum.org/2016/06/17/critical-update-re-dao-vulnerability/"><strong>The DAO Attack</strong> [3]</a>. One way to fix is to decrease the balance of token_holder at somewhere of the function. After The DAO Attack, developers usually insert the code decreasing the balance of accounts before the transmission.</p><p>Second, there is no permission check in the <em>request_dividend()</em> function. It is declared as public and also there is no check for msg.sender. Therefore, anyone can call the function with any address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*lFvZ0TPsiIMTfNqzZIxP0w.png" /><figcaption>Figure 2. fallback function of the contract</figcaption></figure><p>Figure 2 shows fallback function of the contract. In the fallback function, it executes<em> </em>the<em> request_dividend()</em> function when msg.sender is owner. From this code, I guess that the developers intended to design the<em> request_dividend()</em> function that only owner can call it. However, they forgot function visibility, such as <em>internal</em>, and permission check, so it causes a critical bug.</p><h3>Damages</h3><p>Fortunately, this smart contract does not have any Ether, so there is no Ether that attackers can steal. However, attackers continuously monitor the contract and then they can steal the Ether as soon as someone send Ether to the contract. Sadly, but fortunately, ROC token is not promising token (it is not listed on any exchanges yet) so I expect that there will be no users who send Ether to the smart contract of ROC token.</p><h3>Report</h3><p>I had tried to report it to admins of Rasputin Online Coin. However, their<a href="https://ico.rasputinonline.com/"> ICO official site</a> is down, so I can’t find an email address in charge of the smart contract. I found an email <em>livesupport@verotel.com</em> in <a href="https://www.rasputinmansion.com/"><em>https://www.rasputinmansion.com/</em></a><em> </em>and sent an email but there is no response. So, I recommend that do not buy this token until it is fixed.</p><h3>Conclusion</h3><p>Developers should be careful when they implement functions transferring Ether because a small mistake can lead to a serious problem such as this bug, and The DAO Attack. They should consider who is the callers of the function, and carefully check the balances of the accounts and the possibility of duplicate transmission. Finally, it is dangerous to buy a crypto coin that is not verified completely.</p><h3>Reference</h3><ul><li>[1] <a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-10944">http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-10944</a></li><li>[2] <a href="https://etherscan.io/address/0x1bcbc54166f6ba149934870b60506199b6c9db6d#code">https://etherscan.io/address/0x1bcbc54166f6ba149934870b60506199b6c9db6d#code</a></li><li>[3] <a href="https://blog.ethereum.org/2016/06/17/critical-update-re-dao-vulnerability/">https://blog.ethereum.org/2016/06/17/critical-update-re-dao-vulnerability/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae928b4a935a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/attackers-can-steal-all-of-ether-in-roc-rasputin-online-coin-token-smart-contract-ae928b4a935a">Attackers can steal all of Ether in ROC (Rasputin Online Coin) token smart contract…</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UselessEthereumToken(UET), ERC20 token, allows attackers to steal all victim’s balances…]]></title>
            <link>https://medium.com/coinmonks/uselessethereumtoken-uet-erc20-token-allows-attackers-to-steal-all-victims-balances-543d42ac808e?source=rss-8218b7b42412------2</link>
            <guid isPermaLink="false">https://medium.com/p/543d42ac808e</guid>
            <category><![CDATA[erc20]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[vulnerability]]></category>
            <dc:creator><![CDATA[Jonghyuk Song]]></dc:creator>
            <pubDate>Thu, 03 May 2018 05:02:45 GMT</pubDate>
            <atom:updated>2020-01-22T10:43:21.544Z</atom:updated>
            <content:encoded><![CDATA[<h3>UselessEthereumToken(UET), ERC20 token, allows attackers to steal all victim’s balances (CVE-2018–10468)</h3><h3>Abstract</h3><p>I found a vulnerability of a smart contract for UselessEthereumToken(UET), an Ethereum ERC20 token (<a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-10468"><strong>CVE-2018–10468</strong></a>)[1]. Attackers can steal all victim’s balances into their accounts because there is a wrong if statement in <em>transferFrom</em> function.</p><blockquote><a href="https://coincodecap.com/">Discover and review best Blockchain softwares</a></blockquote><h3>Details</h3><p>In ERC20 Token standard, it defines <em>transferFrom</em> function as follows <a href="https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#transferfrom">[2]</a>:</p><blockquote>Transfers _value amount of tokens from address _from to address _to, and MUST fire the Transfer event.</blockquote><p>It transfers balances of address_from to address _to at most _allowed[_from][msg.sender]. It is orginal functionality of <em>transferFrom</em> function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*thfif-WBcAntLgGulkFpuA.png" /><figcaption>Figure 1. Code of transferFrom function in UET smart contract</figcaption></figure><p>However, as you can see in Figure 1, <em>transferFrom </em>in UET smart contract is weired <a href="https://etherscan.io/address/0x27f706edde3aD952EF647Dd67E24e38CD0803DD6#code">[3]</a>. By the above code, a user can transfer balances more than address _from has, if balances[to] + _value is overflowed. It should be fixed as follows:</p><pre>bool sufficientFunds = fromBalance <strong>&gt;=</strong> _value;<br>bool sufficientAllowance = allowance <strong>&gt;=</strong> _value;<br>bool overflowed = balances[_to] + _value &gt; balances[_to];</pre><pre>if (sufficientFunds &amp;&amp; sufficientAllowance &amp;&amp; <strong>overflowed</strong>) {</pre><p>Directions of two inequalities should be changed and ‘!’ in front of ‘<em>overflowed</em>’ variable in the if condition should be removed.</p><h4>what can attackers do?</h4><p>Attackers can steal balances of target addresses into his address. They just select _value that is a big enough to set overflowed variable as false, and select _to as his address. If attackers send a transaction with those arguments, the condition of if statement, at line 60, will be passed and then balances will be manipulated.</p><h4>Exploits</h4><p>It seems that it has already exploited several times by someone. I found two exploit transactions that had tried to transfer a huge number of tokens <a href="https://etherscan.io/tx/0x122ee230d86cea0d1c1df42599e722a849067598777a0f43ccf83b12d0dfd485">[4]</a><a href="https://etherscan.io/tx/0x50a100eaf74469520177db55ea28f6046492034fdf5f5d264768d87c60ec3f3b">[5]</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qldtehwUVIiY0CLRaXdvjQ.png" /><figcaption>Figure 2. Exploit transaction at 04/20/2018</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JYtA_TSSUv1c63dtF9PVew.png" /><figcaption>Figure 3. Exploit transaction at 04/27/2018</figcaption></figure><h3>UET token is scam?</h3><p>After I found this vulnerability, I visited the official homepage of Useless Ethereum Token <a href="https://uetoken.com/">[6]</a>. In the page, they said that “Seriously, <em>don’t buy these tokens</em>”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*s7y97NP4crpeVP73Z8DtGg.png" /><figcaption>Figure 4. Offical page of UET token</figcaption></figure><p>If you visit the offical page and read all text in that page, you can realize that it is scam. However, the developer said honestly that don’t buy it because this token does not have any value. Nevertheless, many people bought UET token and it collected about 310.445 Ether(about $226,274 in these days) during in crowdsale. Moreover, it is available at HitBTC exchange <a href="https://hitbtc.com/UET-to-ETH">[7]</a> (now, deposit/withdraw is not available).</p><h3>Reports</h3><p>I reported it to the developer of UET token, ethereum.org and got CVE id. Around the same time, Peckshiled team reported it and got same CVE id with me. They already published an article before me <a href="https://medium.com/@peckshield/your-tokens-are-mine-a-suspicious-scam-token-in-a-top-exchange-5e864075f7e9">[8]</a>. CVE team confirmed that I reported first and then Peckshied sent a request 30 hours later. So CVE team gave a same CVE id to me and Peckshiled, but Peckshiled published their article before me.</p><h3>Conclusion</h3><p>Developers always should pay attention to the direction of the inequality. Sometimes it causes serious security vulnerabilites in smart contracts as well as in many other softwares. However, in this case, I strongly suspect that it is an intentional bug. Therefore, people should be carefule when they purchage crypto token.</p><h3>References</h3><ul><li>[1] CVE-2018–10468: <a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-10468">http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-10468</a></li><li>[2] tranferFrom in ERC20 Token Standard: <a href="https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#transferfrom">https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#transferfrom</a></li><li>[3] Code of UET smart contract: <a href="https://etherscan.io/address/0x27f706edde3aD952EF647Dd67E24e38CD0803DD6#code">https://etherscan.io/address/0x27f706edde3aD952EF647Dd67E24e38CD0803DD6#code</a></li><li>[4] an exploit transaction at 04/20/2018 : <a href="https://etherscan.io/tx/0x122ee230d86cea0d1c1df42599e722a849067598777a0f43ccf83b12d0dfd485">https://etherscan.io/tx/0x122ee230d86cea0d1c1df42599e722a849067598777a0f43ccf83b12d0dfd485</a></li><li>[5] an exploit transaction at 04/27/2018: <a href="https://etherscan.io/tx/0x50a100eaf74469520177db55ea28f6046492034fdf5f5d264768d87c60ec3f3b">https://etherscan.io/tx/0x50a100eaf74469520177db55ea28f6046492034fdf5f5d264768d87c60ec3f3b</a></li><li>[6] Official page of Useless Ethereum Token: <a href="https://uetoken.com/">https://uetoken.com</a></li><li>[7] UET in HitBTC: <a href="https://hitbtc.com/UET-to-ETH">https://hitbtc.com/UET-to-ETH</a></li><li>[8] Peckshiled’s post: <a href="https://medium.com/@peckshield/your-tokens-are-mine-a-suspicious-scam-token-in-a-top-exchange-5e864075f7e9">https://medium.com/@peckshield/your-tokens-are-mine-a-suspicious-scam-token-in-a-top-exchange-5e864075f7e9</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=543d42ac808e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/uselessethereumtoken-uet-erc20-token-allows-attackers-to-steal-all-victims-balances-543d42ac808e">UselessEthereumToken(UET), ERC20 token, allows attackers to steal all victim’s balances…</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Aurora IDEX Membership(IDXM), ERC20 Token, allows attackers to acquire contract ownership…]]></title>
            <link>https://medium.com/@jonghyk.song/aurora-idex-membership-idxm-erc20-token-allows-attackers-to-acquire-contract-ownership-1ff426cee7c6?source=rss-8218b7b42412------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ff426cee7c6</guid>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[erc20]]></category>
            <dc:creator><![CDATA[Jonghyuk Song]]></dc:creator>
            <pubDate>Thu, 03 May 2018 01:51:06 GMT</pubDate>
            <atom:updated>2018-05-10T05:38:43.444Z</atom:updated>
            <content:encoded><![CDATA[<h3>Aurora IDEX Membership(IDXM), ERC20 Token, allows attackers to acquire contract ownership (CVE-2018–10666)</h3><h3>Abstract</h3><p>I found a new vulnerability in smart contract of IDXM Token (<a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-10666"><strong>CVE-2018–10666</strong></a>)[1]. Attackers can acquire contract ownership because the <em>setOwner </em>function is delcared as public. A new owner can subsequently bypass intended access restrictions by, for example, calling <em>uploadBalances</em>.</p><h3>Details</h3><p>In the following, I will explain more details about the vulnerability. Figure 1 shows the vulnerable <em>setOnwer()</em> function <a href="https://etherscan.io/address/0xcc13fc627effd6e35d2d2706ea3c4d7396c610ea#code">[2]</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*ms6BKc8ugVecHf-u3lvgDg.png" /><figcaption>Figure 1. setOwner() function is delcared as public</figcaption></figure><p>In Solidity, there are four types of visibilities for functions: <em>external</em>, <em>public</em>, <em>internal </em>or <em>private, </em>where the default is <em>public </em><a href="http://solidity.readthedocs.io/en/v0.4.23/contracts.html#visibility-and-getters">[3]</a>. s<em>etOwner()</em> function is declared without any visibility, so it is declared as public. It means that anybody can call it and change <em>owner</em> variable. So, an attacker can change the <em>owner</em> variable to his account address.</p><h4>What can attackers do?</h4><p>There are important functions that should be called by only owner, such as <em>uploadBalances</em>, <em>lockBalances</em>, and so on. Those functions are protected by <em>onlyOwner</em> modifier which prevents calls from users who are not owner. An attacker can get the ownership of the contract using the vulnerability and then he can call any functions with owner authority. Therefore, he can call the functions declared with <em>onlyOwner</em> modifier.</p><h4>Exploit</h4><p>To confirm this vulnerability, I sent a transaction invoking the <em>setOwner</em> function to change the owner as my account address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yM-y6zfrcs0ugX-KpYZ6ag.png" /><figcaption>Figure 2. Before the exploit, the owner is ‘0x000000ba8f84d23de76508547f809d75733ba170’ which is same with contract creator</figcaption></figure><p>Figure 2 shows that the original state of the contract. The owner of the contract is same with the contract creator which is ‘0x000000ba8f84d23de76508547f809d75733ba170’. After my exploit, the owner is changed as my account address ‘0xa4afe8bc10c32e8e0ca9db6f982e4d9490045407’. Figure 3 shows the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GlML4VPaCLyUBHFWQ_CZVw.png" /><figcaption>Figure 3. owner is changed as ‘0xa4afe8bc10c32e8e0ca9db6f982e4d9490045407’ after the exploit.</figcaption></figure><p>Figure 4 shows the <a href="https://etherscan.io/tx/0xebf1137e7e9c0eb399dce6397309ef8e95bf3706f10340212be8082ae69c2f10">exploit transaction [4]</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QNH7_c9a5FBqQAoQDp5jMA.png" /><figcaption>Figure 4. Exploit transaction</figcaption></figure><h3>Reports</h3><p>When I found this vulnerability, I have immediately notified to <a href="https://auroradao.com/"><strong>Aurora </strong></a>which is admins of IDXM [5]. They said that it is a known bug and not critical. Actually, the attacker who gets ownership cannot do critical things such as manipulating user’s balances or destroying contract. The attacker can modify some important variables but admins can change it by getting owership again.</p><h3>Conclusion</h3><p>Declaring visibilitiy of functions is very important. Developers must declare the visibilitiy although it is public function. When they implement a function, they should deeply consider who can or cannot call it. Fortunately, this vulnerability is not critical but many smart contract will danger if their ownership is changed by anyone.</p><h3>About me</h3><p>I’m <a href="https://freest4r.github.io/">Jonghyuk Song</a> who is a security researcher at <strong>Samsung Research</strong>. Recently, I’m intereted in Blockchain security, such as consensus protocol, smart contracts, sodlity and so on.</p><h3>References</h3><ul><li>[1] CVE-2018–10666: <a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-10666">http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-10666</a></li><li>[2] Smart contract source code of IDXM: <a href="https://etherscan.io/address/0xcc13fc627effd6e35d2d2706ea3c4d7396c610ea#code">https://etherscan.io/address/0xcc13fc627effd6e35d2d2706ea3c4d7396c610ea#code</a></li><li>[3] Visibilitiy and Getters: <a href="http://solidity.readthedocs.io/en/v0.4.23/contracts.html#visibility-and-getters">http://solidity.readthedocs.io/en/v0.4.23/contracts.html#visibility-and-getters</a></li><li>[4] exploit transaction: <a href="https://etherscan.io/tx/0xebf1137e7e9c0eb399dce6397309ef8e95bf3706f10340212be8082ae69c2f10">https://etherscan.io/tx/0xebf1137e7e9c0eb399dce6397309ef8e95bf3706f10340212be8082ae69c2f10</a></li><li>[5] Aurora’s official page: <a href="https://auroradao.com/">https://auroradao.com/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ff426cee7c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>