Blockchain Exploitation Labs - Part 3 Exploiting Integer Overflows And Underflows




In part 1 and 2 we covered re-entrancy and authorization attack scenarios within the Ethereum smart contract environment. In this blog we will cover integer attacks against blockchain decentralized applications (DAPs) coded in Solidity.

Integer Attack Explanation:

An integer overflow and underflow happens when a check on a value is used with an unsigned integer, which either adds or subtracts beyond the limits the variable can hold. If you remember back to your computer science class each variable type can hold up to a certain value length. You will also remember some variable types only hold positive numbers while others hold positive and negative numbers.

If you go outside of the constraints of the number type you are using it may handle things in different ways such as an error condition or perhaps cutting the number off at the maximum or minimum value.

In the Solidity language for Ethereum when we reach values past what our variable can hold it in turn wraps back around to a number it understands. So for example if we have a variable that can only hold a 2 digit number when we hit 99 and go past it, we will end up with 00. Inversely if we had 00 and we subtracted 1 we would end up with 99.


Normally in your math class the following would be true:

99 + 1 = 100
00 - 1 = -1


In solidity with unsigned numbers the following is true:

99 + 1 = 00
00 - 1 = 99



So the issue lies with the assumption that a number will fail or provide a correct value in mathematical calculations when indeed it does not. So comparing a variable with a require statement is not sufficiently accurate after performing a mathematical operation that does not check for safe values.

That comparison may very well be comparing the output of an over/under flowed value and be completely meaningless. The Require statement may return true, but not based on the actual intended mathematical value. This in turn will lead to an action performed which is beneficial to the attacker for example checking a low value required for a funds validation but then receiving a very high value sent to the attacker after the initial check. Lets go through a few examples.

Simple Example:

Lets say we have the following Require check as an example:
require(balance - withdraw_amount > 0) ;


Now the above statement seems reasonable, if the users balance minus the withdrawal amount is less than 0 then obviously they don't have the money for this transaction correct?

This transaction should fail and produce an error because not enough funds are held within the account for the transaction. But what if we have 5 dollars and we withdraw 6 dollars using the scenario above where we can hold 2 digits with an unsigned integer?

Let's do some math.
5 - 6 = 99

Last I checked 99 is greater than 0 which poses an interesting problem. Our check says we are good to go, but our account balance isn't large enough to cover the transaction. The check will pass because the underflow creates the wrong value which is greater than 0 and more funds then the user has will be transferred out of the account.

Because the following math returns true:
 require(99 > 0) 

Withdraw Function Vulnerable to an UnderFlow:

The below example snippet of code illustrates a withdraw function with an underflow vulnerability:

function withdraw(uint _amount){

    require(balances[msg.sender] - _amount > 0);
    msg.sender.transfer(_amount);
    balances[msg.sender] -= _amount;

}


In this example the require line checks that the balance is greater then 0 after subtracting the _amount but if the _amount is greater than the balance it will underflow to a value above 0 even though it should fail with a negative number as its true value.

require(balances[msg.sender] - _amount > 0);


It will then send the value of the _amount variable to the recipient without any further checks:

msg.sender.transfer(_amount);

Followed by possibly increasing the value of the senders account with an underflow condition even though it should have been reduced:

balances[msg.sender] -= _amount;


Depending how the Require check and transfer functions are coded the attacker may not lose any funds at all but be able to transfer out large sums of money to other accounts under his control simply by underflowing the require statements which checks the account balance before transferring funds each time.

Transfer Function Vulnerable to a Batch Overflow:

Overflow conditions often happen in situations where you are sending a batched amount of values to recipients. If you are doing an airdrop and have 200 users who are each receiving a large sum of tokens but you check the total sum of all users tokens against the total funds it may trigger an overflow. The logic would compare a smaller value to the total tokens and think you have enough to cover the transaction for example if your integer can only hold 5 digits in length or 00,000 what would happen in the below scenario?


You have 10,000 tokens in your account
You are sending 200 users 499 tokens each
Your total sent is 200*499 or 99,800

The above scenario would fail as it should since we have 10,000 tokens and want to send a total of 99,800. But what if we send 500 tokens each? Lets do some more math and see how that changes the outcome.


You have 10,000 tokens in your account
You are sending 200 users 500 tokens each
Your total sent is 200*500 or 100,000
New total is actually 0

This new scenario produces a total that is actually 0 even though each users amount is 500 tokens which may cause issues if a require statement is not handled with safe functions which stop an overflow of a require statement.



Lets take our new numbers and plug them into the below code and see what happens:

1. uint total = _users.length * _tokens;
2. require(balances[msg.sender] >= total);
3. balances[msg.sender] = balances[msg.sender] -total;

4. for(uint i=0; i < users.length; i++){ 

5.       balances[_users[i]] = balances[_users[i]] + _value;



Same statements substituting the variables for our scenarios values:

1. uint total = _200 * 500;
2. require(10,000 >= 0);
3. balances[msg.sender] = 10,000 - 0;

4. for(uint i=0; i < 500; i++){ 

5.      balances[_recievers[i]] = balances[_recievers[i]] + 500;


Batch Overflow Code Explanation:

1: The total variable is 100,000 which becomes 0 due to the 5 digit limit overflow when a 6th digit is hit at 99,999 + 1 = 0. So total now becomes 0.

2: This line checks if the users balance is high enough to cover the total value to be sent which in this case is 0 so 10,000 is more then enough to cover a 0 total and this check passes due to the overflow.

3: This line deducts the total from the senders balance which does nothing since the total of 10,000 - 0 is 10,000.  The sender has lost no funds.

4-5: This loop iterates over the 200 users who each get 500 tokens and updates the balances of each user individually using the real value of 500 as this does not trigger an overflow condition. Thus sending out 100,000 tokens without reducing the senders balance or triggering an error due to lack of funds. Essentially creating tokens out of thin air.

In this scenario the user retained all of their tokens but was able to distribute 100k tokens across 200 users regardless if they had the proper funds to do so.

Lab Follow Along Time:

We went through what might have been an overwhelming amount of concepts in this chapter regarding over/underflow scenarios now lets do an example lab in the video below to illustrate this point and get a little hands on experience reviewing, writing and exploiting smart contracts. Also note in the blockchain youtube playlist we cover the same concepts from above if you need to hear them rather then read them.

For this lab we will use the Remix browser environment with the current solidity version as of this writing 0.5.12. You can easily adjust the compiler version on Remix to this version as versions update and change frequently.
https://remix.ethereum.org/

Below is a video going through coding your own vulnerable smart contract, the video following that goes through exploiting the code you create and the videos prior to that cover the concepts we covered above:


Download Video Lab Example Code:

Download Sample Code:

//Underflow Example Code: 
//Can you bypass the restriction? 
//--------------------------------------------
 pragma solidity ^0.5.12;

contract Underflow{
     mapping (address =>uint) balances;

     function contribute() public payable{
          balances[msg.sender] = msg.value;  
     }

     function getBalance() view public returns (uint){
          return balances[msg.sender];     
     }

     function transfer(address _reciever, uint _value) public payable{
         require(balances[msg.sender] - _value >= 5);
         balances[msg.sender] = balances[msg.sender] - _value;  

         balances[_reciever] = balances[_reciever] + _value;
     }
    
}

This next video walks through exploiting the code above, preferably hand coded by you into the remix environment. As the best way to learn is to code it yourself and understand each piece:


 

Conclusion: 

We covered a lot of information at this point and the video series playlist associated with this blog series has additional information and walk throughs. Also other videos as always will be added to this playlist including fixing integer overflows in the code and attacking an actual live Decentralized Blockchain Application. So check out those videos as they are dropped and the current ones, sit back and watch and re-enforce the concepts you learned in this blog and in the previous lab. This is an example from a full set of labs as part of a more comprehensive exploitation course we have been working on.

Related news

PHASES OF HACKING

What is the process of hacking or phases of hacking?
Hacking is broken up into six phases:The more you get close to all phases,the more stealth will be your attack.

1-Reconnaissance-This is the primary phase of hacking where hacker tries to collect as much as information as possible about the target.It includes identifying the target,domain name registration records of the target, mail server records,DNS records.The tools that are widely used in the process is NMAP,Hping,Maltego, and Google Dorks.

2-Scanning-This makes up the base of hacking! This is where planning for attack actually begins! The tools used in this process are Nessus,Nexpose,and NMAP. After reconnaissance the attacker scans the target for services running,open ports,firewall detection,finding out vulnerabilities,operating system detection.

3-Gaining Access-In this process the attacker executes the attack based on vulnerabilities which were identified during scanning!  After the successful, he get access to the target network or enter in to the system.The primary tools that is used in this process is Metasploit.

4-Maintaining Access-It is the process where the hacker has already gained access in to a system. After gaining access the hacker, the hacker installs some backdoors in order to enter in to the system when he needs access in this owned system in future. Metasploit is the preffered toll in this process.

5-Clearning track or Covering track-To avoid getting traced and caught,hacker clears all the tracks by clearing all kinds of logs and deleted the uploaded backdoor and anything in this process related stuff which may later reflect his presence!

6-Reporting-Reporting is the last step of finishing the ethical hacking process.Here the Ethical Hacker compiles a report with his findings and the job that was done such as the tools used,the success rate,vulnerabilities found,and the exploit process.

Related word


  1. Hacking Tools Usb
  2. Hack Tool Apk No Root
  3. Hacker Tools Free Download
  4. Hack Website Online Tool
  5. Tools 4 Hack
  6. Hacker Tools 2019
  7. Best Hacking Tools 2020
  8. Hack Website Online Tool
  9. New Hacker Tools
  10. Pentest Tools Tcp Port Scanner
  11. Tools Used For Hacking
  12. How To Hack
  13. Ethical Hacker Tools
  14. Pentest Tools Apk
  15. Tools For Hacker
  16. Hacking Tools Usb
  17. What Are Hacking Tools
  18. Hacker Tools Free
  19. Hack Tool Apk No Root
  20. How To Install Pentest Tools In Ubuntu
  21. Pentest Tools Windows
  22. Pentest Tools Framework
  23. Hacker Tools Mac
  24. Hacking Tools Github
  25. Hacking Tools Windows
  26. Pentest Tools Download
  27. Underground Hacker Sites
  28. Hack Tool Apk
  29. Tools Used For Hacking
  30. Pentest Tools Website Vulnerability
  31. Hacker Tools Hardware
  32. Best Hacking Tools 2020
  33. Pentest Tools Url Fuzzer
  34. Hacking Tools Free Download
  35. World No 1 Hacker Software
  36. Hack App
  37. Hacker Tools 2020
  38. Pentest Tools Url Fuzzer
  39. Hacker Hardware Tools
  40. New Hack Tools
  41. How To Hack
  42. Hacking Tools Windows
  43. Hack Tools Github
  44. Hacking App
  45. Hacker Tools Windows
  46. Hack Tool Apk
  47. Hack Tools 2019
  48. Github Hacking Tools
  49. Hacker Tools 2020
  50. Pentest Tools Open Source
  51. Hack Tools
  52. Nsa Hack Tools
  53. Hacker Tools Hardware
  54. Best Hacking Tools 2019
  55. Hacking Tools For Kali Linux
  56. Blackhat Hacker Tools
  57. Nsa Hacker Tools
  58. Pentest Tools Website Vulnerability
  59. Hack Tools
  60. Pentest Tools Bluekeep
  61. Hacker Tools Free Download
  62. Pentest Tools For Android
  63. Hacking Tools For Kali Linux
  64. Pentest Tools Framework
  65. Nsa Hack Tools Download
  66. Hack Tools Mac
  67. Hacker Security Tools
  68. Blackhat Hacker Tools
  69. Blackhat Hacker Tools
  70. Game Hacking
  71. Hak5 Tools
  72. Pentest Tools Website
  73. Hacker Tools Mac
  74. Hacking Tools Usb
  75. Hacking Tools Download
  76. Hack Apps
  77. Hacker Tools For Ios
  78. Hacker Tools Linux
  79. Pentest Tools For Ubuntu
  80. Hacker Tools For Ios
  81. Wifi Hacker Tools For Windows
  82. Hacking Tools Online
  83. Pentest Tools Tcp Port Scanner
  84. Hack Website Online Tool
  85. Hacker Tools For Windows
  86. Install Pentest Tools Ubuntu
  87. Hack Tool Apk No Root
  88. Hacking Tools Download
  89. Hacker Search Tools
  90. Pentest Tools Alternative
  91. Hacking Tools Usb
  92. Hack Rom Tools

HOW TO BOOST UP BROWSING SPEED?

Internet speed is the most cared factor when you buy an internet connection. What if still, you face a slow speed browsing problem? No worries, as I came with a solution to this problem. I will let you know how to boost up browsing speed. It's very simple to follow.

SO, HOW TO BOOST UP BROWSING SPEED?

There can be many ways you can get a speedy browsing whether you use paid service or free hacks. I am going to share this free speed hack with you.

STEPS TO FOLLOW

  1. Navigate to Control Panel > Network and Internet Options > Network and Sharing Center.
  2. Now look for the active internet connection to which you're currently connected to.
  3. Open up Connection Properties of your active connection.
  4. Click on IPv4 and open its Properties.
  5. Here you will notice your DNS, you just need to change your DNS address with the following DNS.
    Preferred DNS server: 208.67.222.222
    Alternate DNS server: 208.67.220.220
  6. Once done, save it and no configure it for IPv6. Just change the IPv6 DNS with the following DNS.
    Preferred DNS server: 2620:0:ccc::2

    Alternate DNS server: 2620:0:CCD::2
  7. Finally, save and you're done with it.
That's all. You have successfully learned how to boost up browsing speed. Hope it will work for you. Enjoy speedy internet..!
More info

IPHONE PLAYERS Vs POCO X3 PRO GAMEPLAY WHICH DEVICE IS BETTER???

Related news


Scanning TLS Server Configurations With Burp Suite

In this post, we present our new Burp Suite extension "TLS-Attacker".
Using this extension penetration testers and security researchers can assess the security of TLS server configurations directly from within Burp Suite.
The extension is based on the TLS-Attacker framework and the TLS-Scanner, both of which are developed by the Chair for Network and Data Security.

You can find the latest release of our extension at: https://github.com/RUB-NDS/TLS-Attacker-BurpExtension/releases

TLS-Scanner

Thanks to the seamless integration of the TLS-Scanner into the BurpSuite, the penetration tester only needs to configure a single parameter: the host to be scanned.  After clicking the Scan button, the extension runs the default checks and responds with a report that allows penetration testers to quickly determine potential issues in the server's TLS configuration.  Basic tests check the supported cipher suites and protocol versions.  In addition, several known attacks on TLS are automatically evaluated, including Bleichenbacher's attack, Padding Oracles, and Invalid Curve attacks.

Furthermore, the extension allows fine-tuning for the configuration of the underlying TLS-Scanner.  The two parameters parallelProbes and overallThreads can be used to improve the scan performance (at the cost of increased network load and resource usage).

It is also possible to configure the granularity of the scan using Scan Detail and Danger Level. The level of detail contained in the returned scan report can also be controlled using the Report Detail setting.

Please refer to the GitHub repositories linked above for further details on configuration and usage of TLS-Scanner.

Scan History 

If several hosts are scanned, the Scan History tab keeps track of the preformed scans and is a useful tool when comparing the results of subsequent scans.

Additional functions will follow in later versions

Currently, we are working on integrating an at-a-glance rating mechanism to allow for easily estimating the security of a scanned host's TLS configuration.

This is a combined work of Nurullah Erinola, Nils Engelbertz, David Herring, Juraj Somorovsky, Vladislav Mladenov, and Robert Merget.  The research was supported by the European Commission through the FutureTrust project (grant 700542-Future-Trust-H2020-DS-2015-1).

If you would like to learn more about TLS, Juraj and Robert will give a TLS Training at Ruhrsec on the 27th of May 2019. There are still a few seats left.
Related links
  1. Pentest Tools Windows
  2. Nsa Hack Tools Download
  3. Install Pentest Tools Ubuntu
  4. Pentest Tools Framework
  5. Hacking Tools Mac
  6. Hacking Tools And Software
  7. Hack Tools
  8. Beginner Hacker Tools
  9. Hack Tools
  10. Hacker Tools Software
  11. Hacking Tools Windows 10
  12. Hacking Tools For Windows Free Download
  13. Hack Website Online Tool
  14. Best Hacking Tools 2019
  15. Pentest Tools Website Vulnerability
  16. Pentest Tools Nmap
  17. Pentest Tools Website
  18. Nsa Hacker Tools
  19. Hacking Tools Free Download
  20. Hacking Tools Name
  21. Nsa Hack Tools
  22. How To Make Hacking Tools
  23. Pentest Tools For Mac
  24. Pentest Box Tools Download
  25. Pentest Tools Windows
  26. Usb Pentest Tools
  27. Pentest Recon Tools
  28. Pentest Automation Tools
  29. Hacker Tools Free
  30. Nsa Hack Tools Download
  31. Hacking Tools
  32. Hacker Tools Free
  33. Best Pentesting Tools 2018
  34. Pentest Tools Online
  35. Hacker Tools For Pc
  36. Pentest Tools Subdomain
  37. Hackers Toolbox
  38. Hacker
  39. Hack Tool Apk
  40. Tools For Hacker
  41. Top Pentest Tools
  42. Hacker Tools Free
  43. Hacking Tools Usb
  44. Hacker Tools Apk Download
  45. Nsa Hacker Tools
  46. Hacker Tools Apk
  47. Hacking Tools Software
  48. Hack Tools 2019
  49. Black Hat Hacker Tools
  50. Pentest Tools For Android
  51. Pentest Tools For Windows
  52. Hak5 Tools
  53. Pentest Tools Free
  54. Bluetooth Hacking Tools Kali
  55. Free Pentest Tools For Windows
  56. Pentest Automation Tools
  57. Pentest Box Tools Download
  58. Hacker Tool Kit
  59. Hacker Hardware Tools
  60. Hacking Tools Kit
  61. Wifi Hacker Tools For Windows
  62. Kik Hack Tools
  63. Hacking Tools Windows 10
  64. Hack Tools
  65. Pentest Tools Free
  66. Pentest Tools Free
  67. Hacker Security Tools
  68. Pentest Tools Framework
  69. Github Hacking Tools
  70. Hacker Tools 2019
  71. How To Install Pentest Tools In Ubuntu
  72. Kik Hack Tools
  73. Pentest Box Tools Download
  74. Pentest Tools Subdomain
  75. Hack And Tools
  76. Hack Tools For Ubuntu
  77. Hack Tools Github
  78. Pentest Tools List
  79. Hack Tool Apk
  80. Hak5 Tools
  81. Hacking Tools Usb
  82. Pentest Recon Tools
  83. Beginner Hacker Tools
  84. Hacking Tools For Kali Linux