【汇总】codereg.py-ddddocr启动/识别问题


课程:密码暴力猜解——验证码识别
搜索关键词:codereg
工具:Burp Suite
插件:captcha-killer-modified


【汇总】easyocr运行报错
https://wiki.bafangwy.com/doc/495/


前提条件

最近很多问题都是由于电脑上存在多个python版本以及python版本太高引起的。

1、codereg需要使用python3运行

如果你的python.exe修改成了python3.exe,那么就需要使用python3 codereg.py启动。
如果python.exepip.exe没有修改,下面使用的命令是pythonpip

B23-Windows多个Python版本如何切换【必看】
https://wiki.bafangwy.com/doc/697/

2、安装依赖

pip install ddddocr aiohttp -i https://pypi.tuna.tsinghua.edu.cn/simple

如果 pip install 安装依赖报错,需要运行
python -m pip install --upgrade pip

【汇总】Python模块安装相关报错(pip install)
https://wiki.bafangwy.com/doc/251/

3、启动命令

改完以后,关掉cmd窗口,重新启动codereg.py
启动命令:
python codereg.py

说明1:NumPy版本问题

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last):  File "D:\dev_python\codereg\codereg.py", line 5, in <module>
    import ddddocr  # 导入 ddddocr
  File "C:\Python39\lib\site-packages\ddddocr\__init__.py", line 10, in <module>
    import onnxruntime
  File "C:\Python39\lib\site-packages\onnxruntime\__init__.py", line 24, in <module>
    from onnxruntime.capi._pybind_state import get_all_providers, get_available_providers, get_device, set_seed, \
  File "C:\Python39\lib\site-packages\onnxruntime\capi\_pybind_state.py", line 12, in <module>
    from onnxruntime.capi.onnxruntime_pybind11_state import *  # noqa
AttributeError: _ARRAY_API not found
ImportError: numpy.core.multiarray failed to import

解决办法

pip install onnxruntime==1.7.0
pip install  numpy==1.23.4

说明2:图片识别乱码

注意,图片的内容是二进制的,不可能以正常文本的形式显示,所以这个是正常的!
如图:

说明3:验证码不显示

从响应内容来看,响应的不是图片,也就是说,左边请求验证码的内容是不对的。
正确的方法是:
BP自带浏览器打开 http://localhost/yanzheng/yanzhengma.php ,拦截抓包,发送到插件。

说明4:验证码重复

每一个验证码都是一样的,如下图所示:

解决方法

插件处勾选是否使用该插件,再爆破即可:

说明5: 识别验证码时无反应,脚本无报错

插件里面可以获取到验证码的图片,但是点了识别按钮之后没有反应,codereg.py脚本运行过程中也没有报错,如下图所示:

解决方法

原因是用于识别验证码的请求模板有问题,这里的模板通常是从课程资料或者网上复制来的,用肉眼看不出什么区别,但发送后收不到任何响应。
按如下图所示的步骤,从模板库中自动生成一个ddddocr的模板,再点击“识别”即可收到正确的响应:

还有一种方法是在cmd窗口里面按一次回车即可


错误1: captcha-killer-modified插件报错:验证码URL不合法

无法获取验证码图片

解决办法:把localhost改成 127.0.0.1 即可

错误2:TypeError: The port is required to be int

端口只能为int

解决办法

修改codereg.py文件,把"8888" 改为 8888,也就是去掉引号
改完以后,关掉cmd窗口,重新启动codereg.py

错误3:codereg没有响应结果,识别没有反应

情况1 重启codereg可以解决

这种情况比较常见,解决办法是在codereg服务界面,按一下回车即可。
或者重新打开cmd启动codereg服务。

关联问题:
https://www.mashibing.com/question/detail/93226

情况2 过滤规则

BP的规则过滤了127.0.0.1,导致无法获得识别结果。
参考:
https://wiki.bafangwy.com/doc/100/

情况3 开启了上游代理

burp 不能挂上游代理,挂了识别不了

错误4:error: unrecognized arguments

原来使用的启动命令:
codereg.py

错误信息:

usage: codereg.py [-h] [-p P]
codereg.py: error: unrecognized arguments:

解决办法:
修改为命令(前面加上python):
python codereg.py

错误5:AttributeError: module 'PIL. Image' has no attribute 'ANTIALIAS'

报错内容如下所示:

解决方法

修改ddddocr的__init__.py文件
默认位置:
C:\Users\【你的用户名】\AppData\Roaming\Python\Python39\site-packages\ddddocr
注意:将 ANTIALIAS 改成 LANCZOS

image = image.resize((int(image.size[0] * (64/image.size[1])), 64), Image.ANTIALIAS).convert('L')

修改为:

image = image.resize((int(image.size[0] * (64/image.size[1])), 64), Image.LANCZOS).convert('L')

改完以后,关掉cmd窗口,重新启动codereg.py

错误6:module 'ddddocr' has no attribute 'DdddOcr'

报错如下图所示:

解决方法

把ddddocr解压到site-packages目录下,ddddocr.zip可在百度网盘下载:
链接:https://pan.baidu.com/s/1o_IM9W0a-ICC-9pvQt9OUA?pwd=dfgd
提取码:dfgd

怎么找到site-packages目录呢,可以运行where python ,然后复制目录时删掉python.exe,再进入到Lib目录下就有site-packages目录了。

之后运行codereg.py就不会报之前的错误了,继续安装缺少的模块就行,即pip install 模块名。

错误7:ERROR: No matching distribution found for onnxruntime

ERROR: Ignored the following versions that require a 1.0.8 Requires-Python <3.8; 
1.1.0 Requires-Python <3.9 
1.2.0 Requires-Python <3.10; 
1.3. Requires-Python <3.10; 
1.3.1 Require-Python <3.10; 
1.4.0 Requires-Python <3.10; 
1.4.1 Requires-Python <3.10; 
1.4.10 Requires-Python <3.12
1.4.11 Requires-Python <3.12; 
1.4.2 Requires-Pythoon <3.10; 
1.4.3 Requires-Python <3.10; 
1.4.4 Requires-python <=3.10; 
1.4.5 Requires-Python <3.11; 
1.4.7 Requires-Python <3.11;
1.4.8 Requires-Python <3.11; 
1.4.9 Requires-Python <3.12 
ERROR: Could not find a version that satisfies the requirement onnxruntime (from ddddocr) (from versions none )
ERROR: No matching distribution found for onnxruntime

解决办法:


苏玺 2024年12月31日 16:31 收藏文档