ssh蜜罐搭建

0x01 前言

    本来觉得应该不是一件很复杂的事,结果搞了三个小时才搞定(我太菜了),里面有几个坑,记录一下。
一直以来想去做蜜罐这么个东西,ssh is only the begining!
ssh secure shell,就是安全的shell,至于为什么安全呢?怎么就安全了呢?

  1. 较rlogin、rsh等这些不加密的协议,ssh传输是加密的,历史上ssh协议的实现有openssh和ossh,前者是主流,后面非特殊情况涉及到的ssh实现均指的是openssh。
  2. ssh协议有两个版本SSH-1 and SSH-2。ssh提供了两种方式的认证,一种是密码登录方式的认证,另外一种是基于秘钥的认证。第一种就是提供的默认加密算法是椭圆曲线加密算法ecdsa-sha2-nistp256,第二种是将rsa的公钥写到服务器的authorized_keys中实现免密码登录。

    0x02 具体安装步骤

    1
    本次测试是在ubuntu14.04X64环境下测试

1.首先git clone这两个资源https://github.com/openssh/openssh-portable
https://github.com/w8rbt/sshlog
2.’打补丁’。

1
2
$ patch --dry-run < sshlog.patch
$ patch < sshlog.patch

运行上面两条命令,其实就是在auth-passwd.c中加上几行代码

1
2
3
4
5
6
7
8
9
10
11
12
13
struct ssh *ssh = active_state;

if(authctxt->user && password && ssh) {
logit("sshlog: %.100s %s %.200s %lu",
authctxt->user,
password,
ssh_remote_ipaddr(ssh),
(unsigned long)time(NULL));
}

else {
logit("sshlog: unable to log attempt");
}

3.安装前检查
发现源码中没有configure文件,原来是需要自己运行autoreconf这个来生成configure文件,参考官方说明:http://www.openssh.com/portable.html
4.编译
编译的时候需要安装依赖

1
2
$ sudo apt-get install libz-dev
$ sudo apt-get install libssl-dev

5.链接和安装
这个时候又会报一个错
Privilege separation user sshd does not exist
这个时候需要在/etc/passwd文件中加入 :

1
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

6.Done!

0x03 待续

1
图形化界面实时展示ssh被爆破记录

0x04 reference

1.https://www.wikiwand.com/en/Secure_Shell
2.https://www.wikiwand.com/en/Elliptic_curve_cryptography
3.https://my.oschina.net/realfighter/blog/388486
4.https://m14.cc/magic-behind-compiling-software/