GithubHelp home page GithubHelp logo

ishinu / denial-of-service-attack Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 197 KB

Denial Of Service Attack and Prevention.

License: MIT License

Solidity 57.08% JavaScript 42.92%
dos-attack solidity-hack uups-proxy uups-upgradeable-contract

denial-of-service-attack's Introduction

Denial Of Service Attack ( UUPS Upgradeable )

One who donates higher amount of Ether, becomes the King!

But, a malicious attacker comes with a logic to not accept Ether which completely breaks the GAME! ( DOS ATTACK! )

Let's see how it happens.

But...but... fun part is dev made this contract (UUPS) upgradeable due to which it solved the bug, upgraded the proxy and deployed another game contract without losing any Ether!

Test the game on Remix-IDE

Steps to deploy and test KingOfEther contract in Remix :

- Open the `KingOfEther.sol` and `DOSAttack.sol` in Remix-IDE. 
- Select `KingOfEther.sol` in left sidebar, select `Deploy with proxy` and Deploy it. ( It may ask for 2 confirmations about deploying proxy, you may accept.)
- Now select `DOSAttack.sol` file and then in left sidebar, select `Deploy with proxy` and provide the `Address of KingOfEther Proxy` as the argument and select Deploy.
- You can deposit some test Eth to KingOfEther to set the king and topDeposit value.
- Now you may call Attack function of Attack.sol with some test Eth, higher than topDeposit amount.
- As you can check, `Attack contract Proxy` is now the king!
- Now... if anyone tries to deposit higher than topDeposit value, it will fail.

Since, KingOfEther proxy contract will try to send previously deposited ether to king which is in our case the Attack proxy but due to intentionally missed ( receive() or fallback() function) , Attack proxy can't receive Ether. This breaks the function before updating the new king which reverts the transaction.

- To fix this, open `KingOfEtherV2.sol` in Remix.
- Select `upgrade the proxy` and input previously deployed `KingOfEther proxy contract address` as argument.
- It will ask for two confirmations for upgrading previously deployed proxy, you may accept.
- Now you have `KingOfEtherV2 proxy address` which you may ponder, is same as `KingOfEther proxy address`.
- What it did? It deployed `KingOfEtherV2.sol` and upgraded the previous proxy contract `implementation address` to the newer version of game contract!

And the best part, Without changing any of the state variable values!

How amazing is this...!

You may check that in proxy, king is still attack proxy address and topDeposit is unchanged.

But now you have a way out since you solved the bug and seperated out the withdraw(). Now only person who will be having issues is the attack deployed as their Eth is gone forever! ( By adding a mapping, it just increases the uint for the respective address and allows new king assignment. )

Test the game in public testnet ( Eg. Ropsten )

Quick glance of how it may appear once you successfully deploy it on testnet :

Deploying KingOfEther contract...
KingOfEther Proxy Contract deployed at :  0xF4c89f95b91234e690A6f04dF923f8866f7B15a2
KingOfEther Implementation address via (getImplementationAddress) :  0x73179055409eC8eF35195629024cc5Bfa6A79A71
Deploying DOS Attack contract...
DOS Attack Proxy Contract deployed at :  0x2809B1480912d26fB4e8DD6DA23794fB86488a57
DOS Attack Implementation address via (getImplementationAddress) :  0x5cE28cAE117aDABb1144FdFb7782Fe0a4bB2eEE1

And the upgrade...

Deploying KingOfEtherV2...
KingOfEtherV2 proxy contract deployed at :  0xF4c89f95b91234e690A6f04dF923f8866f7B15a2
KingOfEtherV2 contract deployed at :  0xAA994125F90eDDc3C74b7293149964c5f275F68A

Deploy scripts are already available with you as you cloned the repository. Just follow the Pre-requisites by following the guide and you are set to test on public testnet!

denial-of-service-attack's People

Contributors

ishinu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.