项目作者: pdos-team

项目描述 :
DDoS for the people
高级语言: Python
项目地址: git://github.com/pdos-team/pdos.git
创建时间: 2019-08-12T10:55:51Z
项目社区:https://github.com/pdos-team/pdos

开源协议:MIT License

下载


pDoS

DDoS for the people

pDoS is a research project exploring the plausibility of organizing
collaborative large-scale DDoS attacks in a censorhip resistant way.

It relies on the ethereum blockchain to achieve resilience. Users can:

  • submit a new operation, suggesting a target, a start time along with other
    parameters.
  • join and commit to any operation that was previously submitted.
  • participate in a DDoS operation that reached the required number of users.

Warning: Do not attempt to launch a DoS using Tor for obvious ethical reasons.

Architecture

pDoS is a a client operating in the ethereum blockchain through a daemon
communicating with a ethereum client. The wallets paying for the transaction
fees are managed in the user’s ethereum client.

  1. -~* TARGETS *~- +--------+
  2. || | |
  3. || | +--------+
  4. +--------+ +--------+ +--------+ +--------+ |
  5. | +------>+ +------>+ +-----------> +--------+
  6. | | | | | | +--------+ |
  7. | +<------+ +<------+ +<-----------------+ |
  8. +--------+ +--------+ +--------+ +--------+
  9. pdos pdosd ethereum client ethereum
  10. (client) (daemon) supporting RPC blockchain

Operations

pDoS is based on the concept of operations. An operation O is a proposal to
collaboratively attempt a DDoS attack on a defined target. An operation is
executed only if the number of participatnts reaches its defined threshold (it
is then decided).

  1. target: STRING, # target to attack
  2. service: STRING, # type of service to attack
  3. threshold: INT64, # required number of participants
  4. epoch_start: INT64, # epoch in seconds (start of the attack)
  5. epoch_stop: INT64, # epoch in seconds (end of the attack)
  6. staking: INT64, # amount in `ether` required to bid
  7. info: STRING, # free-form information about the operation

Important Note: For now, only the “www” service is supported, accepting a
target defined as a unique FQDN (example: “www.site.com”). pdos will attempt to determine which service to attack between HTTP and HTTPS. You can also provide a unique url (example: “https://www.site.com/“).

Participation to an operation (called joining an operation) represents a
commitment by the participant to lend its resources by running pdosd at the
planned time of the attack.

Quickstart

Download or git clone this repository.

Direct use

Install and run any local ethereum node supporting HTTP or Websockets RPC
(https://geth.ethereum.org/downloads for example).

Install python3 (tested: 3.7) along with pip3, then from the pdos
directory, install with:

  1. pip3 install --user .

The pdos and pdosp executables will generally be installed in
~/.local/bin, you can alternatively use miniconda or virtualenv to
isolate the installation.

You can then:

  • run your ethereum client, with RPC interface on http://127.0.0.1:8545 (by
    default).
  • run an instance of pdosd with:
    pdosd --eth_account 0xADDR, assuming
    0xADDR is the address of one of your node’s
    accounts.
  • if your node does not support private key management or if you don’t want it to, run: pdosd --eth_account 0xADDR --eth_privkey 0xPRIVKEY or pdosd --eth_wallet WALLET_FILE.
  • use pdos, starting with: pdos help.

Note: when using ethereum client’s wallet API, pdosd can’t use any
ethereum funds
that were not previously unlocked inside the ethereum client.
We suggest that you create a dedicated ethereum account for pdos, containing
a very small amount of ethers to pay for pDoS transactions gas.

Docker containers

You may have to enable forwarding when using containers, in order to reach the
real world, especially for the geth container if you need to use it (UDP port
forwarding).

  1. $ sysctl net.ipv4.conf.all.forwarding=1
  2. $ sudo iptables -P FORWARD ACCEPT

The container setup is made of 2 containers (see docker-compose.yaml). The
geth container launches a ethereum node & client, and the pdos container
allows use of pdosd and pdos client.

Note: you can use only 1 of the containers and deal with the other part
yourself, as long as command line parameters are consistent. Beware of exposing
ports to the internet, especially the 8545 geth RPC interface, which would
leave your wallet unprotected.

Launching a geth instance

In project root dir, type docker-compose build.

Then type the following commands to start a geth instance on mainnet and
pdosd instance:

  1. docker-compose run --use-aliases geth
  2. docker-compose run --use-aliases pdosd

Important Note: geth data directory is set to: ~/.config/pdos/geth_datadir.
It will contain the synced blockchain and your private (passphrase encrypted)
data.

For testing on Ropsten network, you can use:

  1. docker-compose run --use-aliases geth --testnet
  2. docker-compose run --use-aliases pdosd --testnet

For development, you can use:

  1. docker-compose run --use-aliases geth --mine --dev
  2. docker-compose run --use-aliases pdosd --deploy --networktype PoA

In dev mode, geth will open a local private node and pdosd will use a geth
generated ethereum address.

Then pdos can be used as follows:

  1. docker-compose run pdos help

or

  1. docker-compose run --entrypoint='' bash
  2. # pdos help

Using pdos

Launch pdos daemon with: docker-compose run pdos pdosd --eth_rpc http://geth_host:8545

Run pdos client commands with: docker-compose run pdos pdos --help

Example setup with infura

This section describes how you can use pdos with infura.

Register to infura

Get an API key from infura:

  • go to and registera free account (a valid mail address is required).
  • create a new project.
  • write down Project ID inside the KEYS section (32 hex chars). Example: 1878a221d804c95b9f806dbbcd3e6aae

Get an ethereum wallet

Create an ethereum wallet. Many ways to do this:

  • you can use https://www.myetherwallet.com and select Create a new wallet then by keystore file to download the file.
  • run geth --console, then eth.newAccount() and get the wallet file inside ~/.ethereum/keystore/.

A wallet file looks like this: UTC--2011-03-11T09-58-22.352Z--adca81daab252C666f84adb18697baaea0d68f57 and contains your password-encrypted private key. The ETH address liked to this wallet is: 0xadca81daab252C666f84adb18697baaea0d68f57.

Using any site, purchase ethereums and transfer a small amount to this (example) address (0xadca81daab252C666f84adb18697baaea0d68f57). For example: 0.01 ether.

Run pdosd

On your machine, run the following commands:

  1. apt-get install python3 python3-pip
  2. git clone https://github.com/pdos-team/pdos
  3. cd pdos
  4. pip3 install --user .

Then open a terminal, run pdosd, and wait until GRPC server is up:

  1. $ pdosd --eth_rpc wss://mainnet.infura.io/ws/<INFURA_PROJECT_ID> --eth_wallet UTC--2011-03-11T09-58-22.352Z--adca81daab252C666f84adb18697baaea0d68f57
  2. [...]
  3. [+] Starting GRPC server on port 7331.

Open another terminal and run:

  1. $ pdos help

You are now ready to join!

pDoS daemon (pdosd)

pDoS daemon listens for requests on a RPC interface specified by the port
parameter. It connects to specified ethereum node (through http, https,
websocket, or websocket over ssl) to make transactions on the blockchain.

pDos daemon can work with local or hosted ethereum private keys.

  • local keys have to be provided to pdosd using command line parameters (see below).
  • hosted keys are managed by the ethereum node to which pdosd connects.
  1. usage: pdosd [-h] [--eth_rpc ETH_RPC] [--eth_account ETH_ACCOUNT]
  2. [--eth_privkey ETH_PRIVKEY] [--eth_wallet ETH_WALLET]
  3. [--gasprice GASPRICE] [--port PORT] [--deploy] [--testnet]
  4. [--reference REFERENCE] [--networktype {PoW,PoA}]
  5. pDoS daemon
  6. optional arguments:
  7. -h, --help show this help message and exit
  8. --eth_rpc ETH_RPC web3 rpc address to use [default:
  9. http://127.0.0.1:8545]
  10. --eth_account ETH_ACCOUNT
  11. ETH (checksummed) address to use (see README)
  12. [default: coinbase]
  13. --eth_privkey ETH_PRIVKEY
  14. ETH private key to use to sign transaction inside this
  15. script [default: empty]
  16. --eth_wallet ETH_WALLET
  17. path to ETH wallet file (instead of suppling
  18. eth_account and eth_privkey) [default: empty]
  19. --gasprice GASPRICE ETH private key to use to sign transaction inside this
  20. script [default: 21 Gwei]
  21. --port PORT port to listen to [default: 7331]
  22. --deploy deploy new R contract. Only for dev purposes (see
  23. README) [default: False]
  24. --testnet use testnet reference contract address instead of
  25. mainnet [default: False]
  26. --reference REFERENCE
  27. override reference contract address (dev/testing
  28. purposes)
  29. --networktype {PoW,PoA}
  30. Network type (PoW/PoA) [default: PoW]

The user can propose and join DDoS operations (see below pdos client).
pdosd will launch DDoS attack (for now, only SlowLoris has been added to this
project, though a rip of
https://github.com/gkbrk/slowloris/blob/master/slowloris.py python code) if
(and only if) the following conditions are all fulfilled:

  • the user has joined the operation.
  • the operation has been decided (= the number of users that committed to the
    operation is above threshold).
  • the epoch given by pdosd operating system matches the operation’s
    requirements (start, stop).

At boot, pdosd will connect to node and ask for all past events to be
up-to-date:

  1. [+] Web3 Connected through RPC
  2. [+] Web3 api version: ______ 4.X.X
  3. [+] Web3 node version: _____ Geth/v1.X.X-stable-XXXXXXXX/linux-amd64/go1.XX.X
  4. [+] Web3 network version: __ 1337
  5. [+] Reference contract address is 0x3Ba46565824Ab9fBb233E1B5455d612A37E5338e.
  6. [+] NewOperationEvent (operation: 0xBedF71677c8d6a04F73474e1906C61d36017BC9e)
  7. [+] NewOperationEvent (operation: 0xD9050E3CD3aEc21f0684F53edA7C3c21464E7F49)
  8. [+] NewOperationEvent (operation: 0x9c7f897b4A486F9c0acEf8eb3A085bDC209D5a2B)
  9. [+] NewOperationEvent (operation: 0x314994e2Bfb2D8B0e78fe3aB42476c590fbCa710)
  10. [+] NewUserEvent (operation: 0xD9050E3CD3aEc21f0684F53edA7C3c21464E7F49, user: 0xf7825c65E62C939c8Cf928f9Bd2F94Dc864349B8)
  11. [+] OperationDecidedEvent (operation: 0xD9050E3CD3aEc21f0684F53edA7C3c21464E7F49)
  12. [+] Target www.site.com as port 80 open, using HTTP ATK
  13. [+] Execution registered: www/0 www.site.com (100000000000, 100000003600)
  14. [+] Starting GRPC server on port 7331.

Examples

You want to use a node or a client that manages private keys for you

Example setups:

  • geth with --syncmode "full" or --syncmode "fast" arguments
  1. $ pdosd

ETH wallet file containing the privatekey

Example setups:

  • parity
  • geth with --syncmode "light" or if you prefer handling privatekeys yourself)
  • any client that does not provide account/wallet API
  • infura.io or any (non evil) hosted node

User will be prompted for password.

  1. $ pdosd --eth_wallet /somedir/UTC--2011-01-01T10-20-40.12345Z--fedc842f2af79b53f93afd28fb098161d0fa7ce2
  2. Wallet file password: (unseen)

Account and private key as arguments (WARNING: PRIVATE KEY WILL appear during a process listing)

  1. $ pdosd --eth_account 0x6FCF1B5dE32d75bbaFF8220cE5A831e12B567740 --eth_privkey 123456789123456789123456789

Use with infura.io nodes

  1. pdosd --eth_rpc wss://<NETWORK>.infura.io/ws/<INFURA API KEY> --eth_wallet <WALLET FILE>

Note: For all nodes like Infura.io free ethereum node as a service that don’t
allow events (https://github.com/INFURA/infura/issues/73), you will have to
use a Websocket interface.

pDoS client (pdos)

  1. $ pdos help
  2. pDoS client
  3. General options:
  4. --pdosd_rpc PDOSD_RPC pdosd RPC address [default: 127.0.0.1:7331]
  5. pdos help [command]
  6. Display help about a command or this messsage if no command is provided.
  7. `pdos help operation join`
  8. pdos operation list
  9. List upcoming operations.
  10. `pdos operation list`
  11. pdos operation propose <target> <threshold> <epoch_start> <duration>
  12. Propose a new operation.
  13. `pdos operation propose www.foo.bar 2000 1563888880 3600`
  14. pdos operation join <address>
  15. Commmit your participation to an operation.
  16. `pdos operation join 0x9E845a89AcacE3B2093A0c5c6a3fe75518758e8f`

Proposing an operation

User has to provide a target, a minimum number of users (threshold), the
starting epoch of the operation, and its duration (in seconds). If you provide
an invalid epoch (like 0), the client will give you the current epoch (from the
system).

Required parameters and options are:

  1. $ pdos help operation propose
  2. pDoS client
  3. Propose a new operation.
  4. Usage:
  5. pdos operation propose <target> <threshold> <epoch_start> <duration>
  6. Arguments:
  7. <target> the domain name of the target.
  8. <threshold> the number of users required to join.
  9. <epoch_start> the operation start epoch.
  10. <duration> the operation duration in seconds.
  11. Options:
  12. --service SERVICE the service to attack (supported values: www) [default: www]
  13. --staking STAKE the required stake for the operation (in wei) [default: 0]
  14. --info INFO human readable rationale for the operation [default: ]
  15. Examples:
  16. pdos operation propose https://www.foo.bar 2000 1563888880 3600
  17. pdos operation propose fcbk.com 2000 1563888880 3600 --info "save the world"
  1. $ pdos operation propose www.site.com 1000 0 0
  2. [ERROR] `epoch_start` must be in the future, current epoch: 1011122333
  3. $ pdos operation propose www.site.com 1000 1011130000 3600
  4. [DONE] Operation created.

The client waits for the daemon to check that the transaction has been approved
in the blockchain. We can check on pdosd logs during the proposition of an
operation:

  1. [-] Sending transaction...
  2. [+] Transaction b'89e9df70bb81f6d1d55f9201c4d29fddef050b9f4ce8b83e24108759b8bcb565' succeeded.
  3. [+] NewOperationEvent (operation: 0x1743f31270398B86CC592D73Fffc7eDD9C008c23)

Any new operation will be seen through the NewOperationEvent notification py
pdosd.

Joining an operation

User has to provide the operation address (checksummed format) of the operation
to be joined:

  1. $ pdos operation join 0x1743f31270398B86CC592D73Fffc7eDD9C008c23
  2. [DONE] Operation joined.

pdosd logs whos the following lines (new user event):

  1. [-] Sending transaction...
  2. [+] Transaction b'eaf345908c2ec5888676434ac0bffbb45037d4ffb7172a84da44b9bda11208ca' succeeded.
  3. [+] NewUserEvent (operation: 0x1743f31270398B86CC592D73Fffc7eDD9C008c23, user: 0x6FCF1B5dE32d75bbaFF8220cE5A831e12B567740)

If another user joins an operation that is joined by current pdosd instance,
then notifications will be showed through NewUserEvent logs.

Listing operations

The following command will allow users to have a look of all pending
operations. They would be marked as ‘joined’ if user has joined them, and with
‘decided’

  1. $ pdos operation list
  2. - 0x1743f31270398B86CC592D73Fffc7eDD9C008c23 -- joined
  3. target: www.site.com [www]
  4. users: 1/1000 [False]
  5. start: 2020-05-07 11:06:20
  6. duration: 3600s
  7. - 0x9527eC0507d329c4F7c83E5B645b42d0144F0Ccd -- joined & decided
  8. target: www.nicesite.org [www]
  9. users: 1250/1000 [False]
  10. start: 2019-11-16 10:46:40
  11. duration: 3600s
  12. - 0xAa871562dBA9b45725CC5AbDB2Dc6F5191371aD7
  13. target: www.othersite.it [www]
  14. users: 0/1000 [False]
  15. start: 2020-01-01 11:48:44
  16. duration: 3600s
  17. - 0x4F7c83E5B6dBA9b45725CC5A371aFffFff98B887 ---------- decided
  18. target: www.someothersite.it [www]
  19. users: 0/1000 [False]
  20. start: 2019-11-20 05:07:00
  21. duration: 3600s
  22. [DONE]

Development

Code contribution rules

Below are a few guidelines for submitting contributions.

  • Python3.
  • You are free to submit on this github project.
  • Versioning is MAJOR.MINOR. MAJOR version changes when API/command line is broken, otherwise it’s a MINOR change.

Python env setup

Example development environment based on miniconda:

  1. conda create -n pdos python=3.7
  2. conda activate pdos
  3. python setup.py develop

Ethereum contracts (solidity/contracts/)

Contracts are written in solidity.

  • O.sol contains the source code for operations contracts.
  • R.sol contains the source code for the (unique) reference contract.

A reference contract is submitted once and for all. As it keeps a list of
propose operations, this R contract allows users to submit new operations and
reach any existing operation.

Operations are O-type contracts. Through this contract, a user can join a
submitted operation, get details about it, and determine if one should process
with the DoS attack.

Contracts testing can be performed through solidity/test_contracts.py.

Reference/root R contracts can be deployed through pdosd and its --deploy
option.

For example, you can deploy a R contract using infura with:

  1. pdosd --eth_rpc https://ropsten.infura.io/<INFURA_PROJECT_ID> --eth_account 0X<YOUR ETH ACCOUNT> --eth_privkey 0x<PRIVATE KEY CORRESPONDING TO THAT ACCOUNT> --deploy

Notes: You will need to provide a checksummed ETH account. This process is
intended to work with any node/client that does not manage wallets through web3
“personal” API endpoint, like parity and more to come.

Compilation

./Makefile can be used as:

  1. make

to build GRPC Stubs. Or:

  1. make contracts

to build O.sol and R.sol contracts into bytecode and abi files (compiled
contracts are in pdosd/contracts/).

Testing

Contracts

See make test in ./solidity/Makefile, using ./solidity/test_contracts.py
to perform a series of tests on O and R contrats.

  1. $ ./test_contracts.py
  2. TESTING CONTRACTS
  3. * Testing propose_operation & enum_operations
  4. * Testing join_operation
  5. * Testing has_user_joined
  6. * Testing get_user_operations
  7. * Testing withdraw_staking
  8. * Testing Events
  9. Ok.

Misc

  • contact us at pdos@tutanota.com.
  • donate ETH to support our research (0xaDcA81DAab252C666f84ADB18697baaea0d68F57).

License

The code is licensed under the MIT License.