{"record":{"id":"9495089900659145","repo":"shadow1ng/fscan","slug":"i18n-gettext-ms17010-ciphertext-too-short","errorCode":null,"errorMessage":"i18n.GetText(\"ms17010_ciphertext_too_short\")","messagePattern":"i18n\\.GetText\\(\"ms17010_ciphertext_too_short\"\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/services/ms17010.go","lineNumber":184,"sourceCode":"}\n\n// 以下是完整的原始MS17010检测和利用代码，保持不变\n\n// AES解密函数 (从legacy/Base.go复制)\nfunc aesDecrypt(crypted string, key string) (string, error) {\n\tcryptedBytes, err := base64.StdEncoding.DecodeString(crypted)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"%s: %w\", i18n.GetText(\"ms17010_base64_decode_failed\"), err)\n\t}\n\n\tkeyBytes := []byte(key)\n\tblock, err := aes.NewCipher(keyBytes)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"%s: %w\", i18n.GetText(\"ms17010_aes_cipher_failed\"), err)\n\t}\n\n\tif len(cryptedBytes) < aes.BlockSize {\n\t\treturn \"\", fmt.Errorf(\"%s\", i18n.GetText(\"ms17010_ciphertext_too_short\"))\n\t}\n\n\tmode := cipher.NewCBCDecrypter(block, keyBytes[:aes.BlockSize])\n\tmode.CryptBlocks(cryptedBytes, cryptedBytes)\n\n\t// 移除PKCS7填充\n\tpadding := int(cryptedBytes[len(cryptedBytes)-1])\n\tif padding > len(cryptedBytes) || padding > aes.BlockSize {\n\t\treturn \"\", fmt.Errorf(\"%s\", i18n.GetText(\"ms17010_invalid_padding\"))\n\t}\n\n\tfor i := len(cryptedBytes) - padding; i < len(cryptedBytes); i++ {\n\t\tif cryptedBytes[i] != byte(padding) {\n\t\t\treturn \"\", fmt.Errorf(\"%s\", i18n.GetText(\"ms17010_padding_check_failed\"))\n\t\t}\n\t}\n\n\treturn string(cryptedBytes[:len(cryptedBytes)-padding]), nil","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/plugins/services/ms17010.go#L166-L202","documentation":"aesDecrypt rejects ciphertext whose decoded length is less than aes.BlockSize (16 bytes) with \"ms17010_ciphertext_too_short\". CBC mode requires at least one full block, so any shorter decoded blob cannot be a valid AES-CBC ciphertext.","triggerScenarios":"aesDecrypt receives a crypted string that base64-decodes to 0–15 bytes: empty string, truncated payload, or data that was never AES-CBC encrypted (e.g. plaintext, checksum, or IV-only).","commonSituations":"Copy/paste truncation of long payloads, feeding the IV alone instead of IV||ciphertext, or decrypting a field produced by a different scheme (GCM tag, hex blob).","solutions":["Base64-decode and assert len >= 16 bytes before calling aesDecrypt.","Verify the payload source actually emits AES-CBC ciphertext (multiple of 16 bytes, IV prepended or keyed separately).","Check the payload wasn't truncated in storage/transport (compare length with the producer's byte count).","If your scheme prepends a 16-byte IV, remember the minimum valid total is 32 bytes (IV + one block)."],"exampleFix":"// before\nplain, err := aesDecrypt(tok, key)\n// after: pre-check decoded size\nraw, _ := base64.StdEncoding.DecodeString(tok)\nif len(raw) < aes.BlockSize || len(raw)%aes.BlockSize != 0 {\n    return fmt.Errorf(\"ciphertext must be >=16 bytes and block-aligned, got %d\", len(raw))\n}\nplain, err := aesDecrypt(tok, key)","handlingStrategy":"validation","validationCode":"raw, err := base64.StdEncoding.DecodeString(payload)\nif err != nil { return err }\nif len(raw) < aes.BlockSize || len(raw)%aes.BlockSize != 0 {\n    return fmt.Errorf(\"ciphertext must be >=16 bytes and 16-byte aligned, got %d\", len(raw))\n}","typeGuard":null,"tryCatchPattern":"plain, err := aesDecrypt(payload, key)\nif err != nil && strings.Contains(err.Error(), \"too_short\") {\n    return fmt.Errorf(\"truncated or non-CBC payload\")\n}","preventionTips":["Verify payload lengths against the producer before decrypting","Remember the minimum is IV(16) + one block(16) if IV is embedded","Use checksums on stored ciphertext to catch truncation"],"tags":["go","aes","cbc","ciphertext","ms17010"],"backgroundTag":"invalid-argument-value","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}