酷代码 AI
菜单
全部AI  /  热门  /  AI问答
服务商

自建蜜罐,开放了ssh服务,想要获取攻击者登陆后的命令,最好用pty进行操作,它好像不需要解密

# 自建SSH蜜罐记录攻击者命令的方法 要在自建SSH蜜罐中记录攻击者登录后执行的命令,使用pty(伪终端)是一个有效的方法。以下是几种实现方案: ## 方法1:使用修改过的shell 1. 创建一个自定义shell脚本(如`/bin/fakessh`): ```bash #!/bin/bash LOG_FILE="/var/log/ssh_honeypot_commands.log" # 创建伪终端 exec script -q -f $LOG_FILE -c "/bin/bash" ``` 2. 将该shell添加到`/etc/shells` 3. 在`/etc/passwd`中将目标用户的shell改为`/bin/fakessh` ## 方法2:使用SSH ForceCommand 在`/etc/ssh/sshd_config`中添加: ``` Match User honeypot ForceCommand script -q -f /var/log/ssh_honeypot_commands.log -c /bin/bash ``` ## 方法3:使用ttylogger工具 1. 安装ttylogger: ```bash git clone https://github.com/rocky/ttylogger cd ttylogger make sudo make install ``` 2. 配置SSH使用ttylogger: ``` Match User honeypot ForceCommand /usr/local/bin/ttylogger -f /var/log/ssh_honeypot_commands.log /bin/bash ``` ## 方法4:使用python实现的pty方案 ```python #!/usr/bin/python import os import pty import sys LOG_FILE = "/var/log/ssh_honeypot_commands.log" def main(): with open(LOG_FILE, 'ab') as f: def read(fd): data = os.read(fd, 1024) f.write(data) f.flush() return data pty.spawn("/bin/bash", read) if __name__ == "__main__": main() ``` ## 安全注意事项 1. 确保日志文件权限设置正确,防止攻击者删除日志 2. 考虑将蜜罐系统与主网络隔离 3. 定期检查和分析收集到的日志 4. 不要在蜜罐中使用真实密码或敏感信息 使用pty方法确实不需要解密SSH会话,因为它是在用户登录后捕获终端输入输出,比解密SSH流量更简单有效。 [2025-04-20 18:02:16 | AI问答 | 509点数解答]

相关提问