2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ValueError: unsupported hash type md4を出さなくする方法

Last updated at Posted at 2022-09-22

ValueError: unsupported hash type md4がでて困った

あるスクリプトを実行するとエラーがでてしまった。

...
File "/usr/lib/python3/dist-packages/ntlm_auth/compute_hash.py", line 66, in _ntowfv1
    digest = hashlib.new('md4', password.encode('utf-16-le')).digest()
  File "/usr/lib/python3.10/hashlib.py", line 166, in __hash_new
    return __get_builtin_constructor(name)(data)
  File "/usr/lib/python3.10/hashlib.py", line 123, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md4

md4が使用できないようだった。
hashlibを確認するとmd4がavailableでなかった。

└─$ python3
>>> import hashlib
>>> print(sorted(hashlib.algorithms_guaranteed))
['blake2b', 'blake2s', 'md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', 'sha512', 'shake_128', 'shake_256']
>>> print(sorted(hashlib.algorithms_available))
['blake2b', 'blake2s', 'md5', 'md5-sha1', 'sha1', 'sha224', 'sha256', 'sha384', 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', 'sha512', 'sha512_224', 'sha512_256', 'shake_128', 'shake_256', 'sm3']

これが原因らしい。
Note: MD4 hash function availability in hashlib library depends on OpenSSL library that Python uses on specific platform. In OpenSSL 3, MD4 is marked as legacy and not available by default.

デフォルトではmd4が使えないようなので使えるように設定を変更する。
こちら(Additions to openssl.conf (settings/openssl.py) are required to work with legacy providers due to openssl upgrade to 3.0.3)を参考に設定を変更する。

opensslの設定ファイルを調べて、上の記述に従って変更する。

└─$ sudo find / -name openssl.cnf 2>/dev/null
└─$ vi /usr/lib/ssl/openssl.cnf
...
#
# OpenSSL configuration file. Forked by Kali.
# This is mostly being used for generation of certificate requests.
#

# Note that you can include other files from the main configuration
# file using the .include directive.
#.include /etc/ssl/kali.cnf #<---ここをコメントアウト

# This definition stops the following lines choking if HOME isn't
# defined.
HOME                    = .

# Extra OBJECT IDENTIFIER info:
#oid_file               = $ENV::HOME/.oid
oid_section             = new_oids

# System default
openssl_conf = default_conf

#move this from top to here
.include /etc/ssl/kali.cnf #<---上の記述をここに移動
...
[default_conf]
ssl_conf = ssl_sect
#add from here>>> ここから追加
providers = provider_sect

[provider_sect]
default = default_sect
legacy = legacy_sect

[default_sect]
activate = 1

[legacy_sect]
activate = 1
#add to here<<< ここまで
...

確認する。

└─$ python3 -c 'import hashlib;hashlib.new("md4", b"text");' # No error
└─$ echo 'test' | openssl dgst -md4
MD4(stdin)= 36d729ab4ff7260da6fb010ef5747bb3

OK。

hashlibも確認する。

└─$ python3
>>> import hashlib
>>> print(sorted(hashlib.algorithms_guaranteed))
['blake2b', 'blake2s', 'md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', 'sha512', 'shake_128', 'shake_256']
>>> print(sorted(hashlib.algorithms_available))
['blake2b', 'blake2s', 'md4', 'md5', 'md5-sha1', 'ripemd160', 'sha1', 'sha224', 'sha256', 'sha384', 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', 'sha512', 'sha512_224', 'sha512_256', 'shake_128', 'shake_256', 'sm3', 'whirlpool']

md4がavailableになった。

最初のスクリプトは無事実行できるようになった。

やりたい事が完了したら、念のためOpenSSLの設定は戻すことをお勧めします。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?