2023-12-26 02:11:12 +00:00
|
|
|
|
# 22 - 对SSH/SFTP的渗透测试
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
|
|
|
|
<details>
|
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
* 如果你在一家**网络安全公司**工作,想在**HackTricks**上看到你的**公司广告**,或者想要获取**PEASS最新版本或下载HackTricks的PDF**?请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
|
|
|
|
|
* 发现[**PEASS家族**](https://opensea.io/collection/the-peass-family),我们独家的[**NFTs**](https://opensea.io/collection/the-peass-family)系列。
|
|
|
|
|
* 获取[**官方PEASS & HackTricks周边商品**](https://peass.creator-spring.com)
|
|
|
|
|
* **加入**[**💬**](https://emojipedia.org/speech-balloon/) [**Discord群组**](https://discord.gg/hRep4RUj7f)或[**telegram群组**](https://t.me/peass)或在**Twitter**上**关注**我[**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**。**
|
|
|
|
|
* **通过向**[**hacktricks仓库**](https://github.com/carlospolop/hacktricks) **和** [**hacktricks-cloud仓库**](https://github.com/carlospolop/hacktricks-cloud) **提交PR来分享你的黑客技巧。**
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
|
|
|
|
</details>
|
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
<img src="../.gitbook/assets/image (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png" alt="" data-size="original">
|
2022-05-24 00:07:19 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
如果你对**黑客职业**感兴趣,并且想要黑入不可黑之物 - **我们正在招聘!**(_需要流利的波兰语书写和口语_)。
|
2022-05-24 00:07:19 +00:00
|
|
|
|
|
|
|
|
|
{% embed url="https://www.stmcyber.com/careers" %}
|
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
## 基本信息
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
**SSH或Secure Shell或Secure Socket Shell,** 是一种网络协议,为用户提供了一种通过不安全网络安全访问计算机的方式。
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
**默认端口:** 22
|
2022-04-27 08:21:36 +00:00
|
|
|
|
```
|
2020-07-15 15:43:14 +00:00
|
|
|
|
22/tcp open ssh syn-ack
|
|
|
|
|
```
|
2023-08-03 19:12:22 +00:00
|
|
|
|
**SSH服务器:**
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
* [openSSH](http://www.openssh.org) – OpenBSD SSH,包含在BSD、Linux发行版和Windows 10及以后版本中
|
|
|
|
|
* [Dropbear](https://matt.ucc.asn.au/dropbear/dropbear.html) – 为内存和处理器资源有限的环境设计的SSH实现,包含在OpenWrt中
|
|
|
|
|
* [PuTTY](https://www.chiark.greenend.org.uk/\~sgtatham/putty/) – Windows平台的SSH实现,客户端常用,但服务器端使用较少
|
|
|
|
|
* [CopSSH](https://www.itefix.net/copssh) – Windows平台的OpenSSH实现
|
2020-12-14 16:53:57 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
**SSH库(实现服务器端):**
|
2020-12-14 16:53:57 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
* [libssh](https://www.libssh.org) – 多平台C语言库,实现SSHv2协议,提供[Python](https://github.com/ParallelSSH/ssh-python)、[Perl](https://github.com/garnier-quentin/perl-libssh/) 和 [R](https://github.com/ropensci/ssh)的绑定;它被KDE用于sftp,也被GitHub用于git SSH基础设施
|
|
|
|
|
* [wolfSSH](https://www.wolfssl.com/products/wolfssh/) – 用ANSI C编写的SSHv2服务器库,针对嵌入式、RTOS和资源受限环境
|
|
|
|
|
* [Apache MINA SSHD](https://mina.apache.org/sshd-project/index.html) – 基于Apache MINA的Apache SSHD Java库
|
|
|
|
|
* [paramiko](https://github.com/paramiko/paramiko) – Python SSHv2协议库
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
## 枚举
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
### Banner 抓取
|
2020-07-15 15:43:14 +00:00
|
|
|
|
```bash
|
|
|
|
|
nc -vn <IP> 22
|
|
|
|
|
```
|
2023-12-26 02:11:12 +00:00
|
|
|
|
### 自动化 ssh-audit
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
ssh-audit 是一个用于 ssh 服务器和客户端配置审计的工具。
|
2020-09-25 08:37:19 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
[https://github.com/jtesta/ssh-audit](https://github.com/jtesta/ssh-audit) 是从 [https://github.com/arthepsy/ssh-audit/](https://github.com/arthepsy/ssh-audit/) 更新的分支。
|
2020-09-25 08:37:19 +00:00
|
|
|
|
|
2023-08-30 09:57:28 +00:00
|
|
|
|
**特点:**
|
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
* 支持 SSH1 和 SSH2 协议服务器;
|
|
|
|
|
* 分析 SSH 客户端配置;
|
|
|
|
|
* 抓取横幅,识别设备或软件和操作系统,检测压缩;
|
|
|
|
|
* 收集密钥交换、主机密钥、加密和消息认证码算法;
|
|
|
|
|
* 输出算法信息(自何时可用,何时移除/禁用,不安全/弱/遗留等);
|
|
|
|
|
* 输出算法建议(根据识别的软件版本添加或移除);
|
|
|
|
|
* 输出安全信息(相关问题,分配的 CVE 列表等);
|
|
|
|
|
* 根据算法信息分析 SSH 版本兼容性;
|
|
|
|
|
* 来自 OpenSSH、Dropbear SSH 和 libssh 的历史信息;
|
|
|
|
|
* 在 Linux 和 Windows 上运行;
|
|
|
|
|
* 无依赖
|
2020-09-23 15:36:14 +00:00
|
|
|
|
```bash
|
|
|
|
|
usage: ssh-audit.py [-1246pbcnjvlt] <host>
|
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
-1, --ssh1 force ssh version 1 only
|
|
|
|
|
-2, --ssh2 force ssh version 2 only
|
|
|
|
|
-4, --ipv4 enable IPv4 (order of precedence)
|
|
|
|
|
-6, --ipv6 enable IPv6 (order of precedence)
|
|
|
|
|
-p, --port=<port> port to connect
|
|
|
|
|
-b, --batch batch output
|
|
|
|
|
-c, --client-audit starts a server on port 2222 to audit client
|
|
|
|
|
software config (use -p to change port;
|
|
|
|
|
use -t to change timeout)
|
|
|
|
|
-n, --no-colors disable colors
|
|
|
|
|
-j, --json JSON output
|
|
|
|
|
-v, --verbose verbose output
|
|
|
|
|
-l, --level=<level> minimum output level (info|warn|fail)
|
|
|
|
|
-t, --timeout=<secs> timeout (in seconds) for connection and reading
|
|
|
|
|
(default: 5)
|
2020-09-23 15:36:14 +00:00
|
|
|
|
$ python3 ssh-audit <IP>
|
|
|
|
|
```
|
2023-12-26 02:11:12 +00:00
|
|
|
|
[查看动作演示 (Asciinema)](https://asciinema.org/a/96ejZKxpbuupTK9j7h8BdClzp)
|
2020-09-23 15:36:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
### 服务器的公共SSH密钥
|
2020-07-15 15:43:14 +00:00
|
|
|
|
```bash
|
|
|
|
|
ssh-keyscan -t rsa <IP> -p <PORT>
|
|
|
|
|
```
|
2023-08-03 19:12:22 +00:00
|
|
|
|
### 弱密码算法
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
**nmap** 默认会发现这个问题。但你也可以使用 **sslcan** 或 **sslyze**。
|
2021-07-06 18:15:59 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
### Nmap 脚本
|
2021-07-06 18:15:59 +00:00
|
|
|
|
```bash
|
|
|
|
|
nmap -p22 <ip> -sC # Send default nmap scripts for SSH
|
|
|
|
|
nmap -p22 <ip> -sV # Retrieve version
|
2023-08-03 19:12:22 +00:00
|
|
|
|
nmap -p22 <ip> --script ssh2-enum-algos # Retrieve supported algorythms
|
2021-07-06 18:15:59 +00:00
|
|
|
|
nmap -p22 <ip> --script ssh-hostkey --script-args ssh_hostkey=full # Retrieve weak keys
|
|
|
|
|
nmap -p22 <ip> --script ssh-auth-methods --script-args="ssh.user=root" # Check authentication methods
|
|
|
|
|
```
|
2022-05-01 13:25:53 +00:00
|
|
|
|
### Shodan
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
|
|
|
|
* `ssh`
|
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
## 暴力破解用户名、密码和私钥
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
### 用户名枚举
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
在某些版本的OpenSSH中,您可以进行时序攻击来枚举用户。您可以使用metasploit模块来利用这一点:
|
2022-04-27 08:21:36 +00:00
|
|
|
|
```
|
2020-07-15 15:43:14 +00:00
|
|
|
|
msf> use scanner/ssh/ssh_enumusers
|
|
|
|
|
```
|
2023-08-03 19:12:22 +00:00
|
|
|
|
### [暴力破解](../generic-methodologies-and-resources/brute-force.md#ssh)
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
一些常见的ssh凭据[在此](https://github.com/danielmiessler/SecLists/blob/master/Passwords/Default-Credentials/ssh-betterdefaultpasslist.txt)和[在此](https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/top-20-common-SSH-passwords.txt),以及下面。
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
### 私钥暴力破解
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
如果你知道一些可能会用到的ssh私钥...让我们尝试一下。你可以使用nmap脚本:
|
2022-04-27 08:21:36 +00:00
|
|
|
|
```
|
2020-07-15 15:43:14 +00:00
|
|
|
|
https://nmap.org/nsedoc/scripts/ssh-publickey-acceptance.html
|
|
|
|
|
```
|
2023-12-26 02:11:12 +00:00
|
|
|
|
或MSF辅助模块:
|
2022-04-27 08:21:36 +00:00
|
|
|
|
```
|
2020-07-15 15:43:14 +00:00
|
|
|
|
msf> use scanner/ssh/ssh_identify_pubkeys
|
|
|
|
|
```
|
2023-12-26 02:11:12 +00:00
|
|
|
|
或使用 `ssh-keybrute.py`(原生 python3,轻量级且启用了传统算法):[snowdroppe/ssh-keybrute](https://github.com/snowdroppe/ssh-keybrute)。
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-16 05:11:08 +00:00
|
|
|
|
#### 已知的不安全密钥可以在这里找到:
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2022-04-27 08:21:36 +00:00
|
|
|
|
{% embed url="https://github.com/rapid7/ssh-badkeys/tree/master/authorized" %}
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
#### 弱SSH密钥 / Debian可预测的PRNG
|
2023-08-16 05:11:08 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
一些系统在生成加密材料时使用的随机种子存在已知缺陷。这可能导致密钥空间大幅减少,可以被暴力破解。在受到弱PRNG影响的Debian系统上预生成的密钥集合可以在这里找到:[g0tmi1k/debian-ssh](https://github.com/g0tmi1k/debian-ssh)。
|
2023-01-21 22:13:23 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
你应该在这里查找受害机器的有效密钥。
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2022-05-01 13:25:53 +00:00
|
|
|
|
### Kerberos
|
2020-09-20 21:47:09 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
**crackmapexec** 使用 `ssh` 协议可以使用 `--kerberos` 选项来**通过kerberos认证**。\
|
|
|
|
|
更多信息请运行 `crackmapexec ssh --help`。
|
2020-09-20 21:47:09 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
## 默认凭证
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
| **供应商** | **用户名** | **密码** |
|
2022-04-27 08:21:36 +00:00
|
|
|
|
| ---------- | ----------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
|
|
|
| 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 |
|
|
|
|
|
|
2022-05-01 13:25:53 +00:00
|
|
|
|
## SSH-MitM
|
2022-04-27 08:21:36 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
如果你和将要使用用户名和密码连接到SSH服务器的受害者在同一本地网络中,你可以尝试**执行中间人攻击来窃取这些凭证:**
|
2022-04-27 08:21:36 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
**攻击路径:**
|
2022-04-27 08:21:36 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
* 用户流量被重定向到攻击机器
|
2023-12-26 02:11:12 +00:00
|
|
|
|
* 攻击者监控尝试连接到SSH服务器的行为,并将它们重定向到其SSH服务器
|
|
|
|
|
* 攻击者的SSH服务器首先配置为记录所有输入的数据,包括用户的密码,其次,向用户想要连接的合法SSH服务器发送命令以执行它们,然后将结果返回给合法用户
|
2022-04-27 08:21:36 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
\*\*\*\*[**SSH MITM**](https://github.com/jtesta/ssh-mitm) \*\*\*\* 正是如上所述的操作。
|
2022-04-27 08:21:36 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
为了捕获实际的中间人攻击,你可以使用ARP欺骗、DNS欺骗或在 [**网络欺骗攻击**](../generic-methodologies-and-resources/pentesting-network/#spoofing) 中描述的其他技术。
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
## 配置错误
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
### Root登录
|
2020-12-14 16:53:57 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
默认情况下,大多数SSH服务器实现将允许root登录,建议禁用它,因为如果这个账户的凭证泄露,攻击者将直接获得管理权限,这也将允许攻击者对这个账户进行暴力破解攻击。
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
**如何为openSSH禁用root登录:**
|
2020-09-25 08:37:19 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
1. 编辑SSH服务器配置 `sudoedit /etc/ssh/sshd_config`
|
|
|
|
|
2. 将 `#PermitRootLogin yes` 改为 `PermitRootLogin no`
|
|
|
|
|
3. 考虑配置更改:`sudo systemctl daemon-reload`
|
2023-12-26 02:11:12 +00:00
|
|
|
|
4. 重启SSH服务器 `sudo systemctl restart sshd`
|
2020-09-25 08:37:19 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
### SFTP命令执行
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
另一个常见的SSH配置错误通常出现在SFTP配置中。大多数时候,当创建一个SFTP服务器时,管理员希望用户有一个SFTP访问权限来共享文件,但不希望在机器上获得远程shell。所以他们认为创建一个用户,给他一个占位符shell(如 `/usr/bin/nologin` 或 `/usr/bin/false`)并将他chroot在一个监狱中足以避免shell访问或对整个文件系统的滥用。但他们错了,**用户可以在默认命令或shell执行之前,请求执行一个命令**。因此,为了绕过将拒绝shell访问的占位符shell,只需在之前请求执行一个命令(例如 `/bin/bash`),只需这样做:
|
2022-04-27 08:21:36 +00:00
|
|
|
|
```
|
2020-12-14 16:53:57 +00:00
|
|
|
|
$ ssh -v noraj@192.168.1.94 id
|
|
|
|
|
...
|
|
|
|
|
Password:
|
|
|
|
|
debug1: Authentication succeeded (keyboard-interactive).
|
|
|
|
|
Authenticated to 192.168.1.94 ([192.168.1.94]:22).
|
|
|
|
|
debug1: channel 0: new [client-session]
|
|
|
|
|
debug1: Requesting no-more-sessions@openssh.com
|
|
|
|
|
debug1: Entering interactive session.
|
|
|
|
|
debug1: pledge: network
|
|
|
|
|
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
|
|
|
|
|
debug1: Sending command: id
|
|
|
|
|
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
|
|
|
|
|
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
|
|
|
|
|
uid=1000(noraj) gid=100(users) groups=100(users)
|
|
|
|
|
debug1: channel 0: free: client-session, nchannels 1
|
|
|
|
|
Transferred: sent 2412, received 2480 bytes, in 0.1 seconds
|
|
|
|
|
Bytes per second: sent 43133.4, received 44349.5
|
|
|
|
|
debug1: Exit status 0
|
|
|
|
|
|
|
|
|
|
$ ssh noraj@192.168.1.94 /bin/bash
|
|
|
|
|
```
|
2023-08-03 19:12:22 +00:00
|
|
|
|
```plaintext
|
2023-12-26 02:11:12 +00:00
|
|
|
|
这是针对用户 `noraj` 的安全SFTP配置示例(`/etc/ssh/sshd_config` - openSSH):
|
2023-08-03 19:12:22 +00:00
|
|
|
|
```
|
|
|
|
|
```
|
|
|
|
|
Match User noraj
|
|
|
|
|
ChrootDirectory %h
|
|
|
|
|
ForceCommand internal-sftp
|
|
|
|
|
AllowTcpForwarding no
|
|
|
|
|
PermitTunnel no
|
|
|
|
|
X11Forwarding no
|
|
|
|
|
PermitTTY no
|
|
|
|
|
```
|
2023-12-26 02:11:12 +00:00
|
|
|
|
这种配置将仅允许SFTP:通过强制启动命令禁用shell访问,并禁用TTY访问,但也禁用所有类型的端口转发或隧道。
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
### SFTP 隧道
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
如果您可以访问SFTP服务器,您也可以通过它隧道传输您的流量,例如使用常见的端口转发:
|
2022-04-27 08:21:36 +00:00
|
|
|
|
```
|
2020-09-25 08:37:19 +00:00
|
|
|
|
sudo ssh -L <local_port>:<remote_host>:<remote_port> -N -f <username>@<ip_compromised>
|
2020-07-15 15:43:14 +00:00
|
|
|
|
```
|
2023-08-03 19:12:22 +00:00
|
|
|
|
### SFTP 符号链接
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
**sftp** 支持 "**symlink**" 命令。因此,如果你在某个文件夹中拥有**可写权限**,你可以创建指向**其他文件夹/文件**的**符号链接**。由于你可能被限制在一个 chroot 环境中,这**并不特别有用**,但是,如果你能够通过一个**非chroot** **服务**访问创建的**符号链接**(例如,如果你能够通过网页访问该符号链接),你可以**通过网页打开链接的文件**。
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
例如,要创建一个从新文件 **"**_**froot**_**" 到 "**_**/**_**"** 的**符号链接**:
|
2022-04-27 08:21:36 +00:00
|
|
|
|
```
|
2020-07-15 15:43:14 +00:00
|
|
|
|
sftp> symlink / froot
|
|
|
|
|
```
|
2023-12-26 02:11:12 +00:00
|
|
|
|
如果您可以通过网络访问文件 "_froot_",您将能够列出系统的根目录("/")。
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
### 认证方法
|
2020-12-14 16:53:57 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
在高安全环境中,通常的做法是仅启用基于密钥或双因素认证,而不是简单因素的基于密码的认证。但往往在启用了更强的认证方法而没有禁用较弱的方法。一个常见的情况是在openSSH配置中启用`publickey`并将其设置为默认方法,但没有禁用`password`。因此,通过使用SSH客户端的详细模式,攻击者可以看到启用了较弱的方法:
|
2022-04-27 08:21:36 +00:00
|
|
|
|
```
|
2020-12-14 16:53:57 +00:00
|
|
|
|
$ ssh -v 192.168.1.94
|
|
|
|
|
OpenSSH_8.1p1, OpenSSL 1.1.1d 10 Sep 2019
|
|
|
|
|
...
|
|
|
|
|
debug1: Authentications that can continue: publickey,password,keyboard-interactive
|
|
|
|
|
```
|
2023-12-26 02:11:12 +00:00
|
|
|
|
例如,如果设置了认证失败限制,并且你永远无法达到密码方法,你可以使用 `PreferredAuthentications` 选项来强制使用这种方法。
|
2022-04-27 08:21:36 +00:00
|
|
|
|
```
|
2020-12-14 16:53:57 +00:00
|
|
|
|
$ ssh -v 192.168.1.94 -o PreferredAuthentications=password
|
|
|
|
|
...
|
|
|
|
|
debug1: Next authentication method: password
|
|
|
|
|
```
|
2023-08-03 19:12:22 +00:00
|
|
|
|
### 配置文件
|
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
检查SSH服务器配置是必要的,以确保只有预期的方法被授权。在客户端上使用详细模式可以帮助查看配置的有效性。
|
2022-04-27 08:21:36 +00:00
|
|
|
|
```
|
2020-12-14 16:53:57 +00:00
|
|
|
|
ssh_config
|
|
|
|
|
sshd_config
|
|
|
|
|
authorized_keys
|
|
|
|
|
ssh_known_hosts
|
|
|
|
|
known_hosts
|
|
|
|
|
id_rsa
|
|
|
|
|
```
|
2022-05-01 13:25:53 +00:00
|
|
|
|
## Fuzzing
|
2020-12-14 16:53:57 +00:00
|
|
|
|
|
|
|
|
|
* [https://packetstormsecurity.com/files/download/71252/sshfuzz.txt](https://packetstormsecurity.com/files/download/71252/sshfuzz.txt)
|
2022-04-27 08:21:36 +00:00
|
|
|
|
* [https://www.rapid7.com/db/modules/auxiliary/fuzzers/ssh/ssh\_version\_2](https://www.rapid7.com/db/modules/auxiliary/fuzzers/ssh/ssh\_version\_2)
|
2020-12-14 16:53:57 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
## 参考资料
|
2020-12-14 16:53:57 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
* 你可以在 [https://www.ssh-audit.com/hardening\_guides.html](https://www.ssh-audit.com/hardening\_guides.html) 找到关于如何加固SSH的有趣指南
|
2020-12-14 16:53:57 +00:00
|
|
|
|
* [https://community.turgensec.com/ssh-hacking-guide](https://community.turgensec.com/ssh-hacking-guide)
|
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
<img src="../.gitbook/assets/image (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png" alt="" data-size="original">
|
2022-05-24 00:07:19 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
如果你对**黑客职业**感兴趣,并且想要黑进那些不可黑的系统 - **我们正在招聘!**(_需要流利的波兰语书写和口语_)。
|
2022-05-24 00:07:19 +00:00
|
|
|
|
|
|
|
|
|
{% embed url="https://www.stmcyber.com/careers" %}
|
|
|
|
|
|
2023-12-16 14:32:12 +00:00
|
|
|
|
## HackTricks 自动命令
|
2022-04-27 08:21:36 +00:00
|
|
|
|
```
|
2021-09-13 15:32:29 +00:00
|
|
|
|
Protocol_Name: SSH
|
|
|
|
|
Port_Number: 22
|
|
|
|
|
Protocol_Description: Secure Shell Hardening
|
|
|
|
|
|
|
|
|
|
Entry_1:
|
2023-08-03 19:12:22 +00:00
|
|
|
|
Name: Hydra Brute Force
|
|
|
|
|
Description: Need Username
|
2023-09-12 08:54:57 +00:00
|
|
|
|
Command: hydra -v -V -u -l {Username} -P {Big_Passwordlist} -t 1 {IP} ssh
|
2023-08-03 19:12:22 +00:00
|
|
|
|
|
2021-10-27 16:00:25 +00:00
|
|
|
|
Entry_2:
|
2023-08-03 19:12:22 +00:00
|
|
|
|
Name: consolesless mfs enumeration
|
|
|
|
|
Description: SSH enumeration without the need to run msfconsole
|
|
|
|
|
Note: sourced from https://github.com/carlospolop/legion
|
|
|
|
|
Command: msfconsole -q -x 'use auxiliary/scanner/ssh/ssh_version; set RHOSTS {IP}; set RPORT 22; run; exit' && msfconsole -q -x 'use scanner/ssh/ssh_enumusers; set RHOSTS {IP}; set RPORT 22; run; exit' && msfconsole -q -x 'use auxiliary/scanner/ssh/juniper_backdoor; set RHOSTS {IP}; set RPORT 22; run; exit'
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
```
|
2023-12-26 02:11:12 +00:00
|
|
|
|
```markdown
|
2022-04-28 16:01:33 +00:00
|
|
|
|
<details>
|
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks 云 ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-12-26 02:11:12 +00:00
|
|
|
|
* 如果你在一家**网络安全公司**工作?你想在**HackTricks**中看到你的**公司广告**?或者你想要访问**最新版本的 PEASS 或下载 HackTricks 的 PDF**?查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
|
|
|
|
|
* 发现[**PEASS 家族**](https://opensea.io/collection/the-peass-family),我们独家的[**NFTs**](https://opensea.io/collection/the-peass-family)系列
|
|
|
|
|
* 获取[**官方的 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
|
|
|
|
|
* **加入** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**telegram 群组**](https://t.me/peass) 或在 **Twitter** 上**关注**我 [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**。**
|
|
|
|
|
* **通过向** [**hacktricks 仓库**](https://github.com/carlospolop/hacktricks) **和** [**hacktricks-cloud 仓库**](https://github.com/carlospolop/hacktricks-cloud) **提交 PR 来分享你的黑客技巧。**
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
|
|
|
|
</details>
|
2023-12-26 02:11:12 +00:00
|
|
|
|
```
|