Grinnode-live / 2020-grin-bug-bash-challenge

Finding bugs in Grin-Wallet & Grin-nodes for a bounty prior to Grin fork v5.
3 stars 1 forks source link

[GRIN-Node][Owner API 2.0] test the unban_peer API method #56

Closed marekyggdrasil closed 3 years ago

marekyggdrasil commented 3 years ago

Description Goal of this issue is to test the unban_peer API method

Prerequisites

  1. GRIN-Node

Test procedure

  1. Perform steps corresponding to https://github.com/Grinnode-live/2020-grin-bug-bash-challenge/issues/51
  2. Unban the banned peer by running unban_peer
  3. Demonstrate that the peer has been unbanned by running API calls such as get_connected_peers and get_peers

Expected result:

We would expect the banned peer to not be connected. Output should match the example. Include all cURL requests and responses.

Include the exact version of your grin-node and also your environment

uname -a
mojitoo commented 3 years ago

Step 1 : Run GRIN-Node in Owner API listener mode

grin server run 

Step 2 : get connected peers

curl -ugrin:$(cat ~/.grin/main/.api_secret) localhost:3413/v2/owner -d '{"jsonrpc": "2.0", "method": "get_connected_peers", "params": [], "id": 1}' -w "\n" -v
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 3413 (#0)
* Server auth using Basic with user 'grin'
> POST /v2/owner HTTP/1.1
> Host: localhost:3413
> Authorization: Basic Z3JpbjpNajJuNDFkUVcyN3Y3SXNtNjBiUw==
> User-Agent: curl/7.64.1
> Accept: */*
> Content-Length: 74
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 74 out of 74 bytes
< HTTP/1.1 200 OK
< access-control-allow-origin: *
< access-control-allow-headers: Content-Type, Authorization
< content-type: application/json
< content-length: 2339
< date: Fri, 01 Jan 2021 12:30:00 GMT
< 
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "Ok": [
      {
        "addr": "95.216.193.239:3414",
        "capabilities": {
          "bits": 15
        },
        "direction": "Outbound",
        "height": 1027616,
        "total_difficulty": 1739084300554532,
        "user_agent": "MW/Grin 4.1.0",
        "version": 1000
      },
      {
        "addr": "78.47.206.120:3414",
        "capabilities": {
          "bits": 31
        },
        "direction": "Outbound",
        "height": 1027616,
        "total_difficulty": 1739084300554532,
        "user_agent": "MW/Grin 5.0.0-rc.2",
        "version": 1000
      },
      {
        "addr": "39.96.171.125:3414",
        "capabilities": {
          "bits": 15
        },
        "direction": "Outbound",
        "height": 1027616,
        "total_difficulty": 1739084300554532,
        "user_agent": "MW/Grin 4.0.1",
        "version": 2
      },
      {
        "addr": "52.57.14.225:3414",
        "capabilities": {
          "bits": 15
        },
        "direction": "Outbound",
        "height": 1027616,
        "total_difficulty": 1739084300554532,
        "user_agent": "MW/Grin 4.1.1",
        "version": 1000
      },
      {
        "addr": "178.196.7.116:3414",
        "capabilities": {
          "bits": 15
        },
        "direction": "Outbound",
        "height": 1027616,
        "total_difficulty": 1739084300554532,
        "user_agent": "MW/Grin 4.1.1",
        "version": 1000
      },
      {
        "addr": "139.99.37.158:3414",
        "capabilities": {
          "bits": 31
        },
        "direction": "Outbound",
        "height": 1027616,
        "total_difficulty": 1739084300554532,
        "user_agent": "MW/Grin 5.0.0-rc.1",
        "version": 1000
      },
      {
        "addr": "85.126.197.236:3414",
        "capabilities": {
          "bits": 31
        },
        "direction": "Outbound",
        "height": 1027616,
        "total_difficulty": 1739084300554532,
        "user_agent": "MW/Grin 5.0.0-beta.2",
        "version": 1000
      },
      {
        "addr": "51.91.154.89:4514",
        "capabilities": {
          "bits": 15
        },
        "direction": "Outbound",
        "height": 1027616,
        "total_difficulty": 1739084300554532,
        "user_agent": "MW/Grin 4.1.1",
        "version": 1000
      }
    ]
  }
* Connection #0 to host localhost left intact

Step 2 : ban peer 85.126.197.236:3414

curl -ugrin:$(cat ~/.grin/main/.api_secret) localhost:3413/v2/owner -d '{"jsonrpc": "2.0", "method": "ban_peer", "params": ["85.126.197.236:3414"], "id": 1}' -w "\n" -v
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 3413 (#0)
* Server auth using Basic with user 'grin'
> POST /v2/owner HTTP/1.1
> Host: localhost:3413
> Authorization: Basic Z3JpbjpNajJuNDFkUVcyN3Y3SXNtNjBiUw==
> User-Agent: curl/7.64.1
> Accept: */*
> Content-Length: 82
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 82 out of 82 bytes
< HTTP/1.1 200 OK
< access-control-allow-origin: *
< access-control-allow-headers: Content-Type, Authorization
< content-type: application/json
< content-length: 67
< date: Fri, 01 Jan 2021 12:31:34 GMT
< 
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "Ok": null
  }
* Connection #0 to host localhost left intact
}
* Closing connection 0

Step 3 : get peer and expect 85.126.197.236:3414 to be banned

curl -ugrin:$(cat ~/.grin/main/.api_secret) localhost:3413/v2/owner -d '{"jsonrpc": "2.0", "method": "get_peers", "params": ["85.126.197.236:3414"], "id": 1}' -w "\n" -v
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 3413 (#0)
* Server auth using Basic with user 'grin'
> POST /v2/owner HTTP/1.1
> Host: localhost:3413
> Authorization: Basic Z3JpbjpNajJuNDFkUVcyN3Y3SXNtNjBiUw==
> User-Agent: curl/7.64.1
> Accept: */*
> Content-Length: 84
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 84 out of 84 bytes
< HTTP/1.1 200 OK
< access-control-allow-origin: *
< access-control-allow-headers: Content-Type, Authorization
< content-type: application/json
< content-length: 350
< date: Fri, 01 Jan 2021 12:48:49 GMT
< 
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "Ok": [
      {
        "addr": "85.126.197.236:3414",
        "ban_reason": "None",
        "capabilities": {
          "bits": 15
        },
        "flags": "Banned",
        "last_banned": 1609505326,
        "last_connected": 1609504335,
        "user_agent": "MW/Grin 4.0.1"
      }
    ]
  }
* Connection #0 to host localhost left intact
}
* Closing connection 0

Step 4 : unban peer 85.126.197.236:3414

curl -ugrin:$(cat ~/.grin/main/.api_secret) localhost:3413/v2/owner -d '{"jsonrpc": "2.0", "method": "unban_peer", "params": ["85.126.197.236:3414"], "id": 1}' -w "\n" -v
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 3413 (#0)
* Server auth using Basic with user 'grin'
> POST /v2/owner HTTP/1.1
> Host: localhost:3413
> Authorization: Basic Z3JpbjpNajJuNDFkUVcyN3Y3SXNtNjBiUw==
> User-Agent: curl/7.64.1
> Accept: */*
> Content-Length: 84
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 84 out of 84 bytes
< HTTP/1.1 200 OK
< access-control-allow-origin: *
< access-control-allow-headers: Content-Type, Authorization
< content-type: application/json
< content-length: 67
< date: Fri, 01 Jan 2021 12:34:24 GMT
< 
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "Ok": null
  }
* Connection #0 to host localhost left intact
}
* Closing connection 0

Step 5 : get peer 85.126.197.236:3414

curl -ugrin:$(cat ~/.grin/main/.api_secret) localhost:3413/v2/owner -d '{"jsonrpc": "2.0", "method": "get_peers", "params": ["85.126.197.236:3414"], "id": 1}' -w "\n" -v
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 3413 (#0)
* Server auth using Basic with user 'grin'
> POST /v2/owner HTTP/1.1
> Host: localhost:3413
> Authorization: Basic Z3JpbjpNajJuNDFkUVcyN3Y3SXNtNjBiUw==
> User-Agent: curl/7.64.1
> Accept: */*
> Content-Length: 83
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 83 out of 83 bytes
< HTTP/1.1 200 OK
< access-control-allow-origin: *
< access-control-allow-headers: Content-Type, Authorization
< content-type: application/json
< content-length: 350
< date: Fri, 01 Jan 2021 12:47:17 GMT
< 
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "Ok": [
      {
        "addr": "85.126.197.236:3414",
        "ban_reason": "None",
        "capabilities": {
          "bits": 15
        },
        "flags": "Healthy",
        "last_banned": 1609504294,
        "last_connected": 1609504182,
        "user_agent": "MW/Grin 4.1.1"
      }
    ]
  }
* Connection #0 to host localhost left intact
}
* Closing connection 0 
marekyggdrasil commented 3 years ago

@mojitoo result looks good, closing and thanks for checking!

I'm wondering, why when you get_peer with IP 85.126.197.236:3414 in the response the addr field is 51.91.154.89:4514? Isn't that a bit strange?

mojitoo commented 3 years ago

i edited my comment after doing a second test and i forget to change some details. will correct this