def start(self, name=''):
     """
     Start a threaded instance of self.start_server() and store it in the
     self.threads dictionary keyed by the listener name.
     """
     listenerOptions = self.options
     if name and name != '':
         self.threads[name] = helpers.KThread(target=self.start_server, args=(listenerOptions,))
         self.threads[name].start()
         time.sleep(1)
         # returns True if the listener successfully started, false otherwise
         return self.threads[name].is_alive()
     else:
         name = listenerOptions['Name']['Value']
         self.threads[name] = helpers.KThread(target=self.start_server, args=(listenerOptions,))
         self.threads[name].start()
         time.sleep(1)
         # returns True if the listener successfully started, false otherwise
         return self.threads[name].is_alive()
Example #2
0
    def do_csharpserver(self, *args):
        """
        Check if the Empire C# server is already running.
        """
        if len(args[0]) > 0:
            self.start = args[0]
        else:
            self.start = self.options['status']['Value']

        if not self.csharpserver_proc or self.csharpserver_proc.poll():
            self.status = "OFF"
        else:
            self.status = "ON"

        if not args:
            self.main_menu.plugin_socketio_message(self.info[0]['Name'],
                                                 "[*] Empire C# server is currently: %s" % self.status)
            self.main_menu.plugin_socketio_message(self.info[0]['Name'],
                                                 "[!] Empire C# <start|stop> <port>")

        elif self.start == "stop":
            if self.status == "ON":
                self.csharpserver_proc.kill()
                self.main_menu.plugin_socketio_message(self.info[0]['Name'],
                                                     "[*] Stopping Empire C# server")
                self.status = "OFF"
            else:
                self.main_menu.plugin_socketio_message(self.info[0]['Name'],
                                                     "[!] Empire C# server is already stopped")

        elif self.start == "start":
            if self.status == "OFF":
                # Will need to update this as we finalize the folder structure
                server_dll = self.installPath + "/csharp/Covenant/bin/Debug/netcoreapp3.1/EmpireCompiler.dll"
                # If dll hasn't been built yet
                if not os.path.exists(server_dll):
                    csharp_cmd = ["dotnet", "build", self.installPath + "/csharp/"]
                    self.csharpserverbuild_proc = subprocess.Popen(csharp_cmd)
                    time.sleep(10)
                    self.csharpserverbuild_proc.kill()

                self.main_menu.plugin_socketio_message(self.info[0]['Name'],
                                                     "[*] Starting Empire C# server")
                csharp_cmd = ["dotnet",
                              self.installPath + "/csharp/Covenant/bin/Debug/netcoreapp3.1/EmpireCompiler.dll"]
                self.csharpserver_proc = subprocess.Popen(csharp_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                self.status = "ON"
            else:
                self.main_menu.plugin_socketio_message(self.info[0]['Name'],
                                                       "[!] Empire C# server is already started")

            thread = helpers.KThread(target=self.thread_csharp_responses, args=())
            thread.daemon = True
            thread.start()