22 - Pentesting SSH/SFTP
バグバウンティのヒント:ハッカーによって作成されたプレミアムなバグバウンティプラットフォームであるIntigritiにサインアップしてください!今すぐhttps://go.intigriti.com/hacktricksに参加して、最大**$100,000**のバウンティを獲得し始めましょう!
基本情報
**SSH(Secure ShellまたはSecure Socket Shell)**は、セキュアな接続を可能にするネットワークプロトコルであり、セキュリティのないネットワーク経由でコンピュータに安全に接続することができます。リモートシステムにアクセスする際にデータの機密性と整合性を維持するために重要です。
デフォルトポート: 22
SSHサーバー:
openSSH – OpenBSD SSH、BSD、Linuxディストリビューション、およびWindows(Windows 10以降)に搭載されています
Dropbear – 低メモリとプロセッサリソース環境向けのSSH実装で、OpenWrtに搭載されています
PuTTY – Windows向けのSSH実装で、クライアントは一般的に使用されていますが、サーバーの使用は稀です
CopSSH – Windows向けのOpenSSHの実装
SSHライブラリ(サーバーサイド実装):
wolfSSH – ANSI Cで記述されたSSHv2サーバーライブラリで、組み込み、RTOS、およびリソース制約の環境向けです
Apache MINA SSHD – Apache SSHD JavaライブラリはApache MINAに基づいています
paramiko – Python SSHv2プロトコルライブラリ
列挙
バナーの取得
自動化されたssh-audit
ssh-auditはsshサーバーおよびクライアントの構成監査のためのツールです。
https://github.com/jtesta/ssh-auditはhttps://github.com/arthepsy/ssh-audit/から更新されたフォークです。
機能:
SSH1およびSSH2プロトコルサーバーサポート;
SSHクライアント構成の分析;
バナーの取得、デバイスまたはソフトウェアおよびオペレーティングシステムの認識、圧縮の検出;
鍵交換、ホストキー、暗号化およびメッセージ認証コードアルゴリズムの収集;
アルゴリズム情報の出力(利用可能な期間、削除/無効化、安全でない/弱い/レガシーなど);
アルゴリズムの推奨事項の出力(認識されたソフトウェアバージョンに基づいて追加または削除);
セキュリティ情報の出力(関連する問題、割り当てられたCVEリストなど);
アルゴリズム情報に基づいたSSHバージョンの互換性の分析;
OpenSSH、Dropbear SSH、libsshからの履歴情報;
LinuxおよびWindowsで実行可能;
依存関係なし
サーバーの公開SSHキー
弱い暗号アルゴリズム
これはデフォルトでnmapによって発見されます。しかし、sslcanやsslyzeを使用することもできます。
Nmapスクリプト
Shodan
ssh
Brute force usernames, passwords and private keys
ユーザー名の列挙
一部のOpenSSHバージョンでは、タイミング攻撃を使用してユーザーを列挙することができます。これを悪用するためにmetasploitモジュールを使用できます:
プライベートキーの総当たり攻撃
使用可能なsshプライベートキーを知っている場合は、試してみましょう。nmapスクリプトを使用できます:
または、MSF補助モジュール:
Known badkeys can be found here:
Weak SSH keys / Debian predictable PRNG
Some systems have known flaws in the random seed used to generate cryptographic material. This can result in a dramatically reduced keyspace which can be bruteforced. Pre-generated sets of keys generated on Debian systems affected by weak PRNG are available here: g0tmi1k/debian-ssh.
You should look here in order to search for valid keys for the victim machine.
Kerberos
crackmapexec using the ssh
protocol can use the option --kerberos
to authenticate via kerberos.
For more info run crackmapexec ssh --help
.
Default Credentials
Vendor | Usernames | Passwords |
APC | apc, device | apc |
Brocade | admin | admin123, password, brocade, fibranne |
Cisco | admin, cisco, enable, hsa, pix, pnadmin, ripeop, root, shelladmin | admin, Admin123, default, password, secur4u, cisco, Cisco, _Cisco, cisco123, C1sco!23, Cisco123, Cisco1234, TANDBERG, change_it, 12345, ipics, pnadmin, diamond, hsadb, c, cc, attack, blender, changeme |
Citrix | root, nsroot, nsmaint, vdiadmin, kvm, cli, admin | C1trix321, nsroot, nsmaint, kaviza, kaviza123, freebsd, public, rootadmin, wanscaler |
D-Link | admin, user | private, admin, user |
Dell | root, user1, admin, vkernel, cli | calvin, 123456, password, vkernel, Stor@ge!, admin |
EMC | admin, root, sysadmin | EMCPMAdm7n, Password#1, Password123#, sysadmin, changeme, emc |
HP/3Com | admin, root, vcx, app, spvar, manage, hpsupport, opc_op | admin, password, hpinvent, iMC123, pvadmin, passw0rd, besgroup, vcx, nice, access, config, 3V@rpar, 3V#rpar, procurve, badg3r5, OpC_op, !manage, !admin |
Huawei | admin, root | 123456, admin, root, Admin123, Admin@storage, Huawei12#$, HwDec@01, hwosta2.0, HuaWei123, fsp200@HW, huawei123 |
IBM | USERID, admin, manager, mqm, db2inst1, db2fenc1, dausr1, db2admin, iadmin, system, device, ufmcli, customer | PASSW0RD, passw0rd, admin, password, Passw8rd, iadmin, apc, 123456, cust0mer |
Juniper | netscreen | netscreen |
NetApp | admin | netapp123 |
Oracle | root, oracle, oravis, applvis, ilom-admin, ilom-operator, nm2user | changeme, ilom-admin, ilom-operator, welcome1, oracle |
VMware | vi-admin, root, hqadmin, vmware, admin | vmware, vmw@re, hqadmin, default |
SSH-MitM
If you are in the local network as the victim which is going to connect to the SSH server using username and password you could try to perform a MitM attack to steal those credentials:
Attack path:
Traffic Redirection: The attacker diverts the victim's traffic to their machine, effectively intercepting the connection attempt to the SSH server.
Interception and Logging: The attacker's machine acts as a proxy, capturing the user's login details by pretending to be the legitimate SSH server.
Command Execution and Relay: Finally, the attacker's server logs the user's credentials, forwards the commands to the real SSH server, executes them, and sends the results back to the user, making the process appear seamless and legitimate.
SSH MITM does exactly what is described above.
In order to capture perform the actual MitM you could use techniques like ARP spoofing, DNS spoofin or others described in the Network Spoofing attacks.
SSH-Snake
If you want to traverse a network using discovered SSH private keys on systems, utilizing each private key on each system for new hosts, then SSH-Snake is what you need.
SSH-Snake performs the following tasks automatically and recursively:
On the current system, find any SSH private keys,
On the current system, find any hosts or destinations (user@host) that the private keys may be accepted,
Attempt to SSH into all of the destinations using all of the private keys discovered,
If a destination is successfully connected to, repeats steps #1 - #4 on the connected-to system.
It's completely self-replicating and self-propagating -- and completely fileless.
Config Misconfigurations
Root login
It's common for SSH servers to allow root user login by default, which poses a significant security risk. Disabling root login is a critical step in securing the server. Unauthorized access with administrative privileges and brute force attacks can be mitigated by making this change.
To Disable Root Login in OpenSSH:
Edit the SSH config file with:
sudoedit /etc/ssh/sshd_config
Change the setting from
#PermitRootLogin yes
toPermitRootLogin no
.Reload the configuration using:
sudo systemctl daemon-reload
Restart the SSH server to apply changes:
sudo systemctl restart sshd
SFTP Brute Force
SFTP command execution
There is a common oversight occurs with SFTP setups, where administrators intend for users to exchange files without enabling remote shell access. Despite setting users with non-interactive shells (e.g., /usr/bin/nologin
) and confining them to a specific directory, a security loophole remains. Users can circumvent these restrictions by requesting the execution of a command (like /bin/bash
) immediately after logging in, before their designated non-interactive shell takes over. This allows for unauthorized command execution, undermining the intended security measures.
以下は、ユーザーnoraj
のセキュアなSFTP構成の例です(/etc/ssh/sshd_config
– openSSH):
この設定では、シェルアクセスを無効にして、開始コマンドを強制し、TTYアクセスを無効にするだけでなく、すべての種類のポート転送やトンネリングも無効にします。
SFTPトンネリング
SFTPサーバーへのアクセス権がある場合、一般的なポート転送を使用してトラフィックをトンネリングすることもできます。
SFTP シンボリックリンク
sftp には symlink コマンドがあります。したがって、あるフォルダで 書き込み権限 がある場合、他のフォルダ/ファイル の シンボリックリンク を作成できます。おそらくあなたは chroot に 閉じ込められている ため、これはあなたにとって 特に有用ではないかもしれませんが、作成した シンボリックリンク に no-chroot サービス から アクセスできる場合(たとえば、Web からシンボリックリンクにアクセスできる場合)、Web を介してシンボリックリンクされたファイルを開くことができます。
たとえば、新しいファイル "froot" から "/" への シンボリックリンク を作成するには:
認証方法
高セキュリティ環境では、単純なパスワード認証よりも鍵ベース認証や二要素認証を有効にすることが一般的です。しかし、より強力な認証方法を有効にしながらも、弱い認証方法を無効にしないことがよくあります。よくあるケースとして、openSSH構成でpublickey
を有効にし、デフォルトの方法として設定するが、password
を無効にしないことが挙げられます。そのため、SSHクライアントの冗長モードを使用することで、攻撃者は弱い方法が有効になっていることを確認できます。
たとえば、認証失敗の制限が設定されており、パスワードメソッドに到達する機会がない場合は、PreferredAuthentications
オプションを使用してこのメソッドを強制的に使用することができます。
設定ファイル
SSHサーバーの構成を確認することは重要です。予想されるメソッドのみが 認可されていることを確認する必要があります。クライアントで詳細モードを 使用すると、構成の効果を確認できます。
Fuzzing
References
You can find interesting guides on how to harden SSH in https://www.ssh-audit.com/hardening_guides.html
Bug bounty tip: sign up for Intigriti, a premium bug bounty platform created by hackers, for hackers! Join us at https://go.intigriti.com/hacktricks today, and start earning bounties up to $100,000!
HackTricks Automatic Commands
Last updated