Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
ssh-tpm-agent — SSH代理,用于创建和管理TPM密封密钥以实现硬件绑定认证,支持密钥生成、导入、封装、PIN保护和代理回退。 | Kitploit
工具/GitHubGitHub/foxboron/ssh-tpm-agent
加密/解密工具云安全DevSecOps硬件安全身份与访问管理 (IAM)身份验证
GitHubfoxboron/ssh-tpm-agent

ssh-tpm-agent

SSH代理,用于创建和管理TPM密封密钥以实现硬件绑定认证,支持密钥生成、导入、封装、PIN保护和代理回退。

查看仓库
7433918天前Kitploit 审核通过

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享

SSH agent for TPM

ssh-tpm-agent 是一个兼容 ssh-agent 的代理程序,允许使用受信任平台模块(TPM)创建密钥,用于向 ssh 服务器进行身份验证。

TPM 密封密钥是在受信任平台模块(TPM)内部创建的私钥,并保存在以 .tpm 为后缀的文件中。这些密钥与生成它们的硬件绑定,无法转移到其他机器上。

这使您能够使用原生客户端,而无需将现有的 PKCS11 库侧加载到 ssh-agent 和/或 ssh 客户端中。

该项目使用 TPM 2.0 Key Files,并通过 go-tpm-keyfiles 项目实现。

特性

  • 一个可用的 ssh-agent。
  • 在 TPM 上创建屏蔽的 ssh 密钥。
  • 创建远程包装的 SSH 密钥以便导入。
  • PIN 支持,TPM 的字典攻击防护允许您使用低熵 PIN 替代密码短语。
  • TPM 会话加密。
  • 对其他 ssh-agent 服务器的代理支持,作为回退方案。

SWTPM 支持

您可以使用 --swtpm 或设置环境变量 export SSH_TPM_AGENT_SWTPM=1,来创建一个由 swtpm 支持的身份,该身份将存储在 /var/tmp/ssh-tpm-agent 下,而不是直接使用 TPM。

请注意,swtpm 不提供任何安全属性,仅应用于测试。

安装

安装此插件最简单的方法是运行以下命令:

root@kitploit:~
go install github.com/foxboron/ssh-tpm-agent/cmd/...@latest

或者下载 预编译的二进制文件。

用法

root@kitploit:~
# 创建密钥
$ ssh-tpm-keygen
Generating a sealed public/private ecdsa key pair.
Enter file in which to save the key (/home/fox/.ssh/id_ecdsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/fox/.ssh/id_ecdsa.tpm
Your public key has been saved in /home/fox/.ssh/id_ecdsa.pub
The key fingerprint is:
SHA256:NCMJJ2La+q5tGcngQUQvEOJP3gPH8bMP98wJOEMV564
The key's randomart image is the color of television, tuned to a dead channel.

$ cat /home/fox/.ssh/id_ecdsa.pub
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBOTOsMXyjTc1wiQSKhRiNhKFsHJNLzLk2r4foXPLQYKR0tuXIBMTQuMmc7OiTgNMvIjMrcb9adgGdT3s+GkNi1g=

# 使用套接字
$ ssh-tpm-agent -l /var/tmp/tpm.sock

$ export SSH_AUTH_SOCK="$(ssh-tpm-agent --print-socket)"

$ ssh [email protected]

注意: 对于 ssh-tpm-agent,您可以使用命令行标志 -o 或 --owner-password 指定 TPM 所有者密码,这是推荐方式。或者,您也可以使用环境变量 SSH_TPM_AGENT_OWNER_PASSWORD。

导入现有密钥

如果您希望将密钥备份到远程安全存储,同时日常在 TPM 上使用该密钥,此功能会很有用。

root@kitploit:~
# 创建一个密钥,或使用现有密钥
$ ssh-keygen -t ecdsa -f id_ecdsa
Generating public/private ecdsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_ecdsa
Your public key has been saved in id_ecdsa.pub
The key fingerprint is:
SHA256:bDn2EpX6XRX5ADXQSuTq+uUyia/eV3Z6MW+UtxjnXvU fox@framework
The key's randomart image is:
+---[ECDSA 256]---+
|           .+=o..|
|           o. oo.|
|          o... .o|
|       . + ..  ..|
|        S .   . o|
|       o * . oo=*|
|        ..+.oo=+E|
|        .++o...o=|
|       .++++. .+ |
+----[SHA256]-----+

# 导入密钥
$ ssh-tpm-keygen --import id_ecdsa
Sealing an existing public/private ecdsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_ecdsa.tpm
The key fingerprint is:
SHA256:bDn2EpX6XRX5ADXQSuTq+uUyia/eV3Z6MW+UtxjnXvU
The key's randomart image is the color of television, tuned to a dead channel.

安装用户服务

套接字激活的服务允许您在系统需要时启动 ssh-tpm-agent。

root@kitploit:~
# 使用套接字
$ ssh-tpm-agent --install-user-units
Installed /home/fox/.config/systemd/user/ssh-tpm-agent.socket
Installed /home/fox/.config/systemd/user/ssh-tpm-agent.service
Enable with: systemctl --user enable --now ssh-tpm-agent.socket

$ systemctl --user enable --now ssh-tpm-agent.socket

$ export SSH_AUTH_SOCK="$(ssh-tpm-agent --print-socket)"

$ ssh [email protected]

代理支持

root@kitploit:~
# 启动常规的 ssh-agent
$ eval $(ssh-agent)

# 创建一个强 RSA 密钥
$ ssh-keygen -t rsa -b 4096 -f id_rsa -C ssh-agent
...
The key fingerprint is:
SHA256:zLSeyU/6NKHGEvyZLA866S1jGqwdwdAxRFff8Z2N1i0 ssh-agent

$ ssh-add id_rsa
Identity added: id_rsa (ssh-agent)

# 打印长长长密钥
$ ssh-add -L
ssh-rsa AAAAB3NzaC1yc[...]8TWynQ== ssh-agent

# 在 TPM 上创建密钥
$ ssh-tpm-keygen -C ssh-tpm-agent
Generating a sealed public/private ecdsa key pair.
Enter file in which to save the key (/home/fox/.ssh/id_ecdsa):
Enter passphrase (empty for no passphrase):
Confirm passphrase:
Your identification has been saved in /home/fox/.ssh/id_ecdsa.tpm
Your public key has been saved in /home/fox/.ssh/id_ecdsa.pub
The key fingerprint is:
SHA256:PoQyuzOpEBLqT+xtP0dnvyBVL6UQTiQeCWN/EXIxPOo
The key's randomart image is the color of television, tuned to a dead channel.

# 使用代理套接字启动 ssh-tpm-agent
$ ssh-tpm-agent -A "${SSH_AUTH_SOCK}" &

$ export SSH_AUTH_SOCK="$(ssh-tpm-agent --print-socket)"

# ssh-tpm-agent 正在代理来自 ssh-agent 的密钥
$ ssh-add -L
ssh-rsa AAAAB3NzaC1yc[...]8TWynQ== ssh-agent
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNo[...]q4whro= ssh-tpm-agent

ssh-tpm-add

root@kitploit:~
$ ssh-tpm-agent --no-load &
2023/08/12 13:40:50 Listening on /run/user/1000/ssh-tpm-agent.sock

$ export SSH_AUTH_SOCK="$(ssh-tpm-agent --print-socket)"

$ ssh-add -L
The agent has no identities.

$ ssh-tpm-add $HOME/.ssh/id_ecdsa.tpm
Identity added: /home/user/.ssh/id_ecdsa.tpm

$ ssh-add -L
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJCxqisGa9IUNh4Ik3kwihrDouxP7S5Oun2hnzTvFwktszaibJruKLJMxHqVYnNwKD9DegCNwUN1qXCI/UOwaSY= test

在远程服务器上为客户机创建并包装私钥

在客户端,先在一个层次下创建一个主密钥。本示例将使用所有者层次和一个 SRK。

输出文件 srk.pem 需要传输到创建密钥的远程端。这可以作为客户端预配置的一部分完成。

root@kitploit:~
$ tpm2_createprimary -C o -G ecc -g sha256 -c prim.ctx -a 'restricted|decrypt|fixedtpm|fixedparent|sensitivedataorigin|userwithauth|noda' -f pem -o srk.pem

在远程端,我们创建一个 p256 ssh 密钥(无密码),并使用客户端提供的 srk.pem 通过 ssh-tpm-keygen 进行包装。

root@kitploit:~
$ ssh-keygen -t ecdsa -b 256 -N "" -f ./ecdsa.key
# 或使用 openssl
$ openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:prime256v1 -out ecdsa.key

# 使用 ssh-tpm-keygen 包装
$ ssh-tpm-keygen --wrap-with srk.pub --wrap ecdsa.key -f wrapped_id_ecdsa

在客户端,我们可以解包 wrapped_id_ecdsa 得到一个可加载的密钥。

root@kitploit:~
$ ssh-tpm-keygen --import ./wrapped_id_ecdsa.tpm -f id_ecdsa.tpm
$ ssh-tpm-add id_ecdsa.tpm

ssh-tpm-hostkey

ssh-tpm-agent 也支持在 TPM 中存储主机密钥。

root@kitploit:~
$ sudo ssh-tpm-keygen -A
2023/09/03 17:03:08 INFO Generating new ECDSA host key
2023/09/03 17:03:08 INFO Wrote /etc/ssh/ssh_tpm_host_ecdsa_key.tpm
2023/09/03 17:03:08 INFO Generating new RSA host key
2023/09/03 17:03:15 INFO Wrote /etc/ssh/ssh_tpm_host_rsa_key.tpm

$ sudo ssh-tpm-hostkeys --install-system-units
Installed /usr/lib/systemd/system/ssh-tpm-agent.service
Installed /usr/lib/systemd/system/ssh-tpm-agent.socket
Installed /usr/lib/systemd/system/ssh-tpm-genkeys.service
Enable with: systemctl enable --now ssh-tpm-agent.socket

$ sudo ssh-tpm-hostkeys --install-sshd-config
Installed /etc/ssh/sshd_config.d/10-ssh-tpm-agent.conf
Restart sshd: systemd restart sshd

$ systemctl enable --now ssh-tpm-agent.socket
$ systemd restart sshd

$ sudo ssh-tpm-hostkeys
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCLDH2xMDIGb26Q3Fa/kZDuPvzLzfAH6CkNs0wlaY2AaiZT2qJkWI05lMDm+mf+wmDhhgQlkJAHmyqgzYNwqWY0= root@framework
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAoMPsv5tEpTDFw34ltkF45dTHAPl4aLu6HigBkNnIzsuWqJxhjN6JK3vaV3eXBzy8/UJxo/R0Ml9/DRzFK8cccdIRT1KQtg8xIikRReZ0usdeqTC+wLpW/KQqgBLZ1PphRINxABWReqlnbtPVBfj6wKlCVNLEuTfzi1oAMj3KXOBDcTTB2UBLcwvTFg6YnbTjrpxY83Y+3QIZNPwYqd7r6k+e/ncUl4zgCvvxhoojGxEM3pjQIaZ0Him0yT6OGmCGFa7XIRKxwBSv9HtyHf5psgI+X5A2NV2JW2xeLhV2K1+UXmKW4aXjBWKSO08lPSWZ6/5jQTGN1Jg3fLQKSe7f root@framework

$ ssh-keyscan -t ecdsa localhost
# localhost:22 SSH-2.0-OpenSSH_9.4
localhost ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCLDH2xMDIGb26Q3Fa/kZDuPvzLzfAH6CkNs0wlaY2AaiZT2qJkWI05lMDm+mf+wmDhhgQlkJAHmyqgzYNwqWY0=

ssh-config

可以将 ssh-tpm-keygen 创建的公钥用于 ssh 配置中。

下面的示例使用了 ssh-tpm-agent,并显式传递了公钥,以确保代理不会泄露所有身份。

root@kitploit:~
Host example.com
    IdentityAgent $SSH_AUTH_SOCK

Host *
    IdentityAgent /run/user/1000/ssh-tpm-agent.sock
    IdentityFile ~/.ssh/id_ecdsa.pub

许可证

根据 MIT 许可证授权。参见 LICENSE 或 https://opensource.org/licenses/MIT

下载工具