> For the complete documentation index, see [llms.txt](https://hacktricks.xsx.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacktricks.xsx.tw/linux-hardening/privilege-escalation/ssh-forward-agent-exploitation.md).

# SSH Forward Agent exploitation

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS Red Team Expert）</strong></a><strong>！</strong></summary>

其他支持HackTricks的方式：

* 如果您想在HackTricks中看到您的**公司广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 发现[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或 **关注**我的**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/carlospolopm)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>

## 摘要

如果您在`/etc/ssh_config`或`$HOME/.ssh/config`配置文件中发现以下内容，您可以做什么：

```
ForwardAgent yes
```

如果您是机器内的root用户，您可能可以访问在/tmp目录中找到的任何代理生成的ssh连接

使用Bob的ssh-agent之一冒充Bob:

```bash
SSH_AUTH_SOCK=/tmp/ssh-haqzR16816/agent.16816 ssh bob@boston
```

### 为什么会起作用？

当你设置变量 `SSH_AUTH_SOCK` 时，你正在访问 Bob 的密钥，这些密钥已经在 Bob 的 ssh 连接中使用过。然后，如果他的私钥仍然存在（通常会存在），你将能够使用它来访问任何主机。

由于私钥以未加密的形式保存在代理的内存中，我认为如果你是 Bob，但不知道私钥的密码，你仍然可以访问代理并使用它。

另一个选项是，代理的用户所有者和 root 用户可能能够访问代理的内存并提取私钥。

## 长说明和利用

**查看**[**原始研究**](https://www.clockwork.com/insights/ssh-agent-hijacking/)
