svg验证码识别

释放双眼,带上耳机,听听看~!

前言

前一段时间,在针对某个网站进行编写爬虫时,遇到一个问题:当持续多次请求一段时间后,需要输入图片验证码后才能继续访问。本以为是常用的图片验证码,于是查看页面源码,去搜索<img>标签,但是在查找一遍之后,并未发现对应的验证码图片,于是审查元素,定位到图片验证码的位置。发现了这样一段代码:

<svg xmlns="http://www.w3.org/2000/svg" width="150" height="50" viewBox="0,0,150,50"><rect width="100%" height="100%" fill="#fff"></rect><path fill="#dc3bdc" d="M64.98 30.32L64.96 30.30L65.00 30.35Q65.09 29.93 65.05 29.51L65.19 29.66L65.19 29.66Q65.03 29.19 64.72 29.00L64.63 28.90L64.76 29.04Q63.99 28.42 63.12 28.57L63.08 28.54L63.13 28.59Q61.98 28.50 60.34 29.60L60.31 29.57L60.44 29.71Q58.91 30.50 58.91 31.68L59.01 31.78L58.91 31.68Q58.90 32.92 58.90 36.24L58.98 36.31L58.98 36.31Q58.91 38.84 59.07 40.86L59.17 40.96L59.12 40.91Q57.41 40.92 57.41 40.92L57.45 40.95L57.37 40.87Q56.40 40.85 55.68 40.93L55.71 40.97L55.76 41.01Q56.07 38.40 56.15 36.15L56.13 36.13L56.25 36.25Q56.21 31.41 55.56 30.12L55.62 30.18L55.61 30.17Q55.38 29.64 54.81 29.33L54.82 29.34L54.83 29.34Q54.07 28.71 52.51 28.59L52.33 28.41L52.46 28.54Q50.34 28.21 49.81 29.81L49.80 29.80L49.87 29.87Q49.63 30.27 49.74 30.77L49.78 30.80L49.77 30.79Q50.45 33.58 50.11 36.36L50.06 36.30L50.06 36.30Q49.83 39.20 48.42 41.63L48.41 41.62L48.42 41.63Q47.38 41.77 45.28 42.19L45.28 42.18L45.34 42.24Q47.81 38.96 47.81 34.66L47.80 34.65L47.83 34.68Q47.77 28.76 43.73 24.53L43.79 24.59L43.83 24.63Q44.53 24.88 45.48 25.10L45.45 25.07L47.28 25.57L47.29 25.58Q47.63 26.07 48.51 27.74L48.53 27.77L48.65 27.89Q48.75 25.93 51.18 25.89L51.18 25.89L51.17 25.88Q51.37 25.88 52.36 25.96L52.40 26.00L52.26 25.87Q57.28 26.20 58.42 29.02L58.44 29.04L58.54 29.14Q60.16 26.38 65.18 25.84L65.12 25.78L65.16 25.82Q65.96 25.74 66.83 25.86L66.74 25.77L66.88 25.91Q68.97 25.98 68.82 27.54L68.87 27.59L68.80 27.52Q68.88 28.32 68.61 29.08L68.49 28.96L68.59 29.06Q67.13 32.01 67.36 35.55L67.34 35.54L67.28 35.48Q67.51 38.99 69.42 41.80L69.52 41.91L69.53 41.92Q67.72 41.44 65.89 41.21L65.85 41.17L65.89 41.21Q64.63 38.61 64.44 35.83L64.56 35.96L64.48 35.88Q64.37 33.10 65.02 30.36ZM65.79 41.72L65.65 41.58L65.71 41.64Q66.46 41.74 67.80 41.93L67.67 41.81L67.85 41.98Q68.27 42.60 69.41 44.00L69.40 44.00L69.51 44.11Q72.35 44.58 74.44 45.23L74.45 45.24L74.49 45.28Q69.40 41.29 69.14 34.78L69.22 34.86L69.12 34.77Q69.07 32.70 69.68 30.79L69.64 30.76L69.74 30.85Q69.99 30.00 69.99 29.28L69.84 29.13L69.93 29.22Q69.85 28.22 69.24 27.65L69.30 27.72L69.20 27.57L69.38 27.75Q69.42 27.23 69.34 26.73L69.25 26.63L69.24 26.62Q69.09 26.06 68.63 25.79L68.66 25.82L68.68 25.84Q68.04 25.39 67.17 25.35L67.06 25.25L67.08 25.27Q64.35 25.27 61.68 26.22L61.74 26.29L61.71 26.26Q59.74 26.94 58.56 28.35L58.53 28.33L58.50 28.30Q56.87 25.75 52.04 25.41L52.09 25.47L52.09 25.47Q51.42 25.44 51.00 25.44L51.02 25.46L50.98 25.42Q49.03 25.53 48.43 26.79L48.38 26.74L48.27 26.63Q48.00 26.17 47.31 25.10L47.42 25.21L47.41 25.20Q44.86 24.59 42.88 23.94L42.92 23.98L42.97 24.04Q47.51 28.31 47.51 34.59L47.54 34.62L47.45 34.53Q47.53 39.33 44.68 42.80L44.78 42.90L44.60 42.72Q45.18 42.69 45.67 42.61L45.58 42.52L46.69 42.49L46.62 42.42Q45.84 43.39 44.74 44.61L44.86 44.73L44.73 44.60Q46.44 44.37 49.56 43.76L49.63 43.83L49.65 43.85Q52.30 39.72 52.30 34.81L52.27 34.78L52.31 34.82Q52.21 33.93 52.14 33.09L52.07 33.02L52.22 33.17Q52.17 32.43 53.16 31.63L53.11 31.58L53.00 31.52L52.97 31.49Q53.67 31.12 54.85 31.00L54.86 31.01L54.88 31.04Q55.37 31.10 55.67 31.10L55.68 31.12L55.63 31.25L55.58 31.21Q55.88 33.94 55.76 36.30L55.77 36.30L55.91 36.44Q55.67 38.60 55.17 41.26L55.28 41.37L55.12 41.21Q56.18 41.25 56.18 41.25L56.27 41.33L56.30 41.37Q57.71 41.33 57.37 41.33L57.24 41.20L57.28 41.24Q57.35 41.80 57.31 42.26L57.30 42.25L57.29 42.23Q57.23 42.67 57.23 43.16L57.30 43.24L59.82 43.29L59.66 43.12Q60.92 43.13 62.18 43.21L62.24 43.27L62.20 43.23Q60.69 39.55 60.88 33.61L61.01 33.74L60.91 33.64Q61.00 32.58 62.18 31.82L62.16 31.81L62.10 31.74Q63.02 30.95 64.28 30.76L64.28 30.77L64.66 30.84L64.63 30.81Q64.19 32.73 64.19 34.71L64.22 34.74L64.13 34.65Q64.22 38.51 65.75 41.67ZM60.26 30.17L60.30 29.98L60.32 30.35L60.13 30.04Z"></path><path d="M12 15 C54 27,92 23,144 4" stroke="#5ae65a" fill="none"></path><path fill="#85e664" d="M125.72 34.77L125.73 34.79L125.56 34.61Q125.57 38.20 122.41 39.50L122.42 39.51L122.46 39.55Q120.50 40.29 116.08 40.44L116.11 40.47L116.12 40.48Q111.42 40.69 109.18 39.51L109.12 39.46L109.06 39.39Q107.31 38.18 107.46 34.83L107.50 34.87L107.40 34.77Q107.40 34.12 107.59 32.14L107.72 32.27L107.69 32.24Q107.73 30.57 107.73 29.58L107.78 29.63L107.79 29.64Q107.77 21.63 103.59 14.20L103.63 14.24L103.67 14.29Q104.78 14.90 107.75 15.97L107.68 15.90L107.79 16.01Q110.57 22.63 110.57 30.02L110.67 30.11L110.67 30.12Q110.58 30.64 110.49 31.82L110.59 31.92L110.48 31.81Q110.36 32.97 110.36 33.58L110.50 33.71L110.41 33.63Q110.44 35.94 112.00 36.93L111.96 36.89L112.04 36.97Q113.56 37.65 116.53 37.65L116.59 37.72L116.50 37.63Q119.17 37.66 120.80 36.48L120.94 36.62L120.83 36.50Q122.72 35.20 122.57 32.69L122.61 32.73L122.51 32.63Q122.51 31.34 122.51 30.01L122.42 29.91L122.49 29.98Q122.36 22.81 124.76 16.30L124.77 16.32L126.98 15.78L126.98 15.78Q128.01 15.55 129.11 15.10L129.07 15.06L129.14 15.13Q125.40 22.23 125.40 29.81L125.34 29.75L125.38 29.80Q125.31 30.56 125.45 32.20L125.47 32.22L125.62 32.37Q125.73 33.99 125.73 34.79ZM127.69 35.49L127.72 35.52L127.72 35.52Q126.90 30.63 127.62 25.52L127.58 25.48L127.58 25.48Q128.47 20.43 130.87 16.05L130.84 16.03L130.79 15.97Q130.19 16.29 128.74 16.94L128.73 16.93L128.72 16.91Q129.11 16.08 129.90 14.52L129.92 14.53L129.80 14.41Q126.42 15.71 124.51 16.06L124.48 16.02L124.60 16.14Q122.07 22.48 122.07 29.76L122.22 29.91L122.16 29.85Q122.07 31.12 122.15 32.53L122.31 32.70L122.16 32.54Q122.43 35.07 120.64 36.28L120.64 36.29L120.57 36.21Q119.16 37.35 116.64 37.39L116.67 37.42L116.52 37.27Q113.80 37.36 112.36 36.60L112.35 36.60L112.35 36.59Q112.26 36.09 112.19 35.63L112.23 35.68L112.19 35.63Q112.08 35.07 112.19 34.57L112.32 34.70L112.22 34.60Q112.43 32.26 112.43 29.93L112.58 30.09L112.57 30.07Q112.45 24.13 110.93 18.23L111.02 18.32L111.01 18.31Q110.30 18.21 108.89 17.87L108.96 17.94L108.96 17.94Q108.35 16.41 107.89 15.50L108.06 15.67L107.97 15.58Q105.35 14.90 102.95 13.53L102.87 13.45L102.96 13.54Q107.52 21.07 107.52 29.79L107.41 29.68L107.43 29.70Q107.47 31.37 107.32 33.09L107.35 33.12L107.25 33.02Q107.06 35.46 107.14 36.64L107.20 36.70L107.27 36.77Q107.42 38.70 108.67 39.85L108.68 39.85L108.67 39.84Q109.49 42.15 114.13 42.53L114.18 42.58L114.27 42.66Q116.27 42.72 118.40 42.80L118.45 42.85L118.46 42.86Q123.88 43.10 126.66 42.15L126.53 42.02L126.56 42.05Q128.19 41.21 128.19 39.15L128.21 39.17L128.14 39.10Q128.24 38.06 127.78 35.58Z"></path><path d="M20 39 C57 17,86 10,143 42" stroke="#b7e689" fill="none"></path><path d="M20 2 C67 6,61 16,131 27" stroke="#91e73a" fill="none"></path><path d="M5 35 C77 26,69 40,133 5" stroke="#eeee67" fill="none"></path><path fill="#ee7bd1" d="M26.42 40.23L26.51 40.32L26.50 40.31Q22.97 40.36 21.34 39.82L21.33 39.82L21.35 39.84Q19.44 39.26 19.13 35.87L19.11 35.84L20.48 34.70L20.55 34.78Q21.21 34.18 21.97 33.68L22.05 33.76L21.90 33.61Q21.60 35.48 23.20 36.70L23.32 36.82L23.33 36.83Q24.56 37.80 26.69 37.61L26.69 37.61L26.72 37.63Q31.17 37.29 30.98 33.75L30.91 33.67L30.88 33.64Q30.81 31.48 28.18 30.26L28.08 30.16L28.19 30.27Q25.23 29.10 22.87 27.89L22.93 27.95L22.86 27.88Q20.45 26.68 19.46 22.00L19.45 21.99L19.38 21.91Q19.30 21.49 19.18 20.73L19.18 20.72L19.20 20.75Q19.11 19.98 19.19 19.41L19.16 19.38L19.20 19.42Q19.22 17.69 20.48 17.23L20.64 17.39L20.63 17.39Q22.87 16.35 26.87 16.54L26.86 16.53L26.87 16.54Q28.73 16.69 29.53 16.77L29.55 16.79L29.51 16.75Q31.02 16.96 32.08 17.41L32.09 17.43L32.21 17.54Q34.27 17.96 34.49 20.43L34.52 20.46L34.49 20.43Q33.49 21.18 31.29 22.52L31.20 22.43L31.14 22.37Q30.81 19.45 26.43 19.45L26.45 19.47L26.48 19.50Q24.42 19.34 23.43 20.03L23.60 20.20L23.47 20.07Q22.30 20.57 22.53 22.36L22.64 22.47L22.63 22.46Q22.93 24.70 25.89 26.22L25.89 26.22L25.83 26.16Q26.26 26.29 30.76 27.93L30.82 27.99L30.77 27.94Q33.44 29.47 33.86 33.85L33.94 33.93L33.91 33.89Q33.90 34.04 33.97 35.29L33.94 35.26L33.94 35.26Q34.05 38.08 32.49 39.18L32.46 39.15L32.45 39.14Q30.59 40.09 26.40 40.21ZM28.69 42.57L28.78 42.66L28.80 42.69Q30.24 42.75 32.22 42.75L32.20 42.73L32.15 42.68Q34.18 42.62 35.44 42.20L35.55 42.31L35.50 42.26Q36.65 41.36 36.58 39.57L36.61 39.60L36.75 39.75Q36.71 38.76 36.33 36.70L36.27 36.64L36.32 36.69Q35.40 32.00 33.31 30.14L33.22 30.05L33.21 30.03Q32.41 28.43 31.07 27.71L31.07 27.71L25.72 25.60L25.74 25.61Q25.53 25.55 25.07 25.32L25.13 25.38L24.99 24.98L24.98 24.62L24.93 24.58Q24.71 23.10 25.85 22.49L25.87 22.51L25.84 22.48Q26.64 21.94 28.35 21.75L28.28 21.68L28.44 21.84Q29.48 21.63 30.62 22.08L30.55 22.01L30.70 22.16Q30.70 22.20 30.89 23.04L30.94 23.08L31.01 23.16Q31.20 23.00 31.69 22.77L31.62 22.70L31.52 22.60Q32.27 23.54 32.39 24.68L32.44 24.74L32.43 24.72Q32.60 24.79 36.26 22.20L36.10 22.04L36.21 22.15Q35.94 19.52 34.50 18.84L34.41 18.75L34.47 18.81Q33.84 17.50 32.40 16.97L32.45 17.02L32.51 17.08Q30.13 16.18 26.93 16.18L26.99 16.24L27.05 16.30Q22.05 16.21 20.19 16.90L20.21 16.92L20.11 16.83Q18.87 17.37 18.75 19.04L18.81 19.10L18.72 19.01Q18.66 19.52 19.08 21.73L19.02 21.67L19.19 21.84Q19.77 25.51 21.94 27.76L21.88 27.69L21.89 27.71Q22.85 29.58 24.36 30.27L24.17 30.08L24.24 30.15Q25.82 30.91 29.74 32.47L29.79 32.52L29.62 32.39L30.24 32.71L30.31 32.81L30.43 32.93Q30.49 33.26 30.53 33.60L30.60 33.68L30.56 33.63Q30.71 37.17 26.79 37.32L26.64 37.18L26.73 37.26Q25.48 37.20 24.19 36.82L24.30 36.93L24.25 36.88Q24.03 36.17 24.03 35.44L23.85 35.26L23.96 35.37Q23.95 35.09 23.99 34.82L23.94 34.77L23.96 34.79Q23.57 35.06 22.77 35.55L22.77 35.54L22.83 35.61Q22.34 34.51 22.49 33.14L22.36 33.01L22.39 33.03Q20.27 34.19 18.67 35.60L18.81 35.74L18.80 35.73Q18.76 36.45 18.84 37.48L18.79 37.43L18.90 37.54Q19.27 39.32 20.56 40.08L20.54 40.06L20.48 40.00Q21.63 41.76 24.18 42.14L24.28 42.24L24.22 42.18Q25.86 42.49 28.80 42.68Z"></path><path d="M7 32 C64 44,81 13,144 9" stroke="#4cd64c" fill="none"></path><path fill="#75ea92" d="M89.69 27.14L89.70 27.15L89.67 27.13Q90.43 27.09 91.84 26.94L91.88 26.97L91.90 27.00Q91.89 27.67 91.89 28.31L91.85 28.28L91.95 29.63L91.93 29.62Q91.03 29.55 90.19 29.63L90.18 29.62L90.22 29.66Q89.31 29.62 88.48 29.59L88.63 29.74L88.45 29.57Q85.76 35.89 82.33 40.50L82.17 40.34L82.21 40.38Q79.71 41.04 78.42 41.65L78.53 41.76L78.49 41.71Q82.50 35.91 85.54 29.62L85.51 29.59L82.97 29.68L83.01 29.71Q83.05 28.43 82.94 27.10L82.89 27.04L82.78 26.93Q84.72 27.12 86.78 27.12L86.89 27.24L88.68 23.44L88.63 23.39Q89.79 21.65 91.01 20.05L90.94 19.98L90.85 19.89Q89.33 20.08 87.73 20.08L87.73 20.08L87.78 20.14Q81.61 20.06 77.84 17.85L77.95 17.96L77.28 16.22L77.23 16.17Q76.90 15.35 76.52 14.47L76.53 14.48L76.45 14.40Q80.96 17.20 86.67 17.43L86.57 17.32L86.69 17.44Q91.75 17.59 96.89 15.61L96.94 15.67L96.90 15.63Q96.69 16.03 96.20 16.90L96.28 16.99L96.21 16.92Q92.67 21.75 89.81 27.27ZM97.85 18.33L97.72 18.19L98.75 16.22L98.82 16.29Q97.80 16.71 96.12 17.44L96.12 17.43L96.27 17.09L96.30 17.12Q96.52 17.07 96.63 16.95L96.58 16.91L96.50 16.83Q96.86 16.12 97.59 14.79L97.62 14.82L97.60 14.80Q92.29 17.11 86.54 16.88L86.58 16.91L86.53 16.86Q80.63 16.72 75.87 13.75L75.72 13.59L75.76 13.64Q76.88 15.59 77.72 18.26L77.61 18.15L77.64 18.18Q78.82 18.90 79.62 19.20L79.67 19.26L79.67 19.25Q79.73 19.51 80.19 21.37L80.23 21.42L80.26 21.45Q83.34 22.62 88.86 22.47L88.81 22.42L88.78 22.40Q88.51 23.00 86.53 26.77L86.62 26.85L86.65 26.89Q84.46 26.75 82.48 26.56L82.55 26.63L82.63 26.71Q82.66 27.50 82.66 28.38L82.54 28.26L82.54 29.97L84.22 29.98L84.40 31.56L84.33 31.49Q80.45 38.92 77.67 42.50L77.67 42.50L77.64 42.47Q79.16 41.62 80.79 41.13L80.75 41.09L80.89 41.23Q80.12 42.05 78.75 43.77L78.76 43.78L78.77 43.79Q81.93 42.68 84.36 42.45L84.46 42.55L84.34 42.43Q87.36 38.75 90.48 31.97L90.43 31.92L93.83 32.08L93.93 32.18Q93.72 31.14 93.72 30.22L93.87 30.38L93.74 28.45L93.88 28.60Q93.59 28.57 93.03 28.61L92.89 28.46L93.02 28.59Q92.48 28.64 92.21 28.64L92.11 28.54L92.23 28.66Q92.05 28.37 92.09 28.22L92.26 28.38L92.15 28.01L92.23 28.09Q94.68 22.89 97.77 18.24Z"></path></svg>

上面的代码对应的图片如下图:

我对前端并不是很熟悉,于是网上查了一下关于svg验证码的相关知识。碰到了一个100%识别的接口,但是接口已经失效。后来又在github上看到了haua大佬的svg验证码识别的项目:svg-captcha-recognize,由于他这个是nodejs写的,我想要的是python版本的,于是分析了一下大佬的代码,并自己改了一个python版本的。

本文只做技术交流,切勿用于非法用途

svg验证码

svg标签:SVG是Scalable Vector Graphics的缩写,意为可缩放矢量图形。

在矢量图形系统中,图形被描述为一些列的形状,它是特定坐标的集合。显示矢量图形需要按照特定的命令来绘制这些坐标,然后显示在屏幕上。矢量图形是对象,而不是一系列的像素。它们可以改变颜色、形状还有大小,图形中的文字都是可以被检索的,这些与栅格图形都有很大的不同。

在svg验证码中,有好几个<path>标签。<svg><path>元素用于定义一些复杂的图形。它可以结合使用直线,曲线等来制作各种不规则的图形。<path>元素是SVG基本图形中最为复杂的一个。

所有的绘制工作都是在<path>中完成的,对于<path>中的众多属性,解释如下:

M = moveto(M X,Y) :将画笔移动到指定的坐标位置
L = lineto(L X,Y) :画直线到指定的坐标位置
H = horizontal lineto(H X):画水平线到指定的X坐标位置
V = vertical lineto(V Y):画垂直线到指定的Y坐标位置
C = curveto(C X1,Y1,X2,Y2,ENDX,ENDY):三次贝赛曲线
S = smooth curveto(S X2,Y2,ENDX,ENDY):平滑曲率
Q = quadratic Belzier curve(Q X,Y,ENDX,ENDY):二次贝赛曲线
T = smooth quadratic Belzier curveto(T ENDX,ENDY):映射
A = elliptical Arc(A RX,RY,XROTATION,FLAG1,FLAG2,X,Y):弧线
Z = closepath():关闭路径

从上面不难看出,svg验证码大致生成的流程就是通过对应的画图命令加上关键点,从而将验证码画出来。

简单分析

svg-captcha项目地址

首先,我们先在本地安装svg-captcha

npm install --save svg-captcha

使用下面命令,就可以创建一个随机的四位svg验证码:

var svgCaptcha = require('svg-captcha');
var captcha = svgCaptcha.create();

使用console.log(captcha)得到如下内容:

{
  text: 'V0ji',
  data: '<svg xmlns="http://www.w3.org/2000/svg" width="150" height="50" viewBox="0,0,150,50"><path d="M5 3 C62 22,85 39,138 43" stroke="#777" fill="none"/><path fill="#333" d="M79.76 47.10L79.68 47.02L79.74 47.08Q78.82 47.30 76.92 47.61L76.95 47.64L76.83 47.52Q78.11 45.34 79.14 44.04L79.30 44.21L79.18 44.08Q81.02 44.48 81.17 44.48L81.09 44.39L81.03 44.34Q81.33 44.40 81.86 44.29L82.01 44.44L81.89 44.32Q82.60 44.27 82.79 44.27L82.80 44.28L82.80 44.28Q85.36 44.03 85.29 41.86L85.32 41.89L85.36 41.92Q85.24 40.36 85.13 34.12L85.20 34.20L85.05 34.04Q85.11 30.60 85.19 26.45L85.17 26.43L8
  .......
  '
}

我们将svg数据部分拷贝粘贴到html文件中,然后用浏览器打开,就可以看到了验证码:

对于svgCaptcha.create(options),如果没有任何参数,则生成的 svg 图片有4个字符。

  • size: 4 // 验证码长度
  • ignoreChars: '0o1i' // 验证码字符中排除 0o1i
  • noise: 1 // 干扰线条的数量
  • color: true // 验证码的字符是否有颜色,默认没有,如果设定了背景,则默认有
  • background: '#cc9966' // 验证码图片背景颜色

该函数返回的对象拥有以下属性

  • data: string // svg 路径
  • text: string // 验证码文字

除此之外,在生成验证码的时候还可以设置字符对应的字体等一些操作,感兴趣的读者可以到此项目了解一下。

我们可以通过svgCaptcha('1234')命令生成指定字符串的验证码。当我们多次生成相同字符串的验证码时,如下图(连续生成了三次的相同字符串的验证码):

好像除了干扰线不同之外,数字似乎位置和形状都相同。

如果我们将1234 的数字调换,再生成一次看看:

var svgCaptcha = require('svg-captcha');
for (i = 0; i < 3; i++) {
  console.log(svgCaptcha('1234') )
  console.log(svgCaptcha('3124'))
  console.log(svgCaptcha('1423') + '<br>')
}

其实可以发现数字即便在位置发生变化时,样式也没有变。

当我们给验证码开启了随机颜色后,也是如此:

我们继续分析,如果把<svg>中的<path>拆分,进行对比,会有什么效果呢。

import re
svg_data = '''
    <svg xmlns="http://www.w3.org/2000/svg" width="150" height="50" viewBox="0,0,150,50"><path fill="#e9e943" d="M82.50 40.25L82.52 40.27L82.59 40.34Q81.18 40.41 79.62 39.99L79.69 
    ......
'''
path_list = re.findall('<path.*?/>', svg_data)
for x in path_list:
    print(x)

然后拿到5个数据:

<path fill="#e9e943" d="M82.50 40.25L82.52 40.27L82.59 40.34Q81.18 40.41 79.62 39.99L79.69 40.07L79.59 39.96Q78.45 39.12 78.29 37.49L78.34 37.54L78.29 37.48Q78.31 37.35 78.50 34.73L78.31 34.54L78.45 34.67Q79.46 34.47 81.48 34.09L81.35 33.96L81.23 34.79L81.27 34.83Q81.00 36.58 82.41 37.15L82.40 37.14L82.34 37.08Q83.25 37.53 85.34 37.53L85.33 37.52L85.26 37.45Q86.91 37.35 87.10 37.27L87.07 37.24L87.08 37.25Q87.92 37.03 88.65 36.53L88.71 36.60L88.69 36.58Q90.16 35.68 89.97 33.59L89.99 33.61L89.95 33.57Q89.80 31.18 88.07 29.62L88.11 29.66L88.07 29.62Q86.23 27.96 83.76 27.96L83.72 27.91L83.80 27.77L83.84 27.81Q84.18 27.73 85.06 27.66L85.04 27.64L85.16 27.75Q87.02 27.59 88.39 26.36L88.24 26.21L88.33 26.30Q89.71 25.07 89.86 23.21L89.89 23.23L89.81 23.16Q89.96 22.88 89.96 22.54L90.04 22.62L89.98 22.57Q89.86 20.92 88.49 20.01L88.56 20.07L88.61 20.12Q87.38 19.31 85.78 19.43L85.83 19.48L85.68 19.33Q84.55 19.35 83.34 19.76L83.23 19.66L83.28 19.71Q81.82 20.22 81.51 21.37L81.51 21.37L81.55 21.40Q81.26 22.07 81.34 22.83L81.32 22.81L81.41 22.90Q80.37 22.66 78.31 21.94L78.32 21.95L78.33 21.95Q78.03 20.21 78.07 19.37L78.18 19.48L78.08 19.38Q78.12 17.78 79.18 17.10L79.31 17.22L79.22 17.13Q80.71 16.61 82.31 16.61L82.21 16.51L82.32 16.62Q85.46 16.56 88.62 16.83L88.58 16.79L88.52 16.72Q93.64 17.20 93.33 20.97L93.33 20.96L93.30 20.94Q93.35 22.55 92.85 24.11L92.77 24.03L92.70 23.95Q91.95 27.20 89.59 28.12L89.51 28.03L89.49 28.01Q92.19 28.62 92.80 31.97L92.72 31.89L92.74 31.91Q93.00 33.08 93.07 35.10L92.99 35.01L93.06 35.09Q93.27 39.60 88.67 40.06L88.63 40.02L88.70 40.09Q87.95 40.13 82.65 40.40ZM87.89 42.67L87.87 42.65L87.85 42.63Q88.44 42.64 91.29 42.72L91.32 42.74L91.36 42.79Q92.94 42.69 94.58 42.05L94.73 42.20L94.70 42.16Q95.81 41.15 95.62 39.40L95.70 39.48L95.62 39.39Q95.45 38.01 95.15 36.26L95.32 36.43L95.28 36.39Q94.47 31.81 92.53 30.18L92.54 30.19L92.33 29.79L92.43 29.85L92.27 29.68Q94.01 28.23 94.77 23.85L94.79 23.88L94.84 23.92Q94.90 23.48 95.01 22.53L94.97 22.49L95.06 22.58Q95.07 21.76 95.00 21.07L94.95 21.03L95.05 21.12Q94.92 19.47 93.62 18.78L93.52 18.68L93.40 18.63L93.53 18.77Q93.15 17.71 92.01 17.17L91.96 17.12L92.10 17.26Q90.48 16.48 85.34 16.17L85.34 16.17L85.35 16.18Q83.78 16.21 82.18 16.21L82.17 16.20L82.06 16.09Q80.55 16.18 79.03 16.83L78.88 16.68L78.93 16.73Q77.83 17.61 77.83 19.36L77.85 19.38L77.82 19.35Q77.83 18.94 78.10 22.29L78.03 22.22L77.99 22.19Q78.36 22.33 80.00 22.94L79.93 22.87L79.95 22.89Q80.05 23.52 80.01 24.01L79.99 23.99L79.94 23.95Q80.01 24.51 80.04 25.04L79.88 24.87L79.98 24.98Q81.69 25.27 83.71 25.39L83.80 25.48L83.81 25.49Q83.78 23.52 84.89 22.68L84.74 22.54L84.79 22.59Q85.68 21.99 87.70 21.77L87.72 21.79L87.74 21.81Q88.74 21.67 89.31 21.86L89.36 21.90L89.33 21.87Q89.46 22.09 89.50 22.20L89.40 22.10L89.42 22.31L89.62 22.97L89.52 22.86Q89.61 23.15 89.57 23.30L89.52 23.24L89.56 23.28Q89.46 24.97 87.94 26.15L87.99 26.20L87.99 26.21Q87.08 27.12 85.06 27.31L85.06 27.31L84.91 27.17Q84.27 27.40 83.40 27.40L83.32 27.32L83.33 27.34Q83.45 27.76 83.61 28.45L83.54 28.38L83.56 28.40Q85.39 28.48 86.83 29.20L86.87 29.24L86.58 29.06L85.19 29.42L85.15 29.38Q85.06 29.60 85.17 30.20L85.16 30.19L85.30 30.33Q87.44 30.26 89.15 31.59L89.14 31.59L89.11 31.55Q89.42 32.02 89.73 33.66L89.66 33.59L89.55 33.48Q89.75 36.41 86.81 36.83L86.90 36.92L86.97 36.99Q84.74 37.12 84.17 37.08L84.19 37.10L84.29 37.20Q83.84 37.10 83.31 37.02L83.17 36.88L83.32 36.57L83.45 36.13L83.40 35.67L83.41 35.34L83.43 35.35Q82.58 35.53 81.78 35.72L81.77 35.71L81.59 35.53Q81.70 35.45 81.70 35.26L81.67 35.23L81.69 35.25Q81.68 35.01 81.68 34.78L81.58 34.69L81.71 34.82Q81.77 34.42 81.93 33.70L81.77 33.54L81.97 33.74Q79.96 33.83 78.10 34.17L78.06 34.13L78.19 34.26Q78.05 34.62 77.94 35.74L78.03 35.84L77.94 35.75Q77.88 36.93 77.88 37.53L77.83 37.48L77.99 37.64Q78.00 39.63 79.37 40.39L79.43 40.45L79.40 40.42Q80.81 42.63 85.53 42.44L85.65 42.56L85.62 42.53Q86.21 42.36 87.73 42.51Z"/>
<path fill="#c86fe5" d="M111.55 32.94L111.55 32.94L111.47 32.86Q114.71 32.64 117.91 32.75L117.85 32.69L117.77 32.61Q117.74 30.07 117.74 27.67L117.86 27.79L117.79 27.72Q117.86 25.31 118.05 22.76L117.93 22.64L118.05 22.77Q116.80 24.44 111.58 32.97ZM121.49 40.33L121.53 40.37L121.41 40.25Q119.74 39.95 117.95 39.87L117.94 39.86L118.09 40.01Q117.74 37.49 117.63 35.02L117.70 35.09L117.61 35.00Q112.28 34.81 107.56 36.22L107.58 36.24L107.63 36.29Q107.69 35.75 107.88 34.76L107.98 34.85L107.91 34.78Q109.83 31.75 113.41 25.47L113.29 25.35L113.24 25.30Q116.14 20.43 119.56 16.55L119.59 16.58L119.69 16.68Q120.46 16.39 122.14 16.12L122.17 16.15L122.19 16.17Q120.37 22.69 120.37 29.73L120.34 29.70L120.30 29.66Q120.23 31.08 120.31 32.56L120.40 32.65L121.69 32.76L121.63 32.70Q122.25 32.75 122.86 32.87L122.86 32.87L122.83 32.83Q123.06 33.95 123.33 35.89L123.21 35.77L123.27 35.82Q121.97 35.48 120.48 35.29L120.59 35.40L120.59 35.39Q120.78 37.38 121.47 40.31ZM123.09 32.45L123.17 32.53L123.08 32.44Q123.00 32.48 122.81 32.48L122.69 32.35L122.42 32.46L122.45 32.49Q122.29 30.97 122.29 29.56L122.17 29.44L122.26 29.53Q122.27 23.14 124.33 17.13L124.24 17.04L124.38 17.18Q123.57 17.40 122.13 17.78L122.15 17.81L122.10 17.75Q122.28 16.94 122.73 15.53L122.76 15.56L122.78 15.58Q121.60 16.07 119.54 16.30L119.36 16.12L119.52 16.28Q115.51 20.53 110.29 29.89L110.38 29.98L112.36 26.21L112.32 26.17Q111.95 27.25 111.68 27.82L111.70 27.83L107.23 36.84L107.31 36.92Q107.87 36.68 109.01 36.30L109.12 36.41L108.87 36.55L108.84 36.52Q108.83 37.30 108.53 38.56L108.53 38.56L108.41 38.44Q112.57 37.16 117.40 37.35L117.50 37.44L117.42 37.37Q117.48 38.34 117.67 40.32L117.68 40.33L117.69 40.33Q118.62 40.20 119.69 40.32L119.87 40.50L119.89 40.52Q119.98 41.14 120.24 42.51L120.17 42.43L120.25 42.51Q122.02 42.61 125.02 43.52L125.20 43.69L125.05 43.54Q124.15 41.50 123.23 38.23L123.27 38.26L124.57 38.57L124.58 38.58Q125.37 38.91 126.05 39.26L126.11 39.32L125.98 39.19Q125.14 36.63 124.99 34.96L125.18 35.15L125.09 35.06Q124.58 34.97 123.44 34.74L123.34 34.64L123.36 34.66Q123.05 33.29 123.05 32.41ZM115.18 32.38L115.06 32.27L115.22 32.42Q116.00 31.14 117.56 28.59L117.41 28.44L117.55 28.58Q117.38 29.37 117.34 30.32L117.34 30.32L117.42 30.39Q117.33 31.30 117.37 32.25L117.49 32.37L117.42 32.30Q116.93 32.34 116.36 32.34L116.39 32.38L116.34 32.32Q115.77 32.36 115.16 32.36Z"/>
<path fill="#d9629e" d="M64.19 37.89L64.16 37.86L64.28 37.98Q64.58 38.97 65.11 40.98L64.95 40.82L65.02 40.88Q60.73 39.49 56.12 39.76L56.26 39.90L56.22 39.86Q51.57 40.04 47.57 42.02L47.65 42.09L47.56 42.00Q47.82 41.35 47.86 41.43L48.01 41.58L47.96 41.53Q51.67 37.56 55.60 33.14L55.51 33.06L55.64 33.18Q59.91 28.05 61.09 23.37L61.20 23.48L61.13 23.41Q61.64 21.71 60.37 20.53L60.40 20.57L60.32 20.48Q59.00 19.26 57.21 19.41L57.21 19.41L57.34 19.54Q56.99 19.50 56.65 19.50L56.60 19.45L56.49 19.34Q54.99 19.36 53.73 20.27L53.86 20.40L53.81 20.36Q52.42 21.63 52.65 24.29L52.66 24.30L52.83 24.47Q51.02 24.11 49.80 23.65L49.75 23.60L49.75 23.61Q49.50 22.14 49.43 20.69L49.46 20.73L49.56 20.83Q49.46 19.16 50.07 18.02L49.95 17.90L49.91 17.86Q51.85 16.64 55.20 16.64L55.05 16.49L56.98 16.67L56.85 16.54Q59.18 16.62 60.13 16.73L60.19 16.79L60.05 16.65Q64.43 17.12 64.70 19.56L64.71 19.57L64.70 19.56Q64.72 20.07 64.65 20.87L64.65 20.87L64.83 21.06Q64.76 21.67 64.61 22.36L64.63 22.38L64.49 22.24Q62.84 30.34 55.27 37.19L55.30 37.23L55.36 37.29Q56.72 37.08 58.09 37.08L58.20 37.19L58.04 37.04Q61.35 37.11 64.21 37.91ZM63.61 17.06L63.61 17.06L63.73 17.18Q62.02 16.42 60.31 16.35L60.29 16.32L56.85 16.12L56.87 16.14Q52.45 15.91 50.24 17.01L50.20 16.97L50.14 16.91Q49.25 18.45 49.25 20.51L49.15 20.42L49.16 20.42Q49.30 21.24 49.60 24.06L49.59 24.06L49.56 24.03Q49.96 24.12 51.14 24.42L51.29 24.57L51.28 25.59L51.19 25.50Q51.19 25.99 51.26 26.52L51.29 26.55L51.22 26.48Q52.52 26.64 54.99 26.87L55.09 26.96L55.06 26.93Q55.04 26.57 55.04 26.22L54.87 26.05L54.92 26.10Q55.05 24.41 56.27 23.06L56.23 23.02L56.19 22.98Q57.46 21.68 59.25 21.79L59.16 21.70L59.08 21.63Q59.86 21.69 60.63 21.84L60.60 21.82L60.65 21.87Q60.75 22.23 60.83 22.65L60.87 22.69L60.83 22.65Q60.96 23.16 60.89 23.51L60.78 23.40L60.90 23.52Q59.66 28.30 55.24 33.13L55.12 33.01L55.18 33.07Q53.12 35.38 47.67 41.44L47.53 41.29L47.59 41.35Q47.37 42.16 47.02 42.73L47.02 42.72L47.08 42.79Q48.75 41.98 50.27 41.44L50.27 41.44L50.15 41.32Q49.56 42.03 48.61 43.52L48.54 43.45L48.50 43.40Q48.37 43.73 48.25 44.07L48.34 44.15L48.21 44.03Q53.20 42.09 58.69 42.28L58.57 42.17L58.73 42.33Q64.41 42.49 68.98 44.85L68.92 44.79L67.96 42.68L67.83 42.55Q67.22 41.26 66.96 40.46L67.03 40.54L67.07 40.58Q66.22 40.03 65.00 39.61L64.96 39.57L65.06 39.67Q64.92 38.96 64.54 37.59L64.46 37.51L64.57 37.62Q62.34 37.03 60.05 36.84L60.03 36.81L59.99 36.77Q64.79 32.33 66.32 24.07L66.22 23.97L66.47 21.14L66.44 21.11Q66.40 19.36 65.19 18.67L65.18 18.67L65.12 18.64L65.13 18.65Q65.04 18.53 64.97 18.53L64.87 18.43L64.99 18.55Q64.82 17.77 63.71 17.16Z"/>
<path d="M17 39 C64 20,67 22,142 3" stroke="#4ad86d" fill="none"/>
<path fill="#5de8e8" d="M27.39 23.50L27.34 23.45L27.24 23.35Q24.18 23.48 22.35 22.41L22.21 22.28L22.31 22.37Q24.82 21.00 29.69 16.78L29.58 16.66L29.64 16.72Q30.38 16.54 31.67 15.93L31.69 15.96L31.63 15.90Q30.39 21.93 30.28 28.29L30.16 28.16L30.24 28.25Q30.14 34.62 31.21 40.71L31.13 40.64L31.12 40.63Q29.55 40.01 27.42 39.89L27.27 39.75L27.44 39.92Q27.30 35.74 27.30 31.67L27.19 31.56L27.17 31.54Q27.27 27.53 27.31 23.41ZM26.83 25.56L26.93 40.25L26.98 40.29Q28.23 40.32 29.18 40.51L29.05 40.38L29.00 40.33Q29.14 41.08 29.33 42.45L29.36 42.48L29.32 42.45Q32.20 43.00 34.63 45.24L34.69 45.30L34.66 45.27Q32.22 38.18 32.18 30.72L32.16 30.70L32.11 30.65Q32.05 23.20 33.87 15.97L33.90 15.99L33.83 15.92Q33.26 16.30 31.66 17.41L31.84 17.59L31.69 17.44Q31.90 16.70 32.20 15.17L32.25 15.22L32.33 15.30Q30.90 15.97 29.46 16.35L29.55 16.44L29.47 16.36Q25.66 19.90 21.36 22.18L21.41 22.24L21.41 22.23Q22.88 23.40 25.24 23.74L25.08 23.58L25.22 23.72Q24.51 24.20 23.22 25.26L23.16 25.20L23.24 25.29Q24.66 25.60 26.87 25.60L26.85 25.58Z"/>

分别拿去填充在<svg>标签中,结果如下图:

既然相同字母,无论位置和是否有颜色形状都相同,那么应该会有一定的规律。当我们对比了各个path中d属性的长度时,会发现绝大多书数字及字符绘制出来时,<path>中的d属性长度都不同,相同的字符的相同。

同样是1234的字符串,结果如下:

# 数字 => d属性值的长度
1 => 998 
2 => 2546
3 => 3878
4 => 2318

以此为基础,我们生成由1234组成的svg验证码,通过判断<path>d属性值的长度进而尝试识别,于是,发现4对应的不止一种长度。将两种不同长度的d属性值提取,并将4展示出来如下图:

<svg xmlns="http://www.w3.org/2000/svg" width="150" height="50" viewBox="0,0,150,50"><path fill="#e9e943" d="M52.37 32.96L52.42 33.01L52.31 32.90Q55.42 32.54 58.62 32.66L58.64 32.68L58.64 32.68Q58.58 30.11 58.58 27.72L58.67 27.80L58.51 27.64Q58.63 25.28 58.82 22.73L58.87 22.78L58.87 22.79Q57.50 24.35 52.29 32.88ZM62.19 40.23L62.24 40.28L62.34 40.38Q60.56 39.97 58.77 39.90L58.87 39.99L58.84 39.96Q58.67 37.63 58.56 35.15L58.40 34.99L58.40 34.99Q53.20 34.93 48.47 36.34L48.39 36.25L48.47 36.33Q48.52 35.78 48.71 34.79L48.76 34.83L48.70 34.77Q50.53 31.65 54.11 25.37L54.12 25.39L54.20 25.46Q56.92 20.42 60.35 16.54L60.38 16.57L60.47 16.65Q61.28 16.40 62.95 16.13L62.94 16.12L62.92 16.10Q61.02 22.53 61.02 29.58L61.06 29.62L61.11 29.67Q61.08 31.12 61.16 32.61L61.11 32.57L62.55 32.83L62.48 32.75Q63.05 32.75 63.66 32.87L63.59 32.80L63.65 32.85Q63.76 33.84 64.03 35.79L64.04 35.79L63.97 35.73Q62.83 35.54 61.35 35.35L61.31 35.31L61.29 35.30Q61.57 37.36 62.25 40.29ZM63.92 32.48L64.03 32.59L64.04 32.60Q63.77 32.45 63.58 32.45L63.64 32.51L63.17 32.41L63.26 32.50Q62.99 30.87 62.99 29.46L63.04 29.50L63.15 29.61Q63.01 23.08 65.06 17.06L65.19 17.19L65.20 17.20Q64.33 17.36 62.88 17.74L62.97 17.83L62.99 17.85Q63.08 16.94 63.53 15.53L63.66 15.66L63.53 15.53Q62.33 16.01 60.28 16.24L60.23 16.18L60.32 16.28Q56.32 20.54 51.10 29.90L51.12 29.92L53.21 26.26L53.17 26.22Q52.74 27.23 52.47 27.81L52.51 27.85L47.99 36.81L48.10 36.91Q48.70 36.71 49.84 36.33L49.93 36.42L49.67 36.54L49.65 36.52Q49.55 37.22 49.25 38.48L49.28 38.51L49.32 38.55Q53.41 37.20 58.24 37.39L58.29 37.44L58.23 37.37Q58.18 38.24 58.37 40.22L58.40 40.25L58.43 40.28Q59.58 40.36 60.65 40.48L60.59 40.42L60.57 40.39Q60.83 41.20 61.10 42.57L61.09 42.56L60.95 42.42Q62.95 42.74 65.96 43.66L65.96 43.65L65.93 43.63Q64.96 41.51 64.04 38.24L63.99 38.19L65.56 38.77L65.51 38.72Q66.05 38.80 66.74 39.14L66.77 39.18L66.91 39.32Q65.94 36.63 65.79 34.95L65.93 35.09L65.95 35.11Q65.32 34.91 64.18 34.68L64.12 34.62L64.11 34.61Q63.97 33.40 63.97 32.53ZM55.92 32.32L55.91 32.32L55.95 32.35Q56.67 31.02 58.23 28.47L58.32 28.56L58.28 28.52Q58.36 29.54 58.32 30.50L58.25 30.43L58.22 30.39Q58.20 31.37 58.24 32.32L58.32 32.40L58.31 32.39Q57.62 32.24 57.05 32.24L57.14 32.32L57.05 32.24Q56.53 32.32 55.92 32.32Z"/></svg>
    <svg xmlns="http://www.w3.org/2000/svg" width="150" height="50" viewBox="0,0,150,50"><path fill="#e9e943" d="M111.55 32.94L111.55 32.94L111.47 32.86Q114.71 32.64 117.91 32.75L117.85 32.69L117.77 32.61Q117.74 30.07 117.74 27.67L117.86 27.79L117.79 27.72Q117.86 25.31 118.05 22.76L117.93 22.64L118.05 22.77Q116.80 24.44 111.58 32.97ZM121.49 40.33L121.53 40.37L121.41 40.25Q119.74 39.95 117.95 39.87L117.94 39.86L118.09 40.01Q117.74 37.49 117.63 35.02L117.70 35.09L117.61 35.00Q112.28 34.81 107.56 36.22L107.58 36.24L107.63 36.29Q107.69 35.75 107.88 34.76L107.98 34.85L107.91 34.78Q109.83 31.75 113.41 25.47L113.29 25.35L113.24 25.30Q116.14 20.43 119.56 16.55L119.59 16.58L119.69 16.68Q120.46 16.39 122.14 16.12L122.17 16.15L122.19 16.17Q120.37 22.69 120.37 29.73L120.34 29.70L120.30 29.66Q120.23 31.08 120.31 32.56L120.40 32.65L121.69 32.76L121.63 32.70Q122.25 32.75 122.86 32.87L122.86 32.87L122.83 32.83Q123.06 33.95 123.33 35.89L123.21 35.77L123.27 35.82Q121.97 35.48 120.48 35.29L120.59 35.40L120.59 35.39Q120.78 37.38 121.47 40.31ZM123.09 32.45L123.17 32.53L123.08 32.44Q123.00 32.48 122.81 32.48L122.69 32.35L122.42 32.46L122.45 32.49Q122.29 30.97 122.29 29.56L122.17 29.44L122.26 29.53Q122.27 23.14 124.33 17.13L124.24 17.04L124.38 17.18Q123.57 17.40 122.13 17.78L122.15 17.81L122.10 17.75Q122.28 16.94 122.73 15.53L122.76 15.56L122.78 15.58Q121.60 16.07 119.54 16.30L119.36 16.12L119.52 16.28Q115.51 20.53 110.29 29.89L110.38 29.98L112.36 26.21L112.32 26.17Q111.95 27.25 111.68 27.82L111.70 27.83L107.23 36.84L107.31 36.92Q107.87 36.68 109.01 36.30L109.12 36.41L108.87 36.55L108.84 36.52Q108.83 37.30 108.53 38.56L108.53 38.56L108.41 38.44Q112.57 37.16 117.40 37.35L117.50 37.44L117.42 37.37Q117.48 38.34 117.67 40.32L117.68 40.33L117.69 40.33Q118.62 40.20 119.69 40.32L119.87 40.50L119.89 40.52Q119.98 41.14 120.24 42.51L120.17 42.43L120.25 42.51Q122.02 42.61 125.02 43.52L125.20 43.69L125.05 43.54Q124.15 41.50 123.23 38.23L123.27 38.26L124.57 38.57L124.58 38.58Q125.37 38.91 126.05 39.26L126.11 39.32L125.98 39.19Q125.14 36.63 124.99 34.96L125.18 35.15L125.09 35.06Q124.58 34.97 123.44 34.74L123.34 34.64L123.36 34.66Q123.05 33.29 123.05 32.41ZM115.18 32.38L115.06 32.27L115.22 32.42Q116.00 31.14 117.56 28.59L117.41 28.44L117.55 28.58Q117.38 29.37 117.34 30.32L117.34 30.32L117.42 30.39Q117.33 31.30 117.37 32.25L117.49 32.37L117.42 32.30Q116.93 32.34 116.36 32.34L116.39 32.38L116.34 32.32Q115.77 32.36 115.16 32.36Z"/></svg>

两个4并没有明显的区别,应该是不同的绘制方式导致的。多次测试发现,4并没有过多的长度对应。

以此类推,如果0-9,a-Z都获取一遍,将d 的属性值长度和字符相对应,就可以100%识别svg验证码了。

在整理后发现,存在一些两个不同字符,相同d属性值长度的(例如:y 和 L ,长度均为:1274)。对于这种情况,可以通过不同字符的绘制过程不同进行区别。

最终,参考svg-captcha-recognize项目中的lengthMap,即得到了:

986: ['I', 'l'],
  998: ['1'],
  1068: ['I', 'l'],
  1081: ['1'],
  1082: ['v'],
  1130: ['Y'],
  1134: ['Y'],
  1172: ['v'],
  1224: ['Y'],
  1274: ['L', 'y'],
  1298: ['V'],
  1311: ['V'],
  1360: ['i'],
  1380: ['L', 'y'],
  1406: ['V'],
  1473: ['i'],
  1478: ['T'],
  1491: ['r'],
  1598: ['N', 'X'],
  1601: ['T'],
  1604: ['X'],
  1610: ['J', 'x'],
  1613: ['x'],
  1614: ['N'],
  1615: ['r', 'N'],
  1616: ['N'],
  1617: ['N'],
  1618: ['N'],
  1634: ['k'],
  1637: ['k'],
  1694: ['z', 't'],
  1706: ['K'],
  1709: ['K'],
  1731: ['X', 'N'],
  1744: ['x', 'J'],
  1754: ['F'],
  1770: ['k'],
  1835: ['z', 't'],
  1838: ['u'],
  1840: ['A'],
  1844: ['A'],
  1848: ['K'],
  1850: ['Z'],
  1853: ['Z'],
  1886: ['h'],
  1900: ['F'],
  1922: ['H'],
  1928: ['H'],
  1960: ['P'],
  1991: ['u'],
  1993: ['A'],
  1996: ['D'],
  2004: ['Z'],
  2018: ['w'],
  2035: ['w'],
  2042: ['7'],
  2043: ['h'],
  2080: ['j'],
  2082: ['H'],
  2104: ['R'],
  2107: ['R'],
  2123: ['P'],
  2140: ['4'],
  2162: ['D'],
  2164: ['O'],
  2183: ['w'],
  2198: ['n', 'C'],
  2199: ['C'],
  2200: ['C'],
  2201: ['C'],
  2202: ['C'],
  2210: ['f'],
  2212: ['7'],
  2246: ['E'],
  2253: ['j'],
  2260: ['o'],
  2272: ['d'],
  2279: ['R', 'M'],
  2282: ['M'],
  2294: ['U'],
  2301: ['U'],
  2310: ['W'],
  2318: ['4', 'W'],
  2321: ['M'],
  2332: ['a'],
  2344: ['O'],
  2345: ['W'],
  2346: ['W'],
  2366: ['s'],
  2380: ['b'],
  2381: ['n', 'C'],
  2382: ['0'],
  2394: ['f'],
  2433: ['E'],
  2448: ['o'],
  2461: ['d'],
  2464: ['p'],
  2466: ['M'],
  2485: ['U'],
  2498: ['c'],
  2501: ['e'],
  2503: ['W'],
  2512: ['q'],
  2526: ['a'],
  2546: ['2'],
  2563: ['s'],
  2578: ['b'],
  2580: ['0'],
  2606: ['5'],
  2632: ['6'],
  2669: ['p'],
  2706: ['c'],
  2709: ['e'],
  2721: ['q'],
  2758: ['2'],
  2800: ['9'],
  2823: ['5'],
  2851: ['6'],
  3033: ['9'],
  3038: ['S'],
  3054: ['B'],
  3160: ['g'],
  3244: ['Q'],
  3254: ['Q'],
  3266: ['G'],
  3291: ['S'],
  3308: ['B'],
  3414: ['8'],
  3423: ['g'],
  3514: ['Q'],
  3538: ['G'],
  3663: ['m'],
  3667: ['m'],
  3698: ['8'],
  3878: ['3'],
  3968: ['m'],
  4201: ['3'] }

只要对相同长度的字符进行再次区分就可以了。例如:NX,生成如下的图片时:

此时获取到的对应长度均为1598:

此时就需要对其进行区分:

def getMinXY(data):
    xs = []
    ys = []
    i = 0
    for f in re.findall('\d+\.\d+', data):
        if i%2 :
            ys.append(float(f))
        else:
            xs.append(float(f))
        i = i+1
    xs.sort()
    ys.sort()
    return [xs[0], ys[0]]

通过获取绘制过程中最小的x轴y轴的坐标,进而加以判断即可区分两者。

其他

以上的分析结果仅对于使用svg-captcha默认配置的有效, 由于svg-captcha可以对显示的字符进行字体的设置,这样就改变了绘制的不同,进而导致<path>属性d 的值长度不同,这时候就需要重新分析,获取对应的长度,重新构造字典了。

svg-captcha项目的Issues中,haua大佬提出了这个100%识别的问题,本文也是参考haua大佬的svg-captcha-recognize作出的简单分析。svg-captcha的作者也回复了这个问题,提出在svg-captcha3.0版本的时候修复这个问题。

小白首贴,感谢阅读

参考

https://github.com/produck/svg-captcha

https://github.com/haua/svg-captcha-recognize/

......

本文来自先知社区

相关文章

人已赞赏
安全教程

DOM Clobbering详解

2020-3-13 0:18:30

安全教程

漫谈 WebLogic CVE-2020-2551

2020-3-13 0:18:48

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索