def simply_command_send(self, command, data, host, port, token):
     # connect
     con = LibPeProtocol(token=token, host=host, port=port)
     con.send_command(command=command, data=data)
     last_error = con.get_last_error()
     # result
     if last_error is not None:
         # ERROR
         print(last_error)
         self.wfile.write(last_error.encode("Ascii"))  # send the error and the GUI will display it
         return False
     else:
         # OK
         self.wfile.write(b"OK") # send "OK" and the GUI will not do anything
         return True
Example #2
0
 def simply_command_send(self, command, data, host, port, token):
     # connect
     con = LibPeProtocol(token=token, host=host, port=port)
     con.send_command(command=command, data=data)
     last_error = con.get_last_error()
     # result
     if last_error is not None:
         # ERROR
         print(last_error)
         self.wfile.write(last_error.encode(
             "Ascii"))  # send the error and the GUI will display it
         return False
     else:
         # OK
         self.wfile.write(
             b"OK")  # send "OK" and the GUI will not do anything
         return True
 def simply_shellcode_send(self, command, data, host, port, token):
     # connect
     con = LibPeProtocol(token=token, host=host, port=port)
     con.send_command(command=command, data=data)
     return con.get_last_error()
    def post_api_keyvalue(self, key, value):

        # read injector ip and port from config
        config = configparser.ConfigParser()
        config.read(CONFIG_FILE)
        token="AAAA000000000000000000000000000000"
        host="127.0.0.1"
        port=31338
        if CONFIG_SECTION_INJ in config:
            token = config[CONFIG_SECTION_INJ].get(CONFIG_KEY_TOKEN, fallback=token)
            host = config[CONFIG_SECTION_INJ].get(CONFIG_KEY_IP, fallback=host)
            port = int(config[CONFIG_SECTION_INJ].get(CONFIG_KEY_PORT, fallback=port))
        else:
            config.add_section(CONFIG_SECTION_INJ)  # importend for 'controlport' and 'controlip'

        # send header
        self.send_response(200)
        self.send_header('Content-Type', 'text/plain')
        self.end_headers()

        # send body
        print("post request: set", key, "to", value)
        # ---------------------------------------------------
        if("injrestart" == key):
            # restart is a void command (value=None)
            value = None
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_RESTART, data=value, host=host, port=port, token=token)

        elif("sectionname" == key):
            # set STRING
            value = value # 'value' is already a string
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_SECTION_NAME, data=value, host=host, port=port, token=token)

        elif("changeflags" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_METHOD_CHANGE_FLAGS, data=value, host=host, port=port, token=token)

        elif("newsection" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_METHOD_NEW_SECTION, data=value, host=host, port=port, token=token)

        elif("alignmentresize" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_METHOD_ALIGNMENT_RESIZE, data=value, host=host, port=port, token=token)

        elif("alignment" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_METHOD_ALIGNMENT, data=value, host=host, port=port, token=token)

        elif("crosssectionjump" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_METHOD_CROSS_SECTION_JUMP, data=value, host=host, port=port, token=token)

        elif("removeintegity" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_REMOVE_INTEGRITY_CHECK, data=value, host=host, port=port, token=token)

        elif("dataport" == key):
            # cast value to int
            value = int(value)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_DATA_PORT, data=value, host=host, port=port, token=token)

        elif("encryptiterations" == key):
            # cast value to int
            value = int(value)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_ENCRYPT_ITERATIONS, data=value, host=host, port=port, token=token)

        elif("crosssectionjumpiterations" == key):
            # cast value to int
            value = int(value)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_METHOD_CROSS_SECTION_JUMP_ITERATIONS, data=value, host=host, port=port, token=token)

        elif("token" == key):
            # cast value to byte
            try:
                he3x = bytes.fromhex(value)
            except Exception:
                he3x = None
            # simply command send
            isok = self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_TOKEN, data=he3x, host=host, port=port, token=token)
            # save local
            if(isok):
                # write token in local config
                config.set(CONFIG_SECTION_INJ, CONFIG_KEY_TOKEN, value)
                with open(CONFIG_FILE, 'w') as configfile:
                    config.write(configfile)

        elif("token_write" == key):
            try:
                # test for hex
                bytes.fromhex(value)
                # write token in local config
                config.set(CONFIG_SECTION_INJ, CONFIG_KEY_TOKEN, value)
                with open(CONFIG_FILE, 'w') as configfile:
                    config.write(configfile)
                # return OK
                self.wfile.write(b"OK")
            except Exception:
                self.wfile.write(b"post request error: invalid hex")

        elif("datainterface" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_DATA_INTERFACE, data=value, host=host, port=port, token=token)

        elif("controlport" == key):
            # cast value to int
            port_new = int(value)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_CONTROL_PORT, data=port_new, host=host, port=port, token=token)

        elif("controlport_write" == key):
            # cast value to int
            port_new = int(value)
            # write port in local config
            config.set(CONFIG_SECTION_INJ, CONFIG_KEY_PORT, str(port_new))
            with open(CONFIG_FILE, 'w') as configfile:
                config.write(configfile)
            # return OK
            self.wfile.write(b"OK")

        elif("controlip" == key):
            # validate
            if len(value) <= 255:
                # write ip in local config
                config.set(CONFIG_SECTION_INJ, CONFIG_KEY_IP, value)
                with open(CONFIG_FILE, 'w') as configfile:
                    config.write(configfile)
                # return OK
                self.wfile.write(b"OK")
            else:
                self.wfile.write(b"post request error: invalid ip or hostname address")

        elif("controlinterface" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_CONTROL_INTERFACE, data=value, host=host, port=port, token=token)

        elif("enableencrypt" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_ENCRYPT, data=value, host=host, port=port, token=token)

        elif("randomsectionname" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_RANDOM_SECTION_NAME, data=value, host=host, port=port, token=token)

        elif("trystaystealth" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_TRY_STAY_STEALTH, data=value, host=host, port=port, token=token)

        elif("enable" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_ENABLE, data=value, host=host, port=port, token=token)

        elif("adminpass" == key):
            # set STRING
            value = value # 'value' is already a string
            # set admin password
            self.setPassHash('admin', value)
            # return OK
            self.wfile.write(b"OK")

        elif("enableauth" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # write config
            config.set(CONFIG_SECTION_WEB, CONFIG_KEY_AUTH, str(value))
            with open(CONFIG_FILE, 'w') as configfile:
                config.write(configfile)
            # return OK
            self.wfile.write(b"OK")

        elif("getconfig" == key):
            # return web-ini
            config = configparser.ConfigParser()
            config.read(CONFIG_FILE)
            for section in config.sections():
                for key in config[section]:
                    writestr = section+'_'+key+"{|~|}"+config[section][key]+'\n'
                    if not key == CONFIG_KEY_PASSHASH:
                        # alles ausser PASSHASH ausgeben
                        self.wfile.write(writestr.encode("Ascii"))
            # get config is a void command (value=None)
            value = None
            # send command
            con = LibPeProtocol(token=token, host=host, port=port)
            result = con.send_command(command=LibPeProtocol.CMD_SEND_GET_CONFIG, data=value)
            last_error = con.get_last_error()
            # result
            if last_error is not None:
                # ERROR
                print(last_error)
                last_error = 'ERROR: '+last_error
                self.wfile.write(last_error.encode("Ascii"))  # send the error and the GUI will display it
            else:
                # OK:  return server-ini
                config = configparser.ConfigParser()
                config.read_string(result.decode("UTF-8"))
                for section in config.sections():
                    for key in config[section]:
                        writestr = section+'_'+key+"{|~|}"+config[section][key]+'\n'
                        self.wfile.write(writestr.encode("Ascii"))

        elif("exportconfig" == key):
            # get config is a void command (value=None)
            value = None
            # send command
            con = LibPeProtocol(token=token, host=host, port=port)
            result = con.send_command(command=LibPeProtocol.CMD_SEND_GET_CONFIG, data=value)
            last_error = con.get_last_error()
            # result
            if last_error is not None:
                # ERROR
                print(last_error)
                last_error = 'ERROR: '+last_error
                self.wfile.write(last_error.encode("Ascii"))  # send the error and the GUI will display it
            else:
                # OK:  return server-ini
                self.wfile.write(result)

        # bad command
        else:
            self.wfile.write(b"post request error: command not found")
        # ---------------------------------------------------
        self.wfile.flush()
Example #5
0
 def simply_shellcode_send(self, command, data, host, port, token):
     # connect
     con = LibPeProtocol(token=token, host=host, port=port)
     con.send_command(command=command, data=data)
     return con.get_last_error()
Example #6
0
    def post_api_keyvalue(self, key, value):

        # read injector ip and port from config
        config = configparser.ConfigParser()
        config.read(CONFIG_FILE)
        token = "AAAA000000000000000000000000000000"
        host = "127.0.0.1"
        port = 31338
        if CONFIG_SECTION_INJ in config:
            token = config[CONFIG_SECTION_INJ].get(CONFIG_KEY_TOKEN,
                                                   fallback=token)
            host = config[CONFIG_SECTION_INJ].get(CONFIG_KEY_IP, fallback=host)
            port = int(config[CONFIG_SECTION_INJ].get(CONFIG_KEY_PORT,
                                                      fallback=port))
        else:
            config.add_section(CONFIG_SECTION_INJ
                               )  # importend for 'controlport' and 'controlip'

        # send header
        self.send_response(200)
        self.send_header('Content-Type', 'text/plain')
        self.end_headers()

        # send body
        print("post request: set", key, "to", value)
        # ---------------------------------------------------
        if ("injrestart" == key):
            # restart is a void command (value=None)
            value = None
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_RESTART,
                                     data=value,
                                     host=host,
                                     port=port,
                                     token=token)

        elif ("sectionname" == key):
            # set STRING
            value = value  # 'value' is already a string
            # simply command send
            self.simply_command_send(
                command=LibPeProtocol.CMD_SEND_SET_SECTION_NAME,
                data=value,
                host=host,
                port=port,
                token=token)

        elif ("changeflags" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(
                command=LibPeProtocol.CMD_SEND_SET_METHOD_CHANGE_FLAGS,
                data=value,
                host=host,
                port=port,
                token=token)

        elif ("newsection" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(
                command=LibPeProtocol.CMD_SEND_SET_METHOD_NEW_SECTION,
                data=value,
                host=host,
                port=port,
                token=token)

        elif ("alignmentresize" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(
                command=LibPeProtocol.CMD_SEND_SET_METHOD_ALIGNMENT_RESIZE,
                data=value,
                host=host,
                port=port,
                token=token)

        elif ("alignment" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(
                command=LibPeProtocol.CMD_SEND_SET_METHOD_ALIGNMENT,
                data=value,
                host=host,
                port=port,
                token=token)

        elif ("crosssectionjump" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(
                command=LibPeProtocol.CMD_SEND_SET_METHOD_CROSS_SECTION_JUMP,
                data=value,
                host=host,
                port=port,
                token=token)

        elif ("removeintegity" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(
                command=LibPeProtocol.CMD_SEND_SET_REMOVE_INTEGRITY_CHECK,
                data=value,
                host=host,
                port=port,
                token=token)

        elif ("dataport" == key):
            # cast value to int
            value = int(value)
            # simply command send
            self.simply_command_send(
                command=LibPeProtocol.CMD_SEND_SET_DATA_PORT,
                data=value,
                host=host,
                port=port,
                token=token)

        elif ("encryptiterations" == key):
            # cast value to int
            value = int(value)
            # simply command send
            self.simply_command_send(
                command=LibPeProtocol.CMD_SEND_SET_ENCRYPT_ITERATIONS,
                data=value,
                host=host,
                port=port,
                token=token)

        elif ("crosssectionjumpiterations" == key):
            # cast value to int
            value = int(value)
            # simply command send
            self.simply_command_send(
                command=LibPeProtocol.
                CMD_SEND_SET_METHOD_CROSS_SECTION_JUMP_ITERATIONS,
                data=value,
                host=host,
                port=port,
                token=token)

        elif ("token" == key):
            # cast value to byte
            try:
                he3x = bytes.fromhex(value)
            except Exception:
                he3x = None
            # simply command send
            isok = self.simply_command_send(
                command=LibPeProtocol.CMD_SEND_SET_TOKEN,
                data=he3x,
                host=host,
                port=port,
                token=token)
            # save local
            if (isok):
                # write token in local config
                config.set(CONFIG_SECTION_INJ, CONFIG_KEY_TOKEN, value)
                with open(CONFIG_FILE, 'w') as configfile:
                    config.write(configfile)

        elif ("token_write" == key):
            try:
                # test for hex
                bytes.fromhex(value)
                # write token in local config
                config.set(CONFIG_SECTION_INJ, CONFIG_KEY_TOKEN, value)
                with open(CONFIG_FILE, 'w') as configfile:
                    config.write(configfile)
                # return OK
                self.wfile.write(b"OK")
            except Exception:
                self.wfile.write(b"post request error: invalid hex")

        elif ("datainterface" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(
                command=LibPeProtocol.CMD_SEND_SET_DATA_INTERFACE,
                data=value,
                host=host,
                port=port,
                token=token)

        elif ("controlport" == key):
            # cast value to int
            port_new = int(value)
            # simply command send
            self.simply_command_send(
                command=LibPeProtocol.CMD_SEND_SET_CONTROL_PORT,
                data=port_new,
                host=host,
                port=port,
                token=token)

        elif ("controlport_write" == key):
            # cast value to int
            port_new = int(value)
            # write port in local config
            config.set(CONFIG_SECTION_INJ, CONFIG_KEY_PORT, str(port_new))
            with open(CONFIG_FILE, 'w') as configfile:
                config.write(configfile)
            # return OK
            self.wfile.write(b"OK")

        elif ("controlip" == key):
            # validate
            if len(value) <= 255:
                # write ip in local config
                config.set(CONFIG_SECTION_INJ, CONFIG_KEY_IP, value)
                with open(CONFIG_FILE, 'w') as configfile:
                    config.write(configfile)
                # return OK
                self.wfile.write(b"OK")
            else:
                self.wfile.write(
                    b"post request error: invalid ip or hostname address")

        elif ("controlinterface" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(
                command=LibPeProtocol.CMD_SEND_SET_CONTROL_INTERFACE,
                data=value,
                host=host,
                port=port,
                token=token)

        elif ("enableencrypt" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(
                command=LibPeProtocol.CMD_SEND_SET_ENCRYPT,
                data=value,
                host=host,
                port=port,
                token=token)

        elif ("randomsectionname" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(
                command=LibPeProtocol.CMD_SEND_SET_RANDOM_SECTION_NAME,
                data=value,
                host=host,
                port=port,
                token=token)

        elif ("trystaystealth" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(
                command=LibPeProtocol.CMD_SEND_SET_TRY_STAY_STEALTH,
                data=value,
                host=host,
                port=port,
                token=token)

        elif ("enable" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # simply command send
            self.simply_command_send(command=LibPeProtocol.CMD_SEND_SET_ENABLE,
                                     data=value,
                                     host=host,
                                     port=port,
                                     token=token)

        elif ("adminpass" == key):
            # set STRING
            value = value  # 'value' is already a string
            # set admin password
            self.setPassHash('admin', value)
            # return OK
            self.wfile.write(b"OK")

        elif ("enableauth" == key):
            # cast value to boolean
            value = (True if (value == "true") else False)
            # write config
            config.set(CONFIG_SECTION_WEB, CONFIG_KEY_AUTH, str(value))
            with open(CONFIG_FILE, 'w') as configfile:
                config.write(configfile)
            # return OK
            self.wfile.write(b"OK")

        elif ("getconfig" == key):
            # return web-ini
            config = configparser.ConfigParser()
            config.read(CONFIG_FILE)
            for section in config.sections():
                for key in config[section]:
                    writestr = section + '_' + key + "{|~|}" + config[section][
                        key] + '\n'
                    if not key == CONFIG_KEY_PASSHASH:
                        # alles ausser PASSHASH ausgeben
                        self.wfile.write(writestr.encode("Ascii"))
            # get config is a void command (value=None)
            value = None
            # send command
            con = LibPeProtocol(token=token, host=host, port=port)
            result = con.send_command(
                command=LibPeProtocol.CMD_SEND_GET_CONFIG, data=value)
            last_error = con.get_last_error()
            # result
            if last_error is not None:
                # ERROR
                print(last_error)
                last_error = 'ERROR: ' + last_error
                self.wfile.write(last_error.encode(
                    "Ascii"))  # send the error and the GUI will display it
            else:
                # OK:  return server-ini
                config = configparser.ConfigParser()
                config.read_string(result.decode("UTF-8"))
                for section in config.sections():
                    for key in config[section]:
                        writestr = section + '_' + key + "{|~|}" + config[
                            section][key] + '\n'
                        self.wfile.write(writestr.encode("Ascii"))

        elif ("exportconfig" == key):
            # get config is a void command (value=None)
            value = None
            # send command
            con = LibPeProtocol(token=token, host=host, port=port)
            result = con.send_command(
                command=LibPeProtocol.CMD_SEND_GET_CONFIG, data=value)
            last_error = con.get_last_error()
            # result
            if last_error is not None:
                # ERROR
                print(last_error)
                last_error = 'ERROR: ' + last_error
                self.wfile.write(last_error.encode(
                    "Ascii"))  # send the error and the GUI will display it
            else:
                # OK:  return server-ini
                self.wfile.write(result)

        # bad command
        else:
            self.wfile.write(b"post request error: command not found")
        # ---------------------------------------------------
        self.wfile.flush()