{"record":{"id":"9491028c4808f9c7","repo":"sqlmapproject/sqlmap","slug":"scram-server-nonce-does-not-extend-the-client-nonc","errorCode":null,"errorMessage":"SCRAM server nonce does not extend the client nonce (rogue server?)","messagePattern":"SCRAM server nonce does not extend the client nonce \\(rogue server\\?\\)","errorType":"exception","errorClass":"OperationalError","httpStatus":null,"severity":"error","filePath":"extra/dbwire/postgres.py","lineNumber":264,"sourceCode":"        elif code == 10:  # SASL (SCRAM-SHA-256)\n            if not hasattr(hashlib, \"pbkdf2_hmac\"):\n                raise NotSupportedError(\"SCRAM-SHA-256 authentication requires Python >= 2.7.8 (hashlib.pbkdf2_hmac)\")\n            client_nonce = base64.b64encode(os.urandom(18)).decode(\"ascii\")\n            cfirst_bare = \"n=,r=%s\" % client_nonce\n            client_first = \"n,,\" + cfirst_bare\n            _send(sock, b\"p\", b\"SCRAM-SHA-256\\x00\" + struct.pack(\"!I\", len(client_first)) + client_first.encode(\"ascii\"))\n        elif code == 11:  # SASLContinue (server-first)\n            try:\n                server_first = payload[4:].decode(\"ascii\")\n                attrs = dict(kv.split(\"=\", 1) for kv in server_first.split(\",\"))\n                snonce, salt, iterations = attrs[\"r\"], base64.b64decode(attrs[\"s\"]), int(attrs[\"i\"])\n            except (KeyError, ValueError, binascii.Error, UnicodeDecodeError) as ex:\n                raise OperationalError(\"malformed SCRAM server-first message (%s)\" % ex)\n            # RFC 5802 5.1: the server nonce MUST start with the client nonce and MUST add material of its\n            # own. Skipping this lets anything that can answer the TCP connection replay a recorded\n            # server-first and drive the exchange - and dbwire has no TLS layer underneath to catch it.\n            if not client_nonce or not snonce.startswith(client_nonce) or len(snonce) <= len(client_nonce):\n                raise OperationalError(\"SCRAM server nonce does not extend the client nonce (rogue server?)\")\n            if iterations < 4096:   # RFC 5802 recommends >= 4096; a tiny count cheapens an offline attack\n                raise OperationalError(\"SCRAM iteration count %d is too low\" % iterations)\n            salted = hashlib.pbkdf2_hmac(\"sha256\", (password or \"\").encode(\"utf-8\"), salt, iterations)\n            client_key = hmac.new(salted, b\"Client Key\", hashlib.sha256).digest()\n            stored_key = hashlib.sha256(client_key).digest()\n            client_final_noproof = \"c=biws,r=%s\" % snonce\n            auth_message = \"%s,%s,%s\" % (cfirst_bare, server_first, client_final_noproof)\n            client_sig = hmac.new(stored_key, auth_message.encode(\"ascii\"), hashlib.sha256).digest()\n            proof = base64.b64encode(_xor(client_key, client_sig)).decode(\"ascii\")\n            _send(sock, b\"p\", (\"%s,p=%s\" % (client_final_noproof, proof)).encode(\"ascii\"))\n        elif code == 12:  # SASLFinal (server-final): verify the server too, or the handshake is one-way\n            # Without this the client proves itself to the server and simply trusts whatever answers back.\n            # ServerSignature = HMAC(ServerKey, AuthMessage) can only be produced by a peer that holds the\n            # stored credentials, so comparing it is what makes the exchange mutual (RFC 5802 5, 5.1).\n            if salted is None or auth_message is None:\n                raise OperationalError(\"unexpected SCRAM server-final message\")\n            try:\n                attrs = dict(kv.split(\"=\", 1) for kv in payload[4:].decode(\"ascii\").split(\",\"))","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/sqlmapproject/sqlmap/blob/0a35b20e3953d341be6c7ac75ccb0b3362540c8d/extra/dbwire/postgres.py#L246-L282","documentation":"Error \"SCRAM server nonce does not extend the client nonce (rogue server?)\" thrown in sqlmapproject/sqlmap.","triggerScenarios":"Thrown at extra/dbwire/postgres.py:264 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0a35b20e3953d341be6c7ac75ccb0b3362540c8d","analyzedAt":"2026-08-26T23:02:52.002Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}